diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5f764feda..abba0b05d 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,6 @@ 7.9.7 + - added #11571: Allow return from photo edit view to gallery edit view + - fixed: Reject form submissions without image selected for upload in edit view of Photo asset - fixed #11596: Calendar: all day events leaking - fixed #11604: scheduled workflows getting deleted - fixed #11613: Thingy: If next action after add is to add more things, previous data remains diff --git a/docs/upgrades/packages-7.9.7/root_import_gallery-templates_admin.css.wgpkg b/docs/upgrades/packages-7.9.7/root_import_gallery-templates_admin.css.wgpkg new file mode 100644 index 000000000..f5cd50d57 Binary files /dev/null and b/docs/upgrades/packages-7.9.7/root_import_gallery-templates_admin.css.wgpkg differ diff --git a/docs/upgrades/packages-7.9.7/root_import_gallery-templates_default-gallery-edit-album.wgpkg b/docs/upgrades/packages-7.9.7/root_import_gallery-templates_default-gallery-edit-album.wgpkg new file mode 100644 index 000000000..14275ac5d Binary files /dev/null and b/docs/upgrades/packages-7.9.7/root_import_gallery-templates_default-gallery-edit-album.wgpkg differ diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 7215c3985..ffa977eda 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2924,6 +2924,10 @@ sub www_editSave { $session->asset($object->getParent); return $session->asset->www_view; } + elsif ($proceed eq "editParent") { + $session->asset($object->getParent); + return $session->asset->www_edit; + } elsif ($proceed eq "goBackToPage" && $session->form->process('returnUrl')) { $session->http->setRedirect($session->form->process("returnUrl")); return undef; diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index 9bb51f134..24fcbd820 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -114,10 +114,10 @@ sub applyConstraints { # Update the asset's size and make a thumbnail my $maxImageSize = $gallery->get("imageViewSize") - || $self->session->setting->get("maxImageSize"); + || $self->session->setting->get("maxImageSize"); my $storage = $self->getStorageLocation; my $file = $self->get("filename"); - + # Adjust orientation based on exif data. Do this before we start to # generate resolutions so that all images have the correct orientation. $self->adjustOrientation; @@ -130,10 +130,12 @@ sub applyConstraints { $storage->resize( $file, undef, undef, $gallery->get( 'imageDensity' ) ); $storage->adjustMaxImageSize($file, $maxImageSize); - $self->generateThumbnail; - $self->setSize; + $self->generateThumbnail; $self->updateExifDataFromFile; + # setSize method is already called by WebGUI::Asset::File::applyConstraints (SUPER) + # $self->setSize; + $self->SUPER::applyConstraints( $options ); } @@ -252,10 +254,11 @@ sub getEditFormUploadControl { } # Control to upload a new file - $html .= WebGUI::Form::file( $session, { - name => 'newFile', - label => $i18n->get('new file'), - hoverHelp => $i18n->get('new file description'), + $html .= WebGUI::Form::image( $session, { + name => 'newFile', + label => $i18n->get('new file'), + hoverHelp => $i18n->get('new file description'), + forceImageOnly => 1, }); return $html; @@ -401,11 +404,19 @@ contained in. sub makeResolutions { my $self = shift; my $resolutions = shift; + my $session = $self->session; my $error; croak "Photo->makeResolutions: resolutions must be an array reference" if $resolutions && ref $resolutions ne "ARRAY"; +# # Return immediately if no image is available +# if ( $self->get("filename") eq '' ) +# { +# $session->log->error("makeResolutions skipped since no image available"); +# return; +# } + # Get default if necessary $resolutions ||= $self->getGallery->getImageResolutions; @@ -436,13 +447,20 @@ Make the default title into the file name minus the extention. sub processPropertiesFromFormPost { my $self = shift; + my $i18n = WebGUI::International->new( $self->session,'Asset_Photo' ); my $form = $self->session->form; my $errors = $self->SUPER::processPropertiesFromFormPost || []; + # Make sure there is an image file attached to this asset. + if ( !$self->get('filename') ) { + push @{ $errors }, $i18n->get('error no image'); + } + # Return if errors return $errors if @$errors; ### Passes all checks + # If no title was given, make it the file name if ( !$form->get('title') ) { my $title = $self->get('filename'); @@ -609,6 +627,7 @@ sub www_edit { $var->{ form_start } = WebGUI::Form::formHeader( $session, { action => $self->getParent->getUrl('func=editSave;assetId=new;class='.__PACKAGE__), + extras => 'name="photoAdd"', }) . WebGUI::Form::hidden( $session, { name => 'ownerUserId', @@ -620,6 +639,7 @@ sub www_edit { $var->{ form_start } = WebGUI::Form::formHeader( $session, { action => $self->getUrl('func=editSave'), + extras => 'name="photoEdit"', }) . WebGUI::Form::hidden( $session, { name => 'ownerUserId', @@ -630,7 +650,7 @@ sub www_edit { $var->{ form_start } .= WebGUI::Form::hidden( $session, { name => "proceed", - value => "showConfirmation", + value => $form->get('proceed') || "showConfirmation", }); $var->{ form_end } = WebGUI::Form::formFooter( $session ); diff --git a/lib/WebGUI/i18n/English/Asset_Photo.pm b/lib/WebGUI/i18n/English/Asset_Photo.pm index a327c23bb..095356b6d 100644 --- a/lib/WebGUI/i18n/English/Asset_Photo.pm +++ b/lib/WebGUI/i18n/English/Asset_Photo.pm @@ -759,6 +759,12 @@ our $I18N = { lastUpdated => 0, context => q{Error when user is out of disk space.}, }, + + 'error no image' => { + message => q{You need to select an image to upload.}, + lastUpdated => 0, + context => q{Error when user tries to add photo without selecting image.}, + }, 'template comment add title' => { message => q{Add comment}, diff --git a/t/Asset/File/GalleryFile/Photo/edit.t b/t/Asset/File/GalleryFile/Photo/edit.t index 389320a9a..8ad38f36d 100644 --- a/t/Asset/File/GalleryFile/Photo/edit.t +++ b/t/Asset/File/GalleryFile/Photo/edit.t @@ -14,18 +14,29 @@ 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::Asset; +use WebGUI::Asset::Wobject::Gallery; +use WebGUI::Asset::Wobject::GalleryAlbum; +use WebGUI::Asset::File::GalleryFile::Photo; use WebGUI::VersionTag; use WebGUI::Session; + plan skip_all => 'set WEBGUI_LIVE to enable this test' unless $ENV{WEBGUI_LIVE}; #---------------------------------------------------------------------------- # Init + my $session = WebGUI::Test->session; my $node = WebGUI::Asset->getImportNode( $session ); -my @versionTags = ( WebGUI::VersionTag->getWorking( $session ) ); + +# Create version tag and make sure it gets cleaned up +my $versionTag = WebGUI::VersionTag->getWorking($session); +addToCleanup($versionTag); # Override some settings to make things easier to test # userFunctionStyleId @@ -34,36 +45,43 @@ $session->setting->set( 'userFunctionStyleId', 'PBtmpl0000000000000132' ); $session->setting->set( 'specialState', '' ); # Create a user for testing purposes -my $user = WebGUI::User->new( $session, "new" ); +my $user = WebGUI::User->new( $session, "new" ); WebGUI::Test->usersToDelete($user); $user->username( 'dufresne' . time ); -my $identifier = 'ritahayworth'; -my $auth = WebGUI::Operation::Auth::getInstance( $session, $user->authMethod, $user->userId ); +my $identifier = 'ritahayworth'; +my $auth = WebGUI::Operation::Auth::getInstance( $session, $user->authMethod, $user->userId ); $auth->saveParams( $user->userId, $user->authMethod, { 'identifier' => Digest::MD5::md5_base64( $identifier ), }); -my ( $mech ); - -# Get the site's base URL -my $baseUrl = 'http://' . $session->config->get('sitename')->[0]; - -my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1 } ); - +# Create gallery and a single album my $gallery = $node->addChild({ className => "WebGUI::Asset::Wobject::Gallery", + title => "gallery", groupIdAddFile => 2, # Registered Users - styleTemplateId => "PBtmpl0000000000000132", # Blank Style + styleTemplateId => "PBtmpl0000000000000132", # Blank Style }); my $album = $gallery->addChild({ className => "WebGUI::Asset::Wobject::GalleryAlbum", - }, @addArgs ); + ownerUserId => $user->getId, + title => "album", + }, + undef, + undef, + { + skipAutoCommitWorkflows => 1, + }); -$versionTags[-1]->commit; +# Commit assets for testing +$versionTag->commit; -my $photo; +# Get the site's base URL +my $baseUrl = 'http://' . $session->config->get('sitename')->[0]; + +# Common variables +my ( $mech, $photo ); #---------------------------------------------------------------------------- @@ -78,18 +96,93 @@ if ( !$mech->success ) { plan skip_all => "Cannot load URL '$baseUrl'. Will not test."; } -plan tests => 5; # Increment this number for each test you create +plan tests => 10; # Increment this number for each test you create + #---------------------------------------------------------------------------- # Test permissions for new photos + $mech = Test::WWW::Mechanize->new; # Save a new photo $mech->get( $baseUrl . $album->getUrl("func=add;class=WebGUI::Asset::File::GalleryFile::Photo") ); $mech->content_lacks( 'value="editSave"' ); + +#---------------------------------------------------------------------------- +# Test editing existing photo + +# Create single photo inside the album +$photo + = $album->addChild({ + className => "WebGUI::Asset::File::GalleryFile::Photo", + ownerUserId => $user->getId, + title => "photo", + synopsis => "synopsis", + keywords => "keywords", + location => "location", + friendsOnly => 0, + }, + undef, + time() - 5 # Create photo asset in the past to avoid duplicate revision dates + ); +# Attach image file to photo asset +$photo->setFile( WebGUI::Test->getTestCollateralPath("rotation_test.png") ); + +# New values for photo properties +my %properties = ( + title => 'new photo', + synopsis => 'new synopsis', + keywords => 'new keywords', + location => 'new location', + friendsOnly => '1', + ); + +# Log in +$mech = getMechLogin( $baseUrl, $user, $identifier ); + +# Request photo edit view +$mech->get_ok( $baseUrl . $photo->getUrl('func=edit'), 'Request Photo edit view' ); +# Try to submit edit form +$mech->submit_form_ok({ + form_name => 'photoEdit', + fields => \%properties, + }, + 'Submit Photo edit form' ); +# Re-create instance of Photo asset +$photo = WebGUI::Asset->newByDynamicClass($session, $photo->getId); +# Check whether properties were changed correctly +cmp_deeply($photo->get, superhashof(\%properties), 'All changes applied'); + + +#---------------------------------------------------------------------------- +# Test redirect to parent's edit view using the "proceed=editParent" parameter + +# Create single photo inside the album +$photo + = $album->addChild({ + className => "WebGUI::Asset::File::GalleryFile::Photo", + ownerUserId => $user->getId, + }, + undef, + time() - 5 # Create photo asset in the past to avoid duplicate revision dates + ); +# Attach image file to photo asset +$photo->setFile( WebGUI::Test->getTestCollateralPath("rotation_test.png") ); + + +# Request photo edit view +$mech->get_ok( $baseUrl . $photo->getUrl('func=edit;proceed=editParent'), 'Request Photo edit view with "proceed=editParent"' ); +# Submit changes +$mech->submit_form( form_name => 'photoEdit' ); +# Currently, a redirect using the proceed parameter will not change the URL +# nor add the proper "func" argument. We have to look at the page content instead. +$mech->content_contains( 'name="galleryAlbumEdit"', "Redirected to parent's edit view" ); + + #---------------------------------------------------------------------------- # Test creating a new Photo + SKIP: { skip "File control needs to be fixed to be more 508-compliant before this can be used", 4; $mech = getMechLogin( $baseUrl, $user, $identifier ); @@ -131,14 +224,6 @@ SKIP: { ); } -#---------------------------------------------------------------------------- -# Cleanup -END { - for my $tag ( @versionTags ) { - $tag->rollback; - } - -} #---------------------------------------------------------------------------- # getMechLogin( baseUrl, WebGUI::User, "identifier" )