--- loncom/interface/loncreateuser.pm 2003/07/18 19:50:28 1.61 +++ loncom/interface/loncreateuser.pm 2003/09/17 17:30:10 1.67 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.61 2003/07/18 19:50:28 www Exp $ +# $Id: loncreateuser.pm,v 1.67 2003/09/17 17:30:10 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,6 +29,36 @@ package Apache::loncreateuser; +=pod + +=head1 NAME + +Apache::loncreateuser - handler to create users and custom roles + +=head1 SYNOPSIS + +Apache::loncreateuser provides an Apache handler for creating users, + editing their login parameters, roles, and removing roles, and + also creating and assigning custom roles. + +=head1 OVERVIEW + +=head2 Custom Roles + +In LON-CAPA, roles are actually collections of privileges. "Teaching +Assistant", "Course Coordinator", and other such roles are really just +collection of privileges that are useful in many circumstances. + +Creating custom roles can be done by the Domain Coordinator through +the Create User functionality. That screen will show all privileges +that can be assigned to users. For a complete list of privileges, +please see C. + +Custom role definitions are stored in the C file of the role +author. + +=cut + use strict; use Apache::Constants qw(:common :http); use Apache::lonnet; @@ -280,13 +310,19 @@ END END - foreach my $area (keys(%rolesdump)) { + foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]); + my $b1=join('_',(split('_',$b))[1,0]); + return $a1 cmp $b1; + } keys(%rolesdump)) { next if ($area =~ /^rolesdef/); my $role = $rolesdump{$area}; my $thisrole=$area; $area =~ s/\_\w\w$//; my ($role_code,$role_end_time,$role_start_time) = split(/_/,$role); +# Is this a custom role? Get role owner and title. + my ($croleudom,$croleuname,$croletitle)= + ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/); my $bgcol='ffffff'; my $allowed=0; my $delallowed=0; @@ -312,10 +348,17 @@ END (&Apache::lonnet::allowed('dro',$ccdomain))) { $delallowed=1; } +# - custom role. Needs more info, too + if ($croletitle) { + if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) { + $allowed=1; + $thisrole.='.'.$role_code; + } + } # Compute the background color based on $area $bgcol=$1.'_'.$2; - $bgcol=~s/[^8-9b-e]//g; - $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6); + $bgcol=~s/[^7-9a-e]//g; + $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6); if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) { $carea.='
Section/Group: '.$3; } @@ -347,7 +390,7 @@ END } } my $row = ''; - $row.='\n"; } } + foreach (sort keys %customroles) { + if (&Apache::lonnet::allowed('ccr',$thiscourse)) { + my $plrole=$_; + my $customrole=$protectedcourse.'_cr_cr_'.$ENV{'user.domain'}. + '_'.$ENV{'user.name'}.'_'.$plrole; + $table .= < + + + + + + +ENDENTRY + } + } } return '' if ($table eq ''); # return nothing if there is nothing # in the table
RevokeDeleteRoleExtentStartEnd
'; + $row.='
'; my $active=1; $active=0 if (($role_end_time) && ($now>$role_end_time)); if (($active) && ($allowed)) { @@ -365,7 +408,14 @@ END } else { $row.=' '; } - $row.= ''.&Apache::lonnet::plaintext($role_code). + my $plaintext=''; + unless ($croletitle) { + $plaintext=&Apache::lonnet::plaintext($role_code); + } else { + $plaintext= + "Customrole '$croletitle' defined by $croleuname\@$croleudom"; + } + $row.= ''.$plaintext. ''.$area. ''.($role_start_time?localtime($role_start_time) : ' ' ). @@ -735,10 +785,11 @@ END next if (! $ENV{$_}); # Revoke roles if ($_=~/^form\.rev/) { - if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) { + if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) { +# Revoke standard role $r->print('Revoking '.$2.' in '.$1.': '. - &Apache::lonnet::assignrole($ENV{'form.ccdomain'}, - $ENV{'form.ccuname'},$1,$2,$now).'
'); + &Apache::lonnet::revokerole($ENV{'form.ccdomain'}, + $ENV{'form.ccuname'},$1,$2).'
'); if ($2 eq 'st') { $1=~/^\/(\w+)\/(\w+)/; my $cid=$1.'_'.$2; @@ -752,6 +803,14 @@ END $ENV{'course.'.$cid.'.home'}).'
'); } } + if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) { +# Revoke custom role + $r->print( + 'Revoking custom role '.$4.' by '.$3.'@'.$2.' in '.$1.': '. +&Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'}, + $ENV{'form.ccuname'},$1,$2,$3,$4). + '
'); + } } elsif ($_=~/^form\.del/) { if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) { $r->print('Deleting '.$2.' in '.$1.': '. @@ -771,7 +830,29 @@ END } } } elsif ($_=~/^form\.act/) { - if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) { + if +($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) { + # Activate a custom role + my $url='/'.$1.'/'.$2; + my $full=$1.'_'.$2.'_cr_cr_'.$3.'_'.$4.'_'.$5; + if ($ENV{'form.sec_'.$full}) { + $url.='/'.$ENV{'form.sec_'.$full}; + } + + my $start = ( $ENV{'form.start_'.$full} ? + $ENV{'form.start_'.$full} : + $now ); + my $end = ( $ENV{'form.end_'.$full} ? + $ENV{'form.end_'.$full} : + 0 ); + + $r->print('Assigning custom role "'.$5.'" by '.$4.'@'.$3.' in '.$url. + ($start?', starting '.localtime($start):''). + ($end?', ending '.localtime($end):'').': '. + &Apache::lonnet::assigncustomrole( + $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$3,$4,$5,$end,$start). + '
'); + } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) { # Activate roles for sections with 3 id numbers # set start, end times, and the url for the class @@ -786,7 +867,7 @@ END $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3}; } # Assign the role and report it - $r->print('Assigning: '.$3.' in '.$url. + $r->print('Assigning '.$3.' in '.$url. ($start?', starting '.localtime($start):''). ($end?', ending '.localtime($end):'').': '. &Apache::lonnet::assignrole( @@ -819,14 +900,16 @@ END 0 ); my $url='/'.$1.'/'; # Assign the role and report it. - $r->print('Assigning: '.$2.' in '.$url.': '. + $r->print('Assigning '.$2.' in '.$url.': '. ($start?', starting '.localtime($start):''). ($end?', ending '.localtime($end):'').': '. &Apache::lonnet::assignrole( $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $url,$2,$end,$start) .'
'); - } + } else { + $r->print('

