[LON-CAPA-cvs] cvs: loncom / lond /auth roles.tab rolesplain.tab /interface loncreateuser.pm lonuserutils.pm /lonnet/perl lonnet.pm

raeburn raeburn@source.lon-capa.org
Thu, 12 Nov 2009 15:59:00 -0000


This is a MIME encoded message

--raeburn1258041540
Content-Type: text/plain

raeburn		Thu Nov 12 15:59:00 2009 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm lonuserutils.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/auth	roles.tab rolesplain.tab 
    /loncom	lond 
  Log:
  - Accommodate Communities
    - Custom role template depends on course type.
    - System-wide bre priv unavailable in custom roles used in Communities.
    - System-wide bro priv (own authored/co-authored published resources) 
       available for custom roles in Communities.
    - Community Roles (including custom roles) will not be displayed in LON-CAPA 
      versions 2.9 or older.
  
  
--raeburn1258041540
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20091112155900.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.323 loncom/interface/loncreateuser.pm:1.324
--- loncom/interface/loncreateuser.pm:1.323	Wed Nov  4 14:13:32 2009
+++ loncom/interface/loncreateuser.pm	Thu Nov 12 15:58:22 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.323 2009/11/04 14:13:32 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.324 2009/11/12 15:58:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,13 +51,14 @@
 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</home/httpd/lonTabs/rolesplain.tab>.
+Custom roles can be defined by a Domain Coordinator, Course Coordinator
+or Community Coordinator via the Manage User functionality.
+The custom role editor screen will show all privileges which can be
+assigned to users. For a complete list of privileges, please see 
+C</home/httpd/lonTabs/rolesplain.tab>.
 
-Custom role definitions are stored in the C<roles.db> file of the role
-author.
+Custom role definitions are stored in the C<roles.db> file of the creator
+of the role.
 
 =cut
 
@@ -487,6 +488,11 @@
         '// ]]>'."\n".
         '</script>'."\n";
 
+    my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
+    if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
+        && (&Apache::lonnet::allowed('mcr','/'))) {
+        $jscript .= &customrole_javascript();
+    }
     my %loaditems = (
                 'onload' => "javascript:setFormElements(document.$formtoset)",
                     );
@@ -512,31 +518,53 @@
     }
     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
                                                      $helpitem);
-    my %existingroles=&Apache::lonuserutils::my_custom_roles();
-    my $choice=&Apache::loncommon::select_form('make new role','rolename',
-		('make new role' => 'Generate new role ...',%existingroles));
     my %lt=&Apache::lonlocal::texthash(
                     'srst' => 'Search for a user and enroll as a student',
                     'srme' => 'Search for a user and enroll as a member',
                     'srad' => 'Search for a user and modify/add user information or roles',
 		    'usr'  => "Username",
                     'dom'  => "Domain",
-                    'ecrp' => "Edit Custom Role Privileges",
-                    'nr'   => "Name of Role",
+                    'ecrp' => "Define or Edit Custom Role",
+                    'nr'   => "role name",
                     'cre'  => "Next",
 				       );
     $r->print($start_page."\n".$crumbs);
     if ($env{'form.action'} eq 'custom') {
         if (&Apache::lonnet::allowed('mcr','/')) {
-            $r->print(<<ENDCUSTOM);
-<form action="/adm/createuser" method="post" name="docustom">
-<input type="hidden" name="action" value="$env{'form.action'}" />
-<input type="hidden" name="phase" value="selected_custom_edit" />
-<h3>$lt{'ecrp'}</h3>
-$choice $lt{'nr'}: <input type="text" size="15" name="newrolename" /><br />
-<input name="customeditor" type="submit" value="$lt{'cre'}" />
-</form>
-ENDCUSTOM
+            my $newroletext = &mt('Define new custom role:');
+            $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
+                      '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
+                      '<input type="hidden" name="phase" value="selected_custom_edit" />'.
+                      '<h3>'.$lt{'ecrp'}.'</h3>'.
+                      &Apache::loncommon::start_data_table().
+                      &Apache::loncommon::start_data_table_row().
+                      '<td>');
+            if (keys(%existingroles) > 0) {
+                $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
+            } else {
+                $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
+            }
+            $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
+                      &Apache::loncommon::end_data_table_row());
+            if (keys(%existingroles) > 0) {
+                $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
+                          '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
+                          &mt('View/Modify existing role:').'</b></label></td>'.
+                          '<td align="center"><br />'.
+                          '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
+                          '<option value="" selected="selected" onchange="">'.
+                          &mt('Select'));
+                foreach my $role (sort(keys(%existingroles))) {
+                    $r->print('<option value="$role">'.$role.'</option>');
+                }
+                $r->print('</select>'.
+                          '</td>'.
+                          &Apache::loncommon::end_data_table_row());
+            }
+            $r->print(&Apache::loncommon::end_data_table().'<p>'.
+                      '<input name="customeditor" type="submit" value="'.
+                      $lt{'cre'}.'" /></p>'.
+                      '</form>');
         }
     } else {
         my $actiontext = $lt{'srad'};
@@ -547,8 +575,7 @@
                 $actiontext = $lt{'srst'};
             }
         }
