--- loncom/interface/loncreateuser.pm 2016/10/22 17:56:12 1.417
+++ loncom/interface/loncreateuser.pm 2016/11/09 16:35:46 1.418
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.417 2016/10/22 17:56:12 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.418 2016/11/09 16:35:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -160,7 +160,8 @@ END_SCRIPT
'
'.$lt{'usrt'}.' '."\n".
&Apache::loncommon::start_data_table();
- if (&Apache::lonnet::allowed('mut',$ccdomain)) {
+ if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
+ (&Apache::lonnet::allowed('udp',$ccdomain))) {
$output .= &build_tools_display($ccuname,$ccdomain,'tools');
}
@@ -267,7 +268,7 @@ sub build_tools_display {
$colspan = ' colspan="2"';
%domconfig =
&Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
- $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
+ $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
} elsif ($context eq 'requestauthor') {
%userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
'requestauthor');
@@ -334,6 +335,7 @@ sub build_tools_display {
' '.$lt{$item}.' '."\n".
' '."\n".
&Apache::loncommon::start_data_table_row()."\n";
+
if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
my ($curroption,$currlimit);
my $envkey = $context.'.'.$item;
@@ -427,8 +429,10 @@ sub build_tools_display {
'';
}
$output .= ' '.$custom_access.(' 'x4).
- $lt{'avai'}.': '.$currdisp.' '."\n".
- &Apache::loncommon::end_data_table_row()."\n".
+ $lt{'avai'}.': '.$currdisp.''."\n";
+ &Apache::loncommon::end_data_table_row()."\n";
+ unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
+ $output .=
&Apache::loncommon::start_data_table_row()."\n".
' '.
$lt{'chse'}.': '.
@@ -437,6 +441,7 @@ sub build_tools_display {
' '.$lt{'uscu'}.' '.$custradio.' '.
&Apache::loncommon::end_data_table_row()."\n";
+ }
}
return $output;
}
@@ -536,7 +541,10 @@ sub domadhocroles {
my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
$confname,'rolesdef_');
- my $output;
+ my ($output,$canmodify);
+ if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
+ $canmodify = 1;
+ }
if (keys(%existing) > 0) {
my @current;
my $curradhoc = 'adhocroles.'.$env{'request.role.domain'};
@@ -544,6 +552,9 @@ sub domadhocroles {
if ($userenv{$curradhoc}) {
@current = split(/,/,$userenv{$curradhoc});
}
+ if (!$canmodify && !@current) {
+ return;
+ }
my %customroles;
foreach my $key (keys(%existing)) {
if ($key=~/^rolesdef\_(\w+)$/) {
@@ -557,22 +568,28 @@ sub domadhocroles {
&mt('Ad Hoc Course Roles Selectable via Helpdesk Role').
''."\n".
&Apache::loncommon::start_data_table().
- &Apache::loncommon::start_data_table_header_row().
- ''.&mt('Action').' '.&mt('Role').' '.
- ''.&mt('Privileges in Course').' '.
- &Apache::loncommon::end_data_table_header_row();
+ &Apache::loncommon::start_data_table_header_row();
+ if ($canmodify) {
+ $output .= ' '.&mt('Action').' ';
+ }
+ $output .= ''.&mt('Role').' '.
+ ''.&mt('Privileges in Course').' '.
+ &Apache::loncommon::end_data_table_header_row();
foreach my $key (sort(keys(%customroles))) {
+ next if ((!$canmodify) && (!grep(/^\Q$key\E$/,@current)));
$output .= &Apache::loncommon::start_data_table_row();
- if (grep(/^\Q$key\E$/,@current)) {
- $output .= ' '.
- ' '.
- &mt('Delete').' '.
- ' ';
- } else {
- $output .= ''.
- ' '.
- &mt('Add').' '.
- ' ';
+ if ($canmodify) {
+ if (grep(/^\Q$key\E$/,@current)) {
+ $output .= ''.
+ ' '.
+ &mt('Delete').' '.
+ ' ';
+ } else {
+ $output .= ''.
+ ' '.
+ &mt('Add').' '.
+ ' ';
+ }
}
$output .= ''.$key.' ';
foreach my $level ('course','domain','system') {
@@ -1207,10 +1224,15 @@ sub print_user_modification_page {
}
$response .= ''
.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
- .' '
- .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
- ,'',' ')
- .'
';
+ .' ';
+ if ($context eq 'domain') {
+ $response .= &mt('Please contact a [_1] for assistance.',
+ &Apache::lonnet::plaintext('dc'));
+ } else {
+ $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
+ ,'',' ');
+ }
+ $response .= ' ';
$env{'form.phase'} = '';
&print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
return;
@@ -1467,14 +1489,20 @@ ENDAUTH
'"'.$ccuname.'"','"'.$ccdomain.'"');
}
} else {
- $title = &mt('Modify existing user: [_1] in domain [_2]',
+ if ($permission->{'cusr'}) {
+ $title = &mt('Modify existing user: [_1] in domain [_2]',
'"'.$ccuname.'"','"'.$ccdomain.'"');
+ } else {
+ $title = &mt('Existing user: [_1] in domain [_2]',
+ '"'.$ccuname.'"','"'.$ccdomain.'"');
+ }
}
$r->print(''.$title.' '."\n");
$r->print('');
$r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
$inst_results{$ccuname.':'.$ccdomain}));
- if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
+ if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
$r->print('
'.&mt('User Can Request Creation of Courses/Communities in this Domain?').' '.
&Apache::loncommon::start_data_table());
if ($env{'request.role.domain'} eq $ccdomain) {
@@ -1489,18 +1517,21 @@ ENDAUTH
my @order = ('auth','quota','tools','requestauthor','adhocroles');
my %user_text;
my ($isadv,$isauthor) =
- &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
+ &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
if ((!$isauthor) &&
- (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))
- && ($env{'request.role.domain'} eq $ccdomain)) {
+ ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
+ ($env{'request.role.domain'} eq $ccdomain)) {
$user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
}
- if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
+ if ((&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
$user_text{'adhocroles'} = &domadhocroles($ccuname,$ccdomain);
}
$user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
- (&Apache::lonnet::allowed('mut',$ccdomain))) {
+ (&Apache::lonnet::allowed('mut',$ccdomain)) ||
+ (&Apache::lonnet::allowed('udp',$ccdomain))) {
# Current user has quota modification privileges
$user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
}
@@ -1558,9 +1589,18 @@ ENDNOTOOLSPRIV
if ($gotdiv) {
$r->print('');
}
+ my $statuses;
+ if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
+ (!&Apache::lonnet::allowed('mau',$ccdomain))) {
+ $statuses = ['active'];
+ } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
+ ($env{'request.course.sec'} &&
+ &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
+ $statuses = ['active'];
+ }
if ($env{'form.action'} ne 'singlestudent') {
&display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
- $roledom,$crstype);
+ $roledom,$crstype,$showcredits,$statuses);
}
} ## End of new user/old user logic
if ($env{'form.action'} eq 'singlestudent') {
@@ -1571,7 +1611,7 @@ ENDNOTOOLSPRIV
$btntxt = &mt('Enroll Student');
}
$r->print(' '."\n");
- } else {
+ } elsif ($permission->{'cusr'}) {
$r->print(''.
'
'.&mt('Add Roles').' ');
my $addrolesdisplay = 0;
@@ -1701,8 +1741,22 @@ sub validation_javascript {
sub display_existing_roles {
my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
- $showcredits) = @_;
+ $showcredits,$statuses) = @_;
my $now=time;
+ my $showall = 1;
+ my ($showexpired,$showactive);
+ if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
+ $showall = 0;
+ if (grep(/^expired$/,@{$statuses})) {
+ $showexpired = 1;
+ }
+ if (grep(/^active$/,@{$statuses})) {
+ $showactive = 1;
+ }
+ if ($showexpired && $showactive) {
+ $showall = 1;
+ }
+ }
my %lt=&Apache::lonlocal::texthash(
'rer' => "Existing Roles",
'rev' => "Revoke",
@@ -1766,6 +1820,13 @@ sub display_existing_roles {
$area =~ s/\_\w\w$//;
my ($role_code,$role_end_time,$role_start_time) =
split(/_/,$role);
+ my $active=1;
+ $active=0 if (($role_end_time) && ($now>$role_end_time));
+ if ($active) {
+ next unless($showall || $showactive);
+ } else {
+ next unless($showall || $showexpired);
+ }
# Is this a custom role? Get role owner and title.
my ($croleudom,$croleuname,$croletitle)=
($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
@@ -1774,6 +1835,7 @@ sub display_existing_roles {
my $sortkey=$role_code;
my $class='Unknown';
my $credits='';
+ my $csec;
if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
$class='Course';
my ($coursedom,$coursedir) = ($1,$2);
@@ -1836,12 +1898,14 @@ sub display_existing_roles {
$thisrole.='.'.$role_code;
}
}
- if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
- $carea.=' '.&mt('Section: [_1]',$3);
- $sortkey.="\0$3";
+ if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
+
+ $csec = $2;
+ $carea.=' '.&mt('Section: [_1]',$csec);
+ $sortkey.="\0$csec";
if (!$allowed) {
- if ($env{'request.course.sec'} eq $3) {
- if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
+ if ($env{'request.course.sec'} eq $csec) {
+ if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
$allowed = 1;
}
}
@@ -1883,29 +1947,30 @@ sub display_existing_roles {
}
}
my $row = '';
- $row.= '';
- my $active=1;
- $active=0 if (($role_end_time) && ($now>$role_end_time));
- if (($active) && ($allowed)) {
- $row.= ' ';
- } else {
- if ($active) {
- $row.=' ';
+ if ($showall) {
+ $row.= ' ';
+ if (($active) && ($allowed)) {
+ $row.= ' ';
} else {
- $row.=&mt('expired or revoked');
+ if ($active) {
+ $row.=' ';
+ } else {
+ $row.=&mt('expired or revoked');
+ }
}
- }
- $row.=' ';
- if ($allowed && !$active) {
- $row.= ' ';
- } else {
- $row.=' ';
- }
- $row.=' ';
- if ($delallowed) {
- $row.= ' ';
- } else {
- $row.=' ';
+ $row.=' ';
+ if ($allowed && !$active) {
+ $row.= ' ';
+ } else {
+ $row.=' ';
+ }
+ $row.=' ';
+ if ($delallowed) {
+ $row.= ' ';
+ } else {
+ $row.=' ';
+ }
+ $row.= ' ';
}
my $plaintext='';
if (!$croletitle) {
@@ -1923,17 +1988,30 @@ sub display_existing_roles {
' ',
$croleuname.':'.$croleudom);
}
- $row.= ' '.$plaintext.
- ' '.$area.
- ' '.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
- : ' ' ).
- ' '.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
- : ' ' )
- ." ";
+ $row.= ''.$plaintext.' '.
+ ''.$area.' '.
+ ''.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
+ : ' ' ).' '.
+ ''.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
+ : ' ' ).' ';
$sortrole{$sortkey}=$envkey;
$roletext{$envkey}=$row;
$roleclass{$envkey}=$class;
- $rolepriv{$envkey}=$allowed;
+ if ($allowed) {
+ $rolepriv{$envkey}='edit';
+ } else {
+ if ($context eq 'domain') {
+ if (&Apache::lonnet::allowed('vur',$ccdomain)) {
+ $rolepriv{$envkey}='view';
+ }
+ } elsif ($context eq 'course') {
+ if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
+ ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
+ &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
+ $rolepriv{$envkey}='view';
+ }
+ }
+ }
} # end of foreach (table building loop)
my $rolesdisplay = 0;
@@ -1966,13 +2044,26 @@ sub display_existing_roles {
} elsif ($env{'request.role'} =~ /^au\./) {
$contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
} else {
- $contextrole = &mt('Existing Roles in this Domain');
+ if ($showall) {
+ $contextrole = &mt('Existing Roles in this Domain');
+ } elsif ($showactive) {
+ $contextrole = &mt('Unexpired Roles in this Domain');
+ } elsif ($showexpired) {
+ $contextrole = &mt('Expired or Revoked Roles in this Domain');
+ }
}
$r->print(''.
'
'.$contextrole.' '.
&Apache::loncommon::start_data_table("LC_createuser").
-&Apache::loncommon::start_data_table_header_row().
-''.$lt{'rev'}.' '.$lt{'ren'}.' '.$lt{'del'}.
+&Apache::loncommon::start_data_table_header_row());
+ if ($showall) {
+ $r->print(
+' '.$lt{'rev'}.' '.$lt{'ren'}.' '.$lt{'del'}
+ );
+ } elsif ($showexpired) {
+ $r->print(' '.$lt{'rev'}.' ');
+ }
+ $r->print(
''.$lt{'rol'}.' '.$lt{'ext'}.
' '.$lt{'sta'}.' '.$lt{'end'}.' '.
&Apache::loncommon::end_data_table_header_row());
@@ -2112,16 +2203,16 @@ sub user_authentication {
my ($ccuname,$ccdomain,$formname) = @_;
my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
my $outcome;
+ my %lt=&Apache::lonlocal::texthash(
+ 'err' => "ERROR",
+ 'uuas' => "This user has an unrecognized authentication scheme",
+ 'adcs' => "Please alert a domain coordinator of this situation",
+ 'sldb' => "Please specify login data below",
+ 'ld' => "Login Data"
+ );
# Check for a bad authentication type
if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
# bad authentication scheme
- my %lt=&Apache::lonlocal::texthash(
- 'err' => "ERROR",
- 'uuas' => "This user has an unrecognized authentication scheme",
- 'adcs' => "Please alert a domain coordinator of this situation",
- 'sldb' => "Please specify login data below",
- 'ld' => "Login Data"
- );
if (&Apache::lonnet::allowed('mau',$ccdomain)) {
&initialize_authen_forms($ccdomain,$formname);
@@ -2147,16 +2238,12 @@ $lt{'uuas'} ($currentauth). $lt{'adcs'}.
ENDBADAUTH
}
} else { # Authentication type is valid
+
&initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
my ($authformcurrent,$can_modify,@authform_others) =
&modify_login_block($ccdomain,$currentauth);
if (&Apache::lonnet::allowed('mau',$ccdomain)) {
# Current user has login modification privileges
- my %lt=&Apache::lonlocal::texthash (
- 'ld' => "Login Data",
- 'ccld' => "Change Current Login Data",
- 'enld' => "Enter New Login Data"
- );
$outcome =
'