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; diff --git a/lib/WebGUI/AssetHelper/Copy.pm b/lib/WebGUI/AssetHelper/Copy.pm new file mode 100644 index 000000000..a57182506 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Copy.pm @@ -0,0 +1,93 @@ +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 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 +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($class->getMessage()), $asset->getTitle); + + my $payload = { + message => $message, + }; + + if (WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { + allowComments => 1, + returnUrl => $asset->getUrl, + }) eq 'redirect') { + $payload->{open_tab} = $session->http->getRedirectLocation; + }; + + return $payload; +} + +1; diff --git a/lib/WebGUI/AssetHelper/Copy/WithChildren.pm b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm new file mode 100644 index 000000000..880a1e71b --- /dev/null +++ b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm @@ -0,0 +1,58 @@ +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 with children, + +=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/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/AssetHelper/Cut.pm b/lib/WebGUI/AssetHelper/Cut.pm new file mode 100644 index 000000000..dad38b074 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Cut.pm @@ -0,0 +1,69 @@ +package WebGUI::AssetHelper::Cut; + +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::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/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/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; diff --git a/lib/WebGUI/AssetHelper/ExportHtml.pm b/lib/WebGUI/AssetHelper/ExportHtml.pm new file mode 100644 index 000000000..bf4948242 --- /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 = $asset->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; 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/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/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/AssetHelper/Revisions.pm b/lib/WebGUI/AssetHelper/Revisions.pm new file mode 100644 index 000000000..6e09fa715 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Revisions.pm @@ -0,0 +1,97 @@ +package WebGUI::AssetHelper::Revisions; + +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::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) = @_; + 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::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/lib/WebGUI/Role/Asset/AlwaysHidden.pm b/lib/WebGUI/Role/Asset/AlwaysHidden.pm index 6493f8dfe..8c866dbb8 100644 --- a/lib/WebGUI/Role/Asset/AlwaysHidden.pm +++ b/lib/WebGUI/Role/Asset/AlwaysHidden.pm @@ -24,6 +24,10 @@ Asset Role that guarantees that the isHidden property is always 1. =head1 SYNOPSIS +Despite using OO style methods, there are no AssetHelper objects. This is simply to provide inheritance. + +=head1 METHODS + with WebGUI::Role::Asset::AlwaysHidden; =cut @@ -40,6 +44,4 @@ around isHidden => sub { $self->$orig(@_); }; - - 1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 1ddb45db8..b84d83e7d 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1370,6 +1370,66 @@ 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.}, + }, + + '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.}, + }, + + '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.}, + }, + + '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.}, + }, + + '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.}, + }, + + '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/Copy.t b/t/AssetHelper/Copy.t new file mode 100644 index 000000000..df52d9b32 --- /dev/null +++ b/t/AssetHelper/Copy.t @@ -0,0 +1,76 @@ +# 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); +my $root = WebGUI::Asset->getRoot($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 = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); + is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children'; + addToCleanup(@{ $clippies }); +} + +{ + $session->setting->set('skipCommitComments', 0); + + $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' + ); + + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); + addToCleanup(@{ $clippies }); +} + +#vim:ft=perl diff --git a/t/AssetHelper/Copy/WithChildren.t b/t/AssetHelper/Copy/WithChildren.t new file mode 100644 index 000000000..19b83b55f --- /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/WithChildren 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 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 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 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/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' +); 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 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 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';