-        $r->print("
-<h3>$actiontext</h3>");
+        $r->print("<h3>$actiontext</h3>");
         if ($env{'form.origform'} ne 'crtusername') {
             $r->print("\n".$response);
         }
@@ -557,6 +584,44 @@
     $r->print(&Apache::loncommon::end_page());
 }
 
+sub customrole_javascript {
+    my $js = <<"END";
+<script type="text/javascript">
+// <![CDATA[
+
+function setCustomFields() {
+    if (document.docustom.customroleaction.length > 0) {
+        for (var i=0; i<document.docustom.customroleaction.length; i++) {
+            if (document.docustom.customroleaction[i].checked) {
+                if (document.docustom.customroleaction[i].value == 'new') {
+                    document.docustom.rolename.selectedIndex = 0;
+                } else {
+                    document.docustom.newrolename.value = '';
+                }
+            }
+        }
+    }
+    return;
+}
+
+function setCustomAction(caller) {
+    if (document.docustom.customroleaction.length > 0) {
+        for (var i=0; i<document.docustom.customroleaction.length; i++) {
+            if (document.docustom.customroleaction[i].value == caller) {
+                document.docustom.customroleaction[i].checked = true;
+            }
+        }
+    }
+    setCustomFields();
+    return;
+}
+
+// ]]>
+</script>
+END
+    return $js;
+}
+
 sub entry_form {
     my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
     my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
@@ -3478,18 +3543,27 @@
 
 sub custom_role_editor {
     my ($r) = @_;
-    my $rolename=$env{'form.rolename'};
-
-    if ($rolename eq 'make new role') {
-	$rolename=$env{'form.newrolename'};
+    my $action = $env{'form.customroleaction'};
+    my $rolename; 
+    if ($action eq 'new') {
+        $rolename=$env{'form.newrolename'};
+    } else {
+        $rolename=$env{'form.rolename'};
     }
 
     $rolename=~s/[^A-Za-z0-9]//gs;
-
     if (!$rolename || $env{'form.phase'} eq 'pickrole') {
 	&print_username_entry_form($r);
         return;
     }
+    my ($crstype,$context);
+    if ($env{'request.course.id'}) {
+        $crstype = &Apache::loncommon::course_type();
+        $context = 'course';
+    } else {
+        $context = 'domain';
+        $crstype = $env{'form.templatecrstype'};
+    }
 # ------------------------------------------------------- What can be assigned?
     my %full=();
     my %courselevel=();
@@ -3507,6 +3581,9 @@
 	$body_top .= &mt('Existing Role').' "';
 # ------------------------------------------------- Get current role privileges
 	($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
+        if ($crstype eq 'Community') {
+            $syspriv =~ s/bre\&S//;   
+        }
     } else {
 	$body_top .= &mt('New Role').' "';
 	$roledef='';
@@ -3548,20 +3625,50 @@
     my $head_script = "\n";
     $head_script .= '<script type="text/javascript">'."\n"
                    .'// <![CDATA['."\n";
-    my $crstype;
-    if ($env{'request.course.id'}) {
-        $crstype = &Apache::loncommon::course_type();
+    my @template_roles = ("in","ta","ep");
+    if ($context eq 'domain') {
+        push(@template_roles,"ad");
     }
-    my @template_roles = ("in","ta","ep","st");
+    push(@template_roles,"st");
     if ($crstype eq 'Community') {
         unshift(@template_roles,'co');
     } else {
         unshift(@template_roles,'cc');
     }
     foreach my $role (@template_roles) {
-        $head_script .= &make_script_template($role);
+        $head_script .= &make_script_template($role,$crstype);
         $button_code .= &make_button_code($role,$crstype).' ';
     }
+    my $context_code;
+    if ($context eq 'domain') {
+        my $checkedCommunity = '';
+        my $checkedCourse = ' checked="checked"';
+        if ($env{'form.templatecrstype'} eq 'Community') {
+            $checkedCommunity = $checkedCourse;
+            $checkedCourse = '';
+        }
+        $context_code = '<label>'.
+                        '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
+                        &mt('Course').
+                        '</label>'.('&nbsp;' x2).
+                        '<label>'.
+                        '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
+                        &mt('Community').
+                        '</label>'.
+                        '</fieldset>'.
+                        '<input type="hidden" name="customroleaction" value="'.
+                        $action.'" />';
+        if ($env{'form.customroleaction'} eq 'new') {
+            $context_code .= '<input type="hidden" name="newrolename" value="'.
+                             $rolename.'" />';
+        } else {
+            $context_code .= '<input type="hidden" name="rolename" value="'.
+                             $rolename.'" />';
+        }
+        $context_code .= '<input type="hidden" name="action" value="custom" />'.
+                         '<input type="hidden" name="phase" value="selected_custom_edit" />';
+    }
+
     $head_script .= "\n".$jsback."\n"
                    .'// ]]>'."\n"
                    .'</script>'."\n";
@@ -3583,13 +3690,22 @@
                     'dml'  => "Domain Level",
                     'ssl'  => "System Level");
 
-    $r->print('<div>'
+
+    $r->print('<div class="LC_left_float">'
              .'<form action=""><fieldset>'
              .'<legend>'.&mt('Select a Template').'</legend>'
              .$button_code
-             .'</fieldset></form>'
-             .'</div>'
-    );
+             .'</fieldset></form></div>');
+    if ($context_code) {
+        $r->print('<div class="LC_left_float">'
+                 .'<form action="/adm/createuser" method="post"><fieldset>'
+                 .'<legend>'.&mt('Context').'</legend>'
+                 .$context_code
+                 .'</form>'
+                 .'</div>'
+        );
+    }
+    $r->print('<br clear="all" />');
 
     $r->print(<<ENDCCF);
 <form name="form1" method="post">
@@ -3601,7 +3717,7 @@
 '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
 '</th><th>'.$lt{'ssl'}.'</th>'.
               &Apache::loncommon::end_data_table_header_row());
-    foreach my $priv (sort keys %full) {
+    foreach my $priv (sort(keys(%full))) {
         my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
         $r->print(&Apache::loncommon::start_data_table_row().
 	          '<td>'.$privtext.'</td><td>'.
@@ -3610,11 +3726,15 @@
     '</td><td>'.
     ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
     ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;').
-    '</td><td>'.
-    ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
-    ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;').
-    '</td>'.
-             &Apache::loncommon::end_data_table_row());
+    '</td><td>');
+        if ($priv eq 'bre' && $crstype eq 'Community') {
+            $r->print('&nbsp;');  
+        } else {
+            $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
+                      ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;');
+        }
+        $r->print('</td>'.
+                  &Apache::loncommon::end_data_table_row());
     }
     $r->print(&Apache::loncommon::end_data_table().
    '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
@@ -3626,7 +3746,7 @@
 }
 # --------------------------------------------------------
 sub make_script_template {
-    my ($role) = @_;
+    my ($role,$crstype) = @_;
     my %full_c=();
     my %full_d=();
     my %full_s=();
@@ -3640,6 +3760,7 @@
         $full_d{$priv}=1;
     }
     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
+        next if (($crstype eq 'Community') && ($item eq 'bre&S'));
         my ($priv,$restrict)=split(/\&/,$item);
         $full_s{$priv}=1;
     }
@@ -5882,7 +6003,8 @@
             }
         }
         if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