ERROR: Unknown command '.$_.'


'); + } } } # End of foreach (keys(%ENV)) $r->print(''); @@ -842,7 +925,7 @@ sub custom_role_editor { $rolename=$ENV{'form.newrolename'}; } - $rolename=~s/\W//gs; + $rolename=~s/[^A-Za-z0-9]//gs; unless ($rolename) { &print_username_entry_form($r); @@ -861,7 +944,6 @@ sub custom_role_editor { $r->print('Existing Role "'); # ------------------------------------------------- Get current role privileges ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef); - $r->print($syspriv.' '.$dompriv.' '.$coursepriv); } else { $r->print('New Role "'); $roledef=''; @@ -932,7 +1014,7 @@ sub set_custom_role { my $rolename=$ENV{'form.rolename'}; - $rolename=~s/\W//gs; + $rolename=~s/[^A-Za-z0-9]//gs; unless ($rolename) { &print_username_entry_form($r); @@ -979,8 +1061,19 @@ sub set_custom_role { $sysrole.=':'.$_; } } - $r->print('Defining Role: '. + $r->print('
Defining Role: '. &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole)); + if ($ENV{'request.course.id'}) { + my $url='/'.$ENV{'request.course.id'}; + $url=~s/\_/\//g; + $r->print('
Assigning Role to Self: '. + &Apache::lonnet::assigncustomrole($ENV{'user.domain'}, + $ENV{'user.name'}, + $url, + $ENV{'user.domain'}, + $ENV{'user.name'}, + $rolename)); + } $r->print(''); } @@ -1026,6 +1119,10 @@ sub handler { sub course_level_table { my %inccourses = @_; my $table = ''; +# Custom Roles? + + my %customroles=&my_custom_roles(); + foreach (sort( keys(%inccourses))) { my $thiscourse=$_; my $protectedcourse=$_; @@ -1034,8 +1131,8 @@ sub course_level_table { my $area=$coursedata{'description'}; if (!defined($area)) { $area='Unavailable course: '.$_; } my $bgcol=$thiscourse; - $bgcol=~s/[^8-9b-e]//g; - $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6); + $bgcol=~s/[^7-9a-e]//g; + $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6); foreach ('st','ta','ep','ad','in','cc') { if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) { my $plrole=&Apache::lonnet::plaintext($_); @@ -1065,6 +1162,26 @@ ENDTIMEENTRY $table.= "
$plrole$area +Set Start Date +Set End Date