Add a workflow activity that reverifies that all subscribers to a CS can still view the CS, otherwise, remove them. Hook up the workflow to the update method in Collaboriation.pm and create an instance for it if the groupIdView changes. Add tests for the activity. Add a new workflow. Update the default WebGUI.conf.

This commit is contained in:
Colin Kuskie 2010-11-30 15:07:49 -08:00
parent e2115411b5
commit dd7e6016dc
9 changed files with 253 additions and 2 deletions

View file

@ -2,6 +2,7 @@
- fixed #11974: Toolbar icons unclickable in Webkit using HTML5
- fixed #11978: Pasting links into TinyMCE
- fixed #11980: DataForm broken
- fixed #11971: Still subscribed to forums you no longer have privilege to view
7.10.5
- fixed #11950: Username set to 0 when edit user

View file

@ -22,7 +22,7 @@ use Getopt::Long;
use WebGUI::Session;
use WebGUI::Storage;
use WebGUI::Asset;
use WebGUI::Workflow;
my $toVersion = '7.10.6';
my $quiet; # this line required
@ -31,10 +31,31 @@ my $quiet; # this line required
my $session = start(); # this line required
# upgrade functions go here
addCollaborationSubscriptionWorkflow($session);
finish($session); # this line required
#----------------------------------------------------------------------------
sub addCollaborationSubscriptionWorkflow {
my $session = shift;
print "\tWe're doing some stuff here that you should know about... " unless $quiet;
# and here's our code
$session->config->addToArray('workflowActivities/WebGUI::Asset', qw/WebGUI::Workflow::Activity::UpdateAssetSubscribers/);
my $workflow = WebGUI::Workflow->create($session,
{
mode => 'parallel',
enabled => 1,
title => 'Update CS Subscription members',
description => "This workflow will be run whenever the viewing permissions are changed on an Asset. It will update the members of the subscription group, and remove members who can no longer view the Asset.",
type => 'WebGUI::Asset',
},
'xR-_GRRbjBojgLsFx3dEMA'
);
$workflow->addActivity('WebGUI::Workflow::Activity::UpdateAssetSubscribers');
print "DONE!\n" unless $quiet;
}
#----------------------------------------------------------------------------
# Describe what our function does
#sub exampleFunction {

View file

