[LON-CAPA-cvs] cvs: loncom /interface portfolio.pm /lonnet/perl lonnet.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Wed, 07 Jun 2006 18:42:00 -0000
This is a MIME encoded message
--raeburn1149705720
Content-Type: text/plain
raeburn Wed Jun 7 14:42:00 2006 EDT
Modified files:
/loncom/interface portfolio.pm
/loncom/lonnet/perl lonnet.pm
Log:
Work in progress. Adding access control entry to file_permissions.db. Current implementation is as additional arrays in array of arrays for each key (key =f file name - including path). New arrays contain either 'access' or 'accesscount' as first element. These will become hashes in the next iteration. Added column to portfolio directory displays to show access status. Some fixes to paths to handle coursegroup portfolios - e.g., new &prepend_group() function.
--raeburn1149705720
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060607144200.txt"
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.101 loncom/interface/portfolio.pm:1.102
--- loncom/interface/portfolio.pm:1.101 Tue May 30 08:46:09 2006
+++ loncom/interface/portfolio.pm Wed Jun 7 14:41:48 2006
@@ -126,12 +126,31 @@
my $checked_files;
my $port_path = &get_port_path($group);
my ($uname,$udom) = &get_name_dom($group);
- my $namespace = &get_namespace($group);
if (defined($group)) {
$groupitem = '<input type="hidden" name="group" value="'.$group.'" />';
$groupecho = '&group='.$group;
}
- my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($namespace,$udom,$uname);
+ my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
+ $uname);
+ my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
+ $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'});
@@ -154,7 +173,7 @@
$r->print('<form method="post" name="checkselect" action="'.$url.'">');
} else {
$r->print('<table border="0" cellspacing="2" cellpadding="2">'.
- '<tr><th colspan="2">Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
+ '<tr><th colspan="2">Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th><th>Current Access Status</th></tr>');
$r->print('<form method="post" action="'.$url.'">');
}
if (defined($group)) {
@@ -185,7 +204,7 @@
} else {
$r->print('<tr bgcolor="#CCCCFF">');
if ($select_mode eq 'true'){
- $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"');
+ $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"');
if ($$checked_files{$filename} eq 'selected') {
$r->print("CHECKED");
}
@@ -207,6 +226,10 @@
$filename.'</a></td>');
$r->print('<td>'.$size.'</td>');
$r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
+ $r->print('<td><nobr>'.&mt($curr_access).' '.
+ '<a href="'.$url.'?access='.$filename.
+ '&currentpath='.$current_path.$groupecho.
+ '">'.&mt('View/Change').'</a></nobr></td>');
$r->print('</tr>');
}
}
@@ -232,7 +255,7 @@
sub open_form {
my ($r,$url)=@_;
my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
- $r->print('<form method="post" action="'.$url.'">');
+ $r->print('<form name="portform" method="post" action="'.$url.'">');
$r->print('<input type="hidden" name="action" value="'.
$env{'form.action'}.'" />');
$r->print('<input type="hidden" name="confirmed" value="1" />');
@@ -301,6 +324,7 @@
my ($r,$url,$group)=@_;
my @check;
my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
+ $file_name = &prepend_group($file_name,$group);
my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
my ($uname,$udom) = &get_name_dom($group);
if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
@@ -376,6 +400,7 @@
my ($r,$url,$group)=@_;
my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
my ($uname,$udom) = &get_name_dom($group);
+ $file_name = &prepend_group($file_name,$group);
if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
$r->print ("The file is locked and cannot be renamed.<br />");
$r->print(&done(undef,$url,$group));
@@ -413,6 +438,7 @@
}
$r->print(&done(undef,$url,$group));
}
+
sub select_files {
my ($r,$group)=@_;
if ($env{'form.continue'} eq 'true') {
@@ -479,8 +505,13 @@
foreach my $line (@dir_list) {
my ($file_name)=split(/\&/,$line,2);
if ($file_name eq $fname){
+ $file_name = $env{'form.currentpath'}.$file_name;
+ $file_name = &prepend_group($file_name,$group);
$found_file = 1;
- if (&Apache::lonnet::is_locked($env{'form.currentpath'}.$file_name,$udom,$uname) eq 'true') {
+ if (defined($group)) {
+ $file_name = $group.'/'.$file_name;
+ }
+ if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
$locked_file = 1;
}
}
@@ -516,21 +547,35 @@
sub lock_info {
my ($r,$url,$group) = @_;
my ($uname,$udom) = &get_name_dom($group);
- my %current_permissions = &Apache::lonnet::dump('file_permissions',$udom,$uname);
+ my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
+ $uname);
my $file_name = $env{'form.lockinfo'};
- foreach my $key(keys(%current_permissions)) {
- if ($file_name eq $key) {
- foreach my $array_item (@{$current_permissions{$key}}) {
- if (ref($array_item)) {
- $r->print('<strong>'.$key.'</strong> was submitted in response to problem: <strong>'.
- &Apache::lonnet::gettitle($$array_item[0]).'</strong><br />');
- my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
- $r->print('In the course: <strong>'.$course_description{'description'}.'</strong><br />');
- # $r->print('the third is '.$$array_item[2].'<br>');
- # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
+ $file_name = &prepend_group($file_name,$group);
+ 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'}.
+ '</strong> (group: '.$group.')';
+ } else {
+ $filetext = '<strong>'.$file_name.'</strong>';
+ }
+ $r->print(&mt('[_1] was submitted in response to problem: ',
+ $filetext).
+ '<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
+ '</strong><br />');
+ my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
+ $r->print(&mt('In the course: <strong>[_1]</strong><br />',
+ $course_description{'description'}));
+ # $r->print('the third is '.$$array_item[2].'<br>');
+ # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
}
- }
+ }
}
$r->print(&done('Back',$url,$group));
return 'ok';
@@ -605,6 +650,14 @@
return ($uname,$udom);
}
+sub prepend_group {
+ my ($filename,$group) = @_;
+ if (defined($group)) {
+ $filename = $group.'/'.$filename;
+ }
+ return $filename;
+}
+
sub get_namespace {
my ($group) = @_;
my $namespace = 'portfolio';
@@ -631,7 +684,7 @@
my $r = shift;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['selectfile','currentpath','meta','lockinfo','currentfile',
- 'action','fieldname','mode','rename','continue','group']);
+ 'action','fieldname','mode','rename','continue','group','access']);
my ($uname,$udom,$portfolio_root,$url,$group,$caller,$title);
if ($r->uri =~ m|^(/adm/)([^/]+)|) {
$url = $1.$2;
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.744 loncom/lonnet/perl/lonnet.pm:1.745
--- loncom/lonnet/perl/lonnet.pm:1.744 Mon Jun 5 16:09:19 2006
+++ loncom/lonnet/perl/lonnet.pm Wed Jun 7 14:41:57 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.744 2006/06/05 20:09:19 albertel Exp $
+# $Id: lonnet.pm,v 1.745 2006/06/07 18:41:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -4556,8 +4556,19 @@
my ($tmp)=keys(%locked);
if ($tmp=~/^error:/) { undef(%locked); }
+
if (ref($locked{$file_name}) eq 'ARRAY') {
- $is_locked = 'true';
+ $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;
+ }
+ }
+ }
} else {
$is_locked = 'false';
}
@@ -4646,44 +4657,108 @@
return (@return_files);
}
-#--------------------------------------------------------------Get Marked as Read Only
-
+#----------------------------------------------Get portfolio file permissions
-sub get_marked_as_readonly {
- my ($domain,$user,$what) = @_;
+sub get_portfile_permissions {
+ my ($domain,$user) = @_;
my %current_permissions = &dump('file_permissions',$domain,$user);
my ($tmp)=keys(%current_permissions);
if ($tmp=~/^error:/) { undef(%current_permissions); }
+ return \%current_permissions;
+}
+
+#---------------------------------------------Get portfolio file access controls
+
+sub get_access_controls {
+ my ($current_permissions,$group,$file) = @_;
+ my @access_checks = ();
+ my %access;
+ if (defined($file)) {
+ @access_checks = ($file);
+ } else {
+ @access_checks = keys(%{$current_permissions});
+ }
+ foreach my $file_name (@access_checks) {
+ my $value = $$current_permissions{$file_name};
+ if (defined($group)) {
+ if ($file_name !~ m-^\Q$group\E/-) {
+ next;
+ }
+ }
+ 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;
+ }
+ }
+ }
+ }
+ }
+ return %access;
+}
+
+#------------------------------------------------------Get Marked as Read Only
+
+sub get_marked_as_readonly {
+ my ($domain,$user,$what,$group) = @_;
+ my $current_permissions = &get_portfile_permissions($domain,$user);
my @readonly_files;
my $cmp1=$what;
if (ref($what)) { $cmp1=join('',@{$what}) };
- while (my ($file_name,$value) = each(%current_permissions)) {
+ while (my ($file_name,$value) = each(%{$current_permissions})) {
+ if (defined($group)) {
+ if ($file_name !~ m-^\Q$group\E/-) {
+ next;
+ }
+ }
if (ref($value) eq "ARRAY"){
foreach my $stored_what (@{$value}) {
my $cmp2=$stored_what;
- if (ref($stored_what)) { $cmp2=join('',@{$stored_what}) };
+ if (ref($stored_what)) {
+ if ($$stored_what[0] eq 'access' ||
+ $$stored_what[0] eq 'accesscount') {
+ next;
+ } else {
+ $cmp2=join('',@{$stored_what});
+ }
+ }
if ($cmp1 eq $cmp2) {
push(@readonly_files, $file_name);
+ last;
} elsif (!defined($what)) {
push(@readonly_files, $file_name);
+ last;
}
}
- }
+ }
}
return @readonly_files;
}
#-----------------------------------------------------------Get Marked as Read Only Hash
sub get_marked_as_readonly_hash {
- my ($domain,$user,$what) = @_;
- my %current_permissions = &dump('file_permissions',$domain,$user);
- my ($tmp)=keys(%current_permissions);
- if ($tmp=~/^error:/) { undef(%current_permissions); }
-
+ my ($current_permissions,$group,$what) = @_;
my %readonly_files;
- while (my ($file_name,$value) = each(%current_permissions)) {
+ while (my ($file_name,$value) = each(%{$current_permissions})) {
+ if (defined($group)) {
+ if ($file_name !~ m-^\Q$group\E/-) {
+ next;
+ }
+ }
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)) {
@@ -4699,13 +4774,13 @@
sub unmark_as_readonly {
# unmarks $file_name (if $file_name is defined), or all files locked by $what
# for portfolio submissions, $what contains [$symb,$crsid]
- my ($domain,$user,$what,$file_name) = @_;
+ my ($domain,$user,$what,$file_name,$group) = @_;
my $symb_crs = $what;
if (ref($what)) { $symb_crs=join('',@$what); }
- my %current_permissions = &dump('file_permissions',$domain,$user);
+ my %current_permissions = &dump('file_permissions',$domain,$user,$group);
my ($tmp)=keys(%current_permissions);
if ($tmp=~/^error:/) { undef(%current_permissions); }
- my @readonly_files = &get_marked_as_readonly($domain,$user,$what);
+ my @readonly_files = &get_marked_as_readonly($domain,$user,$what,$group);
foreach my $file (@readonly_files) {
if (defined($file_name) && ($file_name ne $file)) { next; }
my $current_locks = $current_permissions{$file};
@@ -4714,7 +4789,14 @@
if (ref($current_locks) eq "ARRAY"){
foreach my $locker (@{$current_locks}) {
my $compare=$locker;
- if (ref($locker)) { $compare=join('',@{$locker}) };
+ if (ref($locker) eq 'ARRAY') {
+ if ($$locker[0] eq 'access' ||
+ $$locker[0] eq 'accesscount') {
+ push(@new_locks,$locker);
+ next;
+ }
+ $compare=join('',@{$locker});
+ }
if ($compare ne $symb_crs) {
push(@new_locks, $locker);
}
--raeburn1149705720--