[LON-CAPA-cvs] cvs: loncom /interface loncoursegroups.pm longroup.pm /lonnet/perl lonnet.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Tue, 28 Nov 2006 19:46:04 -0000
This is a MIME encoded message
--raeburn1164743164
Content-Type: text/plain
raeburn Tue Nov 28 14:46:04 2006 EDT
Modified files:
/loncom/interface longroup.pm loncoursegroups.pm
/loncom/lonnet/perl lonnet.pm
Log:
Re-enable a previously deleted group. Member reinstatement requires work.
--raeburn1164743164
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20061128144604.txt"
Index: loncom/interface/longroup.pm
diff -u loncom/interface/longroup.pm:1.12 loncom/interface/longroup.pm:1.13
--- loncom/interface/longroup.pm:1.12 Fri Jul 28 20:31:58 2006
+++ loncom/interface/longroup.pm Tue Nov 28 14:46:00 2006
@@ -40,14 +40,17 @@
1. Optional course domain
2. Optional course number
3. Optional group name
+4. Optional namespace
Course domain and number will be taken from user's
environment if not supplied. Optional group name will
-be passed to lonnet::get_coursegroups() as a regexp to
-use in the call to the dump function.
+be passed to lonnet function as a regexp to
+use in the call to the dump function. Optional namespace
+will determine whether information is retrieved about current
+groups (default) or deleted groups (namespace = deleted_groups).
Output
-Returns hash of groups in the course (subject to the
+Returns hash of groups in a course (subject to the
optional group name filter). In the hash, the keys are
group names, and their corresponding values
are scalars containing group information in XML. This
@@ -60,7 +63,7 @@
###############################################
sub coursegroups {
- my ($cdom,$cnum,$group) = @_;
+ my ($cdom,$cnum,$group,$namespace) = @_;
if (!defined($cdom) || !defined($cnum)) {
my $cid = $env{'request.course.id'};
@@ -69,12 +72,16 @@
$cdom = $env{'course.'.$cid.'.domain'};
$cnum = $env{'course.'.$cid.'.num'};
}
- my %curr_groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group);
- if (my $tmp = &Apache::lonnet::error(%curr_groups)) {
- undef(%curr_groups);
- &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
+ if (!defined($namespace)) {
+ $namespace = 'coursegroups';
+ }
+ my %groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group,
+ $namespace);
+ if (my $tmp = &Apache::lonnet::error(%groups)) {
+ undef(%groups);
+ &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom.' - '.$namespace);
}
- return %curr_groups;
+ return %groups;
}
###############################################
Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.64 loncom/interface/loncoursegroups.pm:1.65
--- loncom/interface/loncoursegroups.pm:1.64 Mon Nov 20 18:49:49 2006
+++ loncom/interface/loncoursegroups.pm Tue Nov 28 14:46:00 2006
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: loncoursegroups.pm,v 1.64 2006/11/20 23:49:49 raeburn Exp $
+# $Id: loncoursegroups.pm,v 1.65 2006/11/28 19:46:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -92,13 +92,13 @@
my $action = $env{'form.action'};
my $state = $env{'form.state'};
- if ((!defined($action)) || ($action eq 'view') || ($action eq 'modify') || ($action eq 'delete')) {
+ if ((!defined($action)) || ($action eq 'view') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) {
if (!defined($state)) {
$state = 'view';
}
}
if ($action eq 'create' || $action eq 'modify' || $action eq 'view' ||
- $action eq 'delete') {
+ $action eq 'delete' || $action eq 'reenable') {
if ($view_permission || $manage_permission) {
if ($state eq 'view') {
&print_main_menu($r,$cdom,$cnum,\%functions,\%idx,
@@ -167,11 +167,14 @@
view => '<a href="/adm/'.$cdom.'/'.$cnum.'/',
delete => '<a href="/adm/coursegroups?action=delete&refpage='.
$env{'form.refpage'}.'&state=verify&groupname=',
+ reenable => '<a href="/adm/coursegroups?action=reenable&refpage='.
+ $env{'form.refpage'}.'&state=verify&groupname=',
);
my %lt = &Apache::lonlocal::texthash(
modify => 'Modify',
view => 'View',
delete => 'Delete',
+ reenable => 'Re-enable',
act => 'Action',
gname => 'Group Name',
desc => 'Group Title',
@@ -195,7 +198,12 @@
if (!defined($action)) {
$action = 'view';
}
- my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
+ my $status;
+ if ($action eq 'reenable') {
+ $status = 'deleted_groups';
+ }
+ my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
+ $status);
if (%curr_groups) {
if ($manage_permission) {
if (!exists($env{'form.refpage'})) {
@@ -293,7 +301,8 @@
$functionality = &mt('None available');
}
my $link = $actionlinks{$action};
- if ($action eq 'modify' || $action eq 'delete') {
+ if ($action eq 'modify' || $action eq 'delete' ||
+ $action eq 'reenable') {
$link .= $group;
} else {
$link .= $group.'/smppg?ref=grouplist';
@@ -433,7 +442,7 @@
$state = 'pick_task';
}
} else {
- %stored = &retrieve_settings($cdom,$cnum,$groupname);
+ %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
if (ref($stored{'types'}) eq 'ARRAY') {
@types = @{$stored{'types'}};
}
@@ -812,6 +821,7 @@
@{$states{'create'}} = ('pick_name','pick_members','pick_privs','result');
@{$states{'modify'}} = ('pick_task');
@{$states{'delete'}} = ('verify','result');
+ @{$states{'reenable'}} = ('verify','result');
@{$branchstates{'noprivs'}} = ('result');
@{$branchstates{'settings'}} = ('change_settings','chgresult');
@{$branchstates{'members'}} = ('change_members','change_privs','memresult');
@@ -822,7 +832,7 @@
push (@{$states{$action}},@{$branchstates{$env{'form.branch'}}});
}
- if (($action eq 'create') || ($action eq 'modify') || ($action eq 'delete')) {
+ if (($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) {
my $done = 0;
my $i=0;
while ($i<@{$states{$action}} && !$done) {
@@ -885,6 +895,10 @@
verify => 'Verify deletion',
result => 'Deletion Complete'
);
+ %{$trail{'reenable'}} = &Apache::lonlocal::texthash(
+ verify => 'Verify Re-enable',
+ result => 'Re-enabled'
+ );
my %navbuttons = &Apache::lonlocal::texthash(
gtns => 'Go to next step',
gtps => 'Go to previous step',
@@ -893,7 +907,7 @@
gtpp => 'Go to previous page',
adme => 'Add members',
);
- if ((($action eq 'create') || ($action eq 'modify') || ($action eq 'delete')) &&
+ if ((($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) &&
($manage_permission)) {
for (my $i=0; $i<@{$states{$action}}; $i++) {
if ($state eq $states{$action}[$i]) {
@@ -938,8 +952,16 @@
}
sub retrieve_settings {
- my ($cdom,$cnum,$groupname) = @_;
- my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$groupname);
+ my ($cdom,$cnum,$groupname,$action) = @_;
+ my %curr_groups;
+ my $namespace;
+ if ($action eq 'reenable') {
+ $namespace = 'deleted_groups';
+ } else {
+ $namespace = 'coursegroups';
+ }
+ %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
+ $namespace);
return if (!%curr_groups);
@@ -1079,13 +1101,21 @@
$sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
}
} elsif ($action eq 'delete') {
- my %stored = &retrieve_settings($cdom,$cnum,$groupname);
+ my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
if ($state eq 'verify') {
&verify_delete($r,$groupname,$state,$action,$page,$states,
\%stored);
} elsif ($state eq 'result') {
&delete_group($r,$cdom,$cnum,$groupname);
}
+ } elsif ($action eq 'reenable') {
+ my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
+ if ($state eq 'verify') {
+ &verify_reenable($r,$groupname,$state,$action,$page,$states,
+ \%stored);
+ } elsif ($state eq 'result') {
+ &reenable_group($r,$cdom,$cnum,$groupname);
+ }
}
}
@@ -1124,13 +1154,13 @@
foreach my $key (sort(keys(%membership))) {
if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
my $user = $1;
- my($end,$start,@userprivs) = split(/:/,$membership{$key});
+ my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
if ($start != -1) {
$num_users ++;
- $usersettings{$groupname.':'.$user} = $now.':-1:';
+ $usersettings{$groupname.':'.$user} = $now.':-1:'.$userprivs;
if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
$groupname,$user,
- $now,'-1','')
+ $now,'-1',$userprivs)
eq 'ok') {
$num_ok ++;
push(@deleted,$user);
@@ -1147,25 +1177,55 @@
\%usersettings);
}
if ($num_fail > 0) {
- $r->print(&mt('Group deletion failed because deletion of [_1] out of [_2] members failed',$num_fail,$num_users));
+ $r->print(&mt('Group deletion failed because deletion of [_1] out of [_2] members failed.',$num_fail,$num_users));
} else {
my ($result,$message) =
- &Apache::lonnet::delete_coursegroup($cdom,$cnum,$groupname);
+ &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,
+ $groupname,'delete');
if ($result eq 'ok') {
my $outcome = &modify_folders($cdom,$cnum,$groupname);
if ($outcome eq '') {
- $r->print(&mt('Group successfully deleted'));
+ $r->print(&mt('Group successfully deleted.'));
} else {
$r->print(&mt("Although the group was deleted, an error ([_1]) occurred when removing the group's folder from the 'Course Groups' folder.",$outcome));
}
} else {
- $r->print(&mt('Group deletion failed'));
+ $r->print(&mt('Group deletion failed.'));
}
}
return;
}
+sub reenable_folder {
+ my ($cdom,$cnum,$groupname,$description) = @_;
+ my $outcome;
+ my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
+ my $allgrpsmap = $crspath.'group_allfolders.sequence';
+ my $foldertitle = &mt('Course Folder -').$description;
+ my $mapurl = $crspath.'group_folder_'.
+ $groupname.'.sequence';
+ my ($errtext,$fatal)=&LONCAPA::map::mapread($allgrpsmap);
+ if ($fatal) {
+ $outcome=&mt('Error reading contents of parent folder to group').
+ " ($allgrpsmap): $errtext".'<br />';
+ } else {
+ my $idx=&LONCAPA::map::getresidx($mapurl);
+ $LONCAPA::map::resources[$idx] = $foldertitle.':'.$mapurl.
+ ':false:normal:res';
+ $LONCAPA::map::order[1+$#LONCAPA::map::order]=$idx;
+ my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1);
+ if ($errtext) {
+ $outcome = &mt('Error storing updated parent folder to group').
+ "- $allgrpsmap - $errtext".'<br />';
+ } else {
+ my ($furl,$ferr) =
+ &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ }
+ }
+ return $outcome;
+}
+
sub modify_folders {
my ($cdom,$cnum,$groupname) = @_;
my $outcome;
@@ -1173,8 +1233,12 @@
my $groupmap = '/uploaded/'.$cdom.'/'.$cnum.'/'.'group_folder_'.
$groupname.'.sequence';
my $groupmapres = $navmap->getResourceByUrl($groupmap);
+ my ($map,$id,$src);
if ($groupmapres) {
- my ($map,$id,$src)=&Apache::lonnet::decode_symb($groupmapres->symb());
+ ($map,$id,$src)=&Apache::lonnet::decode_symb($groupmapres->symb());
+ }
+ undef($navmap);
+ if ($map) {
$map = '/'.$map;
my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
if ($fatal) {
@@ -1201,17 +1265,111 @@
}
$#LONCAPA::map::order--;
my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
- if ($outtext) {
- $outcome = &mt('Error storing updated parent folder to group'). " ($map): $errtext".'<br />';
- return;
- }
+ if ($errtext) {
+ $outcome = &mt('Error storing updated parent folder to group'). "- $map - $errtext".'<br />';
+ } else {
+ my ($furl,$ferr) =
+ &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ }
}
}
}
- undef($navmap);
return $outcome;
}
+sub verify_reenable {
+ my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_;
+ $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
+ $r->print(&mt("You have requested enabling the following previously deleted group: ").'<i>'.
+ $stored->{'description'}.'</i>'.
+ '<br /><br />'.&mt('When a deleted group is re-enabled the following occurs:').'<ul>'.
+ '<li>'.&mt('Group settings and membership at the time the group was deleted are reinstated.').'</li>'.
+ '<li>'.&mt('A group folder is added to the "Course Groups" folder which contains folders for all groups in the course.').'</li></ul>');
+ my $prevtext = &mt('Go back');
+ my $nexttext = &mt('Reenable group');
+ my $prev;
+ if ($env{'form.refpage'} eq 'enrl') {
+ $prev = 'view';
+ }
+ &display_navbuttons($r,$formname,$prev,$prevtext,
+ $$states{$action}[$page+1],$nexttext);
+ return;
+}
+
+sub reenable_group {
+ my ($r,$cdom,$cnum,$groupname,) = @_;
+ my %groups =
+ &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
+ 'deleted_groups');
+ my %groupinfo =
+ &Apache::longroup::get_group_settings($groups{$groupname});
+ my $defstart = $groupinfo{'startdate'};
+ my $defend = $groupinfo{'enddate'};
+ my $showstart = &Apache::lonlocal::locallocaltime($defstart);
+ my $showend;
+ if ($defend == 0) {
+ $showend = &mt('No end date set');
+ } else {
+ $showend = &Apache::lonlocal::locallocaltime($defend);
+ }
+ my $description = &unescape($groupinfo{'description'});
+ my $num_users = 0;
+ my $num_ok = 0;
+ my $num_fail = 0;
+ my (%usersettings,@enabled,@unenabled);
+ my ($result,$message) =
+ &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,$groupname,
+ 'reenable');
+ if ($result eq 'ok') {
+ my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
+ $groupname);
+ foreach my $key (sort(keys(%membership))) {
+ if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
+ my $user = $1;
+ my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
+ if (($start == -1) && ($end == $groupinfo{'modified'})) {
+ $num_users ++;
+ $usersettings{$groupname.':'.$user} = $defend.':'.
+ $defstart.':'.
+ $userprivs;
+ if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
+ $groupname,$user,
+ $defend,$defstart,
+ $userprivs) eq 'ok') {
+ $num_ok ++;
+ push(@enabled,$user);
+ } else {
+ push(@unenabled,$user);
+ $num_fail ++;
+ }
+ }
+ }
+ }
+ if ($num_users > 0) {
+ if ($num_ok > 0) {
+ my $roster_result =
+ &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
+ \%usersettings);
+ if ($roster_result eq 'ok') {
+ $r->print(&mt('Membership reinstated for [_1] users, each with start and end dates for group access set to defaults: [_2] and [_3]',$num_ok,$showstart,$showend).'<br />');
+ }
+ } else {
+ $r->print(&mt('A problem occurred when trying to reinstate [_1] of the [_2] members of the pre-existing group.',$num_fail,$num_users).'<br />');
+ }
+ } else {
+ $r->print(&mt('There were no group members to reinstate, as none were removed when the group was deleted.').'<br />');
+ }
+ my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description);
+ if ($outcome eq '') {
+ $r->print(&mt('Group successfully re-enabled.'));
+ } else {
+ $r->print(&mt("Although the group was re-enabled, an error ([_1]) occurred when adding the group's folder to the 'Course Groups' folder.",$outcome));
+ }
+ } else {
+ $r->print(&mt('Re-enabling group failed'));
+ }
+}
+
sub header {
my ($bodytitle,$jscript,$action,$state,$page,$loaditems) = @_;
my $start_page=
@@ -3713,7 +3871,8 @@
my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
- my %deleted_groups = &Apache::lonnet::get_deleted_groups($cdom,$cnum);
+ my %deleted_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
+ 'deleted_groups');
if (my $tmp = &Apache::lonnet::error(%deleted_groups)) {
undef(%deleted_groups);
&Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.808 loncom/lonnet/perl/lonnet.pm:1.809
--- loncom/lonnet/perl/lonnet.pm:1.808 Mon Nov 27 15:35:10 2006
+++ loncom/lonnet/perl/lonnet.pm Tue Nov 28 14:46:00 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.808 2006/11/27 20:35:10 albertel Exp $
+# $Id: lonnet.pm,v 1.809 2006/11/28 19:46:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3559,7 +3559,7 @@
$uri=&deversion($uri);
my $orguri=$uri;
$uri=&declutter($uri);
-
+
if (defined($env{'allowed.'.$priv})) { return $env{'allowed.'.$priv}; }
# Free bre access to adm and meta resources
if (((($uri=~/^adm\//) && ($uri !~ m{/(?:smppg|bulletinboard)$}))
@@ -4365,13 +4365,8 @@
# ------------------------------------------------------- Course Group routines
sub get_coursegroups {
- my ($cdom,$cnum,$group) = @_;
- return(&dump('coursegroups',$cdom,$cnum,$group));
-}
-
-sub get_deleted_groups {
- my ($cdom,$cnum,$group) = @_;
- return(&dump('deleted_groups',$cdom,$cnum,$group));
+ my ($cdom,$cnum,$group,$namespace) = @_;
+ return(&dump($namespace,$cdom,$cnum,$group));
}
sub modify_coursegroup {
@@ -4379,18 +4374,26 @@
return(&put('coursegroups',$groupsettings,$cdom,$cnum));
}
-sub delete_coursegroup {
- my ($cdom,$cnum,$group) = @_;
- my %curr_group = &get_coursegroups($cdom,$cnum,$group);
+sub toggle_coursegroup_status {
+ my ($cdom,$cnum,$group,$action) = @_;
+ my ($from_namespace,$to_namespace);
+ if ($action eq 'delete') {
+ $from_namespace = 'coursegroups';
+ $to_namespace = 'deleted_groups';
+ } else {
+ $from_namespace = 'deleted_groups';
+ $to_namespace = 'coursegroups';
+ }
+ my %curr_group = &get_coursegroups($cdom,$cnum,$group,$from_namespace);
if (my $tmp = &error(%curr_group)) {
&Apache::lonnet::logthis('Error retrieving group: '.$tmp.' in '.$cnum.':'.$cdom);
return ('read error',$tmp);
} else {
my %savedsettings = %curr_group;
- my $result = &put('deleted_groups',\%savedsettings,$cdom,$cnum);
+ my $result = &put($to_namespace,\%savedsettings,$cdom,$cnum);
my $deloutcome;
if ($result eq 'ok') {
- $deloutcome = &del('coursegroups',[$group],$cdom,$cnum);
+ $deloutcome = &del($from_namespace,[$group],$cdom,$cnum);
} else {
return ('write error',$result);
}
@@ -7712,8 +7715,7 @@
=item *
-allowed($priv,$uri) : check for a user privilege; returns codes for allowed
-actions
+allowed($priv,$uri,$symb) : check for a user privilege; returns codes for allowed actions
F: full access
U,I,K: authentication modes (cxx only)
'': forbidden
--raeburn1164743164--