- fix: A bug where it was possible to delete a system page if it were made

the child of a non-system page that you had edit rights to.
 - api: Added a unified contraints system for the file and image assets.
- fixed several problems with the new attachments control, setup, and tempspace
This commit is contained in:
JT Smith 2007-07-26 16:08:27 +00:00
parent 58ac54b81d
commit 884953607c
11 changed files with 226 additions and 94 deletions

View file

@ -67,6 +67,25 @@ sub addRevision {
return $newSelf;
}
#-------------------------------------------------------------------
=head2 applyConstraints ( options )
Enforce certain things when new files are uploaded.
=head3 options
A hash reference of optional parameters. None at this time.
=cut
sub applyConstraints {
my $self = shift;
$self->getStorageLocation->setPrivileges($self->get('ownerUserId'), $self->get('groupIdView'), $self->get('groupIdEdit'));
$self->setSize;
}
#-------------------------------------------------------------------
=head2 definition ( definition )
@ -285,7 +304,6 @@ sub processPropertiesFromFormPost {
my $storage = $self->getStorageFromPost($storageId);
if (defined $storage) {
$storage->setPrivileges($self->get('ownerUserId'), $self->get('groupIdView'), $self->get('groupIdEdit'));
my $filename = $storage->getFiles()->[0];
if (defined $filename) {
@ -299,6 +317,7 @@ sub processPropertiesFromFormPost {
$self->update(\%data);
}
}
$self->applyConstraints;
}

View file

@ -46,6 +46,53 @@ These methods are available from this class:
#-------------------------------------------------------------------
=head2 applyConstraints ( options )
Things that are done after a new file is attached.
=head3 options
A hash reference of optional parameters.
=head4 maxImageSize
An integer (in pixels) representing the longest edge the image may have.
=head4 thumbnailSize
An integer (in pixels) representing the longest edge a thumbnail may have.
=cut
sub applyConstraints {
my $self = shift;
my $options = shift;
$self->SUPER::applyConstraints($options);
my $maxImageSize = $options->{maxImageSize} || $self->session->setting->get("maxImageSize");
my $thumbnailSize = $options->{thumbnailSize} || $self->session->setting->get("thumbnailSize");
my $parameters = $self->get("parameters");
my $storage = $self->getStorageLocation;
unless ($parameters =~ /alt\=/) {
$self->update({parameters=>$parameters.' alt="'.$self->get("title").'"'});
}
my $file = $self->get("filename");
my ($w, $h) = $storage->getSizeInPixels($file);
if($w > $maxImageSize || $h > $maxImageSize) {
if($w > $h) {
$storage->resize($file, $maxImageSize);
}
else {
$storage->resize($file, 0, $maxImageSize);
}
}
$self->generateThumbnail($thumbnailSize);
$self->setSize;
}
#-------------------------------------------------------------------
=head2 definition ( definition )
@ -219,23 +266,7 @@ sub prepareView {
sub processPropertiesFromFormPost {
my $self = shift;
$self->SUPER::processPropertiesFromFormPost;
my $parameters = $self->get("parameters");
my $storage = $self->getStorageLocation;
unless ($parameters =~ /alt\=/) {
$self->update({parameters=>$parameters.' alt="'.$self->get("title").'"'});
}
my $max_size = $self->session->setting->get("maxImageSize");
my $file = $self->get("filename");
my ($w, $h) = $storage->getSizeInPixels($file);
if($w > $max_size || $h > $max_size) {
if($w > $h) {
$storage->resize($file, $max_size);
}
else {
$storage->resize($file, 0, $max_size);
}
}
$self->generateThumbnail($self->session->form->process("thumbnailSize"));
$self->applyConstraints;
}
#-------------------------------------------------------------------

View file

@ -165,20 +165,6 @@ sub editSave {
$data{templateId} = 'PBtmpl0000000000000024';
if ($selfName eq "WebGUI::Asset::File::Image") {
$data{templateId} = 'PBtmpl0000000000000088';
$data{parameters} = 'alt="'.$self->get("title").'"';
# Resize image if it is bigger than the max allowed image size.
my $maxSize = $self->session->setting->get("maxImageSize");
my ($width, $height) = $tempStorage->getSizeInPixels($filename);
if($width > $maxSize || $height > $maxSize) {
if($width > $height) {
$tempStorage->resize($filename, $maxSize);
}
else {
$tempStorage->resize($filename, 0, $maxSize);
}
}
}
$data{url} = $self->getParent->get('url').'/'.$filename;
@ -188,11 +174,7 @@ sub editSave {
#Get the current storage location
my $storage = $newAsset->getStorageLocation();
$storage->addFileFromFilesystem($tempStorage->getPath($filename));
$storage->setPrivileges($data{"ownerUserId"},$data{"groupIdView"},$data{"groupIdEdit"});
$newAsset->setSize($tempStorage->getFileSize($filename));
$newAsset->generateThumbnail if ($selfName eq "WebGUI::Asset::File::Image");
$newAsset->update({ storageId=> $storage->getId });
$newAsset->applyConstraints;
#Now remove the reference to the storeage location to prevent problems with different revisions.
delete $newAsset->{_storageLocation};

View file

@ -175,7 +175,9 @@ sub getEditForm {
}
$var->{formAttachment} = WebGUI::Form::Attachments($session, {
value => $children,
maxAttachments => $wiki->get("allowAttachments")
maxAttachments => $wiki->get("allowAttachments"),
maxImageSize => $wiki->get("maxImageSize"),
thumbnailSize => $wiki->get("thumbnailSize"),
});
return $self->processTemplate($var, $wiki->getValue('pageEditTemplateId'));
}
@ -236,6 +238,7 @@ sub processPropertiesFromFormPost {
$self->update({isProtected => $self->session->form("isProtected")});
}
# deal with attachments from the attachments form control
my @attachments = $self->session->form->param("attachments");
my @tags = ();
foreach my $assetId (@attachments) {
@ -243,11 +246,18 @@ sub processPropertiesFromFormPost {
if (defined $asset) {
unless ($asset->get("parentId") eq $self->getId) {
$asset->setParent($self);
$asset->update({
ownerUserId => $self->get("ownerUserId"),
groupIdEdit => $self->get("groupIdEdit"),
groupIdView => $self->get("groupIdView"),
});
}
push(@tags, $asset->get("tagId"));
$asset->setVersionTag($self->get("tagId"));
}
}
# clean up empty tags
foreach my $tag (@tags) {
my $version = WebGUI::VersionTag->new($self->session, $tag);
if (defined $version) {
@ -256,6 +266,8 @@ sub processPropertiesFromFormPost {
}
}
}
# wiki pages are auto committed
$self->requestAutoCommit;
}