[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm portfolio.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 11 Dec 2006 03:43:17 -0000


This is a MIME encoded message

--raeburn1165808597
Content-Type: text/plain

raeburn		Sun Dec 10 22:43:17 2006 EDT

  Modified files:              
    /loncom/interface	portfolio.pm loncommon.pm 
  Log:
  Block access to portfolio functions during blocking events unless 'evb' privilege.
  
  Add blocking_status() - called by lonaboutme.pm, lonsimplepage.pm, lonfeedback.pm, portfolio.pm to display block condition
  
  blockcheck() modified so blocking condition is only checked for current course for discussion, chat and group homepage
  
  blockcheck() also modified so that if check is being made for blocking conditions for other than current user (e.g., portfolio files, blogs), check is made for 'evb' privilege for current user for any courses being checked for blokcing conditions.  
  
  
--raeburn1165808597
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20061210224317.txt"

Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.174 loncom/interface/portfolio.pm:1.175
--- loncom/interface/portfolio.pm:1.174	Tue Nov 21 22:56:36 2006
+++ loncom/interface/portfolio.pm	Sun Dec 10 22:43:15 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # portfolio browser
 #
-# $Id: portfolio.pm,v 1.174 2006/11/22 03:56:36 raeburn Exp $
+# $Id: portfolio.pm,v 1.175 2006/12/11 03:43:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2038,7 +2038,6 @@
     return $disk_quota;
 }
 
-
 sub handler {
     # this handles file management
     my $r = shift;
@@ -2134,6 +2133,13 @@
         $r->print(&Apache::loncommon::start_page($title));
     }
     $r->rflush();
