--- loncom/interface/loncreateuser.pm 2003/07/18 20:53:06 1.62 +++ loncom/interface/loncreateuser.pm 2003/07/25 01:18:04 1.66 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.62 2003/07/18 20:53:06 www Exp $ +# $Id: loncreateuser.pm,v 1.66 2003/07/25 01:18:04 bowersj2 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,16 @@ END END - foreach my $area (keys(%rolesdump)) { + foreach my $area (sort 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,6 +345,13 @@ 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/[^7-9a-e]//g; @@ -365,7 +405,14 @@ END } else { $row.=' '; } - $row.= ' + - - + - + +"javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">Set End Date ENDENTRY + } } } return '' if ($table eq ''); # return nothing if there is nothing
RevokeDeleteRoleExtentStartEnd'.&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 +782,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 +800,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 +827,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 +864,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 +897,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 +922,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); @@ -931,7 +1011,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); @@ -978,8 +1058,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(''); } @@ -1069,20 +1160,24 @@ ENDTIMEENTRY } } foreach (sort keys %customroles) { - my $plrole=$_; - $table .= < -
$plrole $area + Set Start Date +"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">Set Start Date Set End Date