Add a new method called getAllGroupsFor, which recursively returns ALL groups

that a group belongs to.  This is required to properly uncache group settings
for groups with more than 2 levels of hierarchy.

Add 7 tests to verify the working of the new method.

Fix a typo in the POD for Operation/Group.pm
This commit is contained in:
Colin Kuskie 2006-05-26 16:43:47 +00:00
parent 174e3df9ef
commit 7100d1df41
3 changed files with 31 additions and 4 deletions

View file

@ -211,14 +211,14 @@ sub autoDelete {
=head2 clearCaches ( )
Clears caches for this group.
Clears all caches for this group and any ancestor groups of the group.
=cut
sub clearCaches {
my $self = shift;
##Clear my cache and the cache of all groups above me.
my $groups = $self->getGroupsFor();
my $groups = $self->getAllGroupsFor();
foreach my $group ( $self->getId, @{ $groups } ) {
WebGUI::Cache->new($self->session, $group)->delete;
}
@ -615,6 +615,25 @@ sub get {
#-------------------------------------------------------------------
=head2 getAllGroupsFor ( )
Returns an array reference containing a list of all groups this group is in, recursively.
=cut
sub getAllGroupsFor {
my $self = shift;
my $groups = $self->getGroupsFor();
foreach my $gid (@{ $groups }) {
push @{ $groups }, @{ WebGUI::Group->new($self->session, $gid)->getAllGroupsFor() };
}
my %unique = map { $_ => 1 } @{ $groups };
$groups = [ keys %unique ];
return $groups;
}
#-------------------------------------------------------------------
=head2 getGroupsFor ( )

View file

@ -238,7 +238,7 @@ sub www_deleteGroupGrouping {
Deletes a set of users from a set of groups. Only Admins may perform this function.
The user and group lists are expected to
be found in form fields names uid and gid, respectively. Visitors are not allowed to
perform this operation, and the
perform this operation.
=cut

View file

@ -75,7 +75,7 @@ my @ipTests = (
);
plan tests => (96 + scalar(@scratchTests) + scalar(@ipTests)); # increment this value for each test you create
plan tests => (103 + scalar(@scratchTests) + scalar(@ipTests)); # increment this value for each test you create
my $session = WebGUI::Test->session;
my $testCache = WebGUI::Cache->new($session, 'myTestKey');
@ -198,6 +198,10 @@ cmp_bag($gB->getGroupsIn(1), [$gA->getId, $gC->getId, $gZ->getId, $gY->getId, $g
$gX->addGroups([$gA->getId]);
cmp_bag($gX->getGroupsIn(), [3], 'Not able to add B tree under Z tree under X');
cmp_bag($gX->getAllGroupsFor(), [ map {$_->getId} ($gZ, $gA, $gB) ], 'getAllGroupsFor X');
cmp_bag($gY->getAllGroupsFor(), [ map {$_->getId} ($gZ, $gA, $gB) ], 'getAllGroupsFor Y');
cmp_bag($gZ->getAllGroupsFor(), [ map {$_->getId} ($gA, $gB) ], 'getAllGroupsFor Z');
my $user = WebGUI::User->new($session, "new");
$gX->userIsAdmin($user->userId, "yes");
ok(!$gX->userIsAdmin($user->userId), "userIsAdmin: User who isn't secondary admin can't be group admin");
@ -493,11 +497,15 @@ $gY->addGroups([$gCache->getId]);
ok( $cacheDude->isInGroup($gY->getId), "Cache dude is a member of group Y by group membership");
ok( $cacheDude->isInGroup($gZ->getId), "Cache dude is a member of group Z by group membership");
ok( $cacheDude->isInGroup($gA->getId), "Cache dude is a member of group A by group membership");
ok( $cacheDude->isInGroup($gB->getId), "Cache dude is a member of group B by group membership");
$gY->deleteGroups([$gCache->getId]);
ok( !$cacheDude->isInGroup($gY->getId), "Cache dude is not a member of group Y");
ok( !$cacheDude->isInGroup($gZ->getId), "Cache dude is not a member of group Z");
ok( !$cacheDude->isInGroup($gA->getId), "Cache dude is not a member of group A");
ok( !$cacheDude->isInGroup($gB->getId), "Cache dude is not a member of group B");
SKIP: {
skip("need to test expiration date in groupings interacting with recursive or not", 1);