[LON-CAPA-cvs] cvs: loncom /interface lonuserutils.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Sat, 22 Dec 2007 19:12:51 -0000
raeburn Sat Dec 22 14:12:51 2007 EDT
Modified files:
/loncom/interface lonuserutils.pm
Log:
Upload a list of users - domain context.
- Retrieve $idresult from call to &modifyuserrole() to get information about ID changes propagated to courses.
- &user_change_result() has 5th arg of $idresult.
Upload a list of users - course context
- when expiring roles, preserve information about original start date
- in bulkaction on users of change section, streamline logic for determining required action on section changes for existing and new section-less roles.
General changes
- &setsections_javascript() has 3rd arg = $mode
- if $mode is upload, then customize action on successful execution of javascript function setSections() to 'ok'.
- otherwise last action, and rolecode (used to determine default role) vary depending on formname.
- branch added for formname of "enrollstudent".
first arg renamed from $form to $formname
- &can_create_user() returns value of 1 on early out if creator has 'mau' priv in domain.
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.27 loncom/interface/lonuserutils.pm:1.28
--- loncom/interface/lonuserutils.pm:1.27 Sat Dec 22 12:33:26 2007
+++ loncom/interface/lonuserutils.pm Sat Dec 22 14:12:51 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.27 2007/12/22 17:33:26 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.28 2007/12/22 19:12:51 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3467,7 +3467,7 @@
}
}
if (!$multiple) {
- ($userresult,$authresult,$roleresult) =
+ ($userresult,$authresult,$roleresult,$idresult) =
&modifyuserrole($context,$setting,
$changeauth,$cid,$domain,$username,
$id,$amode,$password,$fname,
@@ -3487,7 +3487,7 @@
} else {
$flushc =
&user_change_result($r,$userresult,$authresult,
- $roleresult,\%counts,$flushc,
+ $roleresult,$idresult,\%counts,$flushc,
$username,%userchg);
}
} else {
@@ -3732,7 +3732,6 @@
}
}
my $plrole = &Apache::lonnet::plaintext($role);
- my ($uid,$first,$middle,$last,$gene,$sec);
my $start = $env{'form.'.$item.'_start'};
my $end = $env{'form.'.$item.'_end'};
if ($choice eq 'drop') {
@@ -3752,15 +3751,12 @@
&Apache::lonnet::revokerole($udom,$uname,$scope,$role);
}
} elsif ($choice eq 'delete') {
- $start = -1;
- $end = -1;
if ($role eq 'st') {
-# FIXME - how does role deletion affect classlist?
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
} else {
$result =
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
- 0,1);
+ $start,1);
}
} else {
#reenable, activate, change access dates or change section
@@ -3803,27 +3799,36 @@
$nochg = 1;
}
} else {
- if (!grep(/^\Q$sec\E$/,@newsecs)) {
- $revresult =
- &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
+ if (@newsecs > 0) {
+ if (grep(/^\Q$sec\E$/,@newsecs)) {
+ push(@retained,$sec);
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role);
+ }
} else {
- push(@retained,$sec);
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role);
}
}
} else {
- push(@retained,$sec);
+ if ($sec eq '') {
+ $nochg = 1;
+ } else {
+ push(@retained,$sec);
+ }
}
# add new sections
if (@newsecs == 0) {
if (!$nochg) {
- if ($sec ne '') {
- if ($role eq 'st') {
- $result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
- } else {
- my $newscope = $scopestem;
- $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
- }
+ if ($role eq 'st') {
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
+ } else {
+ my $newscope = $scopestem;
+ $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
}
}
} else {
@@ -3986,16 +3991,27 @@
}
sub setsections_javascript {
- my ($form,$groupslist) = @_;
- my ($checkincluded,$finish,$roleplace,$setsection_js);
- if ($form eq 'cu') {
+ my ($formname,$groupslist,$mode) = @_;
+ my ($checkincluded,$finish,$rolecode,$setsection_js);
+ if ($mode eq 'upload') {
+ $checkincluded = 'formname.name == "'.$formname.'"';
+ $finish = "return 'ok';";
+ $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
+ } elsif ($formname eq 'cu') {
$checkincluded = 'formname.elements[i-1].checked == true';
$finish = 'formname.submit()';
- $roleplace = 3;
+ $rolecode = "var match = str.split('_');
+ var role = match[3];\n";
+ } elsif ($formname eq 'enrollstudent') {
+ $checkincluded = 'formname.name == "'.$formname.'"';
+ $finish = 'formname.submit()';
+ $rolecode = "var match = str.split('_');
+ var role = match[1];\n";
} else {
- $checkincluded = 'formname.name == "'.$form.'"';
+ $checkincluded = 'formname.name == "'.$formname.'"';
$finish = "seccheck = 'ok';";
- $roleplace = 1;
+ $rolecode = "var match = str.split('_');
+ var role = match[1];\n";
$setsection_js = "var seccheck = 'alert';";
}
my %alerts = &Apache::lonlocal::texthash(
@@ -4020,8 +4036,7 @@
var checkcurr = str.match(re1);
if (checkcurr != null) {
if ($checkincluded) {
- var match = str.split('_');
- var role = match[$roleplace];
+ $rolecode
if (role == 'cc') {
alert("$alerts{'secd'}\\n$alerts{'accr'}");
}
@@ -4096,6 +4111,9 @@
my ($dom,$context,$usertype) = @_;
my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
my $cancreate = 1;
+ if (&Apache::lonnet::allowed('mau',$dom)) {
+ return $cancreate;
+ }
if (ref($domconf{'usercreation'}) eq 'HASH') {
if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
if ($context eq 'course' || $context eq 'author') {
@@ -4250,7 +4268,8 @@
} else {
my @allroles = &roles_by_context($context);
foreach my $role (@allroles) {
- if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) { $permission{'cusr'} = 1;
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
+ $permission{'cusr'} = 1;
last;
}
}
@@ -4459,6 +4478,5 @@
return %alerts;
}
-
1;