From 33bf0bad973cd34b91a339931c0a80d19bad18ab Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 24 Nov 2009 13:40:56 -0800 Subject: [PATCH 01/22] Finish POD and AssetHelper base class sample code. --- lib/WebGUI/AssetHelper.pm | 55 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/AssetHelper.pm b/lib/WebGUI/AssetHelper.pm index b80ce4c53..4c0e9a73f 100644 --- a/lib/WebGUI/AssetHelper.pm +++ b/lib/WebGUI/AssetHelper.pm @@ -21,6 +21,10 @@ Package WebGUI::AssetHelper Base class for all Asset Helpers, which provide editing and administrative controls for Assets inside the Admin Console. +=head1 SYNOPSIS + +Despite using OO style methods, there are no AssetHelper objects. This is simply to provide inheritance. + =head1 METHODS These methods are available from this class: @@ -29,14 +33,61 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( ) +=head2 process ( $class, $asset ) -Default method called by the Asset Helper content handler. +This is a class method. Process is the default method called by the Asset Helper content handler. +It returns a hashref, that is converted by the content handler to JSON to be passed back to the +Admin Console. + +=head3 $class + +The name of the class this method was called as. + +=head3 $asset + +A WebGUI::Asset object. + +=head3 Hashref Payload + +=head4 error + +Displays an error message to the user. Should always be internationalized. + +=head4 message + +Displays an informational message to the user. Should always be internationalized. + +=head4 redirect + +Will open a tab in the Admin Console. Anything returned by the URL will be displayed in the tab. + +=head4 scriptFile + +Loads the requested JavaScript file, referenced by URL. + +=head4 scriptMethod + +Calls this method. + +=head4 scriptArgs + +An array reference of arguments that, when used with C, will be passed to the javascript method. =cut sub process { + my ($class, $asset) = @_; + ##This method can do work, or it can delegate out to other methods. + + return { + error => q{User, we have a problem.}, + message => q{A friendly informational method}, + redirect => '?op=assetHelper;className=WebGUI::AssetHelper;method=editBranch', + scriptFile => q{URL}, + scriptMethod => q{methodName}, + scriptArgs => [ 'arg1', { another => 'argument' } ], + }; } 1; From dcb4260490cbe6ba37fa13bb5d4cf5bb58d7b3ea Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 24 Nov 2009 14:48:51 -0800 Subject: [PATCH 02/22] Change redirect to open_tab, make redirect change the contents of the view tab in the admin console. --- lib/WebGUI/AssetHelper.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/WebGUI/AssetHelper.pm b/lib/WebGUI/AssetHelper.pm index 4c0e9a73f..fc9c627c3 100644 --- a/lib/WebGUI/AssetHelper.pm +++ b/lib/WebGUI/AssetHelper.pm @@ -49,17 +49,23 @@ A WebGUI::Asset object. =head3 Hashref Payload +Sending all hash keys at the same time may cause unpredictable results. + =head4 error -Displays an error message to the user. Should always be internationalized. +An error message to the user. Should always be internationalized. =head4 message -Displays an informational message to the user. Should always be internationalized. +An informational message to the user. Should always be internationalized. + +=head4 open_tab + +A URL. Will open a tab in the Admin Console. Anything returned by the URL will be displayed in the tab. =head4 redirect -Will open a tab in the Admin Console. Anything returned by the URL will be displayed in the tab. +A URL. Puts new content into the View tab from the requested URL. =head4 scriptFile @@ -83,7 +89,8 @@ sub process { return { error => q{User, we have a problem.}, message => q{A friendly informational method}, - redirect => '?op=assetHelper;className=WebGUI::AssetHelper;method=editBranch', + open_tab => '?op=assetHelper;className=WebGUI::AssetHelper;method=editBranch', + redirect => '/home', scriptFile => q{URL}, scriptMethod => q{methodName}, scriptArgs => [ 'arg1', { another => 'argument' } ], From e6696ee53494e5bfc12716b2d32925fba814d07e Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 24 Nov 2009 14:49:42 -0800 Subject: [PATCH 03/22] Asset Cut to clipboard Asset Helper (a port of www_cut as an Asset Helper) --- lib/WebGUI/AssetHelper/Cut.pm | 69 ++++++++++++++++++++++++++++++++ lib/WebGUI/i18n/English/Asset.pm | 6 +++ 2 files changed, 75 insertions(+) create mode 100644 lib/WebGUI/AssetHelper/Cut.pm diff --git a/lib/WebGUI/AssetHelper/Cut.pm b/lib/WebGUI/AssetHelper/Cut.pm new file mode 100644 index 000000000..7046e5b49 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Cut.pm @@ -0,0 +1,69 @@ +package WebGUI::AssetHelper::Cut; + +use Class::C3; +use base qw/WebGUI::AssetHelper/; +use WebGUI::Asset; + +=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::Cut + +=head1 DESCRIPTION + +Cuts an Asset to the Clipboard. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Cuts the asset to the clipboard. If the user cannot edit the asset, or the asset is a +system 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'), }; + } + elsif ( $asset->get('isSystem') ) { + return { error => $i18n->get('41'), }; + } + + my $success = $asset->cut(); + if (! $success) { + return { error => $i18n->get('41'), }; + } + + my $parent = $asset->getContainer; + if ($asset->getId eq $parent->getId) { + $parent = $asset->getParent; + } + return { + message => sprintf($i18n->get('cut asset', 'Asset'), $asset->getTitle), + redirect => $parent->getUrl, + }; +} + +1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 1ddb45db8..a0a412ce9 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1370,6 +1370,12 @@ Couldn't open %-s because %-s
context => q{}, }, + 'cut asset' => { + message => q{Asset %s was cut to the clipboard.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + }; 1; From da567e1fccd5c9d95b07ebd0ae2ed8bef99876f0 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 24 Nov 2009 21:36:02 -0800 Subject: [PATCH 04/22] Remove Database and FileCache modules. --- lib/WebGUI/Cache/Database.pm | 205 ------------------------ lib/WebGUI/Cache/FileCache.pm | 284 ---------------------------------- 2 files changed, 489 deletions(-) delete mode 100644 lib/WebGUI/Cache/Database.pm delete mode 100644 lib/WebGUI/Cache/FileCache.pm diff --git a/lib/WebGUI/Cache/Database.pm b/lib/WebGUI/Cache/Database.pm deleted file mode 100644 index b292ffb2b..000000000 --- a/lib/WebGUI/Cache/Database.pm +++ /dev/null @@ -1,205 +0,0 @@ -package WebGUI::Cache::Database; - -=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 - -use strict; -use base "WebGUI::Cache"; -use Storable (); - -=head1 NAME - -Package WebGUI::Cache::Database - -=head1 DESCRIPTION - -This package provides a means for WebGUI to cache data to the database. - -=head1 SYNOPSIS - - use WebGUI::Cache::Database; - -=head1 METHODS - -These methods are available from this class: - -=cut - - - - -#------------------------------------------------------------------- - -=head2 delete ( ) - -Remove content from the filesystem cache. - -=cut - -sub delete { - my $self = shift; - $self->session->db->write("delete from cache where namespace=? and cachekey=?",[$self->{_namespace}, $self->{_key}]); -} - -#------------------------------------------------------------------- - -=head2 deleteChunk ( key ) - -Remove a partial composite key from the cache. - -=head3 key - -A partial composite key to remove. - -=cut - -sub deleteChunk { - my $self = shift; - my $key = $self->parseKey(shift); - $self->session->db->write("delete from cache where namespace=? and cachekey like ?",[$self->{_namespace}, $key.'%']); -} - -#------------------------------------------------------------------- - -=head2 flush ( ) - -Remove all objects from the filecache system. - -=cut - -sub flush { - my $self = shift; - $self->SUPER::flush(); - $self->session->db->write("delete from cache where namespace=?",[$self->{_namespace}]); -} - -#------------------------------------------------------------------- - -=head2 get ( ) - -Retrieve content from the database cache. - -=cut - -sub get { - my $self = shift; - my $session = $self->session; - return undef if ($session->config->get("disableCache")); - my $sth = $session->db->dbh->prepare("select content from cache where namespace=? and cachekey=? and expires>?"); - $sth->execute($self->{_namespace},$self->{_key},time()); - my $data = $sth->fetchrow_arrayref; - $sth->finish; - my $content = $data->[0]; - return undef unless ($content); - # Storable doesn't like non-reference arguments, so we wrap it in a scalar ref. - eval { - $content = Storable::thaw($content); - }; - return undef unless $content && ref $content; - return $$content; -} - -#------------------------------------------------------------------- - -=head2 getNamespaceSize ( ) - -Returns the size (in bytes) of the current cache under this namespace. Consequently it also cleans up expired cache items. - -=cut - -sub getNamespaceSize { - my $self = shift; - my $expiresModifier = shift || 0; - $self->session->db->write("delete from cache where expires < ?",[time()+$expiresModifier]); - my ($size) = $self->session->db->quickArray("select sum(size) from cache where namespace=?",[$self->{_namespace}]); - return $size; -} - -#------------------------------------------------------------------- - -=head2 new ( session, key [, namespace ] ) - -Constructor. - -=head3 session - -A reference to the current session. - -=head3 key - -A key unique to this namespace. It is used to uniquely identify the cached content. - -=head3 namespace - -Defaults to the config filename for the current site. The only reason to override the default is if you want the cached content to be shared among all WebGUI instances on this machine. A common alternative namespace is "URL", which is typically used when caching content using the setByHTTP method. - -=cut - -sub new { - my $cache; - my $class = shift; - my $session = shift; - my $key = $class->parseKey(shift); - my $namespace = shift || $session->config->getFilename; - bless {_session=>$session, _key=>$key, _namespace=>$namespace}, $class; -} - - -#------------------------------------------------------------------- - -=head2 set ( content [, ttl ] ) - -Save content to the filesystem cache. - -=head3 content - -A scalar variable containing the content to be set. - -=head3 ttl - -The time to live for this content. This is the amount of time (in seconds) that the content will remain in the cache. Defaults to "60". - -=cut - -sub set { - my $self = shift; - # Storable doesn't like non-reference arguments, so we wrap it in a scalar ref. - my $content = Storable::nfreeze(\(scalar shift)); - my $ttl = shift || 60; - my $size = length($content); - # getting better performance using native dbi than webgui sql - my $dbh = $self->session->db->dbh; - my $sth = $dbh->prepare("replace into cache (namespace,cachekey,expires,size,content) values (?,?,?,?,?)"); - $sth->execute($self->{_namespace}, $self->{_key}, time()+$ttl, $size, $content); - $sth->finish; -} - - -#------------------------------------------------------------------- - -=head2 stats ( ) - -Returns statistic information about the caching system. - -=cut - -sub stats { - my $self = shift; - my ($size) = $self->session->db->quickArray("select sum(size) from cache where namespace=?",[$self->{_namespace}]); - return $size." bytes"; -} - -1; - - diff --git a/lib/WebGUI/Cache/FileCache.pm b/lib/WebGUI/Cache/FileCache.pm deleted file mode 100644 index 0ce7a2a35..000000000 --- a/lib/WebGUI/Cache/FileCache.pm +++ /dev/null @@ -1,284 +0,0 @@ -package WebGUI::Cache::FileCache; - -=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 - -use strict; -use Storable (); -use File::Path (); -use File::Find (); - -our @ISA = qw(WebGUI::Cache); - -=head1 NAME - -Package WebGUI::Cache::FileCache - -=head1 DESCRIPTION - -This package provides a means for WebGUI to cache data to the filesystem. - -=head1 SYNOPSIS - - use WebGUI::Cache::FileCache; - -=head1 METHODS - -These methods are available from this class: - -=cut - - - - -#------------------------------------------------------------------- - -=head2 delete ( ) - -Remove content from the filesystem cache. - -=cut - -sub delete { - my $self = shift; - my $folder = $self->getFolder; - if (-e $folder) { - File::Path::rmtree($folder); - } -} - -#------------------------------------------------------------------- - -=head2 deleteChunk ( key ) - -Remove a partial composite key from the cache. - -=head3 key - -A partial composite key to remove. - -=cut - -sub deleteChunk { - my $self = shift; - my $folder = $self->getNamespaceRoot."/".$self->parseKey(shift); - if (-e $folder) { - File::Path::rmtree($folder); - } -} - -#------------------------------------------------------------------- - -=head2 flush ( ) - -Remove all objects from the filecache system. - -=cut - -sub flush { - my $self = shift; - $self->SUPER::flush(); - my $folder = $self->getNamespaceRoot; - if (-e $folder) { - File::Path::rmtree($folder); - } -} - -#------------------------------------------------------------------- - -=head2 get ( ) - -Retrieve content from the filesystem cache. - -=cut - -sub get { - my $self = shift; - return undef if ($self->session->config->get("disableCache")); - my $folder = $self->getFolder; - if (-e $folder."/expires" && -e $folder."/cache" && open(my $FILE,"<",$folder."/expires")) { - my $expires = <$FILE>; - close($FILE); - return undef if ($expires < time); - my $value; - eval {$value = Storable::retrieve($folder."/cache")}; - if (ref $value eq "SCALAR") { - return $$value; - } else { - return $value; - } - } - return undef; -} - -#------------------------------------------------------------------- - -=head2 getFolder ( ) - -Returns the path to the cache folder for this key. - -=cut - -sub getFolder { - my $self = shift; - return $self->getNamespaceRoot()."/".$self->{_key}; -} - -#------------------------------------------------------------------- - -=head2 getNamespaceRoot ( ) - -Figures out what the cache root for this namespace should be. A class method. - -=cut - -sub getNamespaceRoot { - my $self = shift; - my $root = $self->session->config->get("fileCacheRoot"); - unless ($root) { - if ($self->session->os->get("windowsish")) { - $root = $self->session->env->get("TEMP") || $self->session->env->get("TMP") || "/temp"; - } else { - $root = "/tmp"; - } - $root .= "/WebGUICache"; - } - $root .= "/".$self->{_namespace}; - return $root; -} - -#------------------------------------------------------------------- - -=head2 getNamespaceSize ( ) - -Returns the size (in bytes) of the current cache under this namespace. Consequently it also cleans up expired cache items. - -=cut - -sub getNamespaceSize { - my $self = shift; - my $expiresModifier = shift || 0; - my $cacheSize = 0; - File::Find::find({ - no_chdir => 1, - wanted => sub { - return - unless $File::Find::name =~ m/expires$/; - if ( open my $FILE, "<", $File::Find::name ) { - my $expires = <$FILE>; - close $FILE; - if ($expires < time + $expiresModifier) { - File::Path::rmtree($File::Find::dir); - $File::Find::prune = 1; - return - } - else { - $cacheSize += -s $File::Find::dir.'/cache'; - } - } - }, - }, $self->getNamespaceRoot); - return $cacheSize; -} - -#------------------------------------------------------------------- - -=head2 new ( session, key [, namespace ] ) - -Constructor. - -=head3 session - -A reference to the current session. - -=head3 key - -A key unique to this namespace. It is used to uniquely identify the cached content. - -=head3 namespace - -Defaults to the config filename for the current site. The only reason to override the default is if you want the cached content to be shared among all WebGUI instances on this machine. A common alternative namespace is "URL", which is typically used when caching content using the setByHTTP method. - -=cut - -sub new { - my $cache; - my $class = shift; - my $session = shift; - my $key = $class->parseKey(shift); - my $namespace = shift || $session->config->getFilename; - bless {_session=>$session, _key=>$key, _namespace=>$namespace}, $class; -} - - -#------------------------------------------------------------------- - -=head2 set ( content [, ttl ] ) - -Save content to the filesystem cache. - -=head3 content - -A scalar variable containing the content to be set. - -=head3 ttl - -The time to live for this content. This is the amount of time (in seconds) that the content will remain in the cache. Defaults to "60". - -=cut - -sub set { - my $self = shift; - my $content = shift; - my $ttl = shift || 60; - my $oldumask = umask(); - umask(0000); - my $path = $self->getFolder(); - unless (-e $path) { - eval {File::Path::mkpath($path,0)}; - if ($@) { - $self->session->errorHandler->error("Couldn't create cache folder: ".$path." : ".$@); - return undef; - } - } - my $value; - unless (ref $content) { - $value = \$content; - } else { - $value = $content; - } - Storable::nstore($value, $path."/cache"); - open my $FILE, ">", $path."/expires"; - print $FILE time + $ttl; - close $FILE; - umask($oldumask); -} - - -#------------------------------------------------------------------- - -=head2 stats ( ) - -Returns statistic information about the caching system. - -=cut - -sub stats { - my $self = shift; - return $self->getNamespaceSize." bytes"; -} - -1; - - From ed8f2c4a8fc79b3a1bb5e0a7a242ff92e47f9303 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 25 Nov 2009 10:31:06 -0800 Subject: [PATCH 05/22] A few small tweaks, and a test. --- lib/WebGUI/AssetHelper/Cut.pm | 2 +- t/AssetHelper/Cut.t | 79 +++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 t/AssetHelper/Cut.t diff --git a/lib/WebGUI/AssetHelper/Cut.pm b/lib/WebGUI/AssetHelper/Cut.pm index 7046e5b49..dad38b074 100644 --- a/lib/WebGUI/AssetHelper/Cut.pm +++ b/lib/WebGUI/AssetHelper/Cut.pm @@ -1,8 +1,8 @@ package WebGUI::AssetHelper::Cut; +use strict; use Class::C3; use base qw/WebGUI::AssetHelper/; -use WebGUI::Asset; =head1 LEGAL diff --git a/t/AssetHelper/Cut.t b/t/AssetHelper/Cut.t new file mode 100644 index 000000000..50adabedd --- /dev/null +++ b/t/AssetHelper/Cut.t @@ -0,0 +1,79 @@ +# 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::Cut; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 5; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# put your tests here + +my $output; +my $home = WebGUI::Asset->getDefault($session); + +$session->user({userId => 1}); +$output = WebGUI::AssetHelper::Cut->process($home); +cmp_deeply( + $output, + { + error => re('You do not have sufficient privileges'), + }, + 'AssetHelper/Cut checks for editing privileges' +); + +$session->user({userId => 3}); +$output = WebGUI::AssetHelper::Cut->process($home); +cmp_deeply( + $output, + { + error => re('vital component'), + }, + 'AssetHelper/Cut checks for system pages' +); + +my $safe_page = $home->getFirstChild; +$output = WebGUI::AssetHelper::Cut->process($safe_page); +cmp_deeply( + $output, + { + message => re('was cut to the clipboard'), + redirect => $home->getUrl, + }, + 'AssetHelper/Cut returns a message and a redirect' +); +is $safe_page->get('state'), 'clipboard', '... and the asset was really cut'; + +$home->paste($safe_page->getId); + +$safe_page = $safe_page->cloneFromDb(); +is $safe_page->get('state'), 'published', 'reset asset for further testing'; + +#vim:ft=perl From 7298af49ea0f41897f50bb0b89a2a5ae42a675dd Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 25 Nov 2009 16:32:52 -0800 Subject: [PATCH 06/22] Copy Asset Helper (self only). --- lib/WebGUI/AssetHelper/Copy.pm | 82 ++++++++++++++++++++++++++++++++ lib/WebGUI/i18n/English/Asset.pm | 6 +++ t/AssetHelper/Copy.t | 73 ++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 lib/WebGUI/AssetHelper/Copy.pm create mode 100644 t/AssetHelper/Copy.t diff --git a/lib/WebGUI/AssetHelper/Copy.pm b/lib/WebGUI/AssetHelper/Copy.pm new file mode 100644 index 000000000..a5363a7d6 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Copy.pm @@ -0,0 +1,82 @@ +package WebGUI::AssetHelper::Copy; + +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::Copy + +=head1 DESCRIPTION + +Copy an Asset to the Clipboard, with no children. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 duplicate ( $class, $asset ) + +Duplicates the asset. Extracted out so that it can be subclassed by copy with children, +and copy with descendants. + +=cut + +sub duplicate { + my ($class, $asset) = @_; + return $asset->duplicate; +} + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Copies the asset to the clipboard. There are no privilege or safety checks, since all operations +are done on the copy. + +=cut + +sub process { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, 'Asset'); + + my $newAsset = $class->duplicate($asset); + $newAsset->update({ title=>sprintf("%s (%s)",$asset->getTitle,$i18n->get('copy'))}); + $newAsset->cut; + + my $message = sprintf($i18n->get('copied asset'), $asset->getTitle); + + my $payload = { + message => $message, + }; + + if (WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { + allowComments => 1, + returnUrl => $asset->getUrl, + }) eq 'redirect') { + return undef; + $payload->{open_tab} = $session->http->getRedirectLocation; + }; + + return $payload; +} + +1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index a0a412ce9..128acc023 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1376,6 +1376,12 @@ Couldn't open %-s because %-s
context => q{%s will be replaced by the title of the asset.}, }, + 'copied asset' => { + message => q{Asset %s was copied to the clipboard.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + }; 1; diff --git a/t/AssetHelper/Copy.t b/t/AssetHelper/Copy.t new file mode 100644 index 000000000..e8d66755f --- /dev/null +++ b/t/AssetHelper/Copy.t @@ -0,0 +1,73 @@ +# 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::Copy; + +#---------------------------------------------------------------------------- +# 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); + +$output = WebGUI::AssetHelper::Copy->process($home); +cmp_deeply( + $output, + { + message => re('was copied to the clipboard'), + }, + 'AssetHelper/Copy redirects the back to the copied asset' +); + +my $clippies = $home->getAssetsInClipboard(); +is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children'; + +foreach my $asset (@{ $clippies }) { + $asset->purge; +} + +$session->setting->set('skipCommitComments', 0); + +$output = WebGUI::AssetHelper::Copy->process($home); +cmp_deeply( + $output, + { + message => re('was copied to the clipboard'), + open_tab => $home->getUrl, + }, + 'AssetHelper/Copy opens a tab for commit comments' +); + +foreach my $asset (@{ $clippies }) { + $asset->purge; +} +#vim:ft=perl From 0b124f269c3d3172774c52e1af97f30a497c9187 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 25 Nov 2009 16:45:09 -0800 Subject: [PATCH 07/22] Finish Copy (self) Helper. --- lib/WebGUI/AssetHelper/Copy.pm | 1 - t/AssetHelper/Copy.t | 50 ++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/WebGUI/AssetHelper/Copy.pm b/lib/WebGUI/AssetHelper/Copy.pm index a5363a7d6..36c00aab6 100644 --- a/lib/WebGUI/AssetHelper/Copy.pm +++ b/lib/WebGUI/AssetHelper/Copy.pm @@ -72,7 +72,6 @@ sub process { allowComments => 1, returnUrl => $asset->getUrl, }) eq 'redirect') { - return undef; $payload->{open_tab} = $session->http->getRedirectLocation; }; diff --git a/t/AssetHelper/Copy.t b/t/AssetHelper/Copy.t index e8d66755f..25171015f 100644 --- a/t/AssetHelper/Copy.t +++ b/t/AssetHelper/Copy.t @@ -39,35 +39,37 @@ plan tests => 3; # Increment this number for each test you create my $output; my $home = WebGUI::Asset->getDefault($session); -$output = WebGUI::AssetHelper::Copy->process($home); -cmp_deeply( - $output, - { - message => re('was copied to the clipboard'), - }, - 'AssetHelper/Copy redirects the back to the copied asset' -); +{ -my $clippies = $home->getAssetsInClipboard(); -is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children'; + $output = WebGUI::AssetHelper::Copy->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard'), + }, + 'AssetHelper/Copy redirects the back to the copied asset' + ); -foreach my $asset (@{ $clippies }) { - $asset->purge; + my $clippies = $home->getAssetsInClipboard(); + is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children'; + addToCleanup(@{ $clippies }); } -$session->setting->set('skipCommitComments', 0); +{ + $session->setting->set('skipCommitComments', 0); -$output = WebGUI::AssetHelper::Copy->process($home); -cmp_deeply( - $output, - { - message => re('was copied to the clipboard'), - open_tab => $home->getUrl, - }, - 'AssetHelper/Copy opens a tab for commit comments' -); + $output = WebGUI::AssetHelper::Copy->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard'), + open_tab => re('^'.$home->getUrl), + }, + 'AssetHelper/Copy opens a tab for commit comments' + ); -foreach my $asset (@{ $clippies }) { - $asset->purge; + my $clippies = $home->getAssetsInClipboard(); + addToCleanup(@{ $clippies }); } + #vim:ft=perl From 9eadb2642a44b8be4b1613a5e6fe82d64cf89e40 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Nov 2009 09:37:10 -0800 Subject: [PATCH 08/22] Make the message subclassable, too. --- lib/WebGUI/AssetHelper/Copy.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/AssetHelper/Copy.pm b/lib/WebGUI/AssetHelper/Copy.pm index 36c00aab6..a57182506 100644 --- a/lib/WebGUI/AssetHelper/Copy.pm +++ b/lib/WebGUI/AssetHelper/Copy.pm @@ -46,6 +46,18 @@ sub duplicate { #------------------------------------------------------------------- +=head2 getMessage ( ) + +Returns the name of the i18n message to use + +=cut + +sub getMessage { + return 'copied asset'; +} + +#------------------------------------------------------------------- + =head2 process ( $class, $asset ) Copies the asset to the clipboard. There are no privilege or safety checks, since all operations @@ -62,7 +74,7 @@ sub process { $newAsset->update({ title=>sprintf("%s (%s)",$asset->getTitle,$i18n->get('copy'))}); $newAsset->cut; - my $message = sprintf($i18n->get('copied asset'), $asset->getTitle); + my $message = sprintf($i18n->get($class->getMessage()), $asset->getTitle); my $payload = { message => $message, From 80a6b90353a824560fa9c006747f44e1ad6ad03c Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Nov 2009 09:37:56 -0800 Subject: [PATCH 09/22] Add Copy with children Asset Helper --- lib/WebGUI/AssetHelper/Copy/WithChildren.pm | 59 ++++++++++++++++ lib/WebGUI/i18n/English/Asset.pm | 6 ++ t/AssetHelper/Copy.t | 5 +- t/AssetHelper/Copy/WithChildren.t | 78 +++++++++++++++++++++ 4 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 lib/WebGUI/AssetHelper/Copy/WithChildren.pm create mode 100644 t/AssetHelper/Copy/WithChildren.t diff --git a/lib/WebGUI/AssetHelper/Copy/WithChildren.pm b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm new file mode 100644 index 000000000..980c43000 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm @@ -0,0 +1,59 @@ +package WebGUI::AssetHelper::Copy::WithChildren; + +use strict; +use Class::C3; +use base qw/WebGUI::AssetHelper::Copy/; + +=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::Copy::WithChildren + +=head1 DESCRIPTION + +Copy an Asset to the Clipboard, with children only. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 duplicate ( $class, $asset ) + +Duplicates the asset. Extracted out so that it can be subclassed by copy with children, +and copy with descendants. + +=cut + +sub duplicate { + my ($class, $asset) = @_; + return $asset->duplicateBranch(1); +} + +#------------------------------------------------------------------- + +=head2 getMessage ( ) + +Returns the name of the i18n message to use + +=cut + +sub getMessage { + return 'copied asset with children'; +} + +1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 128acc023..2a71c0ab8 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1382,6 +1382,12 @@ Couldn't open %-s because %-s
context => q{%s will be replaced by the title of the asset.}, }, + 'copied asset with children' => { + message => q{Asset %s was copied to the clipboard with its children.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + }; 1; diff --git a/t/AssetHelper/Copy.t b/t/AssetHelper/Copy.t index 25171015f..df52d9b32 100644 --- a/t/AssetHelper/Copy.t +++ b/t/AssetHelper/Copy.t @@ -38,6 +38,7 @@ plan tests => 3; # Increment this number for each test you create my $output; my $home = WebGUI::Asset->getDefault($session); +my $root = WebGUI::Asset->getRoot($session); { @@ -50,7 +51,7 @@ my $home = WebGUI::Asset->getDefault($session); 'AssetHelper/Copy redirects the back to the copied asset' ); - my $clippies = $home->getAssetsInClipboard(); + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children'; addToCleanup(@{ $clippies }); } @@ -68,7 +69,7 @@ my $home = WebGUI::Asset->getDefault($session); 'AssetHelper/Copy opens a tab for commit comments' ); - my $clippies = $home->getAssetsInClipboard(); + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); addToCleanup(@{ $clippies }); } diff --git a/t/AssetHelper/Copy/WithChildren.t b/t/AssetHelper/Copy/WithChildren.t new file mode 100644 index 000000000..98050e9b5 --- /dev/null +++ b/t/AssetHelper/Copy/WithChildren.t @@ -0,0 +1,78 @@ +# 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::Copy::WithChildren; + +#---------------------------------------------------------------------------- +# 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); +my $root = WebGUI::Asset->getRoot($session); + +$session->user({userId => 3}); + +{ + + $output = WebGUI::AssetHelper::Copy::WithChildren->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard with its children'), + }, + 'AssetHelper/Copy redirects the back to the copied asset' + ); + + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); + is @{ $clippies }, 10, '... only copied the asset to the clipboard with children'; + addToCleanup(@{ $clippies }); +} + +{ + $session->setting->set('skipCommitComments', 0); + + $output = WebGUI::AssetHelper::Copy::WithChildren->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard with its children'), + open_tab => re('^'.$home->getUrl), + }, + 'AssetHelper/Copy/WithChildren opens a tab for commit comments' + ); + + my $clippies = $home->getAssetsInClipboard(); + addToCleanup(@{ $clippies }); +} + +#vim:ft=perl From 2ea377b87dcf0f393bcde741ff953417b7ee172a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Nov 2009 09:41:12 -0800 Subject: [PATCH 10/22] Fix test comment. --- t/AssetHelper/Copy/WithChildren.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/AssetHelper/Copy/WithChildren.t b/t/AssetHelper/Copy/WithChildren.t index 98050e9b5..19b83b55f 100644 --- a/t/AssetHelper/Copy/WithChildren.t +++ b/t/AssetHelper/Copy/WithChildren.t @@ -50,7 +50,7 @@ $session->user({userId => 3}); { message => re('was copied to the clipboard with its children'), }, - 'AssetHelper/Copy redirects the back to the copied asset' + 'AssetHelper/Copy/WithChildren redirects the back to the copied asset' ); my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); From 39ffaba487774ba8f2980568c982a1fa46c44d3a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Nov 2009 09:46:14 -0800 Subject: [PATCH 11/22] Add copy with descendants. --- lib/WebGUI/AssetHelper/Copy/WithChildren.pm | 3 +- .../AssetHelper/Copy/WithDescendants.pm | 58 ++++++++++++++ lib/WebGUI/i18n/English/Asset.pm | 6 ++ t/AssetHelper/Copy/WithDescendants.t | 78 +++++++++++++++++++ 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 lib/WebGUI/AssetHelper/Copy/WithDescendants.pm create mode 100644 t/AssetHelper/Copy/WithDescendants.t diff --git a/lib/WebGUI/AssetHelper/Copy/WithChildren.pm b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm index 980c43000..880a1e71b 100644 --- a/lib/WebGUI/AssetHelper/Copy/WithChildren.pm +++ b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm @@ -34,8 +34,7 @@ These methods are available from this class: =head2 duplicate ( $class, $asset ) -Duplicates the asset. Extracted out so that it can be subclassed by copy with children, -and copy with descendants. +Duplicates the asset with children, =cut diff --git a/lib/WebGUI/AssetHelper/Copy/WithDescendants.pm b/lib/WebGUI/AssetHelper/Copy/WithDescendants.pm new file mode 100644 index 000000000..b0e3600b5 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Copy/WithDescendants.pm @@ -0,0 +1,58 @@ +package WebGUI::AssetHelper::Copy::WithDescendants; + +use strict; +use Class::C3; +use base qw/WebGUI::AssetHelper::Copy/; + +=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::Copy::WithDescendants + +=head1 DESCRIPTION + +Copy an Asset to the Clipboard, with all descendants. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 duplicate ( $class, $asset ) + +Duplicates the asset with descendants. + +=cut + +sub duplicate { + my ($class, $asset) = @_; + return $asset->duplicateBranch(); +} + +#------------------------------------------------------------------- + +=head2 getMessage ( ) + +Returns the name of the i18n message to use + +=cut + +sub getMessage { + return 'copied asset with descendants'; +} + +1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 2a71c0ab8..300189fc7 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1388,6 +1388,12 @@ Couldn't open %-s because %-s
context => q{%s will be replaced by the title of the asset.}, }, + 'copied asset with descendants' => { + message => q{Asset %s was copied to the clipboard with all descendants.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + }; 1; diff --git a/t/AssetHelper/Copy/WithDescendants.t b/t/AssetHelper/Copy/WithDescendants.t new file mode 100644 index 000000000..d44f394bc --- /dev/null +++ b/t/AssetHelper/Copy/WithDescendants.t @@ -0,0 +1,78 @@ +# 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::Copy::WithDescendants; + +#---------------------------------------------------------------------------- +# 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); +my $root = WebGUI::Asset->getRoot($session); + +$session->user({userId => 3}); + +{ + + $output = WebGUI::AssetHelper::Copy::WithDescendants->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard with all descendants'), + }, + 'AssetHelper/Copy/WithDescendants redirects the back to the copied asset' + ); + + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); + is @{ $clippies }, 27, '... only copied the asset to the clipboard with children'; + addToCleanup(@{ $clippies }); +} + +{ + $session->setting->set('skipCommitComments', 0); + + $output = WebGUI::AssetHelper::Copy::WithDescendants->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard with all descendants'), + open_tab => re('^'.$home->getUrl), + }, + 'AssetHelper/Copy/WithDescendants opens a tab for commit comments' + ); + + my $clippies = $home->getAssetsInClipboard(); + addToCleanup(@{ $clippies }); +} + +#vim:ft=perl From 7d9ee7b0a68cf72b13f05a60ebef38aab95dd660 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Nov 2009 10:29:49 -0800 Subject: [PATCH 12/22] Add Promote and Demote helpers. --- lib/WebGUI/AssetHelper/Demote.pm | 62 +++++++++++++++++++++ lib/WebGUI/AssetHelper/Promote.pm | 62 +++++++++++++++++++++ lib/WebGUI/i18n/English/Asset.pm | 24 ++++++++ t/AssetHelper/Demote.t | 91 +++++++++++++++++++++++++++++++ t/AssetHelper/Promote.t | 91 +++++++++++++++++++++++++++++++ 5 files changed, 330 insertions(+) create mode 100644 lib/WebGUI/AssetHelper/Demote.pm create mode 100644 lib/WebGUI/AssetHelper/Promote.pm create mode 100644 t/AssetHelper/Demote.t create mode 100644 t/AssetHelper/Promote.t diff --git a/lib/WebGUI/AssetHelper/Demote.pm b/lib/WebGUI/AssetHelper/Demote.pm new file mode 100644 index 000000000..5a75f86be --- /dev/null +++ b/lib/WebGUI/AssetHelper/Demote.pm @@ -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; diff --git a/lib/WebGUI/AssetHelper/Promote.pm b/lib/WebGUI/AssetHelper/Promote.pm new file mode 100644 index 000000000..943628dc3 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Promote.pm @@ -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; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 300189fc7..2cfb248e5 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1394,6 +1394,30 @@ Couldn't open %-s because %-s
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; diff --git a/t/AssetHelper/Demote.t b/t/AssetHelper/Demote.t new file mode 100644 index 000000000..e56da6a41 --- /dev/null +++ b/t/AssetHelper/Demote.t @@ -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 diff --git a/t/AssetHelper/Promote.t b/t/AssetHelper/Promote.t new file mode 100644 index 000000000..640b3f4c2 --- /dev/null +++ b/t/AssetHelper/Promote.t @@ -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 From e006139a98ad4f018c880bc3b0dbf61cf2a9378d Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Nov 2009 10:44:29 -0800 Subject: [PATCH 13/22] Note which Asset Helpers need to be done. --- README | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README b/README index ff995c2b5..f0fd59575 100644 --- a/README +++ b/README @@ -1 +1,15 @@ This is a WebGUI 8 development branch for the creation of Asset Helpers. + +Top level Asset Helpers + +* Promote +* Demote +* Copy +* Copy with children +* Copy with descendants +* Cut +Manage +* Revisions +Edit Branch +Edit Url +Export From eba37b8bc1d864ceb5e06308885d2a6c2f491a65 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 28 Nov 2009 09:36:34 -0800 Subject: [PATCH 14/22] Beginning work on Revision assetHelper --- lib/WebGUI/AssetHelper/Revisions.pm | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/WebGUI/AssetHelper/Revisions.pm diff --git a/lib/WebGUI/AssetHelper/Revisions.pm b/lib/WebGUI/AssetHelper/Revisions.pm new file mode 100644 index 000000000..92b33a939 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Revisions.pm @@ -0,0 +1,49 @@ +package WebGUI::AssetHelper::Revisions; + +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::Revisions + +=head1 DESCRIPTION + +Displays the revisions for this asset. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Opens a new tab for displaying revisions of this asset. + +=cut + +sub process { + my ($class, $asset) = @_; + + return { + open_tab => $asset->getUrl('func=manageRevisions'), + }; +} + +1; From 3eb0ac756f9a4d04ea16084ffc32c655223429a1 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 29 Nov 2009 16:03:51 -0800 Subject: [PATCH 15/22] Flesh out Revisions assetHelper. Add a simple method to WebGUI::HTML to format an array as a table row. Do not join non-asset tables in queries. --- lib/WebGUI/AssetHelper/Revisions.pm | 50 ++++++++++++++++++++++++++++- lib/WebGUI/HTML.pm | 22 +++++++++++++ t/HTML/addToRow.t | 37 +++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 t/HTML/addToRow.t diff --git a/lib/WebGUI/AssetHelper/Revisions.pm b/lib/WebGUI/AssetHelper/Revisions.pm index 92b33a939..6e09fa715 100644 --- a/lib/WebGUI/AssetHelper/Revisions.pm +++ b/lib/WebGUI/AssetHelper/Revisions.pm @@ -3,6 +3,8 @@ package WebGUI::AssetHelper::Revisions; use strict; use Class::C3; use base qw/WebGUI::AssetHelper/; +use WebGUI::User; +use WebGUI::HTML; =head1 LEGAL @@ -40,10 +42,56 @@ Opens a new tab for displaying revisions of this asset. sub process { my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } return { - open_tab => $asset->getUrl('func=manageRevisions'), + open_tab => $asset->getUrl('op=assetHelper;className=WebGUI::AssetHelper::Revisions;func=manageRevisions'), }; } +#------------------------------------------------------------------- + +=head2 www_manageRevisions ( $class, $asset ) + +Displays a table of revision data for this asset, along with links to edit each revision, view it, or delete it. + +=cut + +sub www_manageRevisions { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } + my $output = sprintf qq{\n + \n}, + $i18n->get('revision date'), $i18n->get('revised by'), $i18n->get('tag name'); + my $sth = $session->db->read("select ad.revisionDate, ad.revisedBy, at.name, ad.tagId from assetData as ad + left join assetVersionTag as at on ad.tagId=at.tagId where ad.assetId=? order by revisionDate desc", [$asset->getId]); + my $url = $asset->get('url'); + while (my ($date, $userId, $tagName, $tagId) = $sth->array) { + my $user = WebGUI::User->new($session, $userId); + $output .= WebGUI::HTML::arrayToRow( + $session->icon->delete("func=purgeRevision;revisionDate=".$date, $url, $i18n->get("purge revision prompt")) + .$session->icon->view( "func=view;revision=" . $date ) + .$session->icon->edit( "func=edit;revision=" . $date ), + $session->datetime->epochToHuman($date), + $user->username, + ''.$tagName.'' + ); + } + $sth->finish; + $output .= '
%s%s%s
'; + return $output; +} + 1; diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm index 2e9c80f1d..478698b2d 100644 --- a/lib/WebGUI/HTML.pm +++ b/lib/WebGUI/HTML.pm @@ -39,6 +39,7 @@ A package for manipulating and massaging HTML. $html = WebGUI::HTML::makeAbsolute($session, $html); $html = WebGUI::HTML::processReplacements($session, $html); $html = WebGUI::HTML::splitTag([$tag,]$html[,$count]); # defaults to ( 'p', $html, 1 ) + $html = WebGUI::HTML::arrayToRow(@columnData); =head1 METHODS @@ -47,6 +48,27 @@ These methods are available from this package: =cut +#------------------------------------------------------------------- + +=head2 arrayToRow ( @columnData ) + +Wraps each element of @columnData in a table cell tag, concatenates them all together, +and then wraps that in table row tags. + +=head3 @columnData + +An array of strings to wrap. + +=cut + +sub arrayToRow { + my @columnData = @_; + my $output = ''; + $output .= join '', @columnData; + $output .= ''; + return $output; +} + #------------------------------------------------------------------- =head2 cleanSegment ( html , preserveStyleScript ) diff --git a/t/HTML/addToRow.t b/t/HTML/addToRow.t new file mode 100644 index 000000000..6384a02e4 --- /dev/null +++ b/t/HTML/addToRow.t @@ -0,0 +1,37 @@ +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; +use WebGUI::HTML; +use WebGUI::Session; + +use Test::More; +use Test::Deep; +use Data::Dumper; + +my $session = WebGUI::Test->session; + +plan tests => 3; + +is WebGUI::HTML::arrayToRow(1), + '1', + 'addToRow: 1 element'; + +is WebGUI::HTML::arrayToRow(1,2), + '12', + '... 2 elements'; + +is WebGUI::HTML::arrayToRow(), + '', + '... 0 elements'; From b065f20397867fdfce6e43b6bb74636f845e2257 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 29 Nov 2009 21:34:35 -0800 Subject: [PATCH 16/22] ChangeUrl Asset Helper Needs tests, and will have issues with closing the Admin Console IFRAME when done. --- README | 2 +- lib/WebGUI/AssetHelper/ChangeUrl.pm | 135 ++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 lib/WebGUI/AssetHelper/ChangeUrl.pm diff --git a/README b/README index f0fd59575..2cb2dffcf 100644 --- a/README +++ b/README @@ -11,5 +11,5 @@ Top level Asset Helpers Manage * Revisions Edit Branch -Edit Url +* Edit Url Export diff --git a/lib/WebGUI/AssetHelper/ChangeUrl.pm b/lib/WebGUI/AssetHelper/ChangeUrl.pm new file mode 100644 index 000000000..784edebf9 --- /dev/null +++ b/lib/WebGUI/AssetHelper/ChangeUrl.pm @@ -0,0 +1,135 @@ +package WebGUI::AssetHelper::ChangeUrl; + +use strict; +use Class::C3; +use base qw/WebGUI::AssetHelper/; +use WebGUI::Session; + +=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::ChangeUrl + +=head1 DESCRIPTION + +Changes the current URL for this Asset, and delete all previous versions of the +asset so that it only exists via this URL. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Opens a new tab for displaying the form to change the Asset's URL. + +=cut + +sub process { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } + + return { + open_tab => $asset->getUrl('op=assetHelper;className=WebGUI::AssetHelper::ChangeUrl;func=changeUrl'), + }; +} + +#------------------------------------------------------------------- + +=head2 www_changeUrl ( $class, $asset ) + +Displays a form to change the URL for this asset. + +=cut + +sub www_changeUrl { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } + my $f = WebGUI::HTMLForm->new($session, action=>$asset->getUrl); + $f->hidden(name=>"func", value=>"changeUrlSave"); + $f->hidden(name=>"proceed", value=>$session->form->param("proceed")); + $f->text( + name => "url", + value => $asset->get('url'), + label => $i18n->get("104"), + hoverHelp=> $i18n->get('104 description'), + ); + $f->yesNo( + name => "confirm", + value => 0, + label => $i18n->get("confirm change"), + hoverHelp=> $i18n->get("confirm change url message"), + subtext => '
'.$i18n->get("confirm change url message") + ); + $f->submit; + return $f->print; +} + +#------------------------------------------------------------------- + +=head2 www_changeUrlSave ( ) + +This actually does the change url of the www_changeUrl() function. + +=cut + +sub www_changeUrlSave { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } + $asset->_invokeWorkflowOnExportedFiles($session->setting->get('changeUrlWorkflow'), 1); + + my $newUrl = $session->form->process("url","text"); + if ($session->form->process("confirm","yesNo") && $newUrl) { + $asset->update({url => $newUrl}); + my $rs = $session->db->read("select revisionDate from assetData where assetId=? and revisionDate<>?",[$asset->getId, $asset->get("revisionDate")]); + while (my ($version) = $rs->array) { + my $old = WebGUI::Asset->new($session, $asset->getId, $asset->get("className"), $version); + $old->purgeRevision if defined $old; + } + } + + if ($session->form->param("proceed") eq "manageAssets") { + $session->http->setRedirect($asset->getManagerUrl); + } + else { + $session->http->setRedirect($asset->getUrl()); + } + + return undef; +} + + +1; From 5375fbbf8f34bb6be755684fe99ef596c3dc3bdf Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 30 Nov 2009 17:31:42 -0800 Subject: [PATCH 17/22] AssetManager Helper, which just opens a tab to the ContentHandler. --- lib/WebGUI/AssetHelper/Manage.pm | 58 ++++++++++++++++++++++ t/AssetHelper/Manage.t | 84 ++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 lib/WebGUI/AssetHelper/Manage.pm create mode 100644 t/AssetHelper/Manage.t diff --git a/lib/WebGUI/AssetHelper/Manage.pm b/lib/WebGUI/AssetHelper/Manage.pm new file mode 100644 index 000000000..cdd1aac32 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Manage.pm @@ -0,0 +1,58 @@ +package WebGUI::AssetHelper::Manage; + +use strict; +use Class::C3; +use base qw/WebGUI::AssetHelper/; +use WebGUI::User; +use WebGUI::HTML; + +=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::Manage + +=head1 DESCRIPTION + +Displays the asset manager, starting at this Asset. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Opens a new tab for displaying the Asset Manager, starting at this Asset. + +=cut + +sub process { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } + + return { + open_tab => $asset->getManagerUrl, + }; +} + +1; diff --git a/t/AssetHelper/Manage.t b/t/AssetHelper/Manage.t new file mode 100644 index 000000000..86d5e96fc --- /dev/null +++ b/t/AssetHelper/Manage.t @@ -0,0 +1,84 @@ +# 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::Manage; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 2; # 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::Manage->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::Manage->process($article2); +cmp_deeply( + $output, + { + open_tab => $article2->getManagerUrl, + }, + 'AssetHelper/Promote returns a message' +); + +#vim:ft=perl From 76d8c48691ea520e492bb75a82fe7dbc63400e23 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 1 Dec 2009 09:56:05 -0800 Subject: [PATCH 18/22] Add EditBranch Note that the form URL need to be set. --- README | 2 +- lib/WebGUI/AssetHelper/EditBranch.pm | 390 +++++++++++++++++++++++++++ 2 files changed, 391 insertions(+), 1 deletion(-) create mode 100644 lib/WebGUI/AssetHelper/EditBranch.pm diff --git a/README b/README index 2cb2dffcf..72ffe02ed 100644 --- a/README +++ b/README @@ -8,7 +8,7 @@ Top level Asset Helpers * Copy with children * Copy with descendants * Cut -Manage +* Manage * Revisions Edit Branch * Edit Url diff --git a/lib/WebGUI/AssetHelper/EditBranch.pm b/lib/WebGUI/AssetHelper/EditBranch.pm new file mode 100644 index 000000000..f452969b7 --- /dev/null +++ b/lib/WebGUI/AssetHelper/EditBranch.pm @@ -0,0 +1,390 @@ +package WebGUI::AssetHelper::EditBranch; + +use strict; +use Class::C3; +use base qw/WebGUI::AssetHelper/; +use WebGUI::User; +use WebGUI::HTML; + +=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::EditBranch + +=head1 DESCRIPTION + +Displays the revisions for this asset. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Opens a new tab for displaying the form and the output for editing a branch. + +=cut + +sub process { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } + + return { + open_tab => $asset->getUrl('op=assetHelper;className=WebGUI::AssetHelper::EditBranch;func=editBranch'), + }; +} + +#------------------------------------------------------------------- + +=head2 www_editBranch ( ) + +Creates a tabform to edit the Asset Tree. If canEdit returns False, returns insufficient Privilege page. + +=cut + +sub www_editBranch { + my ($class, $asset) = @_; + my $session = $asset->session; + my $ac = WebGUI::AdminConsole->new($session,"assets"); + my $i18n = WebGUI::International->new($session,"Asset"); + my $i18n2 = WebGUI::International->new($session,"Asset_Wobject"); + return $session->privilege->insufficient() unless ($asset->canEdit); + my $change = '
'.$i18n->get("change") . ' '; + my $tabform = WebGUI::TabForm->new($session); + $tabform->hidden({name=>"func",value=>"editBranchSave"}); + $tabform->addTab("properties",$i18n->get("properties"),9); + $tabform->getTab("properties")->readOnly( + label => $i18n->get(104), + hoverHelp=> $i18n->get('edit branch url help'), + uiLevel => 9, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_url"}), + value => WebGUI::Form::selectBox($session, { + name => "baseUrlBy", + extras => 'onchange="toggleSpecificBaseUrl()"', + id => "baseUrlBy", + options => { + parentUrl => $i18n->get("parent url"), + specifiedBase => $i18n->get("specified base"), + none => $i18n->get("none"), + }, + }) + . ' / ' + . WebGUI::Form::selectBox($session, { + name => "endOfUrl", + options => { + menuTitle => $i18n->get(411), + title => $i18n->get(99), + currentUrl => $i18n->get("current url"), + } + }) + . q!! + ); + $tabform->addTab("display",$i18n->get(105),5); + $tabform->getTab("display")->yesNo( + name => "isHidden", + value => $asset->get("isHidden"), + label => $i18n->get(886), + uiLevel => 6, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_isHidden"}), + hoverHelp => $i18n->get('886 description',"Asset"), + ); + $tabform->getTab("display")->yesNo( + name => "newWindow", + value => $asset->get("newWindow"), + label => $i18n->get(940), + hoverHelp=> $i18n->get('940 description'), + uiLevel => 6, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_newWindow"}), + ); + $tabform->getTab("display")->yesNo( + name => "displayTitle", + label => $i18n2->get(174), + hoverHelp=> $i18n2->get('174 description'), + value => $asset->getValue("displayTitle"), + uiLevel => 5, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_displayTitle"}) + ); + $tabform->getTab("display")->template( + name => "styleTemplateId", + label => $i18n2->get(1073), + value => $asset->getValue("styleTemplateId"), + hoverHelp => $i18n2->get('1073 description'), + namespace => 'style', + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_styleTemplateId"}) + ); + $tabform->getTab("display")->template( + name => "printableStyleTemplateId", + label => $i18n2->get(1079), + hoverHelp => $i18n2->get('1079 description'), + value => $asset->getValue("printableStyleTemplateId"), + namespace => 'style', + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_printableStyleTemplateId"}) + ); + if ( $session->setting->get('useMobileStyle') ) { + $tabform->getTab("display")->template( + name => 'mobileStyleTemplateId', + label => $i18n2->get('mobileStyleTemplateId label'), + hoverHelp => $i18n2->get('mobileStyleTemplateId description'), + value => $asset->getValue('mobileStyleTemplateId'), + namespace => 'style', + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_mobileStyleTemplateId"}), + ); + } + $tabform->addTab("security",$i18n->get(107),6); + if ($session->config->get("sslEnabled")) { + $tabform->getTab("security")->yesNo( + name => "encryptPage", + value => $asset->get("encryptPage"), + label => $i18n->get('encrypt page'), + hoverHelp => $i18n->get('encrypt page description',"Asset"), + uiLevel => 6, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_encryptPage"}) + ); + } + $tabform->getTab("security")->user( + name => "ownerUserId", + label => $i18n->get(108), + hoverHelp => $i18n->get('108 description',"Asset"), + value => $asset->get("ownerUserId"), + uiLevel => 6, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_ownerUserId"}) + ); + $tabform->getTab("security")->group( + name => "groupIdView", + label => $i18n->get(872), + hoverHelp => $i18n->get('872 description',"Asset"), + value => [$asset->get("groupIdView")], + uiLevel => 6, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_groupIdView"}) + ); + $tabform->getTab("security")->group( + name => "groupIdEdit", + label => $i18n->get(871), + hoverHelp => $i18n->get('871 description',"Asset"), + value => [$asset->get("groupIdEdit")], + excludeGroups => [1,7], + uiLevel => 6, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_groupIdEdit"}) + ); + $tabform->addTab("meta",$i18n->get("Metadata"),3); + $tabform->getTab("meta")->textarea( + name => "extraHeadTags", + label => $i18n->get("extra head tags"), + hoverHelp => $i18n->get('extra head tags description'), + value => $asset->get("extraHeadTags"), + uiLevel => 5, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_extraHeadTags"}) + ); + + + $tabform->getTab("meta")->yesNo( + name => 'usePackedHeadTags', + label => $i18n->get('usePackedHeadTags label'), + hoverHelp => $i18n->get('usePackedHeadTags description'), + uiLevel => 7, + fieldType => 'yesNo', + defaultValue => 0, + subtext => $change . WebGUI::Form::yesNo( $session, { name => "change_usePackedHeadTags" } ), + ); + $tabform->getTab("meta")->yesNo( + name => 'isPackage', + label => $i18n->get("make package"), + hoverHelp => $i18n->get('make package description'), + uiLevel => 7, + fieldType => 'yesNo', + defaultValue => 0, + subtext => $change . WebGUI::Form::yesNo( $session, { name => "change_isPackage" } ), + ); + $tabform->getTab("meta")->yesNo( + name => 'isPrototype', + label => $i18n->get("make prototype"), + hoverHelp => $i18n->get('make prototype description'), + uiLevel => 9, + fieldType => 'yesNo', + defaultValue => 0, + subtext => $change . WebGUI::Form::yesNo( $session, { name => "change_isPrototype" } ), + ); + $tabform->getTab("meta")->yesNo( + name => 'isExportable', + label => $i18n->get('make asset exportable'), + hoverHelp => $i18n->get('make asset exportable description'), + uiLevel => 9, + fieldType => 'yesNo', + defaultValue => 1, + subtext => $change . WebGUI::Form::yesNo( $session, { name => "change_isExportable" } ), + ); + $tabform->getTab("meta")->yesNo( + name => 'inheritUrlFromParent', + label => $i18n->get('does asset inherit URL from parent'), + hoverHelp => $i18n->get('does asset inherit URL from parent description'), + uiLevel => 9, + fieldType => 'yesNo', + defaultValue => 0, + subtext => $change . WebGUI::Form::yesNo( $session, { name => "change_inheritUrlFromParent" } ), + ); + + if ($session->setting->get("metaDataEnabled")) { + my $meta = $asset->getMetaDataFields(); + foreach my $field (keys %$meta) { + my $fieldType = $meta->{$field}{fieldType} || "text"; + my $options = $meta->{$field}{possibleValues}; + # Add a "Select..." option on top of a select list to prevent from + # saving the value on top of the list when no choice is made. + if("\l$fieldType" eq "selectBox") { + $options = "|" . $i18n->get("Select") . "\n" . $options; + } + $tabform->getTab("meta")->dynamicField( + fieldType => $fieldType, + name => "metadata_".$meta->{$field}{fieldId}, + label => $meta->{$field}{fieldName}, + uiLevel => 5, + value => $meta->{$field}{value}, + extras => qq/title="$meta->{$field}{description}"/, + options => $options, + defaultValue => $meta->{$field}{defaultValue}, + subtext => $change . WebGUI::Form::yesNo($session,{name=>"change_metadata_".$meta->{$field}{fieldId}}), + ); + } + } + return $tabform->print; +} + +#------------------------------------------------------------------- + +=head2 www_editBranchSaveStatus ( ) + +Verifies proper inputs in the Asset Tree and saves them. Returns ManageAssets method. If canEdit returns False, returns an insufficient privilege page. + +=cut + +sub www_editBranchSave { + my ($class, $asset) = @_; + my $session = $asset->session; + return $session->privilege->insufficient() unless ($asset->canEdit && $session->user->isInGroup('4')); + my $form = $session->form; + my %data; + my $pb = WebGUI::ProgressBar->new($session); + my $i18n = WebGUI::International->new($session, 'Asset'); + $data{isHidden} = $form->yesNo("isHidden") if ($form->yesNo("change_isHidden")); + $data{newWindow} = $form->yesNo("newWindow") if ($form->yesNo("change_newWindow")); + $data{encryptPage} = $form->yesNo("encryptPage") if ($form->yesNo("change_encryptPage")); + $data{ownerUserId} = $form->selectBox("ownerUserId") if ($form->yesNo("change_ownerUserId")); + $data{groupIdView} = $form->group("groupIdView") if ($form->yesNo("change_groupIdView")); + $data{groupIdEdit} = $form->group("groupIdEdit") if ($form->yesNo("change_groupIdEdit")); + $data{extraHeadTags} = $form->textarea("extraHeadTags") if $form->yesNo("change_extraHeadTags"); + $data{usePackedHeadTags} = $form->yesNo("usePackedHeadTags") if $form->yesNo("change_usePackedHeadTags"); + $data{isPackage} = $form->yesNo("isPackage") if $form->yesNo("change_isPackage"); + $data{isPrototype} = $form->yesNo("isPrototype") if $form->yesNo("change_isPrototype"); + $data{isExportable} = $form->yesNo("isExportable") if $form->yesNo("change_isExportable"); + $data{inheritUrlFromParent} = $form->yesNo("inheritUrlFromParent") if $form->yesNo("change_inheritUrlFromParent"); + + my %wobjectData = %data; + $wobjectData{displayTitle} = $form->yesNo("displayTitle") if $form->yesNo("change_displayTitle"); + $wobjectData{styleTemplateId} = $form->template("styleTemplateId") if $form->yesNo("change_styleTemplateId"); + $wobjectData{printableStyleTemplateId} = $form->template("printableStyleTemplateId") if $form->yesNo("change_printableStyleTemplateId"); + $wobjectData{mobileStyleTemplateId} = $form->template("mobileStyleTemplateId") if $form->yesNo("change_mobileStyleTemplateId"); + + my ($urlBaseBy, $urlBase, $endOfUrl); + my $changeUrl = $form->yesNo("change_url"); + if ($changeUrl) { + $urlBaseBy = $form->selectBox("baseUrlBy"); + $urlBase = $form->text("baseUrl"); + $endOfUrl = $form->selectBox("endOfUrl"); + } + $pb->start($i18n->get('edit branch'), $session->url->extras('adminConsole/assets.gif')); + my $descendants = $asset->getLineage(["self","descendants"],{returnObjects=>1}); + DESCENDANT: foreach my $descendant (@{$descendants}) { + if ( !$descendant->canEdit ) { + $pb->update(sprintf $i18n->get('skipping %s'), $descendant->getTitle); + next DESCENDANT; + } + $pb->update(sprintf $i18n->get('editing %s'), $descendant->getTitle); + my $url; + if ($changeUrl) { + if ($urlBaseBy eq "parentUrl") { + delete $descendant->{_parent}; + $data{url} = $descendant->getParent->get("url")."/"; + } + elsif ($urlBaseBy eq "specifiedBase") { + $data{url} = $urlBase."/"; + } + else { + $data{url} = ""; + } + if ($endOfUrl eq "menuTitle") { + $data{url} .= $descendant->get("menuTitle"); + } + elsif ($endOfUrl eq "title") { + $data{url} .= $descendant->get("title"); + } + else { + $data{url} .= $descendant->get("url"); + } + $wobjectData{url} = $data{url}; + } + my $newData = $descendant->isa('WebGUI::Asset::Wobject') ? \%wobjectData : \%data; + my $revision; + if (scalar %$newData > 0) { + $revision = $descendant->addRevision( + $newData, + undef, + {skipAutoCommitWorkflows => 1, skipNotification => 1}, + ); + } + else { + $revision = $descendant; + } + foreach my $param ($form->param) { + if ($param =~ /^metadata_(.*)$/) { + my $fieldName = $1; + if ($form->yesNo("change_metadata_".$fieldName)) { + $revision->updateMetaData($fieldName,$form->process($form)); + } + } + } + } + if (WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { + allowComments => 1, + returnUrl => $asset->getUrl, + }) eq 'redirect') { + return undef; + }; + delete $asset->{_parent}; + $session->asset($asset->getParent); + ##Since this method originally returned the user to the AssetManager, we don't need + ##to use $pb->finish to redirect back there. + return $asset->getParent->www_manageAssets; +} + + +1; From 40a850c739d7e851d6f8ae8f60df58224b212721 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 1 Dec 2009 10:08:03 -0800 Subject: [PATCH 19/22] Export as HTML Asset Helper. Note, needs Admin Console integration for title, content and URLs. --- lib/WebGUI/AssetHelper/ExportHtml.pm | 154 +++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 lib/WebGUI/AssetHelper/ExportHtml.pm diff --git a/lib/WebGUI/AssetHelper/ExportHtml.pm b/lib/WebGUI/AssetHelper/ExportHtml.pm new file mode 100644 index 000000000..c2a55cb3d --- /dev/null +++ b/lib/WebGUI/AssetHelper/ExportHtml.pm @@ -0,0 +1,154 @@ +package WebGUI::AssetHelper::ExportHtml; + +use strict; +use Class::C3; +use base qw/WebGUI::AssetHelper/; +use WebGUI::User; +use WebGUI::HTML; + +=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::ExportHtml + +=head1 DESCRIPTION + +Export this assets, and all children as HTML. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Opens a new tab for displaying the form and the output for exporting a branch. + +=cut + +sub process { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } + + return { + open_tab => $asset->getUrl('op=assetHelper;className=WebGUI::AssetHelper::Export;func=editBranch'), + }; +} + +#------------------------------------------------------------------- + +=head2 www_export + +Displays the export page administrative interface + +=cut + +sub www_export { + my ($class, $asset) = @_; + my $session = $asset->session; + return $session->privilege->insufficient() unless ($session->user->isInGroup(13)); + my $i18n = WebGUI::International->new($session, "Asset"); + my $f = WebGUI::HTMLForm->new($session, -action => $asset->getUrl); + $f->hidden( + name => "func", + value => "exportStatus" + ); + $f->integer( + label => $i18n->get('Depth'), + hoverHelp => $i18n->get('Depth description'), + name => "depth", + value => 99, + ); + $f->selectBox( + label => $i18n->get('Export as user'), + hoverHelp => $i18n->get('Export as user description'), + name => "userId", + options => $session->db->buildHashRef("select userId, username from users"), + value => [1], + ); + $f->text( + label => $i18n->get("directory index"), + hoverHelp => $i18n->get("directory index description"), + name => "index", + value => "index.html" + ); + + $f->text( + label => $i18n->get("Export site root URL"), + name => 'exportUrl', + value => '', + hoverHelp => $i18n->get("Export site root URL description"), + ); + + # TODO: maybe add copy options to these boxes alongside symlink + $f->selectBox( + label => $i18n->get('extrasUploads form label'), + hoverHelp => $i18n->get('extrasUploads form hoverHelp'), + name => "extrasUploadsAction", + options => { + 'symlink' => $i18n->get('extrasUploads form option symlink'), + 'none' => $i18n->get('extrasUploads form option none') }, + value => ['none'], + ); + $f->selectBox( + label => $i18n->get('rootUrl form label'), + hoverHelp => $i18n->get('rootUrl form hoverHelp'), + name => "rootUrlAction", + options => { + 'symlink' => $i18n->get('rootUrl form option symlinkDefault'), + 'none' => $i18n->get('rootUrl form option none') }, + value => ['none'], + ); + $f->submit; + my $message; + eval { $asset->exportCheckPath }; + if($@) { + $message = $@; + } + return $message . $f->print; +} + + +#------------------------------------------------------------------- + +=head2 www_exportStatus + +Displays the export status page + +=cut + +sub www_exportStatus { + my ($class, $asset) = @_; + my $session = $asset->session; + return $session->privilege->insufficient() unless ($session->user->isInGroup(13)); + my $i18n = WebGUI::International->new($session, "Asset"); + my $iframeUrl = $self->getUrl('func=exportGenerate'); + foreach my $formVar (qw/index depth userId extrasUploadsAction rootUrlAction exportUrl/) { + $iframeUrl = $session->url->append($iframeUrl, $formVar . '=' . $session->form->process($formVar)); + } + + my $output = ''; + return $output; +} + +1; From e17a783efa1dbffc66bcb53274799820381865d7 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 1 Dec 2009 10:11:51 -0800 Subject: [PATCH 20/22] Update README, and fix a syntax error in ExportHtml. --- README | 4 ++-- lib/WebGUI/AssetHelper/ExportHtml.pm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index 72ffe02ed..9a019ec85 100644 --- a/README +++ b/README @@ -10,6 +10,6 @@ Top level Asset Helpers * Cut * Manage * Revisions -Edit Branch +* Edit Branch * Edit Url -Export +* Export diff --git a/lib/WebGUI/AssetHelper/ExportHtml.pm b/lib/WebGUI/AssetHelper/ExportHtml.pm index c2a55cb3d..bf4948242 100644 --- a/lib/WebGUI/AssetHelper/ExportHtml.pm +++ b/lib/WebGUI/AssetHelper/ExportHtml.pm @@ -142,7 +142,7 @@ sub www_exportStatus { my $session = $asset->session; return $session->privilege->insufficient() unless ($session->user->isInGroup(13)); my $i18n = WebGUI::International->new($session, "Asset"); - my $iframeUrl = $self->getUrl('func=exportGenerate'); + my $iframeUrl = $asset->getUrl('func=exportGenerate'); foreach my $formVar (qw/index depth userId extrasUploadsAction rootUrlAction exportUrl/) { $iframeUrl = $session->url->append($iframeUrl, $formVar . '=' . $session->form->process($formVar)); } From 3e11f711b3ecf51ea8d0cdafa3790aa5b78f8f51 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 2 Dec 2009 15:25:31 -0800 Subject: [PATCH 21/22] Add the Lock Asset AssetHelper --- lib/WebGUI/AssetHelper/Lock.pm | 61 +++++++++++++++++++++ lib/WebGUI/i18n/English/Asset.pm | 12 +++++ t/AssetHelper/Lock.t | 92 ++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 lib/WebGUI/AssetHelper/Lock.pm create mode 100644 t/AssetHelper/Lock.t diff --git a/lib/WebGUI/AssetHelper/Lock.pm b/lib/WebGUI/AssetHelper/Lock.pm new file mode 100644 index 000000000..131846d7b --- /dev/null +++ b/lib/WebGUI/AssetHelper/Lock.pm @@ -0,0 +1,61 @@ +package WebGUI::AssetHelper::Lock; + +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::Locks + +=head1 DESCRIPTION + +Puts an edit lock on an Asset. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Locks the asset with a version tag. If the user cannot edit the asset, or the asset is +already locked, it returns an error message. + +=cut + +sub process { + my ($class, $asset) = @_; + my $session = $asset->session; + + my $i18n = WebGUI::International->new($session, 'Asset'); + if (! $asset->canEdit) { + return { error => $i18n->get('38', 'WebGUI'), }; + } + elsif ( $asset->isLocked ) { + return { error => sprintf $i18n->get('already locked'), $asset->getTitle}; + } + + $asset = $asset->addRevision; + + return { + message => sprintf($i18n->get('locked asset'), $asset->getTitle), + }; +} + +1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 2cfb248e5..b84d83e7d 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1418,6 +1418,18 @@ Couldn't open %-s because %-s
context => q{%s will be replaced by the title of the asset.}, }, + 'already locked' => { + message => q{The asset %s is already locked.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + + 'locked asset' => { + message => q{Locked the asset %s.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + }; 1; diff --git a/t/AssetHelper/Lock.t b/t/AssetHelper/Lock.t new file mode 100644 index 000000000..0ce0c236e --- /dev/null +++ b/t/AssetHelper/Lock.t @@ -0,0 +1,92 @@ +# 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::Lock; + +#---------------------------------------------------------------------------- +# 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); + +my $editor = WebGUI::User->create($session); +$editor->addToGroups([4]); +addToCleanup($editor); + +$session->user({userId => 3}); +my $newPage = $home->addChild({ + className => 'WebGUI::Asset::Wobject::Layout', + title => 'Test page', + groupIdEdit => '4', + ownerUserId => '3', +}, undef, WebGUI::Test->webguiBirthday, { skipAutoCommitWorkflows => 1, }); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->commit; +addToCleanup($versionTag); + +$newPage = $newPage->cloneFromDb; + +$session->user({userId => 1}); +$output = WebGUI::AssetHelper::Lock->process($newPage); +cmp_deeply( + $output, + { + error => re('You do not have sufficient privileges'), + }, + 'AssetHelper/Lock checks for editing privileges' +); + +$session->user({userId => 3}); +$output = WebGUI::AssetHelper::Lock->process($newPage); +cmp_deeply( + $output, + { + message => 'Locked the asset Test page.', + }, + '... locks the asset' +); + +$newPage = $newPage->cloneFromDb; + +my $versionTag2 = WebGUI::VersionTag->getWorking($session); +addToCleanup($versionTag2); + +$session->user({userId => $editor->getId}); +$output = WebGUI::AssetHelper::Lock->process($newPage); +cmp_deeply( + $output, + { + error => 'The asset Test page is already locked.', + }, + '... returns an error message if the asset is already locked' +); From bf1953b9b008e7afa387eee0d3d40b39b5d59306 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 2 Dec 2009 15:25:54 -0800 Subject: [PATCH 22/22] Update the list of Helpers --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index 9a019ec85..606f33033 100644 --- a/README +++ b/README @@ -8,6 +8,7 @@ Top level Asset Helpers * Copy with children * Copy with descendants * Cut +* Lock * Manage * Revisions * Edit Branch