Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix the duplicating of events with related links that have restrictiv…
…e permissions. Fixes bug #12010.
  • Loading branch information
perlDreamer committed Mar 20, 2012
1 parent 1eb5579 commit fcd9334
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
6 changes: 5 additions & 1 deletion lib/WebGUI/Asset/Event.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) {
Expand Down
25 changes: 21 additions & 4 deletions t/Asset/Event.t
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
[{
Expand All @@ -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'
);

#######################################
#
Expand All @@ -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(),
[{
Expand All @@ -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

#######################################
#
Expand Down

0 comments on commit fcd9334

Please sign in to comment.