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.
This commit is contained in:
Doug Bell 2008-05-29 18:37:54 +00:00
parent adcd560cba
commit d43065b122
8 changed files with 180 additions and 17 deletions

View file

@ -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<userId> 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

View file

@ -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, {

View file

@ -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;
}

View file

@ -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<userId> 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.

View file

@ -12,6 +12,10 @@ our $HELP = {
},
],
variables => [
{
name => 'isPending',
description => 'helpvar isPending',
},
{
name => 'canAddFile',
description => 'helpvar canAddFile',

View file

@ -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_',

View file

@ -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;

View file

@ -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;