[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /auth lonroles.pm

raeburn raeburn at source.lon-capa.org
Sun Jan 22 09:28:21 EST 2017


raeburn		Sun Jan 22 14:28:21 2017 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/auth	lonroles.pm 
  Log:
  - For 2.11
    - Backport 1.323, 1.324.
  
  
-------------- next part --------------
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.269.2.29 loncom/auth/lonroles.pm:1.269.2.30
--- loncom/auth/lonroles.pm:1.269.2.29	Wed Nov  9 17:48:38 2016
+++ loncom/auth/lonroles.pm	Sun Jan 22 14:28:20 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.269.2.29 2016/11/09 17:48:38 raeburn Exp $
+# $Id: lonroles.pm,v 1.269.2.30 2017/01/22 14:28:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -316,11 +316,9 @@
             my $cnum = $3;
             my $sec = $4;
             if ($custom_adhoc) {
-                my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
-                                                                  'adhocroles.'.$cdom);
-                if (keys(%adhocroles)) {
-                    my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom});
-                    if (grep(/^\Q$rolename\E$/, at adhoc)) {
+                my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1);
+                if (ref($possroles) eq 'ARRAY') {
+                    if (grep(/^\Q$rolename\E$/,@{$possroles})) {
                         if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
                                                                "cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) {
                             &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
@@ -404,18 +402,9 @@
 # Is this an ad hoc custom role in a course/community?
                     if (my ($domain,$rolename,$coursenum,$sec) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)(?:/(\w+)|$)})) {
                         if ($dhroles{$domain}) {
-                            my @adhoc;
-                            if ($env{'environment.adhocroles.'.$domain}) {
-                                @adhoc = split(',',$env{'environment.adhocroles.'.$domain});
-                            } else {
-                                my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
-                                                                                  'adhocroles.'.$domain);
-                                if (keys(%adhocroles)) {
-                                    @adhoc = split(',',$adhocroles{'adhocroles.'.$domain});
-                                }
-                            }
-                            if ((@adhoc > 0) && ($rolename ne '')) {
-                                if (grep(/^\Q$rolename\E$/, at adhoc)) {
+                            my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($domain.'_'.$coursenum,1);
+                            if (ref($possroles) eq 'ARRAY') {
+                                if (grep(/^\Q$rolename\E$/,@{$possroles})) {
                                     if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,$update,$refresh,$now,
                                                                            "cr/$domain/$domain".'-domainconfig/'.$rolename,
                                                                            undef,$sec)) {
@@ -572,7 +561,7 @@
 					 $env{'user.name'},
 					 $env{'user.home'},
 					 "Role ".$trolecode);
-		    
+
 		    &Apache::lonnet::appenv(
 					   {'request.role'        => $trolecode,
 					    'request.role.domain' => $cdom,
@@ -581,6 +570,15 @@
                     my $tadv=0;
 
 		    if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
+                        if ($role =~ m{^\Qcr/$cdom/$cdom\E\-domainconfig/(\w+)$}) {
+                            my $rolename = $1;
+                            my %domdef = &Apache::lonnet::get_domain_defaults($cdom);
+                            if (ref($domdef{'adhocroles'}) eq 'HASH') {
+                                if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
+                                    &Apache::lonnet::appenv({'request.role.desc' => $domdef{'adhocroles'}{$rolename}{'desc'}});
+                                }
+                            }
+                        }
                         my $msg;
                         my ($furl,$ferr)=
                             &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
@@ -1002,7 +1000,7 @@
             my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
                                                $nochoose);
             &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
-                            \%roletext);
+                            \%roletext,$update,$then);
             my $tremark='';
             my $tbg;
             if ($env{'request.role'} eq 'cm') {
@@ -1063,9 +1061,8 @@
                 if ($role =~ m{^dc\./($match_domain)/$} 
 		    && $dcroles{$1}) {
 		    $output .= &adhoc_roles_row($1,'recent');
-                } elsif ($role =~ m{^dh\./($match_domain)/$}
-                         && ($env{'environment.adhocroles.'.$1} ne '')) {
-                    $output .= &adhoc_customroles_row($1,'recent');
+                } elsif ($role =~ m{^(dh)\./($match_domain)/$}) {
+                    $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then);
                 }
 	    } elsif ($numdc > 0) {
                 unless ($role =~/^error\:/) {
@@ -1094,7 +1091,7 @@
             $doheaders ++;
 	}
     }
