From fa04d01518d1528de5cbd5d947d6f05c1ca0b3c5 Mon Sep 17 00:00:00 2001 From: kimd Date: Tue, 8 Jun 2010 22:57:37 +0200 Subject: [PATCH] o Allow return from photo edit view to gallery edit view (RFE 11571) o Reject form submissions without image selected for upload in edit view of Photo asset --- docs/changelog/7.x.x.txt | 2 + ...t_import_gallery-templates_admin.css.wgpkg | Bin 0 -> 1960 bytes ...templates_default-gallery-edit-album.wgpkg | Bin 0 -> 2693 bytes lib/WebGUI/Asset.pm | 4 + lib/WebGUI/Asset/File/GalleryFile/Photo.pm | 38 +++-- lib/WebGUI/i18n/English/Asset_Photo.pm | 6 + t/Asset/File/GalleryFile/Photo/edit.t | 133 ++++++++++++++---- 7 files changed, 150 insertions(+), 33 deletions(-) create mode 100644 docs/upgrades/packages-7.9.7/root_import_gallery-templates_admin.css.wgpkg create mode 100644 docs/upgrades/packages-7.9.7/root_import_gallery-templates_default-gallery-edit-album.wgpkg 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 0000000000000000000000000000000000000000..f5cd50d5751fab2d0285add6d2bb6f476717ca68 GIT binary patch literal 1960 zcmV;Z2UqwXiwFP!00000|Ls^ybK5o$*15leqfT#;OiGp%Q71QXTBoV&)=raY-N`^A zOraqO762_P8vXZTu>c85a+;=bPnKsq7O;F+-FdjvtP7sBIXwnHZ%fo*vsff_fWLXvO*PpLX8>v5FBz!(!&i~A5&_>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=Q*Qrh$(T$7$=RZgdC0*Habmyd-LZY_T*G7HFH?GSk*Y_rTCa$zE}o zR%a8)$;S3)2A_vyKhn0G>jXS7lH2IKhHrugZ#@U+G_b*Cd;TC8)CyDEQQ5?I(;La0 zG4%|`V@q34ay+#;v@_4~&U2QX>TnL|{OW8^_ZEez1(@*ts_^44qK~b4elKq6l zMaoIW-1GOTT}yGRs>K};|LgLkD!Y9G;}m*l(Kzi#NWoAa`~i{AeBe2}cuMhBCZYpH0y`vhTL zINbY)|9;0LJ~hIB&xXl+*f1}Yt!I&FIvEbb@#JZvu{1Aa7G8Sx?&|J`-stl9`FVAF uJXn=ydA@3h>!%Wn58g+&Uu_@wW%g10qX!;6@aTbu^}yd?r~W$t9smHKE7R!! literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..14275ac5d62fb7e93fff1f74ca27804618939b33 GIT binary patch literal 2693 zcmV;03VQV)iwFP!00000|Lt0BZ`(K$&gcCV+8l6ci#mQu95;^Z+q6krqusXHq_+n& zZ9q%3%|@mKkxt?}?0>(RAt_OcoiwjK;OY;yC6Y4_=Z!NXt*_kwr_pG1+U=EOijg_F;Xf?N10$6hYpPAAu186Fp$&>lb`N1aPgPX+9 z&FMVwN-+a8>hZ8Z*t0nbs_vOu5u*HRuMPzdWUJrIU<}xqmCol9Xp!aGFSDkW!d&pcB2A z?bh9&yCqM8vf{Z@+!(Ry_;oA1^+#Ef=(?Dqsn*9Vj(Ik(IR{a> zP!tRcIbI-kJ&$?GenO={^S>FA!7Pg(eZ7i{<+~0`AMadiC5up~v<_?yvGfafNX{hB zJ}I6JjJ13IS#pSnb%mqsNZz|U+=_|wgk1XzP3%@Iu5yc85x?9uu0#4N!*!Bc<{rq) z@LS?0G(lg>ziOSsGd7g%w{Jfj?+(XrH$Lv475)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{Ni5rZeGfl!>lXZ@th*VDOJnHlzw=DPLQi+{?G-u?ER2Z8$6hvA(YjYm(bQg ziqK_W*zrT1UqLP`gMkN@yYQ1+8(m>JTkxj>7Uz&plwztaTFYK>&0@8>lgrE00#=@R zQ1GMj)D9L|J3Ri#<|(v}%sW`Ce$B_m_Tlfgln1+NTMWXJ&AA%t59bHXWVaw9)WKXq zB3P{*sA_S=kpIdSRDtxu)}lI)-t#JzI!&mDo^?9UJZw;*L95Hc8xM{T&)?SC2b+8E zXQ!L3vve?>`p>3ajbriQi)VlR^4C4T|MrvoPYL{#z)uPMze?c0;%Evs05AXm<*7d+ literal 0 HcmV?d00001 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" )