diff --git a/docs/upgrades/packages-7.5.11/root_import_gallery-templates.wgpkg b/docs/upgrades/packages-7.5.11/root_import_gallery-templates.wgpkg index 3ce9e7b82..cd6f3c1e6 100644 Binary files a/docs/upgrades/packages-7.5.11/root_import_gallery-templates.wgpkg and b/docs/upgrades/packages-7.5.11/root_import_gallery-templates.wgpkg differ diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index 0165cff02..33069ce91 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -653,9 +653,15 @@ sub processCommentEditForm { sub processPropertiesFromFormPost { my $self = shift; + my $i18n = __PACKAGE__->i18n( $self->session ); my $form = $self->session->form; my $errors = $self->SUPER::processPropertiesFromFormPost || []; + # Make sure we have the disk space for this + if ( !$self->getGallery->hasSpaceAvailable( $self->get( 'assetSize' ) ) ) { + push @{ $errors }, $i18n->get( "error no space" ); + } + # Return if errors return $errors if @$errors; @@ -668,6 +674,11 @@ sub processPropertiesFromFormPost { } ); } + # Fix URLs + $self->update( { + url => $self->getParent->get( "url" ) . '/' . $self->session->url->urlize( $self->get( "menuTitle" ) ) + } ); + $self->requestAutoCommit; return; diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index acc6822e7..5b34c7b4d 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -506,6 +506,15 @@ sub www_edit { url_addArchive => $self->getParent->getUrl('func=addArchive'), url_album => $self->getParent->getUrl('func=album'), }; + + # Process errors if any + if ( $session->stow->get( 'editFormErrors' ) ) { + for my $error ( @{ $session->stow->get( 'editFormErrors' ) } ) { + push @{ $var->{ errors } }, { + error => $error, + }; + } + } if ( $form->get('func') eq "add" ) { $var->{ isNewPhoto } = 1; diff --git a/lib/WebGUI/Asset/Wobject/Gallery.pm b/lib/WebGUI/Asset/Wobject/Gallery.pm index 0f1c1e384..99445f07e 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery.pm @@ -812,6 +812,46 @@ sub getUserFilePaginator { #---------------------------------------------------------------------------- +=head2 hasSpaceAvailable ( spaceWanted [, userId ] ) + +Returns true if the user has at least the specified bytes of C +available to use in this Gallery. + +=cut + +sub hasSpaceAvailable { + my $self = shift; + my $spaceWanted = shift; + my $userId = shift || $self->session->user->userId; + + # If we don't care, just return + return 1 if ( $self->get( "maxSpacePerUser" ) == 0 ); + + my $db = $self->session->db; + + # Compile the amount of disk space used + my $maxSpace = $self->get( "maxSpacePerUser" ) * ( 1_024 ** 2 ); # maxSpacePerUser is in MB + my $spaceUsed = 0; + my $fileIds + = $self->getLineage( [ 'descendants' ], { + joinClass => 'WebGUI::Asset::File::GalleryFile', + whereClause => 'ownerUserId = ' . $db->quote( $userId ), + } ); + + for my $assetId ( @{ $fileIds } ) { + my $asset = WebGUI::Asset->newByDynamicClass( $self->session, $assetId ); + next unless $asset; + $spaceUsed += $asset->get( 'assetSize' ); + + return 0 if ( $spaceUsed + $spaceWanted >= $maxSpace ); + } + + # We must have enough space + return 1; +} + +#---------------------------------------------------------------------------- + =head2 prepareView ( ) See WebGUI::Asset::prepareView() for details. diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index f4535b78b..7e5f3f56b 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -649,6 +649,10 @@ sub processPropertiesFromFormPost { return $errors if @$errors; ### Passes all checks + # Fix URLs + $self->update( { + url => $self->getParent->get( "url" ) . '/' . $self->session->url->urlize( $self->get( "menuTitle" ) ) + } ); $self->requestAutoCommit; } diff --git a/lib/WebGUI/Help/Asset_Photo.pm b/lib/WebGUI/Help/Asset_Photo.pm index 9d0d34cd8..55541b5ab 100644 --- a/lib/WebGUI/Help/Asset_Photo.pm +++ b/lib/WebGUI/Help/Asset_Photo.pm @@ -198,6 +198,16 @@ our $HELP = { title => 'help edit title', body => 'help edit body', variables => [ + { + name => 'errors', + description => 'helpvar errors', + variables => [ + { + name => 'error', + description => 'helpvar error', + }, + ], + }, { name => 'isNewPhoto', description => 'helpvar isNewPhoto', diff --git a/lib/WebGUI/i18n/English/Asset_Photo.pm b/lib/WebGUI/i18n/English/Asset_Photo.pm index 1af096185..46608eaa2 100644 --- a/lib/WebGUI/i18n/English/Asset_Photo.pm +++ b/lib/WebGUI/i18n/English/Asset_Photo.pm @@ -649,6 +649,12 @@ our $I18N = { context => q{Description of template variable}, }, + 'error no space' => { + message => q{You do not have enough disk space to upload this file.}, + lastUpdated => 0, + context => q{Error when user is out of disk space.}, + }, + }; 1; diff --git a/t/Asset/Event/edit.t b/t/Asset/Event/edit.t index 65adada54..e719661f9 100644 --- a/t/Asset/Event/edit.t +++ b/t/Asset/Event/edit.t @@ -34,6 +34,8 @@ my %oldSettings; # userFunctionStyleId $oldSettings{ userFunctionStyleId } = $session->setting->get( 'userFunctionStyleId' ); $session->setting->set( 'userFunctionStyleId', 'PBtmpl0000000000000132' ); +$oldSettings{ defaultVersionTagWorkflow } = $session->setting->get( 'defaultVersionTagWorkflow' ); +$session->setting->set( 'defaultVersionTagWorkflow', 'pbworkflow000000000003' ); # Create a user for testing purposes my $user = WebGUI::User->new( $session, "new" ); @@ -54,7 +56,7 @@ my $calendar = $node->addChild( { className => 'WebGUI::Asset::Wobject::Calendar', groupIdEventEdit => '2', # Registered Users groupIdEdit => '3', # Admins - workflowIdCommit => 'realtimeworkflow-00001', # Commit content immediately + workflowIdCommit => 'pbworkflow000000000003', # Commit Without approval } ); # Remember this event url when we want to edit it later diff --git a/t/Asset/Wobject/GalleryAlbum/edit.t b/t/Asset/Wobject/GalleryAlbum/edit.t index afa259421..57cbff324 100644 --- a/t/Asset/Wobject/GalleryAlbum/edit.t +++ b/t/Asset/Wobject/GalleryAlbum/edit.t @@ -56,7 +56,7 @@ my $gallery = $node->addChild( { className => 'WebGUI::Asset::Wobject::Gallery', groupIdAddFile => '2', # Registered Users - workflowIdCommit => 'realtimeworkflow-00001', # Commit Content Immediately + workflowIdCommit => 'pbworkflow000000000003', # Commit Content Immediately } ); $versionTags[-1]->commit;