@ -900,6 +900,9 @@
"WebGUI::Asset::Wobject::Thingy" : [
"WebGUI::Workflow::Activity::NotifyAboutThing"
],
"WebGUI::Asset" : [
"WebGUI::Workflow::Activity::UpdateAssetSubscribers"
],
"WebGUI::User" : [
"WebGUI::Workflow::Activity::CreateCronJob",
"WebGUI::Workflow::Activity::NotifyAboutUser",

View file

@ -1566,6 +1566,31 @@ sub unsubscribe {
}
#-------------------------------------------------------------------
=head2 update ( )
Update the base method to handle checking valid users in the subscription group if
view permissions have changed.
=cut
sub update {
my $self = shift;
my $origGroupIdView = $self->get('groupIdView');
$self->next::method(@_);
return if $self->get('groupIdView') eq $origGroupIdView;
my $instance_data = {
workflowId => 'xR-_GRRbjBojgLsFx3dEMA',
className => 'WebGUI::Asset',
methodName => 'newByDynamicClass',
parameters => $self->getId,
};
my $instance = WebGUI::Workflow::Instance->create($self->session, $instance_data);
$instance->start('skipRealtime');
}
#-------------------------------------------------------------------
=head2 view

View file

@ -0,0 +1,100 @@
package WebGUI::Workflow::Activity::UpdateAssetSubscribers;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::User;
use WebGUI::Group;
=head1 NAME
Package WebGUI::Workflow::Activity::UpdateCollaborationSubscribers
=head1 DESCRIPTION
This workflow activity should be called whenever permissions to view a Collaboration System
are changed. It will remove users who are no longer able to view the CS.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::definition() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "Workflow_Activity_UpdateAssetSubscribers");
push(@{$definition}, {
name => $i18n->get("name"),
properties => { }
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $asset = shift;
return unless $asset->get('subscriptionGroupId');
my $expireTime = time() + $self->getTTL();
my $subscriptionGroup = WebGUI::Group->new($self->session, $asset->get('subscriptionGroupId'));
##Deserialize from scratch
my @users = @{ $subscriptionGroup->getUsers }; ##Cache
my @usersToDelete = (); ##Cache
##Note, we could use grep here, but we can't interrupt if the workflow runs too long
USER: foreach my $userId (@users) {
if (time() > $expireTime) {
#return $self->WAITING(1);
}
next USER if $asset->canView($userId);
push @usersToDelete, $userId;
}
if (@usersToDelete) {
$subscriptionGroup->deleteUsers(\@usersToDelete);
}
#Clear scratch
return $self->COMPLETE;
}
1;

View file

@ -0,0 +1,14 @@
package WebGUI::i18n::English::Workflow_Activity_UpdateAssetSubscribers;
use strict;
our $I18N = {
'name' => {
message => q|Update Collaboration Subscribers|,
context => q|Name for the Workflow activity|,
lastUpdated => 1165363730,
},
};
1;

View file

@ -48,7 +48,7 @@ is_deeply($wf->getCrons, [], 'workflow has no crons');
isa_ok(WebGUI::Workflow->getList($session), 'HASH', 'getList returns a hashref');
ok(!isIn($wfId, keys %{WebGUI::Workflow->getList($session)}), 'workflow not in enabled list');
is(scalar keys %{WebGUI::Workflow->getList($session)}, 12, 'There are twelve enabled, default workflows, of all types, shipped with WebGUI');
is(scalar keys %{WebGUI::Workflow->getList($session)}, 13, 'There are twelve enabled, default workflows, of all types, shipped with WebGUI');
$wf->set({enabled => 1});
ok($wf->get('enabled'), 'workflow is enabled');

View file

@ -0,0 +1,86 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Utility;
use WebGUI::Workflow::Activity::UpdateAssetSubscribers;
use WebGUI::Asset;
use Test::More;
use Test::Deep;
plan tests => 4; # increment this value for each test you create
my $session = WebGUI::Test->session;
$session->user({userId => 3});
my $subscriberGroup = WebGUI::Group->new($session, "new"); ##Group to hold subscribers
my $oldGroup = WebGUI::Group->new($session, "new"); ##Pretend group, old groupIdView
my $betterGroup = WebGUI::Group->new($session, "new"); ##New group for groupIdView
my $oldUser = WebGUI::User->create($session); ##User who should be unsubscribed
my $betterUser = WebGUI::User->create($session); ##User who should remain subscribed
my $otherUser = WebGUI::User->create($session); ##Just a user, we should never see him
my $root = WebGUI::Asset->getRoot($session);
my $cs = $root->addChild({
className => 'WebGUI::Asset::Wobject::Collaboration',
title => 'Test Calendar',
subscriptionGroupId => $subscriberGroup->getId,
groupIdView => $betterGroup->getId,
});
my $tag = WebGUI::VersionTag->getWorking($session);
$tag->commit;
WebGUI::Test->addToCleanup($tag, $subscriberGroup, $betterGroup, $oldUser, $betterUser, $otherUser);
$subscriberGroup->addUsers([$oldUser->getId, $betterUser->getId, ]);
$betterGroup->addUsers([$betterUser->getId, ]);
##Plan, since spectre isn't running, we manually simulate an update event and run the
##workflow activity by hand.
cmp_bag(
$subscriberGroup->getUsers,
[$oldUser->getId, $betterUser->getId],
'Initial subscribers are correct'
);
##This workflowId needs to exist, since it's hardcoded in the CS asset
my $workflow = WebGUI::Workflow->new($session, 'xR-_GRRbjBojgLsFx3dEMA');
my $instance1 = WebGUI::Workflow::Instance->create($session,
{
workflowId => $workflow->getId,
skipSpectreNotification => 1,
className => 'WebGUI::Asset',
methodName => 'newByDynamicClass',
parameters => $cs->getId,
}
);
WebGUI::Test->addToCleanup($instance1);
my $retVal;
$retVal = $instance1->run();
is($retVal, 'complete', 'cleanup: activity complete');
$retVal = $instance1->run();
is($retVal, 'done', 'cleanup: activity is done');
$instance1->delete('skipNotify');
$subscriberGroup->clearCaches;
cmp_bag(
$subscriberGroup->getUsers,
[$betterUser->getId],
'Corrent user removed'
);

View file

@ -835,6 +835,7 @@ Example call:
pbworkflow000000000006
pbworkflow000000000007
send_webgui_statistics
xR-_GRRbjBojgLsFx3dEMA
};
},
);