diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ba1c8cc9f..1aba01f1d 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.6.0 + - rfe: let package import inherit permissions - added fieldsets around form controls with multiple elements - rfe: Town Hall: Menu title in search results - rfe: Process Macros in HTTP Proxy's URL diff --git a/lib/WebGUI/AssetPackage.pm b/lib/WebGUI/AssetPackage.pm index 0f3538768..db20a3fd5 100644 --- a/lib/WebGUI/AssetPackage.pm +++ b/lib/WebGUI/AssetPackage.pm @@ -130,6 +130,7 @@ A hash reference containing the exported data. sub importAssetData { my $self = shift; my $data = shift; + my $options = shift || {}; my $error = $self->session->errorHandler; my $id = $data->{properties}{assetId}; my $class = $data->{properties}{className}; @@ -140,6 +141,12 @@ sub importAssetData { my $asset; my $revisionExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version); + my %properties = %{ $data->{properties} }; + if ($options->{inheritPermissions}) { + delete $properties{ownerUserId}; + delete $properties{groupIdView}; + delete $properties{groupIdEdit}; + } if ($revisionExists) { # update an existing revision $asset = WebGUI::Asset->new($self->session, $id, $class, $version); $error->info("Updating an existing revision of asset $id"); @@ -162,7 +169,13 @@ sub importAssetData { } else { # add an entirely new asset $error->info("Adding $id that didn't previously exist."); - $asset = $self->addChild($data->{properties}, $id, $version, {skipAutoCommitWorkflows => 1}); + my %properties = %{ $data->{properties} }; + if ($options->{inheritPermissions}) { + $properties{ownerUserId} = $self->get('ownerUserId'); + $properties{groupIdView} = $self->get('groupIdView'); + $properties{groupIdEdit} = $self->get('groupIdEdit'); + } + $asset = $self->addChild(\%properties, $id, $version, {skipAutoCommitWorkflows => 1}); } } @@ -205,6 +218,7 @@ A reference to a WebGUI::Storage object that contains a webgui package file. sub importPackage { my $self = shift; my $storage = shift; + my $options = shift; my $decompressed = $storage->untar($storage->getFiles->[0]); return undef if $storage->getErrorCount; @@ -215,7 +229,7 @@ sub importPackage { foreach my $file (sort(@{$decompressed->getFiles})) { next unless ($decompressed->getFileExtension($file) eq "json"); $error->info("Found data file $file"); - my $data = eval{ + my $data = eval { JSON->new->utf8->relaxed(1)->decode($decompressed->getFileContentsAsScalar($file)) }; if ($@ || $data->{properties}{assetId} eq "" || $data->{properties}{className} eq "" || $data->{properties}{revisionDate} eq "") { @@ -228,7 +242,7 @@ sub importPackage { $decompressed->untar($storageId.".storage", $assetStorage); } my $asset = $assets{$data->{properties}{parentId}} || $self; - my $newAsset = $asset->importAssetData($data); + my $newAsset = $asset->importAssetData($data, $options); $newAsset->importAssetCollateralData($data); $assets{$newAsset->getId} = $newAsset; # First imported asset must be the "package" @@ -302,6 +316,7 @@ sub www_importPackage { my $self = shift; return $self->session->privilege->insufficient() unless ($self->canEdit && $self->session->user->isInGroup(4)); my $storage = WebGUI::Storage->createTemp($self->session); + my $inheritPermissions = $self->session->form->process('inheritPermissions'); ##This is a hack. It should use the WebGUI::Form::File API to insulate ##us from future form name changes. @@ -309,7 +324,7 @@ sub www_importPackage { my $error = ""; if ($storage->getFileExtension($storage->getFiles->[0]) eq "wgpkg") { - $error = $self->importPackage($storage); + $error = $self->importPackage($storage, {inheritPermissions => $inheritPermissions}); } if (!blessed $error) { my $i18n = WebGUI::International->new($self->session, "Asset"); diff --git a/lib/WebGUI/Content/AssetManager.pm b/lib/WebGUI/Content/AssetManager.pm index 0d581eede..d0b562b84 100644 --- a/lib/WebGUI/Content/AssetManager.pm +++ b/lib/WebGUI/Content/AssetManager.pm @@ -520,11 +520,16 @@ ENDHTML .$session->icon->export("func=exportPackage",$asset->get("url")) .'
'; } - $output .= '
'.WebGUI::Form::formHeader($session, {action=>$currentAsset->getUrl}) - .WebGUI::Form::hidden($session, {name=>"func", value=>"importPackage"}) - .'' - .WebGUI::Form::submit($session, {value=>$i18n->get("import"), extras=>'style="font-size: 10px;"'}) - .WebGUI::Form::formFooter($session); + $output .= '
' + . WebGUI::Form::formHeader($session, {action=>$currentAsset->getUrl}) + . WebGUI::Form::hidden($session, {name=>"func", value=>"importPackage"}) + . '
' + . '
' + . WebGUI::Form::checkbox($session, { label => $i18n->get('inherit parent permissions'), checked => 1, name => 'inheritPermissions', value => 1 }) + . '   ' . WebGUI::Form::submit($session, { value=>$i18n->get("import"), 'extras' => ' ' }) + . '
' + . WebGUI::Form::formFooter($session) + ; $output .= ' '; ### Clearing div diff --git a/lib/WebGUI/Form/Checkbox.pm b/lib/WebGUI/Form/Checkbox.pm index acaf31188..ee486e33f 100644 --- a/lib/WebGUI/Form/Checkbox.pm +++ b/lib/WebGUI/Form/Checkbox.pm @@ -66,6 +66,9 @@ sub definition { defaultValue=>{ defaultValue=> undef }, + label => { + defaultValue => undef, + }, }); return $class->SUPER::definition($session, $definition); } @@ -122,7 +125,11 @@ sub toHtml { $value = defined $value ? $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($value))) : ''; my $checkedText = $self->get("checked") ? ' checked="checked"' : ''; my $idText = $self->get('id') ? ' id="'.$self->get('id').'" ' : ''; - return 'get("extras")||'').' />'; + my $control = 'get("extras")||'').' />'; + if ($self->get('label')) { + return "'; + } + return $control; } diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 8515a534a..6c31df850 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1115,6 +1115,11 @@ Couldn't open %-s because %-s
context => q{Error message in Asset.pm}, }, + 'inherit parent permissions' => { + message => q{Inherit parent's permissions} + + } + }; 1;