[LON-CAPA-cvs] cvs: loncom /interface lonuserutils.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Sat, 05 Jan 2008 05:22:42 -0000
This is a MIME encoded message
--raeburn1199510562
Content-Type: text/plain
raeburn Sat Jan 5 00:22:42 2008 EDT
Modified files:
/loncom/interface lonuserutils.pm
Log:
- initialize @secs array containing sections for each row in the csv file
- &roles_on_upload() takes three args. Second is now $settings, so @permitted_roles is correct when uploading a CSV to a course as a Domain Coordinator.
- Remove non-word characters (\W) from ssection names
- Check supplied role for each user against @permitted_roles (not @courseroles) so custom roles can be assigned.
--raeburn1199510562
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080105002242.txt"
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.41 loncom/interface/lonuserutils.pm:1.42
--- loncom/interface/lonuserutils.pm:1.41 Wed Jan 2 04:01:02 2008
+++ loncom/interface/lonuserutils.pm Sat Jan 5 00:22:42 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.41 2008/01/02 09:01:02 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.42 2008/01/05 05:22:42 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3399,7 +3399,7 @@
);
my $flushc=0;
my %student=();
- my (%curr_groups,@sections,@cleansec,@secs,$defaultwarn,$groupwarn);
+ my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
my %userchg;
if ($context eq 'course' || $setting eq 'course') {
if ($context eq 'course') {
@@ -3438,10 +3438,10 @@
}
my (%curr_rules,%got_rules,%alerts);
my %customroles = &my_custom_roles();
- my ($custom_ok,@permitted_roles) =
- &roles_on_upload($context,%customroles);
+ my @permitted_roles = &roles_on_upload($context,$setting,%customroles);
# Get new users list
foreach my $line (@userdata) {
+ my @secs;
my %entries=&Apache::loncommon::record_sep($line);
# Determine user name
unless (($entries{$fields{'username'}} eq '') ||
@@ -3475,8 +3475,8 @@
my $username = $entries{$fields{'username'}};
if (defined($fields{'sec'})) {
if (defined($entries{$fields{'sec'}})) {
+ $entries{$fields{'sec'}} =~ s/\W//g;
my $item = $entries{$fields{'sec'}};
- $item =~ s/(\s+$|^\s+)//g;
if ($item eq "none" || $item eq 'all') {
$r->print('<br />'.&mt('<b>[_1]</b>: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',$username,$fname,$mname,$lname,$gen,$item));
next;
@@ -3535,13 +3535,10 @@
my $role = '';
if (defined($fields{'role'})) {
if ($entries{$fields{'role'}}) {
- if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
- $role=$entries{$fields{'role'}};
- $role =~ s/(\s+$|^\s+)//g;
- }
- if ($custom_ok) {
- if ($customroles{$role}) {
- $role = 'cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$entries{$fields{'role'}};
+ $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
+ if ($entries{$fields{'role'}} ne '') {
+ if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
+ $role = $entries{$fields{'role'}};
}
}
if ($role eq '') {
@@ -3636,59 +3633,60 @@
my $multiple = 0;
my ($userresult,$authresult,$roleresult,$idresult);
my (%userres,%authres,%roleres,%idres);
+ my $singlesec = '';
if ($role eq 'st') {
my $sec;
- if ($cid) {
- if (@secs > 0) {
- $sec = $secs[0];
- }
- &modifystudent($domain,$username,$cid,$sec,
- $desiredhost);
- $roleresult =
- &Apache::lonnet::modifystudent
- ($domain,$username,$id,$amode,$password,
- $fname,$mname,$lname,$gen,$sec,$enddate,
- $startdate,$env{'form.forceid'},
- $desiredhost,$email,'manual','',$cid);
- $userresult = $roleresult;
+ if (@secs > 0) {
+ $sec = $secs[0];
}
+ &modifystudent($domain,$username,$cid,$sec,
+ $desiredhost);
+ $roleresult =
+ &Apache::lonnet::modifystudent
+ ($domain,$username,$id,$amode,$password,
+ $fname,$mname,$lname,$gen,$sec,$enddate,
+ $startdate,$env{'form.forceid'},
+ $desiredhost,$email,'manual','',$cid);
+ $userresult = $roleresult;
} else {
- if (($context eq 'course') ||
- (grep(/^\Q$role\E$/,@courseroles))) {
- if (!$cid) {
- next;
- }
- }
- my $singlesec;
- if ((grep(/^\Q$role\E$/,@courseroles)) && ($role ne 'cc')) {
- if (@secs > 1) {
- $multiple = 1;
- foreach my $sec (@secs) {
- ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
- &modifyuserrole($context,$setting,
- $changeauth,$cid,$domain,$username,
- $id,$amode,$password,$fname,
- $mname,$lname,$gen,$sec,
- $env{'form.forceid'},$desiredhost,
- $email,$role,$enddate,$startdate,$checkid);
+ if ($role ne '') {
+ if ($context eq 'course' || $setting eq 'course') {
+ if ($customroles{$role}) {
+ $role = 'cr_'.$env{'user.domain'}.'_'.
+ $env{'user.name'}.'_'.$role;
+ }
+ if ($role ne 'cc') {
+ if (@secs > 1) {
+ $multiple = 1;
+ foreach my $sec (@secs) {
+ ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
+ &modifyuserrole($context,$setting,
+ $changeauth,$cid,$domain,$username,
+ $id,$amode,$password,$fname,
+ $mname,$lname,$gen,$sec,
+ $env{'form.forceid'},$desiredhost,
+ $email,$role,$enddate,
+ $startdate,$checkid);
+ }
+ } elsif (@secs > 0) {
+ $singlesec = $secs[0];
+ }
}
- } elsif (@secs > 0) {
- $singlesec = $secs[0];
}
}
if (!$multiple) {
($userresult,$authresult,$roleresult,$idresult) =
&modifyuserrole($context,$setting,
- $changeauth,$cid,$domain,$username,
- $id,$amode,$password,$fname,
- $mname,$lname,$gen,$singlesec,
- $env{'form.forceid'},$desiredhost,
- $email,$role,$enddate,$startdate,$checkid);
+ $changeauth,$cid,$domain,$username,
+ $id,$amode,$password,$fname,
+ $mname,$lname,$gen,$singlesec,
+ $env{'form.forceid'},$desiredhost,
+ $email,$role,$enddate,$startdate,$checkid);
}
}
if ($multiple) {
foreach my $sec (sort(keys(%userres))) {
- $flushc =
+ $flushc =
&user_change_result($r,$userres{$sec},$authres{$sec},
$roleres{$sec},$idres{$sec},\%counts,$flushc,
$username,\%userchg);
@@ -4556,24 +4554,17 @@
}
sub roles_on_upload {
- my ($context,%customroles) = @_;
+ my ($context,$setting,%customroles) = @_;
my (@possible_roles,@permitted_roles);
- if ($context eq 'domain') {
- @possible_roles = &curr_role_permissions($context,undef,1);
- push(@possible_roles,&curr_role_permissions($context,'course',1));
- } else {
- @possible_roles = &curr_role_permissions($context,undef,1);
- }
- my $custom_ok = 0;
+ @possible_roles = &curr_role_permissions($context,$setting,1);
foreach my $role (@possible_roles) {
if ($role eq 'cr') {
- $custom_ok = 1;
push(@permitted_roles,keys(%customroles));
} else {
push(@permitted_roles,$role);
}
}
- return ($custom_ok,@permitted_roles);
+ return @permitted_roles;
}
sub get_course_identity {
--raeburn1199510562--