+    my ($blocked,$blocktext) = 
+        &Apache::loncommon::blocking_status('port',$uname,$udom);
+    if ($blocked) {
+         $r->print($blocktext);
+         $r->print(&Apache::loncommon::end_page());
+         return OK;
+    }
 	if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
    	    $r->print('<span class="LC_error">'.
 		      'No file was selected to upload.'.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.489 loncom/interface/loncommon.pm:1.490
--- loncom/interface/loncommon.pm:1.489	Fri Dec  8 15:09:29 2006
+++ loncom/interface/loncommon.pm	Sun Dec 10 22:43:15 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.489 2006/12/08 20:09:29 raeburn Exp $
+# $Id: loncommon.pm,v 1.490 2006/12/11 03:43:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2850,7 +2850,7 @@
                 $cnum = $cnumpart;
                 ($sec,$role) = split(/_/,$secpart);
                 $realsec = $sec;
-            }   
+            }
             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
         }
     } else {
@@ -2885,15 +2885,50 @@
 
 sub blockcheck {
     my ($setters,$activity,$uname,$udom) = @_;
-    # Retrieve active course roles - course coordinator, instructor, exam proctor, ta, student or custom role.
+
+    if (!defined($udom)) {
+        $udom = $env{'user.domain'};
+    }
+    if (!defined($uname)) {
+        $uname = $env{'user.name'};
+    }
+
+    my ($startblock,$endblock);
+
+    # If uname and udom are for a course, check for blocks in the course.
+
+    if (&Apache::lonnet::is_course($udom,$uname)) {
+        my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
+        ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
+        return ($startblock,$endblock);
+    }
 
     my %live_courses = &findallcourses(undef,$uname,$udom);
 
-    # Retrieve blocking times and identity of blocker for active courses
-    # of specified user, unless user has 'evb' privilege.
+    # If uname is for a user, and activity is course-specific, i.e.,
+    # boards, chat or groups, check for blocking in current course only.
 
-    my $startblock = 0;
-    my $endblock = 0;
+    if (($activity eq 'boards' || $activity eq 'chat' ||
+         $activity eq 'groups') && ($env{'request.course.id'})) {
+        foreach my $key (keys(%live_courses)) {
+            if ($key ne $env{'request.course.id'}) {
+                delete($live_courses{$key});
+            }
+        }
+    }
+
+    my $otheruser = 0;
+    my %own_courses;
+    if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
+        # Resource belongs to user other than current user.
+        $otheruser = 1;
+        # Gather courses for current user
+        %own_courses = 
+            &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
+    }
+
+    # Gather active course roles - course coordinator, instructor, 
+    # exam proctor, ta, student, or custom role.
 
     foreach my $course (keys(%live_courses)) {
         my ($cdom,$cnum);
@@ -2901,17 +2936,38 @@
             $cdom = $env{'course.'.$course.'.domain'};
             $cnum = $env{'course.'.$course.'.num'};
         } else {
-           ($cdom,$cnum) = split(/_/,$course); 
+            ($cdom,$cnum) = split(/_/,$course); 
         }
         my $no_ownblock = 0;
         my $no_userblock = 0;
+        if ($otheruser) {
+            # Check if current user has 'evb' priv for this
+            if (defined($own_courses{$course})) {
+                foreach my $sec (keys(%{$own_courses{$course}})) {
+                    my $checkrole = 'cm./'.$cdom.'/'.$cnum;
+                    if ($sec ne 'none') {
+                        $checkrole .= '/'.$sec;
+                    }
+                    if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
+                        $no_ownblock = 1;
+                        last;
+                    }
+                }
+            }
+            # if they have 'evb' priv and are currently not playing student
+            next if (($no_ownblock) &&
+                 ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
+        }
         foreach my $sec (keys(%{$live_courses{$course}})) {
             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
             if ($sec ne 'none') {
                 $checkrole .= '/'.$sec;
             }
-            if ((defined($uname) && ($uname ne $env{'user.name'})) ||
-                 (defined($udom) && ($udom ne $env{'user.domain'}))) { 
+            # Resource belongs to user other than current user.
+            # Assemble privs for that user, and check for 'evb' priv.  
+            if ($otheruser) {
+                # Resource belongs to user other than current user.
+                # Assemble privs for that user, and check for 'evb' priv.
                 my ($trole,$tdom,$tnum,$tsec);
                 my $entry = $live_courses{$course}{$sec};
                 if ($entry =~ /^cr/) {
@@ -2942,7 +2998,9 @@
                         last;
                     }
                 }
-             } else {
+            } else {
+                # Resource belongs to current user
+                # Check for 'evb' priv via lonnet::allowed().
                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                     $no_ownblock = 1;
                     last;
@@ -2954,23 +3012,36 @@
                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
         next if ($no_userblock);
 
-        $setters->{$course} = {};
-        $setters->{$course}{'staff'} = [];
-        $setters->{$course}{'times'} = [];
-        my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
-        foreach my $record (keys(%records)) {
-            my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
-            if ($start <= time && $end >= time) {
-                my ($staff_name,$staff_dom,$title,$blocks) =
-                    &parse_block_record($records{$record});
-                if ($blocks->{$activity} eq 'on') {
-                    push(@{$$setters{$course}{'staff'}}, [$staff_name,$staff_dom]);                    push(@{$$setters{$course}{'times'}}, [$start,$end]);
-                    if ( ($startblock == 0) || ($startblock > $1) ) {
-                        $startblock = $1;
-                    }
-                    if ( ($endblock == 0) || ($endblock < $2) ) {
-                        $endblock = $2;
-                    }
+        # Retrieve blocking times and identity of blocker for course
+        # of specified user, unless user has 'evb' privilege.
+
+        ($startblock,$endblock)=&get_blocks($setters,$activity,$cdom,$cnum);
+    }
+    return ($startblock,$endblock);
+}
+
+sub get_blocks {
+    my ($setters,$activity,$cdom,$cnum) = @_;
+    my $startblock = 0;
+    my $endblock = 0;
+    my $course = $cdom.'_'.$cnum;
+    $setters->{$course} = {};
+    $setters->{$course}{'staff'} = [];
+    $setters->{$course}{'times'} = [];
+    my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
+    foreach my $record (keys(%records)) {
+        my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
+        if ($start <= time && $end >= time) {
+            my ($staff_name,$staff_dom,$title,$blocks) =
+                &parse_block_record($records{$record});
+            if ($blocks->{$activity} eq 'on') {
+                push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
+                push(@{$$setters{$course}{'times'}}, [$start,$end]);
+                if ( ($startblock == 0) || ($startblock > $1) ) {
+                    $startblock = $1;
+                }
+                if ( ($endblock == 0) || ($endblock < $2) ) {
+                    $endblock = $2;
                 }
             }
         }
@@ -3020,20 +3091,83 @@
         my %courseinfo=&Apache::lonnet::coursedescription($course);
         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
-            my $fullname = &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
+            my $fullname = &plainname($uname,$udom);
+            if (defined($env{'user.name'}) && defined($env{'user.domain'})
+                && $env{'user.name'} ne 'public' 
+                && $env{'user.domain'} ne 'public') {
+                $fullname = &aboutmewrapper($fullname,$uname,$udom);
+            }
             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
             $openblock = &Apache::lonlocal::locallocaltime($openblock);
             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
             $output .= &Apache::loncommon::start_data_table_row().
                        '<td>'.$courseinfo{'description'}.'</td>'.
                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
-                       '<td>'.$fullname.'.</td>'.
+                       '<td>'.$fullname.'</td>'.
                         &Apache::loncommon::end_data_table_row();
         }
     }
     $output .= &end_data_table();
 }
 
+sub blocking_status {
+    my ($activity,$uname,$udom) = @_;
+    my %setters;
+    my ($blocked,$output,$ownitem,$is_course);
+    my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
+    if ($startblock && $endblock) {
+        $blocked = 1;
+        if (wantarray) {
+            my $category;
+            if ($activity eq 'boards') {
+                $category = 'Discussion posts in this course';
+            } elsif ($activity eq 'blogs') {
+                $category = 'Blogs';
+            } elsif ($activity eq 'port') {
+                if (defined($uname) && defined($udom)) {
+                    if ($uname eq $env{'user.name'} &&
+                        $udom eq $env{'user.domain'}) {
+                        $ownitem = 1;
+                    }
+                }
+                $is_course = &Apache::lonnet::is_course($udom,$uname);
+                if ($ownitem) { 
+                    $category = 'Your portfolio files';  
+                } elsif ($is_course) {
+                    my $coursedesc;
+                    foreach my $course (keys(%setters)) {
+                        my %courseinfo =
+                             &Apache::lonnet::coursedescription($course);
+                        $coursedesc = $courseinfo{'description'};
+                    }
+                    $category = "Group files in the course '$coursedesc'";
+                } else {
+                    $category = 'Portfolio files belonging to ';
+                    if ($env{'user.name'} eq 'public' && 
+                        $env{'user.domain'} eq 'public') {
+                        $category .= &plainname($uname,$udom);
+                    } else {
+                        $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
+                    }
+                }
+            } elsif ($activity eq 'groups') {
+                $category = 'Groups in this course';
+            }
+            my $showstart = &Apache::lonlocal::locallocaltime($startblock);
+            my $showend = &Apache::lonlocal::locallocaltime($endblock);
+            $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
+            if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
+                $output .= &build_block_table($startblock,$endblock,\%setters);
+            }
+        }
+    }
+    if (wantarray) {
+        return ($blocked,$output);
+    } else {
+        return $blocked;
+    }
+}
+
 ###############################################
 
 =pod

--raeburn1165808597--