Fixing require loops. Moose overrides for canEdit using packages.

This commit is contained in:
Colin Kuskie 2010-04-08 15:13:13 -07:00
parent d69ed84fd4
commit c835344813
14 changed files with 69 additions and 60 deletions

View file

@ -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 );
};
#-------------------------------------------------------------------

View file

@ -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;
};
#-------------------------------------------------------------------

View file

@ -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);
}
};
#-------------------------------------------------------------------

View file

@ -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;
}
};
#----------------------------------------------------------------------------

View file

@ -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 )
);
};
#-------------------------------------------------------------------

View file

@ -266,12 +266,14 @@ part of the C<groupToAdd> 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 {

View file

@ -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(@_)
);
};
#-------------------------------------------------------------------

View file

@ -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'));

View file

@ -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

View file

@ -16,7 +16,6 @@ package WebGUI::International;
use strict qw(vars subs);
use WebGUI::Session;
use WebGUI::Pluggable;
use Module::Find qw(findsubmod);

View file

@ -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'} = '<!--morebody-->');
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 = {};

View file

@ -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;

View file

@ -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}); };

View file

@ -65,6 +65,7 @@ BEGIN {
}
}
use WebGUI::Asset;
use WebGUI::Session;
use WebGUI::PseudoRequest;