From abaeab36e098be5fdc2291344c3a52c3827d29c5 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 16 Feb 2010 08:50:00 -0800 Subject: [PATCH] Refactor code to force assets to always be hidden into a role and use it. --- lib/WebGUI/Asset/Event.pm | 9 +---- lib/WebGUI/Asset/File/GalleryFile.pm | 10 +----- lib/WebGUI/Asset/Post.pm | 9 +---- lib/WebGUI/Asset/Story.pm | 10 +----- lib/WebGUI/Asset/WikiPage.pm | 9 +---- lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 10 +----- lib/WebGUI/AssetRole/AlwaysHidden.pm | 45 ++++++++++++++++++++++++ t/Asset/Event.t | 21 ++++++++++- 8 files changed, 71 insertions(+), 52 deletions(-) create mode 100644 lib/WebGUI/AssetRole/AlwaysHidden.pm diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 5ea7f437f..39964c3f4 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -133,14 +133,7 @@ property userDefined5 => ( default => '', ); -around isHidden => sub { - my $orig = shift; - my $self = shift; - if (@_ > 0) { - $_[0] = 1; - } - $self->$orig(@_); -}; +with 'WebGUI::AssetRole::AlwaysHidden'; use WebGUI::DateTime; diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index fc1a58f6d..93a744fd3 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -39,15 +39,7 @@ for my $i ( 1 .. 5 ) { ); } -around isHidden => sub { - my $orig = shift; - my $self = shift; - if (@_ > 0) { - $_[0] = 1; - } - $self->$orig(@_); -}; - +with 'WebGUI::AssetRole::AlwaysHidden'; use Carp qw( croak confess ); use URI::Escape; diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index c98be9408..2d78ec028 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -73,14 +73,7 @@ property content => ( default => undef, ); -around isHidden => sub { - my $orig = shift; - my $self = shift; - if (@_ > 0) { - $_[0] = 1; - } - $self->$orig(@_); -}; +with 'WebGUI::AssetRole::AlwaysHidden'; sub _set_ownerUserId { my ($self, $new, $old) = @_; diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index 1dc84607b..da2af33d8 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -67,15 +67,7 @@ property photo => ( noFormPost => 1, ); -around isHidden => sub { - my $orig = shift; - my $self = shift; - if (@_ > 0) { - $_[0] = 1; - } - $self->$orig(@_); -}; - +with 'WebGUI::AssetRole::AlwaysHidden'; use WebGUI::Utility; use WebGUI::International; diff --git a/lib/WebGUI/Asset/WikiPage.pm b/lib/WebGUI/Asset/WikiPage.pm index 6397f4638..7785ede25 100644 --- a/lib/WebGUI/Asset/WikiPage.pm +++ b/lib/WebGUI/Asset/WikiPage.pm @@ -55,14 +55,7 @@ property isFeatured => ( noFormPost => 1, ); -around isHidden => sub { - my $orig = shift; - my $self = shift; - if (@_ > 0) { - $_[0] = 1; - } - $self->$orig(@_); -}; +with 'WebGUI::AssetRole::AlwaysHidden'; use WebGUI::International; use WebGUI::Utility; diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index 2b30eeaea..9612ab772 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -41,15 +41,7 @@ for my $i ( 1 .. 5 ) { ); } -around isHidden => sub { - my $orig = shift; - my $self = shift; - if (@_ > 0) { - $_[0] = 1; - } - $self->$orig(@_); -}; - +with 'WebGUI::AssetRole::AlwaysHidden'; use Carp qw( croak ); use File::Find; diff --git a/lib/WebGUI/AssetRole/AlwaysHidden.pm b/lib/WebGUI/AssetRole/AlwaysHidden.pm new file mode 100644 index 000000000..72c5f66f5 --- /dev/null +++ b/lib/WebGUI/AssetRole/AlwaysHidden.pm @@ -0,0 +1,45 @@ +package WebGUI::AssetRole::AlwaysHidden; + +=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 + +=head1 NAME + +Package WebGUI::AssetRole::AlwaysHidden + +=head1 DESCRIPTION + +Asset Role that guarantees that the isHidden property is always 1. + +=head1 SYNOPSIS + +with WebGUI::AssetRole::AlwaysHidden; + +=cut + +use Moose::Role; + +around isHidden => sub { + my $orig = shift; + my $self = shift; + if (@_ > 0) { + shift @_; + unshift @_, 1; + } + $self->$orig(@_); +}; + + + +1; diff --git a/t/Asset/Event.t b/t/Asset/Event.t index 87c67b662..fe063b3f8 100644 --- a/t/Asset/Event.t +++ b/t/Asset/Event.t @@ -19,7 +19,7 @@ use WebGUI::Asset::Event; use Test::More; # increment this value for each test you create use Test::Deep; -plan tests => 18; +plan tests => 20; my $session = WebGUI::Test->session; @@ -131,3 +131,22 @@ ok($session->id->valid($event6a->get('storageId')), 'addRevision gives the new r isnt($event6a->get('storageId'), $event6->get('storageId'), '... and it is different from the previous revision'); my $versionTag2 = WebGUI::VersionTag->getWorking($session); WebGUI::Test->tagsToRollback($versionTag2); +$versionTag2->commit; + +my $event7 = $cal->addChild( + { + className => 'WebGUI::Asset::Event', + assetId => 'EventAssetTestStorage6', + url => 'hidden_event', + }, undef, undef, { skipNotifications => 1, skipAutoCommitWorkflows => 1 }, +); + +my $tag = WebGUI::VersionTag->getWorking($session); +$tag->commit; +addToCleanup($tag); + +is $event7->isHidden, 1, 'isHidden set to 1 by default'; + +$event7->isHidden(0); +is $event7->isHidden, 1, 'isHidden cannot be set to 0'; +