[LON-CAPA-cvs] cvs: loncom /interface portfolio.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Thu, 19 Oct 2006 00:23:21 -0000
raeburn Wed Oct 18 20:23:21 2006 EDT
Modified files:
/loncom/interface portfolio.pm
Log:
Deleting or renaming portfolio file deletes access control records for old file name (renaming and deleting) and adds equivalent ones for new filename (if renaming). Not fully tested.
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.163 loncom/interface/portfolio.pm:1.164
--- loncom/interface/portfolio.pm:1.163 Tue Sep 19 10:02:42 2006
+++ loncom/interface/portfolio.pm Wed Oct 18 20:23:21 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network
# portfolio browser
#
-# $Id: portfolio.pm,v 1.163 2006/09/19 14:02:42 raeburn Exp $
+# $Id: portfolio.pm,v 1.164 2006/10/19 00:23:21 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -538,18 +538,54 @@
}
sub delete_confirmed {
- my ($r,$url)=@_;
+ my ($r,$url,$group)=@_;
my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
my $result;
my ($uname,$udom) = &get_name_dom();
my $port_path = &get_port_path();
+ my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
+ $uname);
foreach my $delete_file (@files) {
$result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
$env{'form.currentpath'}.
$delete_file);
if ($result ne 'ok') {
- $r->print('<span class="LC_error"> An error occured ('.$result.
- ') while trying to delete '.&display_file(undef, $delete_file).'</span><br />');
+ $r->print('<span class="LC_error"> An error occured ('.$result.
+ ') while trying to delete '.
+ &display_file(undef, $delete_file).'</span><br />');
+ } else {
+ $r->print(&mt('File: [_1] deleted.',
+ &display_file(undef,$delete_file)));
+ my $file_name = $env{'form.currentpath'}.$delete_file;
+ $file_name = &prepend_group($file_name);
+ my %access_controls =
+ &Apache::lonnet::get_access_controls($current_permissions,
+ $group,$file_name);
+ if (keys(%access_controls) > 0) {
+ my %changes;
+ foreach my $key (%{$access_controls{$file_name}}) {
+ $changes{'delete'}{$key} = 1;
+ }
+ if (keys(%changes) > 0) {
+ my ($outcome,$deloutcome,$new_values,$translation) =
+ &Apache::lonnet::modify_access_controls($file_name,\%changes,
+ $udom,$uname);
+ if ($outcome ne 'ok') {
+ $r->print(&mt('<br />'."An error occured ($outcome) while ".
+ "trying to delete access controls for the file.").
+ '</span><br />');
+ } else {
+ if ($deloutcome eq 'ok') {
+ $r->print(&mt('<br />Access controls also deleted for the file.'));
+ } else {
+ $r->print('<span class="LC_error">'.
+ &mt('<br />'."An error occured ($deloutcome) while ".
+ "trying to delete access controls for the file.").
+ '</span><br />');
+ }
+ }
+ }
+ }
}
}
$r->print(&done(undef,$url));
@@ -608,7 +644,7 @@
}
sub rename_confirmed {
- my ($r,$url)=@_;
+ my ($r,$url,$group)=@_;
my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
my ($uname,$udom) = &get_name_dom();
my $port_path = &get_port_path();
@@ -619,24 +655,78 @@
$r->print(&done(undef,$url));
return;
}
+ my $chg_access;
my $result=
&Apache::lonnet::renameuserfile($uname,$udom,
$port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
$port_path.$env{'form.currentpath'}.$filenewname);
- if ($result ne 'ok') {
+ if ($result eq 'ok') {
+ $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
+ } else {
$r->print('<span class="LC_error">'.
- &mt('An errror occured ([_1]) while trying to rename [_2]'
+ &mt('An error occured ([_1]) while trying to rename [_2]'
.' to [_3]',$result,&display_file(),
&display_file('',$filenewname)).'</span><br />');
+ return;
}
if ($filenewname ne $env{'form.filenewname'}) {
$r->print(&mt("The new file name was changed from:<br />[_1] to [_2]",
'<strong>'.&display_file('',$env{'form.filenewname'}).'</strong>',
'<strong>'.&display_file('',$filenewname).'</strong>'));
}
+ $r->print($chg_access);
$r->print(&done(undef,$url));
}
+sub access_for_renamed {
+ my ($filenewname,$group,$udom,$uname) = @_;
+ my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'};
+ $oldfile = &prepend_group($oldfile);
+ my $newfile = $env{'form.currentpath'}.$filenewname;
+ $newfile = &prepend_group($newfile);
+ my $current_permissions =
+ &Apache::lonnet::get_portfile_permissions($udom,$uname);
+ my %access_controls =
+ &Apache::lonnet::get_access_controls($current_permissions,
+ $group,$oldfile);
+ my $chg_text;
+ if (keys(%access_controls) > 0) {
+ my %change_old;
+ my %change_new;
+ foreach my $key (%{$access_controls{$oldfile}}) {
+ $change_old{'delete'}{$key} = 1;
+ $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key};
+ }
+ my ($outcome,$deloutcome,$new_values,$translation) =
+ &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
+ $udom,$uname);
+ if ($outcome ne 'ok') {
+ $chg_text = &mt('<br /><br />'."An error occured ($outcome) while ".
+ "trying to delete access control records for the old name.").
+ '</span><br />';
+ } else {
+ if ($deloutcome ne 'ok') {
+ $chg_text = '<br /><br /><span class="LC_error">'.
+ &mt('<br />'."An error occured ($deloutcome) while ".
+ "trying to delete access control records for the old name.").
+ '</span><br />';
+ }
+ }
+ ($outcome,$deloutcome,$new_values,$translation) =
+ &Apache::lonnet::modify_access_controls($newfile,\%change_new,
+ $udom,$uname);
+ if ($outcome ne 'ok') {
+ $chg_text .= &mt('<br /><br />'."An error occured ($outcome) while ".
+ "trying to update access control records for the new name.").
+ '</span><br />';
+ }
+ if ($chg_text eq '') {
+ $chg_text = '<br /><br />'.&mt('Access controls updated to reflect the name change.');
+ }
+ }
+ return $chg_text;
+}
+
sub display_access {
my ($r,$url,$group,$can_setacl,$port_path) = @_;
my ($uname,$udom) = &get_name_dom();
@@ -1941,7 +2031,7 @@
}
} elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
if ($can_delete) {
- &delete_confirmed($r,$url);
+ &delete_confirmed($r,$url,$group);
} else {
&missing_priv($r,$url,'delete');
}
@@ -1965,7 +2055,7 @@
}
} elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
if ($can_modify) {
- &rename_confirmed($r,$url);
+ &rename_confirmed($r,$url,$group);
} else {
&missing_priv($r,$url,'rename');
}