-    &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
+    &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext,$update,$then);
     if ($countactive > 1) {
         my $tremark='';
         my $tbg;
@@ -1171,6 +1168,7 @@
     my $tryagain = $env{'form.tryagain'};
     my @ids = &Apache::lonnet::current_machine_ids();
     if (ref($roles_in_env) eq 'HASH') {
+        my %adhocdesc;
         foreach my $envkey (sort(keys(%{$roles_in_env}))) {
             my $button = 1;
             my $switchserver='';
@@ -1273,8 +1271,27 @@
                     $ttype = &Apache::loncommon::course_type($tcourseid);
                     if ($role !~ /^cr/) {
                         $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
-                    } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
-                        $trole = &mt('Helpdesk[_1]',' '.$2);
+                    } elsif ($role =~ m{^\Qcr/$tdom/$tdom\E\-domainconfig/(\w+)$}) {
+                        my $rolename = $1;
+                        my $desc;
+                        if (ref($adhocdesc{$tdom}) eq 'HASH') {
+                            $desc = $adhocdesc{$tdom}{$rolename};
+                        } else {
+                            my %domdef = &Apache::lonnet::get_domain_defaults($tdom);
+                            if (ref($domdef{'adhocroles'}) eq 'HASH') {
+                                foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) {
+                                    if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
+                                        $adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'};
+                                        $desc = $adhocdesc{$tdom}{$rolename};
+                                    }
+                                }
+                            }
+                        }
+                        if ($desc ne '') {
+                            $trole = $desc;
+                        } else {
+                            $trole = &mt('Helpdesk[_1]',' '.$rolename);
+                        }
                     } else {
                         $trole = (split(/\//,$role,4))[-1];
                     }
@@ -1446,7 +1463,7 @@
 }
 
 sub print_rolerows {
-    my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
+    my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext,$update,$then) = @_;
     if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
         my @types = &roletypes();
         foreach my $type (@types) {
@@ -1470,9 +1487,8 @@
                                     $output .= &adhoc_roles_row($1,'');
                                 }
                             }
-                        } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) &&
-                                 ($env{'environment.adhocroles.'.$1} ne '')) {
-                            $output .= &adhoc_customroles_row($1,'');
+                        } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh)\./($match_domain)/}) {
+                            $output .= &adhoc_customroles_row($1,$2,'',$update,$then);
                         }
                     }
                 }
@@ -1756,8 +1772,11 @@
                         $numdc++;
                     } else {
                         $dhroles->{$roledom} = $envkey;
-                        if ($env{'environment.adhocroles.'.$roledom} ne '') {
-                            $numadhoc ++;
+                        my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom);
+                        if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
+                            if (keys(%{$domdefaults{'adhocroles'}})) {
+                                $numadhoc ++;
+                            }
                         }
                         $numdh++;
                     }
@@ -1979,20 +1998,25 @@
 }
 
 sub adhoc_customroles_row {
-    my ($dhdom,$rowtype) = @_;
-    my $output = &Apache::loncommon::continue_data_table_row()
-                 .' <td colspan="5" class="LC_textsize_mobile">'
-                 .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --',
-                      '<span class="LC_cusr_emph">','</span>',$dhdom);
-    my @customroles = split(/,/,$env{'environment.adhocroles.'.$dhdom});
-    my $count = 0;
-    foreach my $role (@customroles) {
-        next if (($role eq '') || ($role =~ /\W/));
-        $output .= ' '.$role.': '.&courselink($dhdom,$rowtype,$role).' |';
-        $count ++;
-    }
-    if ($count) {
-        return $output;
+    my ($role,$dhdom,$rowtype,$update,$then) = @_;
+    my $liverole = 1;
+    my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$dhdom/"});
+    my $limit = $update;
+    if (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$dhdom.'/')) {
+        $limit = $then;
+    }
+    if ($tstart && $tstart>$limit) { $liverole = 0; }
+    if ($tend   && $tend  <$limit) { $liverole = 0; }
+    return unless ($liverole);
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom);
+    if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
+        if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) {
+            return &Apache::loncommon::continue_data_table_row()
+                  .' <td colspan="5" class="LC_textsize_mobile">'
+                  .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --',
+                       '<span class="LC_cusr_emph">','</span>',$dhdom)
+                  .' '.&courselink($dhdom,$rowtype,$role);
+        }
     }
     return;
 }


More information about the LON-CAPA-cvs mailing list