From d43065b1228244df3ac0d156221d3ff87266180f Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Thu, 29 May 2008 18:37:54 +0000 Subject: [PATCH] Added more keys to the list of bad EXIF keys. CameraID and CameraType seem to make JSON croak... Fixed issue where bad EXIF cache would kill the entire album Added more variables for resolutions Added better handling of Pending albums and photos. --- lib/WebGUI/Asset/File/GalleryFile.pm | 69 +++++++++++++++---- lib/WebGUI/Asset/File/GalleryFile/Photo.pm | 20 +++++- lib/WebGUI/Asset/Wobject/Gallery.pm | 17 ++++- lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 51 ++++++++++++++ lib/WebGUI/Help/Asset_GalleryAlbum.pm | 4 ++ lib/WebGUI/Help/Asset_Photo.pm | 12 ++++ lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm | 6 ++ lib/WebGUI/i18n/English/Asset_Photo.pm | 18 +++++ 8 files changed, 180 insertions(+), 17 deletions(-) diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index 90503f5e0..0165cff02 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -208,6 +208,21 @@ sub canEdit { #---------------------------------------------------------------------------- +=head2 canEditIfLocked ( [userId] ) + +Override this to allow editing when locked under a different version tag. + +=cut + +sub canEditIfLocked { + my $self = shift; + my $userId = shift; + + return $self->canEdit( $userId ); +} + +#---------------------------------------------------------------------------- + =head2 canView ( [userId] ) Returns true if the user can view this asset. C is a WebGUI user ID. @@ -330,6 +345,42 @@ sub getCommentPaginator { #---------------------------------------------------------------------------- +=head2 getCurrentRevisionDate ( session, assetId ) + +Override this to allow instanciation of "pending" GalleryFiles for those who +are authorized to see them. + +=cut + +sub getCurrentRevisionDate { + my $class = shift; + my $session = shift; + my $assetId = shift; + + # Get the highest revision date, instanciate the asset, and see if + # the permissions are enough to return the revisionDate. + my $revisionDate + = $session->db->quickScalar( + "SELECT MAX(revisionDate) FROM GalleryFile WHERE assetId=?", + [ $assetId ] + ); + + return undef unless $revisionDate; + + my $asset = WebGUI::Asset->new( $session, $assetId, $class, $revisionDate ); + + return undef unless $asset; + + if ( $asset->get( 'status' ) eq "approved" || $asset->canEdit ) { + return $revisionDate; + } + else { + return $class->SUPER::getCurrentRevisionDate( $session, $assetId ); + } +} + +#---------------------------------------------------------------------------- + =head2 getGallery ( ) Gets the Gallery asset this GalleryFile is a member of. @@ -338,18 +389,10 @@ Gets the Gallery asset this GalleryFile is a member of. sub getGallery { my $self = shift; - - # We're using getLinage instead of getParent->getParent because of the - # overridden getParent, below. - # We need to be able to get the Gallery WITHOUT having to get the GalleryAlbum - my $gallery - = $self->getLineage( ['ancestors'], { - includeOnlyClasses => [ 'WebGUI::Asset::Wobject::Gallery' ], - returnObjects => 1, - invertTree => 1, - } )->[ 0 ]; - - return $gallery; + + # We must use getParent->getParent because brand-new assets do not + # have a lineage, but they do get assigned a parent. + return $self->getParent->getParent; } #---------------------------------------------------------------------------- @@ -363,7 +406,7 @@ Get the parent GalleryAlbum. If the only revision of the GalleryAlbum is sub getParent { my $self = shift; - if ( my $album = $self->getParent ) { + if ( my $album = $self->SUPER::getParent ) { return $album; } # Only get the pending version if we're allowed to see this photo in its pending status diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index dc0785175..5b6e26012 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -176,7 +176,19 @@ sub getExifData { my $self = shift; return unless $self->get('exifData'); - return decode_json( $self->get('exifData') ); + + # Our processing and eliminating of bad / unparsable keys + # isn't perfect, so handle errors gracefully + my $exif = eval { decode_json( $self->get('exifData') ) }; + if ( $@ ) { + $self->session->errorHandler->warn( + "Could not parse JSON data for EXIF in Photo '" . $self->get('title') + . "' (" . $self->getId . "): " . $@ + ); + return; + } + + return $exif; } #---------------------------------------------------------------------------- @@ -394,8 +406,8 @@ sub updateExifDataFromFile { } } - # Remove other, pointless keys - for my $key ( qw( Directory NativeDigest ) ) { + # Remove other, pointless, possibly harmful keys + for my $key ( qw( Directory NativeDigest CameraID CameraType ) ) { delete $info->{ $key }; } @@ -505,6 +517,8 @@ sub www_edit { name => "title", value => ( $form->get("title") || $self->get("title") ), }); + + $self->getGallery; $var->{ form_synopsis } = WebGUI::Form::HTMLArea( $session, { diff --git a/lib/WebGUI/Asset/Wobject/Gallery.pm b/lib/WebGUI/Asset/Wobject/Gallery.pm index 0d38e1e4a..b2e160109 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery.pm @@ -557,10 +557,25 @@ sub getAlbumIds { my $orderBy = $options->{ orderBy } || "lineage ASC"; + # Deal with "pending" albums. + my %pendingRules; + if ( $self->canEdit ) { + $pendingRules{ statusToInclude } = [ 'pending', 'approved' ]; + } + else { + $pendingRules{ statusToInclude } = [ 'pending', 'approved' ]; + $pendingRules{ whereClause } = q{ + ( + status = "approved" || ownerUserId = "} . $self->session->user->userId . q{" + ) + }; + } + my $assets = $self->getLineage(['descendants'], { includeOnlyClasses => ['WebGUI::Asset::Wobject::GalleryAlbum'], orderByClause => $orderBy, + ( %pendingRules ), }); return $assets; @@ -873,7 +888,7 @@ sub view_listAlbums { $p->appendTemplateVars( $var ); for my $assetId ( @{ $p->getPageData } ) { - my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); + my $asset = WebGUI::Asset::Wobject::GalleryAlbum->newPending( $session, $assetId ); push @{ $var->{albums} }, $asset->getTemplateVars; } diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index f962fb0fa..e03fbea08 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -295,6 +295,21 @@ sub canEdit { #---------------------------------------------------------------------------- +=head2 canEditIfLocked ( [userId] ) + +Override this to allow editing when locked under a different version tag. + +=cut + +sub canEditIfLocked { + my $self = shift; + my $userId = shift; + + return $self->canEdit( $userId ); +} + +#---------------------------------------------------------------------------- + =head2 canView ( [userId] ) Returns true if the user can view this asset. C is a WebGUI user ID. @@ -350,6 +365,42 @@ sub getAutoCommitWorkflowId { #---------------------------------------------------------------------------- +=head2 getCurrentRevisionDate ( session, assetId ) + +Override this to allow instanciation of "pending" GalleryAlbums for those who +are authorized to see them. + +=cut + +sub getCurrentRevisionDate { + my $class = shift; + my $session = shift; + my $assetId = shift; + + # Get the highest revision date, instanciate the asset, and see if + # the permissions are enough to return the revisionDate. + my $revisionDate + = $session->db->quickScalar( + "SELECT MAX(revisionDate) FROM GalleryAlbum WHERE assetId=?", + [ $assetId ] + ); + + return undef unless $revisionDate; + + my $asset = WebGUI::Asset->new( $session, $assetId, $class, $revisionDate ); + + return undef unless $asset; + + if ( $asset->get( 'status' ) eq "approved" || $asset->canEdit ) { + return $revisionDate; + } + else { + return $class->SUPER::getCurrentRevisionDate( $session, $assetId ); + } +} + +#---------------------------------------------------------------------------- + =head2 getFileIds ( ) Gets an array reference of asset IDs for all the files in this album. diff --git a/lib/WebGUI/Help/Asset_GalleryAlbum.pm b/lib/WebGUI/Help/Asset_GalleryAlbum.pm index 706443629..3eb2e23c4 100644 --- a/lib/WebGUI/Help/Asset_GalleryAlbum.pm +++ b/lib/WebGUI/Help/Asset_GalleryAlbum.pm @@ -12,6 +12,10 @@ our $HELP = { }, ], variables => [ + { + name => 'isPending', + description => 'helpvar isPending', + }, { name => 'canAddFile', description => 'helpvar canAddFile', diff --git a/lib/WebGUI/Help/Asset_Photo.pm b/lib/WebGUI/Help/Asset_Photo.pm index 2948ddba4..9d0d34cd8 100644 --- a/lib/WebGUI/Help/Asset_Photo.pm +++ b/lib/WebGUI/Help/Asset_Photo.pm @@ -38,6 +38,10 @@ our $HELP = { }, ], variables => [ + { + name => 'isPending', + description => 'helpvar isPending', + }, { name => 'canComment', description => 'helpvar canComment', @@ -98,8 +102,16 @@ our $HELP = { name => 'url_download', description => 'helpvar resolutions_loop url_download', }, + { + name => 'resolution', + description => 'helpvar resolutions_loop resolution', + }, ], }, + { + name => 'resolutions_', + description => 'helpvar resolutions_', + }, { name => 'exif_', description => 'helpvar exif_', diff --git a/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm b/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm index 065c1ccb9..d078e4777 100644 --- a/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm +++ b/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm @@ -484,6 +484,12 @@ our $I18N = { context => q{Description of template variable}, }, + 'helpvar isPending' => { + message => q{A flag to set if the GalleryAlbum is not yet approved. Users who can edit the GalleryAlbum are allowed to see them before they are approved.}, + lastUpdated => 0, + context => q{Description of template variable}, + }, + }; 1; diff --git a/lib/WebGUI/i18n/English/Asset_Photo.pm b/lib/WebGUI/i18n/English/Asset_Photo.pm index 7b96ee171..512fa5087 100644 --- a/lib/WebGUI/i18n/English/Asset_Photo.pm +++ b/lib/WebGUI/i18n/English/Asset_Photo.pm @@ -631,6 +631,24 @@ our $I18N = { context => q{Description of template variable}, }, + 'helpvar resolutions_loop resolution' => { + message => q{The resolution of the photo.}, + lastUpdated => 0, + context => q{Description of template variable}, + }, + + 'helpvar resolution_' => { + message => q{A URL direct to a known resolution. "800" resolution would be "resolution_800".} + lastUpdated => 0, + context => q{Description of template variable}, + }, + + 'helpvar isPending' => { + message => q{A flag to set if the Photo is not yet approved. Users who can edit the photo are allowed to see them before they are approved.}, + lastUpdated => 0, + context => q{Description of template variable}, + }, + }; 1;