[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Mon, 31 Dec 2007 01:58:17 -0000
This is a MIME encoded message
--raeburn1199066297
Content-Type: text/plain
raeburn Sun Dec 30 20:58:17 2007 EDT
Modified files:
/loncom/interface loncreateuser.pm
Log:
&update_roles() returns an array (containing roles modified) instead of a scalar (count of number of roles modified).
The output from update_roles() is used in course context to propagate any name/ID change to the classlist if the user has a student role, but the role modifications made did not include a change to the student role.
--raeburn1199066297
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071230205817.txt"
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.224 loncom/interface/loncreateuser.pm:1.225
--- loncom/interface/loncreateuser.pm:1.224 Mon Dec 24 11:00:13 2007
+++ loncom/interface/loncreateuser.pm Sun Dec 30 20:58:17 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.224 2007/12/24 16:00:13 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.225 2007/12/31 01:58:17 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2030,15 +2030,18 @@
if ($env{'form.action'} eq 'singlestudent') {
&enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser);
} else {
- my $rolechanges = &update_roles($r);
- if (!$rolechanges && $namechanged) {
+ my @rolechanges = &update_roles($r);
+ if ($namechanged) {
if ($context eq 'course') {
if (@userroles > 0) {
- if (grep(/^st$/,@userroles)) {
- my $classlistupdated =
- &Apache::lonuserutils::update_classlist($cdom,
+ if ((@rolechanges == 0) ||
+ (!(grep(/^st$/,@rolechanges)))) {
+ if (grep(/^st$/,@userroles)) {
+ my $classlistupdated =
+ &Apache::lonuserutils::update_classlist($cdom,
$cnum,$env{'form.ccdomain'},
$env{'form.ccuname'},\%userupdate);
+ }
}
}
}
@@ -2050,7 +2053,7 @@
sub update_roles {
my ($r) = @_;
my $now=time;
- my $rolechanges = 0;
+ my @rolechanges;
my %disallowed;
$r->print('<h3>'.&mt('Modifying Roles').'</h3>');
foreach my $key (keys (%env)) {
@@ -2074,6 +2077,9 @@
$now);
$r->print($result);
}
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
}
if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
# Revoke custom role
@@ -2082,8 +2088,10 @@
&Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
$env{'form.ccuname'},$1,$2,$3,$4).
'</b><br />');
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- $rolechanges ++;
} elsif ($key=~/^form\.del/) {
if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
# Delete standard role
@@ -2101,6 +2109,9 @@
$now);
$r->print($result);
}
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
}
if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
@@ -2110,8 +2121,10 @@
&Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
$env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
0,1).'</b><br />');
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- $rolechanges ++;
} elsif ($key=~/^form\.ren/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
@@ -2144,6 +2157,9 @@
$role,$url,$result).'<br />';
}
$r->print($output);
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
}
# Re-enable custom role
if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
@@ -2153,8 +2169,10 @@
$url,$rdom,$rnam,$rolename,0,$now);
$r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
$rolename,$rnam,$rdom,$url,$result).'<br />');
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- $rolechanges ++;
} elsif ($key=~/^form\.act/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
@@ -2189,6 +2207,9 @@
$r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
}
}
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
} elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
# Activate roles for sections with 3 id numbers
# set start, end times, and the url for the class
@@ -2227,7 +2248,10 @@
if ($emptysec) {
$r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
}
- }
+ }
+ if (!grep(/^\Q$three\E$/,@rolechanges)) {
+ push(@rolechanges,$three);
+ }
} elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
# Activate roles for sections with two id numbers
# set start, end times, and the url for the class
@@ -2237,26 +2261,31 @@
my $end = ( $env{'form.end_'.$1.'_'.$2} ?
$env{'form.end_'.$1.'_'.$2} :
0 );
- my $url='/'.$1.'/';
+ my $one = $1;
+ my $two = $2;
+ my $url='/'.$one.'/';
# split multiple sections
my %sections = ();
- my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
+ my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
} else {
my $emptysec = 0;
foreach my $sec (sort {$a cmp $b} keys %sections) {
if ($sec ne '') {
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
}
}
+ if (!grep(/^\Q$two\E$/,@rolechanges)) {
+ push(@rolechanges,$two);
+ }
} else {
$r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
}
@@ -2268,15 +2297,14 @@
}
$r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
}
- $rolechanges ++;
}
} # End of foreach (keys(%env))
# Flush the course logs so reverse user roles immediately updated
&Apache::lonnet::flushcourselogs();
- if (!$rolechanges) {
+ if (@rolechanges == 0) {
$r->print(&mt('No roles to modify'));
}
- return $rolechanges;
+ return @rolechanges;
}
sub enroll_single_student {
--raeburn1199066297--