[LON-CAPA-cvs] cvs: loncom /interface lonaboutme.pm lonmenu.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Fri Nov 9 12:27:18 EST 2012


raeburn		Fri Nov  9 17:27:18 2012 EDT

  Modified files:              
    /loncom/interface	lonmenu.pm lonaboutme.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Consistent Interface for templated pages (bug 6128).
  - Make functions for Templated "About Me" page visible.
  - Additional arg for lonnet::in_course() -- $hideprivileged
    - if true, exclude DC + SU users, unless overridden in course environment. 
  - perldoc (lonnet.pm): &in_course(), &can_edit_resource(), &is_course_upload() 
  
  
-------------- next part --------------
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.390 loncom/interface/lonmenu.pm:1.391
--- loncom/interface/lonmenu.pm:1.390	Thu Nov  8 18:37:44 2012
+++ loncom/interface/lonmenu.pm	Fri Nov  9 17:27:10 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.390 2012/11/08 18:37:44 raeburn Exp $
+# $Id: lonmenu.pm,v 1.391 2012/11/09 17:27:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -492,15 +492,8 @@
                        || $forcereg );
     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
         $forceview,$editbutton);
-    if ($env{'request.noversionuri'} =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) {
-        ($cfile,$home,$switchserver,$forceedit,$forceview) =
-            &Apache::lonnet::can_edit_resource($env{'request.noversionuri'},$cnum,$cdom,
-                &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
-        if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
-            $editbutton = &get_editbutton($cfile,$home,$switchserver,
-                                          $forceedit,$forceview,$forcereg);
-        }
-    } elsif ($env{'request.role'} !~/^(aa|ca|au)/) {
+    if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
+        ($env{'request.role'} !~/^(aa|ca|au)/)) {
         $editbutton = &prepare_functions($resurl,$forcereg,$group);
     }
     if ($editbutton eq '') {
@@ -763,19 +756,15 @@
 # Determine whether or not to display 'Edit' icon/button
 #
     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
-#
-# This applies to a user's own about me page
-#
-        my ($sdom,$sname) = ($1,$2);
         my $file=&Apache::lonnet::declutter($env{'request.filename'});
-        if (($sdom eq $env{'user.domain'}) && ($sname eq $env{'user.name'})) {
-            ($cfile,$home,$switchserver,$forceedit,$forceview) =
-                &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
-                    &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
-            $editbutton = &get_editbutton($cfile,$env{'user.home'},$switchserver,
+        ($cfile,$home,$switchserver,$forceedit,$forceview) =
+            &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
+                &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
+        if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
+            $editbutton = &get_editbutton($cfile,$home,$switchserver,
                                           $forceedit,$forceview,$forcereg);
         }
-    } elsif ((!$editbutton) && (!$env{'request.course.id'}) &&
+    } elsif ((!$env{'request.course.id'}) &&
              ($env{'user.author'}) && ($env{'request.filename'}) &&
              ($env{'request.role'} !~/^(aa|ca|au)/)) {
 #
@@ -786,7 +775,6 @@
         ($cfile,$home,$switchserver,$forceedit,$forceview) =
             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
-        # Turn the button on or off
         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                                           $forceedit,$forceview,$forcereg);
@@ -830,7 +818,7 @@
 
 # This applies to about me page for users in a course
     if ($env{'request.course.id'}) {
-        if ($resurl =~ m{^adm/($match_domain)/($match_username)/aboutme$}) {
+        if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
             my ($sdom,$sname) = ($1,$2);
             unless (&Apache::lonnet::is_course($sdom,$sname)) {
                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
@@ -838,7 +826,9 @@
                         "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
                             'Send message to specific user');
             }
-            if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum)) {
+            my $hideprivileged = 1;
+            if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
+                                           $hideprivileged)) {
                 foreach my $priv ('vsa','vgr','srm') {
                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
Index: loncom/interface/lonaboutme.pm
diff -u loncom/interface/lonaboutme.pm:1.150 loncom/interface/lonaboutme.pm:1.151
--- loncom/interface/lonaboutme.pm:1.150	Thu Nov  8 18:37:44 2012
+++ loncom/interface/lonaboutme.pm	Fri Nov  9 17:27:10 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Personal Information Page
 #
-# $Id: lonaboutme.pm,v 1.150 2012/11/08 18:37:44 raeburn Exp $
+# $Id: lonaboutme.pm,v 1.151 2012/11/09 17:27:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -374,7 +374,7 @@
 
     if ($env{'request.course.id'}
         && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
-        && &Apache::lonnet::in_course($cdom,$cnum)) {
+        && &Apache::lonnet::in_course($cdom,$cnum,$coursedomain,$coursenum,undef,1)) {
         if ($target ne 'tex') {
             $r->print('<a name="coursecomment" />');
             &Apache::lontemplate::print_start_template($r,&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course'),'LC_Box');
@@ -787,7 +787,7 @@
     }
     if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
         (&Apache::lonnet::allowed('dff',$privcheck))) {
-        if (&Apache::lonnet::in_course($uname,$udom,$cnum,$cdom)) {
+        if (&Apache::lonnet::in_course($uname,$udom,$cnum,$cdom,undef,1)) {
             return 1;
         }
     }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1194 loncom/lonnet/perl/lonnet.pm:1.1195
--- loncom/lonnet/perl/lonnet.pm:1.1194	Thu Nov  8 18:37:52 2012
+++ loncom/lonnet/perl/lonnet.pm	Fri Nov  9 17:27:18 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1194 2012/11/08 18:37:52 raeburn Exp $
+# $Id: lonnet.pm,v 1.1195 2012/11/09 17:27:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2800,7 +2800,31 @@
 }
 
 sub in_course {
-    my ($udom,$uname,$cdom,$cnum,$type) = @_;
+    my ($udom,$uname,$cdom,$cnum,$type,$hideprivileged) = @_;
+    if ($hideprivileged) {
+        my $skipuser;
+        if (&privileged($uname,$udom)) {
+            $skipuser = 1;
+            my %coursehash = &coursedescription($cdom.'_'.$cnum);
+            if ($coursehash{'nothideprivileged'}) {
+                foreach my $item (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
+                    my $user;
+                    if ($item =~ /:/) {
+                        $user = $item;
+                    } else {
+                        $user = join(':',split(/[\@]/,$item));
+                    }
+                    if ($user eq $uname.':'.$udom) {
+                        undef($skipuser);
+                        last;
+                    }
+                }
+            }
+            if ($skipuser) {
+                return 0;
+            }
+        }
+    }
     $type ||= 'any';
     if (!defined($cdom) || !defined($cnum)) {
         my $cid  = $env{'request.course.id'};
@@ -2808,7 +2832,7 @@
         $cnum = $env{'course.'.$cid.'.num'};
     }
     my $typesref;
-    if ($type eq 'all') {
+    if (($type eq 'any') || ($type eq 'all')) {
         $typesref = ['active','previous','future'];
     } elsif ($type eq 'previous' || $type eq 'future') {
         $typesref = [$type];
@@ -12233,6 +12257,16 @@
 to restrict the list of roles reported. If no array ref is 
 provided for types, will default to return only active roles.
 
+=item *
+
+in_course($udom,$uname,$cdom,$cnum,$type,$hideprivileged) : determine if
+user: $uname:$udom has a role in the course: $cdom_$cnum. Additional
+optional arguments are: $type (if role checking is to be restricted to
+certain user status types -- previous (expired roles), active (currently
+available roles) or future (roles available in the future), and
+$hideprivileged -- if true will not report course roles for users who
+have active Domain Coordinator or Super User roles.
+
 =back
 
 =head2 User Modification
@@ -12435,7 +12469,6 @@
 values that are the resource value.  I believe that the timestamps and
 versions are also returned.
 
-
 =back
 
 =head2 Course Modification
@@ -12596,6 +12629,36 @@
 devalidate($symb) : devalidate temporary spreadsheet calculations,
 forcing spreadsheet to reevaluate the resource scores next time.
 
+=item * 
+
+can_edit_resource($file,$cnum,$cdom,$resurl,$symb,$group)
+
+Determine if the current user should be able to edit a particular resource,
+when viewing in course context.
+(a) When viewing resource used to determine if "Edit" item is included in
+     Functions.
+(b) When displaying folder contents in course editor, used to determine if
+    "Edit" link will be displayed alongside resource.
+
+ input: 3 args -- filename (decluttered), course number and course domain.
+ output: array of four scalars --
+         $cfile -- url for file editing if editable on current server
+         $home -- homeserver of resource (i.e., for author if published,
+                                          or course if uploaded.).
+         $switchserver --  1 if server switch will be needed.
+         $uploaded -- 1 if resource is a file uploaded to a course.
+
+=item *
+
+is_course_upload($file,$cnum,$cdom)
+
+Used in course context to determine if current file was uploaded to 
+the course (i.e., would be found in /userfiles/docs on the course's 
+homeserver.
+
+  input: 3 args -- filename (decluttered), course number and course domain.
+  output: boolean -- 1 if file was uploaded.
+
 =back
 
 =head2 Storing/Retreiving Data


More information about the LON-CAPA-cvs mailing list