From fcd933489b0c70953636f2a9292a143c2c0603ee Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 20 Mar 2012 11:59:13 -0700 Subject: [PATCH] Fix the duplicating of events with related links that have restrictive permissions. Fixes bug #12010. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Event.pm | 6 +++++- t/Asset/Event.t | 25 +++++++++++++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 6eb16b31c..55fece932 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.10.25 + - fixed #12010 related link duplication where links have group view restrictions - fixed #12297: keywords.form missing from Post template help - fixed #12321: Error while deleting a group. - fixed #12322: Cache/CHI stomps on the config file diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index bece1b65f..b680c7978 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -420,7 +420,7 @@ sub duplicate { my $newAsset = $self->SUPER::duplicate(@_); my $newStorage = $self->getStorageLocation->copy; $newAsset->update({storageId=>$newStorage->getId}); - my $links = $self->getRelatedLinks(); + my $links = $self->getRelatedLinks('nolimit'); my $id = $self->session->id; foreach my $link (@{ $links }) { $link->{new_event} = 1; @@ -1076,12 +1076,16 @@ Gets an arrayref of hashrefs of related links. sub getRelatedLinks { my $self = shift; + my $limitflag = shift || 'yes'; my $sth = $self->session->db->prepare( "SELECT * FROM Event_relatedlink WHERE assetId=? ORDER BY sequenceNumber", ); $sth->execute([ $self->getId ]); + if( $limitflag eq 'nolimit' ) { + return [ map { $sth->hashRef } ( 1..$sth->rows ) ]; + } my @links; while ( my $link = $sth->hashRef ) { diff --git a/t/Asset/Event.t b/t/Asset/Event.t index a67b73ef7..1b6705c58 100644 --- a/t/Asset/Event.t +++ b/t/Asset/Event.t @@ -16,7 +16,8 @@ use WebGUI::Test; use Test::More; # increment this value for each test you create use Test::Deep; -plan tests => 30; + +plan tests => 31; use WebGUI::Session; use WebGUI::Storage; @@ -172,10 +173,11 @@ $event6->setRelatedLinks([ sequenceNumber => 2, linkurl => 'http://www.somewhere.com', linktext => 'Another great link', - groupIdView => '7', + groupIdView => '2', eventlinkId => '28', }, ]); +$session->user({userId => 3}); # admin can see all the links cmp_deeply( $event6->getRelatedLinks(), [{ @@ -190,12 +192,25 @@ cmp_deeply( sequenceNumber => 2, linkURL => 'http://www.somewhere.com', linktext => 'Another great link', - groupIdView => '7', + groupIdView => '2', eventlinkId => '28', assetId => $event6->getId, }], 'related links stored in the database correctly' ); +$session->user({userId => 1}); # visitor can only see one link +cmp_deeply( + $event6->getRelatedLinks(), + [{ + sequenceNumber => 1, + linkURL => 'http://www.nowhere.com', + linktext => 'Great link', + groupIdView => '7', + eventlinkId => '27', + assetId => $event6->getId, + }], + 'related links:user access restriction works' +); ####################################### # @@ -206,6 +221,7 @@ cmp_deeply( my $event6b = $event6->duplicate(); ok($session->id->valid($event6b->get('storageId')), 'duplicated event got a valid storageId'); isnt($event6b->get('storageId'), $event6->get('storageId'), 'duplicating an asset creates a new storage location'); +$session->user({userId => 3}); # admin can see all the links cmp_deeply( $event6b->getRelatedLinks(), [{ @@ -220,12 +236,13 @@ cmp_deeply( sequenceNumber => 2, linkURL => 'http://www.somewhere.com', linktext => 'Another great link', - groupIdView => '7', + groupIdView => '2', eventlinkId => ignore(), assetId => $event6b->getId, }], 'duplicated event has relatedLinks' ); +$session->user({userId => 1}); # run remaining tests as visitor ####################################### #