-            foreach my $cust (sort keys %customroles) {
+            foreach my $cust (sort(keys(%customroles))) {
+                next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
                 my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
                 $table .= &course_level_row($protectedcourse,$role,$area,$domain,
                                             $cust,\%sections_count,\%lt);
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.103 loncom/interface/lonuserutils.pm:1.104
--- loncom/interface/lonuserutils.pm:1.103	Wed Nov  4 15:35:56 2009
+++ loncom/interface/lonuserutils.pm	Thu Nov 12 15:58:22 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.103 2009/11/04 15:35:56 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.104 2009/11/12 15:58:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1176,7 +1176,7 @@
     my %customroles;
     my ($options,$coursepick,$cb_jscript);
     if ($context ne 'author') {
-        %customroles = &my_custom_roles();
+        %customroles = &my_custom_roles($crstype);
     }
 
     my %lt=&Apache::lonlocal::texthash(
@@ -1350,10 +1350,14 @@
 # ======================================================= Existing Custom Roles
 
 sub my_custom_roles {
+    my ($crstype) = @_;
     my %returnhash=();
     my %rolehash=&Apache::lonnet::dump('roles');
-    foreach my $key (keys %rolehash) {
+    foreach my $key (keys(%rolehash)) {
         if ($key=~/^rolesdef\_(\w+)$/) {
+            if ($crstype eq 'Community') {
+                next if ($rolehash{$key} =~ /bre\&S/); 
+            }
             $returnhash{$1}=$1;
         }
     }
@@ -3900,7 +3904,7 @@
             }
         }
         my (%curr_rules,%got_rules,%alerts);
-        my %customroles = &my_custom_roles();
+        my %customroles = &my_custom_roles($crstype);
         my @permitted_roles = 
             &roles_on_upload($context,$setting,$crstype,%customroles); 
         # Get new users list
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1042 loncom/lonnet/perl/lonnet.pm:1.1043
--- loncom/lonnet/perl/lonnet.pm:1.1042	Fri Nov  6 01:49:10 2009
+++ loncom/lonnet/perl/lonnet.pm	Thu Nov 12 15:58:34 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1042 2009/11/06 01:49:10 raeburn Exp $
+# $Id: lonnet.pm,v 1.1043 2009/11/12 15:58:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3908,6 +3908,9 @@
         if (($rdummy ne 'con_lost') && ($roledef ne '')) {
             my ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
             if (defined($syspriv)) {
+                if ($trest =~ /^$match_community$/) {
+                    $syspriv =~ s/bre\&S//; 
+                }
                 $$allroles{'cm./'}.=':'.$syspriv;
                 $$allroles{$spec.'./'}.=':'.$syspriv;
             }
@@ -5046,7 +5049,7 @@
     my $courseprivid='';
 
     my $ownaccess;
-    # Community Coordinator browsing resource space.
+    # Community Coordinator or Assistant Co-author browsing resource space.
     if (($priv eq 'bro') && ($env{'user.author'})) {
         if ($uri eq '') {
             $ownaccess = 1;
@@ -5095,7 +5098,7 @@
 # Course
 
     if ($env{'user.priv.'.$env{'request.role'}.'./'}=~/\Q$priv\E\&([^\:]*)/) {
-        unless (($priv eq 'bro' && !$ownaccess)) {
+        unless (($priv eq 'bro') && (!$ownaccess)) {
             $thisallowed.=$1;
         }
     }
@@ -5104,7 +5107,7 @@
 
     if ($env{'user.priv.'.$env{'request.role'}.'./'.(split(/\//,$uri))[0].'/'}
        =~/\Q$priv\E\&([^\:]*)/) {
-        unless (($priv eq 'bro' && !$ownaccess)) {
+        unless (($priv eq 'bro') && (!$ownaccess)) {
             $thisallowed.=$1;
         }
     }
@@ -5116,7 +5119,7 @@
 
     if ($env{'user.priv.'.$env{'request.role'}.'.'.$courseuri}
        =~/\Q$priv\E\&([^\:]*)/) {
-        unless (($priv eq 'bro' && !$ownaccess)) {
+        unless (($priv eq 'bro') && (!$ownaccess)) {
             $thisallowed.=$1;
         }
     }
Index: loncom/auth/roles.tab
diff -u loncom/auth/roles.tab:1.59 loncom/auth/roles.tab:1.60
--- loncom/auth/roles.tab:1.59	Sat Nov  7 17:25:33 2009
+++ loncom/auth/roles.tab	Thu Nov 12 15:58:47 2009
@@ -12,7 +12,7 @@
 ep:s adv
 ep:d sma
 ep:c bre&R:mgr&R:mqg&R:dcm:evb:las:pav:pfo
-cr:s adv&SR:bre&S
+cr:s adv&SR:bre&S:bro&S
 cr:d sma
 cr:c bre&R:vgr&SCR:mgr&SCR:mqg&SCR:mgq&SCR:gan&SCR:dcm&SC:evb&SC:srm&SC:dff&SC:pch:plc:dch&S:pac:rin&S:las&SR:opa&SR:mdc&SR:cst&IK:pav&C:pfo&C:whn&C
 st:d sma&L
Index: loncom/auth/rolesplain.tab
diff -u loncom/auth/rolesplain.tab:1.40 loncom/auth/rolesplain.tab:1.41
--- loncom/auth/rolesplain.tab:1.40	Thu Oct 29 05:33:55 2009
+++ loncom/auth/rolesplain.tab	Thu Nov 12 15:58:47 2009
@@ -50,7 +50,7 @@
 mpq:Modify disk space allocated to portfolio files for a user
 mut:Set availability of user tools for a user - Personal Information Page, Blog and Portfolio
 bre:Browse resources
-bro:Browse own resources
+bro:Browse own authored/co-authored published resources
 are:Assemble resources
 cre:Copy resources
 ere:Create, edit, modify and publish resources
Index: loncom/lond
diff -u loncom/lond:1.432 loncom/lond:1.433
--- loncom/lond:1.432	Thu Oct 29 03:23:52 2009
+++ loncom/lond	Thu Nov 12 15:59:00 2009
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.432 2009/10/29 03:23:52 raeburn Exp $
+# $Id: lond,v 1.433 2009/11/12 15:59:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,7 +59,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.432 $'; #' stupid emacs
+my $VERSION='$Revision: 1.433 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -3123,9 +3123,11 @@
 	my $count=0;
 	while (my ($key,$value) = each(%$hashref)) {
             if ($namespace eq 'roles') {
-                if ($key =~ /^($LONCAPA::match_domain)_($LONCAPA::match_community)_cc$/) {
-                    if ($clientversion =~ /^(\d+\.\d+)$/) {
-                        next if ($1 <= 2.9);
+                if ($key =~ /^($LONCAPA::match_domain)_($LONCAPA::match_community)_(cc|co|in|ta|ep|ad|st|cr)/) {
+                    if ($clientversion =~ /^(\d+)\.(\d+)$/) {
+                        my $major = $1;
+                        my $minor = $2;
+                        next if (($major < 2) || (($major == 2) && ($minor < 10)));
                     }
                 }
             }

--raeburn1258041540--