[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm loncreateuser.pm lonuserutils.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 12 Dec 2007 23:59:42 -0000
This is a MIME encoded message
--raeburn1197503982
Content-Type: text/plain
raeburn Wed Dec 12 18:59:42 2007 EDT
Modified files:
/loncom/interface loncreateuser.pm lonuserutils.pm loncommon.pm
Log:
bug 5501 - single textbox and domain selector available on CUSR single user screen (the pre 2.5 functionality) as a shortcut to creating a user when the DC/CC/AU knows that the username does not exist.
lonuserutils.pm
- &can_create_user() routine added
- checks whether creation of new users is permitted in the current context/domain.
loncreateuser.pm
- call to lonuserutils::can_create_user() determines whether createuser shortcut should be displayed.
- 'Display User Lists' link included in main menu if user has $permission->{cusr}, even if permission->{view} is lacking
- only include a user information field in the disallowed list, if it was originally available for text entry on the previous screen, but role-specific constraints prohibit modification of the field.
- warning text switches based on singular/plural case for disallowed field changes
--raeburn1197503982
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071212185942.txt"
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.206 loncom/interface/loncreateuser.pm:1.207
--- loncom/interface/loncreateuser.pm:1.206 Mon Dec 10 21:27:24 2007
+++ loncom/interface/loncreateuser.pm Wed Dec 12 18:59:41 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.206 2007/12/11 02:27:24 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.207 2007/12/12 23:59:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -209,12 +209,14 @@
# =================================================================== Phase one
sub print_username_entry_form {
- my ($r,$response,$srch,$forcenewuser) = @_;
+ my ($r,$context,$response,$srch,$forcenewuser) = @_;
my $defdom=$env{'request.role.domain'};
my $formtoset = 'crtuser';
if (exists($env{'form.startrolename'})) {
$formtoset = 'docustom';
$env{'form.rolename'} = $env{'form.startrolename'};
+ } elsif ($env{'form.origform'} eq 'crtusername') {
+ $formtoset = $env{'form.origform'};
}
my ($jsback,$elements) = &crumb_utilities();
@@ -252,7 +254,7 @@
'ecrp' => "Edit Custom Role Privileges",
'nr' => "Name of Role",
'cre' => "Custom Role Editor",
- 'mod' => "to add/modify roles",
+ 'mod' => "to edit user information or add/modify roles",
);
my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
@@ -266,7 +268,7 @@
$r->print("
<h3>$lt{'srch'} $sellink $lt{'mod'}$helpsiur</h3>
$response");
- $r->print(&entry_form($defdom,$srch,$forcenewuser));
+ $r->print(&entry_form($defdom,$srch,$forcenewuser,$context));
} elsif ($env{'form.action'} eq 'custom') {
if (&Apache::lonnet::allowed('mcr','/')) {
$r->print(<<ENDCUSTOM);
@@ -284,19 +286,55 @@
}
sub entry_form {
- my ($dom,$srch,$forcenewuser) = @_;
+ my ($dom,$srch,$forcenewuser,$context) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my $cancreate = &Apache::lonuserutils::can_create_user($dom,$context);
+ if (!$cancreate) {
+ $forcenewuser = '';
+ }
my $userpicker =
&Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
'document.crtuser');
my $srchbutton = &mt('Search');
- my $output = <<"ENDDOCUMENT";
+ my $output = <<"ENDBLOCK";
<form action="/adm/createuser" method="post" name="crtuser">
<input type="hidden" name="action" value="$env{'form.action'}" />
<input type="hidden" name="phase" value="get_user_info" />
$userpicker
<input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
</form>
+ENDBLOCK
+ if ($cancreate) {
+ my $defdom=$env{'request.role.domain'};
+ my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
+ my $helpcrt=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
+ my %lt=&Apache::lonlocal::texthash(
+ 'crnu' => 'Create a new user',
+ 'usr' => 'Username',
+ 'dom' => 'in domain',
+ 'cra' => 'Create user',
+ );
+ $output .= <<"ENDDOCUMENT";
+<form action="/adm/createuser" method="post" name="crtusername">
+<input type="hidden" name="action" value="$env{'form.action'}" />
+<input type="hidden" name="phase" value="createnewuser" />
+<input type="hidden" name="srchtype" value="exact" />
+<input type="hidden" name="srchby" value="username" />
+<input type="hidden" name="srchin" value="dom" />
+<input type="hidden" name="forcenewuser" value="1" />
+<input type="hidden" name="origform" value="crtusername" />
+<h3>$lt{crnu}$helpcrt</h3>
+<table>
+ <tr>
+ <td>$lt{'usr'}:</td>
+ <td><input type="text" size="15" name="srchterm" /></td>
+ <td> $lt{'dom'}:</td><td>$domform</td>
+ <td> <input name="userrole" type="submit" value="$lt{'cra'}" /></td>
+ </tr>
+</table>
+</form>
ENDDOCUMENT
+ }
return $output;
}
@@ -329,7 +367,7 @@
# =================================================================== Phase two
sub print_user_selection_page {
- my ($r,$response,$srch,$srch_results,$operation,$srcharray) = @_;
+ my ($r,$response,$srch,$srch_results,$operation,$srcharray,$context) = @_;
my @fields = ('username','domain','lastname','firstname','permanentemail');
my $sortby = $env{'form.sortby'};
@@ -374,7 +412,7 @@
faq=>282,bug=>'Instructor Interface',});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
$r->print("<b>$lt{'usrch'}</b><br />");
- $r->print(&entry_form($srch->{'srchdomain'},$srch));
+ $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
$r->print('<h3>'.$lt{'usel'}.'</h3>');
} else {
$r->print($jscript."<b>$lt{'stusrch'}</b><br />");
@@ -446,7 +484,7 @@
my ($r,$ccuname,$ccdomain,$srch,$response,$context) = @_;
if (($ccuname eq '') || ($ccdomain eq '')) {
my $usermsg = &mt('No username and/or domain provided.');
- &print_username_entry_form($r,$usermsg);
+ &print_username_entry_form($r,$context,$usermsg);
return;
}
my %abv_auth = &auth_abbrev();
@@ -474,7 +512,7 @@
$domdesc,$curr_rules{$ccdomain}{'username'},
'username');
}
- &print_username_entry_form($r,$userchkmsg);
+ &print_username_entry_form($r,$context,$userchkmsg);
return;
}
}
@@ -1710,8 +1748,10 @@
# Strip leading and trailing whitespace
$env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
if (!$canmodify) {
- if ($env{'form.c'.$item} ne $userenv{$item}) {
- push(@mod_disallowed,$item);
+ if (defined($env{'form.c'.$item})) {
+ if ($env{'form.c'.$item} ne $userenv{$item}) {
+ push(@mod_disallowed,$item);
+ }
}
$env{'form.c'.$item} = $userenv{$item};
}
@@ -1943,7 +1983,14 @@
foreach my $field (@mod_disallowed) {
$r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
}
- $r->print('</ul>'.&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles: <span class=\"LC_cusr_emph\">[_2]</span>.",$contextname,$rolestr).'<br />'.&mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
+ $r->print('</ul>');
+ if (@mod_disallowed == 1) {
+ $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
+ } else {
+ $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
+ }
+ $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
+ &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
}
$r->print($no_forceid_alert.
&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
@@ -2198,6 +2245,9 @@
foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
$outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
}
+ if ($env{'form.origname'} ne '') {
+ $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
+ }
foreach my $item ('sortby','seluname','seludom') {
if (exists($env{'form.'.$item})) {
$outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
@@ -2631,8 +2681,20 @@
$srch->{$item} = $env{'form.'.$item};
}
- if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) {
- if ($env{'form.phase'} eq 'get_user_info') {
+ if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
+ ($phase eq 'createnewuser')) {
+ if ($env{'form.phase'} eq 'createnewuser') {
+ my $response;
+ if ($env{'form.srchterm'} !~ /^$match_username$/) {
+ my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
+ &print_username_entry_form($r,$context,$response,$srch);
+ } else {
+ my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
+ my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
+ &print_user_modification_page($r,$ccuname,$ccdomain,
+ $srch,$response,$context);
+ }
+ } elsif ($env{'form.phase'} eq 'get_user_info') {
my ($currstate,$response,$forcenewuser,$results) =
&user_search_result($srch);
if ($env{'form.currstate'} eq 'modify') {
@@ -2640,7 +2702,7 @@
}
if ($currstate eq 'select') {
&print_user_selection_page($r,$response,$srch,$results,
- 'createuser',\@search);
+ 'createuser',\@search,$context);
} elsif ($currstate eq 'modify') {
my ($ccuname,$ccdomain);
if (($srch->{'srchby'} eq 'uname') &&
@@ -2661,7 +2723,7 @@
} elsif ($currstate eq 'query') {
&print_user_query_page($r,'createuser');
} else {
- &print_username_entry_form($r,$response,$srch,
+ &print_username_entry_form($r,$context,$response,$srch,
$forcenewuser);
}
} elsif ($env{'form.phase'} eq 'userpicked') {
@@ -2673,7 +2735,7 @@
} elsif ($env{'form.phase'} eq 'update_user_data') {
&update_user_data($r,$context);
} else {
- &print_username_entry_form($r,undef,$srch);
+ &print_username_entry_form($r,$context,undef,$srch);
}
} elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
if ($env{'form.phase'} eq 'set_custom_roles') {
@@ -2681,7 +2743,8 @@
} else {
&custom_role_editor($r);
}
- } elsif ($env{'form.action'} eq 'listusers' && $permission->{'view'}) {
+ } elsif (($env{'form.action'} eq 'listusers') &&
+ ($permission->{'view'} || $permission->{'cusr'})) {
if ($env{'form.phase'} eq 'bulkchange') {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'backPage(document.studentform)',
@@ -2750,7 +2813,7 @@
} else {
$r->print(&header());
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
- $r->print(&print_main_menu($permission));
+ $r->print(&print_main_menu($permission,$context));
$r->print(&Apache::loncommon::end_page());
}
return OK;
@@ -2859,14 +2922,17 @@
}
if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
$permission{'view'} = 1;
- if (!$permission{'view'}) {
- my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
- $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
- if ($permission{'view'}) {
- $permission{'view_section'} = $env{'request.course.sec'};
- }
+ }
+ if (!$permission{'view'}) {
+ my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
+ $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
+ if ($permission{'view'}) {
+ $permission{'view_section'} = $env{'request.course.sec'};
}
}
+ if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
+ $permission{'grp_manage'} = 1;
+ }
} elsif ($context eq 'author') {
$permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
$permission{'view'} = $permission{'cusr'};
@@ -3293,6 +3359,10 @@
srchtype => 'selectbox',
srchdomain => 'selectbox',
},
+ crtusername => {
+ srchterm => 'text',
+ srchdomain => 'selectbox',
+ },
docustom => {
rolename => 'selectbox',
newrolename => 'textbox',
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.14 loncom/interface/lonuserutils.pm:1.15
--- loncom/interface/lonuserutils.pm:1.14 Wed Dec 12 14:47:56 2007
+++ loncom/interface/lonuserutils.pm Wed Dec 12 18:59:41 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.14 2007/12/12 19:47:56 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.15 2007/12/12 23:59:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1920,7 +1920,7 @@
$rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
}
my $results_description = &results_header_row($rolefilter,$statusmode,
- $context);
+ $context,$permission);
$r->print('<b>'.$results_description.'</b><br />');
my ($output,$actionselect);
if ($mode eq 'html' || $mode eq 'view') {
@@ -2530,7 +2530,7 @@
}
sub results_header_row {
- my ($rolefilter,$statusmode,$context) = @_;
+ my ($rolefilter,$statusmode,$context,$permission) = @_;
my ($description,$showfilter);
if ($rolefilter ne 'Any') {
$showfilter = $rolefilter;
@@ -2550,6 +2550,13 @@
$description .= &mt('All users in course with [_1] roles',$rolefilter);
}
}
+ if (exists($permission->{'view_section'})) {
+ if ($env{'form.showrole'} eq 'st') {
+ $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'});
+ } elsif ($env{'form.showrole'} eq 'any') {
+ $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'});
+ }
+ }
} elsif ($context eq 'author') {
$description =
&mt('Author space for <span class="LC_cusr_emph">[_1]</span>',
@@ -3693,5 +3700,28 @@
return $setsection_js;
}
+sub can_create_user {
+ my ($dom,$context,$usertype) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my $cancreate = 1;
+ if (ref($domconf{'usercreation'}) eq 'HASH') {
+ if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
+ if ($context eq 'course' || $context eq 'author') {
+ my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
+ if ($creation eq 'none') {
+ $cancreate = 0;
+ } elsif ($creation ne 'any') {
+ if (defined($usertype)) {
+ if ($creation ne $usertype) {
+ $cancreate = 0;
+ }
+ }
+ }
+ }
+ }
+ }
+ return $cancreate;
+}
+
1;
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.624 loncom/interface/loncommon.pm:1.625
--- loncom/interface/loncommon.pm:1.624 Mon Dec 10 19:47:58 2007
+++ loncom/interface/loncommon.pm Wed Dec 12 18:59:41 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.624 2007/12/11 00:47:58 raeburn Exp $
+# $Id: loncommon.pm,v 1.625 2007/12/12 23:59:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -6243,7 +6243,7 @@
srchby => 'lastname',
);
my $srchterm;
- if (ref($srch) eq 'HASH') {
+ if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
if ($srch->{'srchby'} ne '') {
$curr_selected{'srchby'} = $srch->{'srchby'};
}
--raeburn1197503982--