From c8353448130179c054f908015a80581d2e0a4b94 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 8 Apr 2010 15:13:13 -0700 Subject: [PATCH] Fixing require loops. Moose overrides for canEdit using packages. --- lib/WebGUI/Asset/MapPoint.pm | 7 +++-- lib/WebGUI/Asset/Shortcut.pm | 11 ++++--- lib/WebGUI/Asset/Story.pm | 7 +++-- lib/WebGUI/Asset/Wobject/Calendar.pm | 7 +++-- lib/WebGUI/Asset/Wobject/Collaboration.pm | 37 ++++++++++++----------- lib/WebGUI/Asset/Wobject/Matrix.pm | 10 +++--- lib/WebGUI/Asset/Wobject/WikiMaster.pm | 35 ++++++++++----------- lib/WebGUI/AssetTrash.pm | 3 +- lib/WebGUI/Group.pm | 2 +- lib/WebGUI/International.pm | 1 - lib/WebGUI/Session/Style.pm | 4 +-- lib/WebGUI/Shop/AddressBook.pm | 2 +- lib/WebGUI/User.pm | 2 +- t/lib/WebGUI/Test.pm | 1 + 14 files changed, 69 insertions(+), 60 deletions(-) diff --git a/lib/WebGUI/Asset/MapPoint.pm b/lib/WebGUI/Asset/MapPoint.pm index c512803b6..667f32f93 100644 --- a/lib/WebGUI/Asset/MapPoint.pm +++ b/lib/WebGUI/Asset/MapPoint.pm @@ -150,12 +150,13 @@ group to edit the parent Map are allowed to edit MapPoint. =cut -sub canEdit { +around canEdit => sub { + my $orig = shift; my $self = shift; my $userId = shift || $self->session->user->userId; return 1 if $userId eq $self->ownerUserId; - return $self->SUPER::canEdit( $userId ); -} + return $self->$orig( $userId ); +}; #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 81eebdde8..3abbf5e9c 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -200,11 +200,12 @@ can manage the parent you can edit this Shortcut. =cut -sub canEdit { - my $self = shift; -return 1 if ($self->SUPER::canEdit || ($self->isDashlet && $self->getParent->canManage)); - return 0; -} +around canEdit => sub { + my $orig = shift; + my $self = shift; + return 1 if ($self->$orig(@_) || ($self->isDashlet && $self->getParent->canManage)); + return 0; +}; #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index 7670c3b01..d6fc263d0 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -136,16 +136,17 @@ You can't add children to a Story. =cut -sub canEdit { +around canEdit => sub { + my $orig = shift; my $self = shift; my $userId = shift || $self->session->user->userId; if ($userId eq $self->ownerUserId) { return 1; } my $user = WebGUI::User->new($self->session, $userId); - return $self->SUPER::canEdit($userId) + return $self->$orig($userId) || $self->getArchive->canPostStories($userId); -} +}; #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index 8171fed22..38b78a133 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -412,7 +412,8 @@ around the canEdit check when www_editSave is being used to add an asset). =cut -sub canEdit { +around canEdit => sub { + my $orig = shift; my $self = shift; my $userId = shift || $self->session->user->userId; my $form = $self->session->form; @@ -430,13 +431,13 @@ sub canEdit { ); # Who can edit the Calendar can do everything - if ( $self->SUPER::canEdit( $userId ) ) { + if ( $self->$orig( $userId ) ) { return 1; } # Fails all checks return 0; -} +}; #---------------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 3a251d86a..582ccd3f3 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -715,24 +715,25 @@ the current session user. =cut -sub canEdit { - my $self = shift; - my $userId = shift || $self->session->user->userId; - return ( - ( - ( - $self->session->form->process("func") eq "add" || - ( - $self->session->form->process("assetId") eq "new" && - $self->session->form->process("func") eq "editSave" && - $self->session->form->process("class") eq "WebGUI::Asset::Post::Thread" - ) - ) && - $self->canStartThread( $userId ) - ) || # account for new threads - $self->next::method( $userId ) - ); -} +around canEdit => sub { + my $orig = shift; + my $self = shift; + my $userId = shift || $self->session->user->userId; + return ( + ( + ( + $self->session->form->process("func") eq "add" || + ( + $self->session->form->process("assetId") eq "new" && + $self->session->form->process("func") eq "editSave" && + $self->session->form->process("class") eq "WebGUI::Asset::Post::Thread" + ) + ) && + $self->canStartThread( $userId ) + ) || # account for new threads + $self->$orig( $userId ) + ); +}; #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index ec49ce0a5..79b45788e 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -266,12 +266,14 @@ part of the C group. =cut sub canEdit { - my $self = shift; + my $orig = shift; + my $self = shift; my $userId = shift || $self->session->user->userId; - my $form = $self->session->form; - if ( $form->get('func') eq "editSave" && $form->get('assetId') eq "new" && $form->get( 'class' )->isa( -'WebGUI::Asset::MatrixListing' ) ) { + my $form = $self->session->form; + if ( $form->get('func') eq "editSave" + && $form->get('assetId') eq "new" + && $form->get( 'class' )->isa( 'WebGUI::Asset::MatrixListing' ) ) { return $self->canAddMatrixListing(); } else { diff --git a/lib/WebGUI/Asset/Wobject/WikiMaster.pm b/lib/WebGUI/Asset/Wobject/WikiMaster.pm index 6bc275aa2..a8c91fa1d 100644 --- a/lib/WebGUI/Asset/Wobject/WikiMaster.pm +++ b/lib/WebGUI/Asset/Wobject/WikiMaster.pm @@ -402,23 +402,24 @@ Overriding canEdit method to check permissions correctly when someone is adding =cut -sub canEdit { - my $self = shift; - return ( - ( - ( - $self->session->form->process("func") eq "add" || - ( - $self->session->form->process("assetId") eq "new" && - $self->session->form->process("func") eq "editSave" && - $self->session->form->process("class") eq "WebGUI::Asset::WikiPage" - ) - ) && - $self->canEditPages - ) || # account for new posts - $self->next::method() - ); -} +around canEdit => sub { + my $orig = shift; + my $self = shift; + return ( + ( + ( + $self->session->form->process("func") eq "add" || + ( + $self->session->form->process("assetId") eq "new" && + $self->session->form->process("func") eq "editSave" && + $self->session->form->process("class") eq "WebGUI::Asset::WikiPage" + ) + ) && + $self->canEditPages + ) || # account for new posts + $self->$orig(@_) + ); +}; #------------------------------------------------------------------- diff --git a/lib/WebGUI/AssetTrash.pm b/lib/WebGUI/AssetTrash.pm index f5e9761c1..01cc48586 100644 --- a/lib/WebGUI/AssetTrash.pm +++ b/lib/WebGUI/AssetTrash.pm @@ -15,7 +15,6 @@ package WebGUI::Asset; =cut use strict; -require WebGUI::Asset::Shortcut; use WebGUI::Utility qw(isIn formatBytes); =head1 NAME @@ -164,6 +163,7 @@ sub purge { # Delete shortcuts to this asset # Also publish any shortcuts to this asset that are in the trash $outputSub->($i18n->get('Purging shortcuts')); + require WebGUI::Asset::Shortcut; my $shortcuts = WebGUI::Asset::Shortcut->getShortcutsForAssetId($self->session, $self->getId, { returnObjects => 1, @@ -277,6 +277,7 @@ sub trash { } # Trash any shortcuts to this asset + require WebGUI::Asset::Shortcut; my $shortcuts = WebGUI::Asset::Shortcut->getShortcutsForAssetId($session, $self->getId, { returnObjects => 1}); $outputSub->($i18n->get('Purging shortcuts')); diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index a35a935d6..1d63424ed 100644 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -19,7 +19,7 @@ use WebGUI::LDAPLink; use WebGUI::Macro; use WebGUI::Utility; use WebGUI::Pluggable; -use WebGUI::Asset; +require WebGUI::Asset; use WebGUI::International; =head1 NAME diff --git a/lib/WebGUI/International.pm b/lib/WebGUI/International.pm index 900fb9160..f2fed1a2c 100644 --- a/lib/WebGUI/International.pm +++ b/lib/WebGUI/International.pm @@ -16,7 +16,6 @@ package WebGUI::International; use strict qw(vars subs); -use WebGUI::Session; use WebGUI::Pluggable; use Module::Find qw(findsubmod); diff --git a/lib/WebGUI/Session/Style.pm b/lib/WebGUI/Session/Style.pm index 54eb692ab..563c9bb44 100644 --- a/lib/WebGUI/Session/Style.pm +++ b/lib/WebGUI/Session/Style.pm @@ -19,7 +19,7 @@ use strict; use Tie::CPHash; use WebGUI::International; use WebGUI::Macro; -use WebGUI::Asset::Template; +require WebGUI::Asset; use WebGUI; use HTML::Entities (); @@ -269,7 +269,7 @@ if ($self->session->user->isRegistered || $self->session->setting->get("preventP $var{'head_attachments'} = $var{'head.tags'}; $var{'head.tags'} .= ($var{'body_attachments'} = ''); - my $style = eval { WebGUI::Asset::Template->newById($self->session, $templateId); }; + my $style = eval { WebGUI::Asset->newById($self->session, $templateId); }; my $output; if (! Exception::Class->caught()) { my $meta = {}; diff --git a/lib/WebGUI/Shop/AddressBook.pm b/lib/WebGUI/Shop/AddressBook.pm index 17393a09d..06d95afd5 100644 --- a/lib/WebGUI/Shop/AddressBook.pm +++ b/lib/WebGUI/Shop/AddressBook.pm @@ -4,7 +4,7 @@ use strict; use Class::InsideOut qw{ :std }; use JSON; -use WebGUI::Asset::Template; +require WebGUI::Asset::Template; use WebGUI::Exception::Shop; use WebGUI::Form; use WebGUI::International; diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 803471b5d..5476d365f 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -18,7 +18,6 @@ use strict; use WebGUI::Group; use WebGUI::Utility; use WebGUI::Workflow::Instance; -use WebGUI::Shop::AddressBook; use JSON (); use WebGUI::ProfileField; use Tie::CPHash; @@ -410,6 +409,7 @@ sub delete { # Shop cleanups my $sth = $session->db->prepare('select addressBookId from addressBook where userId=?'); $sth->execute([$userId]); + require WebGUI::Shop::AddressBook; BOOK: while (my $bookId = $sth->hashRef) { my $book; eval { $book = WebGUI::Shop::AddressBook->new($session, $bookId->{addressBookId}); }; diff --git a/t/lib/WebGUI/Test.pm b/t/lib/WebGUI/Test.pm index f1c3dfa8a..ff0bf5628 100644 --- a/t/lib/WebGUI/Test.pm +++ b/t/lib/WebGUI/Test.pm @@ -65,6 +65,7 @@ BEGIN { } } +use WebGUI::Asset; use WebGUI::Session; use WebGUI::PseudoRequest;