Add Promote and Demote helpers.
This commit is contained in:
parent
39ffaba487
commit
7d9ee7b0a6
5 changed files with 330 additions and 0 deletions
62
lib/WebGUI/AssetHelper/Demote.pm
Normal file
62
lib/WebGUI/AssetHelper/Demote.pm
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package WebGUI::AssetHelper::Demote;
|
||||
|
||||
use strict;
|
||||
use Class::C3;
|
||||
use base qw/WebGUI::AssetHelper/;
|
||||
|
||||
=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
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::AssetHelper::Demote
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Demotes the asset with respect to its siblings.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 process ( $class, $asset )
|
||||
|
||||
Demotes the asset. If the user cannot edit the asset it returns an error message.
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my ($class, $asset) = @_;
|
||||
my $session = $asset->session;
|
||||
|
||||
my $i18n = WebGUI::International->new($session, 'WebGUI');
|
||||
if (! $asset->canEdit) {
|
||||
return { error => $i18n->get('38'), };
|
||||
}
|
||||
|
||||
my $success = $asset->demote();
|
||||
if (! $success) {
|
||||
return {
|
||||
error => sprintf($i18n->get('unable to demote assset', 'Asset'), $asset->getTitle),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
message => sprintf($i18n->get('demoted asset', 'Asset'), $asset->getTitle),
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
62
lib/WebGUI/AssetHelper/Promote.pm
Normal file
62
lib/WebGUI/AssetHelper/Promote.pm
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package WebGUI::AssetHelper::Promote;
|
||||
|
||||
use strict;
|
||||
use Class::C3;
|
||||
use base qw/WebGUI::AssetHelper/;
|
||||
|
||||
=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
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::AssetHelper::Promote
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Promotes the asset with respect to its siblings.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 process ( $class, $asset )
|
||||
|
||||
Promotes the asset. If the user cannot edit the asset it returns an error message.
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my ($class, $asset) = @_;
|
||||
my $session = $asset->session;
|
||||
|
||||
my $i18n = WebGUI::International->new($session, 'WebGUI');
|
||||
if (! $asset->canEdit) {
|
||||
return { error => $i18n->get('38'), };
|
||||
}
|
||||
|
||||
my $success = $asset->promote();
|
||||
if (! $success) {
|
||||
return {
|
||||
error => sprintf($i18n->get('unable to promote assset', 'Asset'), $asset->getTitle),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
message => sprintf($i18n->get('promoted asset', 'Asset'), $asset->getTitle),
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -1394,6 +1394,30 @@ Couldn't open %-s because %-s <br />
|
|||
context => q{%s will be replaced by the title of the asset.},
|
||||
},
|
||||
|
||||
'promoted asset' => {
|
||||
message => q{Asset %s was promoted.},
|
||||
lastUpdated => 0,
|
||||
context => q{%s will be replaced by the title of the asset.},
|
||||
},
|
||||
|
||||
'unable to promote asset' => {
|
||||
message => q{Unable to promote asset %s.},
|
||||
lastUpdated => 0,
|
||||
context => q{%s will be replaced by the title of the asset.},
|
||||
},
|
||||
|
||||
'demoted asset' => {
|
||||
message => q{Asset %s was demoted.},
|
||||
lastUpdated => 0,
|
||||
context => q{%s will be replaced by the title of the asset.},
|
||||
},
|
||||
|
||||
'unable to demote asset' => {
|
||||
message => q{Unable to demote asset %s.},
|
||||
lastUpdated => 0,
|
||||
context => q{%s will be replaced by the title of the asset.},
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
91
t/AssetHelper/Demote.t
Normal file
91
t/AssetHelper/Demote.t
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Write a little about what this script tests.
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::AssetHelper::Demote;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 3; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# put your tests here
|
||||
|
||||
my $output;
|
||||
my $home = WebGUI::Asset->getDefault($session);
|
||||
|
||||
$session->user({userId => 3});
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
|
||||
my $newPage = $home->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Layout',
|
||||
title => 'Test page',
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
my $article1 = $newPage->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Article',
|
||||
title => 'Article_1',
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
my $article2 = $newPage->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Article',
|
||||
title => 'Article_2',
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
$versionTag->commit;
|
||||
addToCleanup($versionTag);
|
||||
|
||||
$session->user({userId => 1});
|
||||
$output = WebGUI::AssetHelper::Demote->process($article1);
|
||||
cmp_deeply(
|
||||
$output,
|
||||
{
|
||||
error => re('You do not have sufficient privileges'),
|
||||
},
|
||||
'AssetHelper/Demote checks for editing privileges'
|
||||
);
|
||||
|
||||
$session->user({userId => 3});
|
||||
$output = WebGUI::AssetHelper::Demote->process($article1);
|
||||
cmp_deeply(
|
||||
$output,
|
||||
{
|
||||
message => re('was demoted'),
|
||||
},
|
||||
'AssetHelper/Demote returns a message'
|
||||
);
|
||||
|
||||
my $assets = $newPage->getLineage(['children'], { returnObjects => 1 });
|
||||
cmp_deeply(
|
||||
[ map { $_->getTitle } @{ $assets } ],
|
||||
[ qw{Article_2 Article_1} ],
|
||||
'... and assets were rearranged'
|
||||
);
|
||||
|
||||
#vim:ft=perl
|
||||
91
t/AssetHelper/Promote.t
Normal file
91
t/AssetHelper/Promote.t
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Write a little about what this script tests.
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::AssetHelper::Promote;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 3; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# put your tests here
|
||||
|
||||
my $output;
|
||||
my $home = WebGUI::Asset->getDefault($session);
|
||||
|
||||
$session->user({userId => 3});
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
|
||||
my $newPage = $home->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Layout',
|
||||
title => 'Test page',
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
my $article1 = $newPage->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Article',
|
||||
title => 'Article_1',
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
my $article2 = $newPage->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Article',
|
||||
title => 'Article_2',
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
$versionTag->commit;
|
||||
addToCleanup($versionTag);
|
||||
|
||||
$session->user({userId => 1});
|
||||
$output = WebGUI::AssetHelper::Promote->process($article2);
|
||||
cmp_deeply(
|
||||
$output,
|
||||
{
|
||||
error => re('You do not have sufficient privileges'),
|
||||
},
|
||||
'AssetHelper/Promote checks for editing privileges'
|
||||
);
|
||||
|
||||
$session->user({userId => 3});
|
||||
$output = WebGUI::AssetHelper::Promote->process($article2);
|
||||
cmp_deeply(
|
||||
$output,
|
||||
{
|
||||
message => re('was promoted'),
|
||||
},
|
||||
'AssetHelper/Promote returns a message'
|
||||
);
|
||||
|
||||
my $assets = $newPage->getLineage(['children'], { returnObjects => 1 });
|
||||
cmp_deeply(
|
||||
[ map { $_->getTitle } @{ $assets } ],
|
||||
[ qw{Article_2 Article_1} ],
|
||||
'... and assets were rearranged'
|
||||
);
|
||||
|
||||
#vim:ft=perl
|
||||
Loading…
Add table
Add a link
Reference in a new issue