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

raeburn lon-capa-cvs@mail.lon-capa.org
Wed, 07 Jun 2006 21:15:13 -0000


This is a MIME encoded message

--raeburn1149714913
Content-Type: text/plain

raeburn		Wed Jun  7 17:15:13 2006 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  file_permissions.db now stores information for each file as an array of arrays and a hash. In the hash, keys can either be accesscount or access. For key = access value is an anonymous hash containing key=value pairs defining access controls. For key = accesscount, value is a scalar (integer to be used when creating the next accesscontrol). Documentation added.
  
  
--raeburn1149714913
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060607171513.txt"

Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.102 loncom/interface/portfolio.pm:1.103
--- loncom/interface/portfolio.pm:1.102	Wed Jun  7 14:41:48 2006
+++ loncom/interface/portfolio.pm	Wed Jun  7 17:15:01 2006
@@ -136,21 +136,6 @@
                                                   $current_permissions,$group);
     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
     my $now = time;
-    my $curr_access;
-    my $pub_access = 0;
-    foreach my $key (sort(keys(%access_controls))) {
-        my ($scope,$end,$start) = ($key =~ /^\d+:(\w+)_(\d*)_?(\d*)$/);
-        if (($now > $start) && (!$end || $end > $now)) {
-            if ($scope eq 'public')  {
-                $pub_access = 1;
-            }
-         }
-    }
-    if (!$pub_access) {
-        $curr_access = 'Private'
-    } elsif ($pub_access) {
-        $curr_access = 'Public';
-    }
     if ($env{"form.mode"} eq 'selectfile'){
 	&select_files($r);
 	$checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
@@ -203,6 +188,8 @@
                 $r->print('</tr>'); 
             } else {
                 $r->print('<tr bgcolor="#CCCCFF">');
+                my $fullpath = $current_path.$filename;
+                $fullpath = &prepend_group($fullpath,$group);
                 if ($select_mode eq 'true'){
                     $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"');
                     if ($$checked_files{$filename} eq 'selected') {
@@ -210,7 +197,7 @@
                     }
                     $r->print('></td>');
                 } else {
-                    if (exists $locked_files{$current_path.$filename}){
+                    if (exists $locked_files{$fullpath}) {
                         $r->print('<td colspan="2"><a href="'.$url.'?lockinfo='.$current_path.$filename.$groupecho.'">Locked</a></td>');
                     } else {
 			my $cat='<img alt="'.&mt('Catalog Information').
@@ -221,6 +208,22 @@
                             </td>');
                     }
                 }
+                my $curr_access;
+                my $pub_access = 0;
+                foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
+                    my ($scope,$end,$start) = ($key =~ /^\d+:(\w+)_(\d*)_?(\d*)$/);
+                    if (($now > $start) && (!$end || $end > $now)) {
+                        if ($scope eq 'public')  {
+                            $pub_access = 1;
+                            last;
+                        }
+                    }
+                }
+                if (!$pub_access) {
+                    $curr_access = 'Private'
+                } elsif ($pub_access) {
+                    $curr_access = 'Public';
+                }
                 $r->print('<td><img src="'.&Apache::loncommon::icon($filename).'"></td>');
                 $r->print('<td><a href="'.$href_location.$filename.'">'.
 			    $filename.'</a></td>'); 
@@ -554,10 +557,6 @@
     if (defined($file_name) && defined($$current_permissions{$file_name})) {
         foreach my $array_item (@{$$current_permissions{$file_name}}) {
             if (ref($array_item) eq 'ARRAY') {
-                if ($$array_item[0] eq 'access' ||
-                    $$array_item[0] eq 'accesscount' ) {
-                    next;
-                }
                 my $filetext;
                 if (defined($group)) {
                     $filetext = '<strong>'.$env{'form.lockinfo'}.
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.745 loncom/lonnet/perl/lonnet.pm:1.746
--- loncom/lonnet/perl/lonnet.pm:1.745	Wed Jun  7 14:41:57 2006
+++ loncom/lonnet/perl/lonnet.pm	Wed Jun  7 17:15:10 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.745 2006/06/07 18:41:57 raeburn Exp $
+# $Id: lonnet.pm,v 1.746 2006/06/07 21:15:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4555,18 +4555,13 @@
 		      $env{'user.domain'},$env{'user.name'});
     my ($tmp)=keys(%locked);
     if ($tmp=~/^error:/) { undef(%locked); }
-
     
     if (ref($locked{$file_name}) eq 'ARRAY') {
         $is_locked = 'false';
         foreach my $entry (@{$locked{$file_name}}) {
            if (ref($entry) eq 'ARRAY') { 
-               if ($$entry[0] eq 'access' || $$entry[0] eq 'accesscount') {
-                   next;
-               } else {
-                   $is_locked = 'true';
-                   last;
-               }
+               $is_locked = 'true';
+               last;
            }
        }
     } else {
@@ -4660,6 +4655,7 @@
 #----------------------------------------------Get portfolio file permissions
 
 sub get_portfile_permissions {
+    # returns a reference to a hash containing contents of file_permissions.db 
     my ($domain,$user) = @_;
     my %current_permissions = &dump('file_permissions',$domain,$user);
     my ($tmp)=keys(%current_permissions);
@@ -4670,6 +4666,20 @@
 #---------------------------------------------Get portfolio file access controls
 
 sub get_access_controls  {
+    # returns a hash containing access control information retrieved from
+    # file_permissions.db. The hash contains key=value pairs where key is
+    # the control type, end date and start date, in the form type_end_start
+    # and value is a string containing access control settings (in XML),
+    #
+    # Internally access_controls are stored in file_permissions.db in an
+    # array of arrays and a hash, where arrays are locks set when a portfolio   
+    # file has been uploaded to an essayresponse problem in a course, and
+    # the hash contains other data. Two keys are currently defined in the hash:  
+    # access and accesscount. The value for accesscount is a scalar - equal to 
+    # the next number to use as the first part of an access control key
+    # when defining a new control. The value for access is an anonymous hash
+    # where keys are access controls and values are settings.
+    #    
     my ($current_permissions,$group,$file) = @_;
     my @access_checks = ();
     my %access; 
@@ -4687,15 +4697,8 @@
         }
         if (ref($value) eq "ARRAY") {
             foreach my $stored_what (@{$value}) {
-                if (ref($stored_what) eq 'ARRAY') {
-                    if ($$stored_what[0] eq 'access') {
-                        if (!defined($access{$file_name})) {
-                            %{$access{$file_name}} = ();
-                        } 
-                        $access{$file_name}{$$stored_what[1]}=$$stored_what[2];
-                    } else {
-                        next;
-                    }
+                if (ref($stored_what) eq 'HASH') {
+                    $access{$file_name} = $$stored_what{'access'};
                 }
             }
         }
@@ -4720,13 +4723,10 @@
         if (ref($value) eq "ARRAY"){
             foreach my $stored_what (@{$value}) {
                 my $cmp2=$stored_what;
-                if (ref($stored_what)) {
-                    if ($$stored_what[0] eq 'access' || 
-                        $$stored_what[0] eq 'accesscount') {
-                        next;
-                    } else {
-                        $cmp2=join('',@{$stored_what});
-                    }
+                if (ref($stored_what eq 'HASH')) {
+                    next;
+                } elsif (ref($stored_what eq 'ARRAY')) {
+                    $cmp2=join('',@{$stored_what});
                 }
                 if ($cmp1 eq $cmp2) {
                     push(@readonly_files, $file_name);
@@ -4754,16 +4754,12 @@
         if (ref($value) eq "ARRAY"){
             foreach my $stored_what (@{$value}) {
                 if (ref($stored_what) eq 'ARRAY') {
-                    if ($$stored_what[0] eq 'access' ||
-                        $$stored_what[0] eq 'accesscount') {
-                        next;
+                    if ($stored_what eq $what) {
+                        $readonly_files{$file_name} = 'locked';
+                    } elsif (!defined($what)) {
+                        $readonly_files{$file_name} = 'locked';
                     }
                 }
-                if ($stored_what eq $what) {
-                    $readonly_files{$file_name} = 'locked';
-                } elsif (!defined($what)) {
-                    $readonly_files{$file_name} = 'locked';
-                }
             }
         } 
     }
@@ -4789,16 +4785,13 @@
         if (ref($current_locks) eq "ARRAY"){
             foreach my $locker (@{$current_locks}) {
                 my $compare=$locker;
-                if (ref($locker) eq 'ARRAY') {
-                    if ($$locker[0] eq 'access' || 
-                        $$locker[0] eq 'accesscount') {
-                        push(@new_locks,$locker);
-                        next;
-                    }   
+                if (!ref($locker) eq 'ARRAY') {
+                    push(@new_locks,$locker);
+                } else {   
                     $compare=join('',@{$locker});
-                }
-                if ($compare ne $symb_crs) {
-                    push(@new_locks, $locker);
+                    if ($compare ne $symb_crs) {
+                        push(@new_locks, $locker);
+                    }
                 }
             }
             if (scalar(@new_locks) > 0) {

--raeburn1149714913--