[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm lonuserutils.pm

raeburn raeburn at source.lon-capa.org
Tue Aug 21 11:43:28 EDT 2012


raeburn		Tue Aug 21 15:43:28 2012 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm loncreateuser.pm 
  Log:
  - Bug 6340.
    - Course owner can revoke/modify Course Coordinator roles from list 
      users screen. (One exception - course owner can not revoke his/her
      own CC role from this screen).
    - Move &is_courseowner() routine from loncreateuser.pm to
      lonuserutils.pm to facilitate re-use. 
  
  
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.140 loncom/interface/lonuserutils.pm:1.141
--- loncom/interface/lonuserutils.pm:1.140	Tue Aug 21 01:50:34 2012
+++ loncom/interface/lonuserutils.pm	Tue Aug 21 15:43:27 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.140 2012/08/21 01:50:34 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.141 2012/08/21 15:43:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2539,6 +2539,12 @@
                             if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
                                 $canchangesec{$role} = $env{'request.course.sec'};
                             }
+                        } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
+                                 (($role eq 'cc') && ($crstype eq 'Course'))) {
+                            if (&is_courseowner($env{'request.course.id'},
+                                                $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
+                                $canchange{$role} = 1;
+                            }
                         }
                     }
                 }
@@ -2854,17 +2860,26 @@
                     if ($showcheckbox) {
                         $checkval = $user; 
                         if ($context eq 'course') {
-                            if ($role eq 'st') {
-                                $checkval .= ':st';
-                            }
-                            $checkval .= ':'.$in{'section'};
-                            if ($role eq 'st') {
-                                $checkval .= ':'.$in{'type'}.':'.
-                                             $in{'lockedtype'};
-                            }
+                            if (($role eq 'co' || $role eq 'cc') &&
+                                ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
+                                $showcheckbox = 0;
+                            } else {
+                                if ($role eq 'st') {
+                                    $checkval .= ':st';
+                                }
+                                $checkval .= ':'.$in{'section'};
+                                if ($role eq 'st') {
+                                    $checkval .= ':'.$in{'type'}.':'.
+                                                 $in{'lockedtype'};
+                                }
+                             }
+                        }
+                        if ($showcheckbox) {
+                            $r->print('<td><input type="checkbox" name="'.
+                                      'actionlist" value="'.$checkval.'" /></td>');
+                        } else {
+                            $r->print('<td> </td>');
                         }
-                        $r->print('<td><input type="checkbox" name="'.
-                                  'actionlist" value="'.$checkval.'" /></td>');
                     } else {
                         $r->print('<td> </td>');
                     }
@@ -3110,15 +3125,20 @@
     }
     if ($context eq 'course') {
         if ($env{'form.showrole'} ne 'Any') {
-             if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
-                                           $env{'request.course.id'})) {
-                 if ($env{'request.course.sec'} eq '') {
-                     return;
-                 } else {
-                     if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
-                         return;
-                     }
-                 }
+            my $showactions;
+            if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
+                                          $env{'request.course.id'})) {
+                $showactions = 1;  
+            } elsif ($env{'request.course.sec'} ne '') {
+                if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
+                    $showactions = 1;
+                }
+            }
+            unless ($showactions) {
+                unless (&is_courseowner($env{'request.course.id'},
+                                       $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
+                    return; 
+                }
             }
         }
     }
@@ -5751,5 +5771,20 @@
     return %alerts;
 }
 
+sub is_courseowner {
+    my ($thiscourse,$courseowner) = @_;
+    if ($courseowner eq '') {
+        if ($env{'request.course.id'} eq $thiscourse) {
+            $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
+        }
+    }
+    if ($courseowner ne '') {
+        if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
+            return 1;
+        }
+    }
+    return;
+}
+
 1;
 
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.364 loncom/interface/loncreateuser.pm:1.365
--- loncom/interface/loncreateuser.pm:1.364	Tue Aug 21 01:50:33 2012
+++ loncom/interface/loncreateuser.pm	Tue Aug 21 15:43:27 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.364 2012/08/21 01:50:33 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.365 2012/08/21 15:43:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1651,7 +1651,7 @@
                 $allowed=1;
             }
             unless ($allowed) {
-                my $isowner = &is_courseowner($cid,$coursedata{'internal.courseowner'});
+                my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
                 if ($isowner) {
                     if (($role_code eq 'co') && ($class eq 'Community')) {
                         $allowed = 1;
@@ -6439,7 +6439,7 @@
 	my $thiscourse=$protectedcourse;
 	$thiscourse=~s:_:/:g;
 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
-        my $isowner = &is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
+        my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
 	my $area=$coursedata{'description'};
         my $crstype=$coursedata{'type'};
 	if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
@@ -6963,21 +6963,6 @@
     return (\@row,\%lt);
 }
 
-sub is_courseowner {
-    my ($thiscourse,$courseowner) = @_;
-    if ($courseowner eq '') {
-        if ($env{'request.course.id'} eq $thiscourse) {
-            $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
-        }
-    }
-    if ($courseowner ne '') {
-        if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
-            return 1;
-        }
-    }
-    return;
-}
-
 #---------------------------------------------- end functions for &phase_two
 
 #--------------------------------- functions for &phase_two and &phase_three




More information about the LON-CAPA-cvs mailing list