From 5a7fedc731d0a08982f5756bdfd82c56e89502ce Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 29 Mar 2006 20:22:09 +0000 Subject: [PATCH] - Added an option for hosters to limit the number of assets that may be created on a WebGUI site. fixed some bugs --- docs/changelog/6.x.x.txt | 2 ++ etc/WebGUI.conf.original | 7 +++++++ lib/WebGUI/Asset.pm | 5 +++++ lib/WebGUI/AssetLineage.pm | 9 ++++++++- lib/WebGUI/Session/ErrorHandler.pm | 10 +++++----- lib/WebGUI/i18n/English/Asset.pm | 6 ++++++ 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index dd091f1a4..866d94553 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -11,6 +11,8 @@ - Run on registration and alert on new user have been converted to a single workflow. - Added a Photogallery prototype to the default installation. + - Added an option for hosters to limit the number of assets that may be + created on a WebGUI site. - Added a change url function that will allow an editor to change the URL of an asset permanently (circumventing normal versioning). - Added a wiki-like feature that will automatically bring a user to the diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 181a0e330..bc53add53 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -147,6 +147,13 @@ "htm" : "/bin/cat" }, +# Enter the maximum number of assets that should be allowed to +# be created on this site. Keep in mind that a base install of +# WebGUI has around 300 assets. Enter zero (0) if you want to +# allow an unlimited number. + +"maximumAssets" : 0, + # Specify a the list of assets you want to appear in your # Add Content menus. diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 858819cd0..466221cf0 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1799,6 +1799,11 @@ NOTE: Don't try to override or overload this method. It won't work. What you are sub www_editSave { my $self = shift; return $self->session->privilege->insufficient() unless $self->canEdit; + if ($self->session->config("maximumAssets")) { + my ($count) = $self->session->db->quickArray("select count(*) from asset"); + my $i18n = WebGUI::International->new($self->session, "Asset"); + $self->session->style->userStyle($i18n->get("over max assets")) if ($self->session->config("maximumAssets") <= $count); + } my $object; if ($self->session->form->process("assetId") eq "new") { $object = $self->addChild({className=>$self->session->form->process("class")}); diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index bd11f3c14..102a7b1d1 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -54,11 +54,18 @@ sub addChild { my $self = shift; my $properties = shift; my $id = shift || $self->session->id->generate(); + # add a few things just in case the creator forgets + $properties->{ownerUserId} ||= '3'; + $properties->{groupIdEdit} ||= '12'; + $properties->{groupIdView} ||= '7'; + $properties->{styleTemplateId} ||= 'PBtmpl0000000000000060'; + my $lineage = $self->get("lineage").$self->getNextChildRank; $self->{_hasChildren} = 1; $self->session->db->beginTransaction; my $now =$self->session->datetime->time(); - $self->session->db->write("insert into asset (assetId, parentId, lineage, creationDate, createdBy, className, state) values (".$self->session->db->quote($id).",".$self->session->db->quote($self->getId).", ".$self->session->db->quote($lineage).", ".$now.", ".$self->session->db->quote($self->session->user->userId).", ".$self->session->db->quote($properties->{className}).", 'published')"); + $self->session->db->write("insert into asset (assetId, parentId, lineage, creationDate, createdBy, className, state) values (?,?,?,?,?,?,'published')", + [$id,$self->getId,$lineage,$now,$self->session->user->userId,$properties->{className}]); my $temp = WebGUI::Asset->newByPropertyHashRef($self->session,{ assetId=>$id, className=>$properties->{className} diff --git a/lib/WebGUI/Session/ErrorHandler.pm b/lib/WebGUI/Session/ErrorHandler.pm index 26d55ec9c..41c8197fb 100644 --- a/lib/WebGUI/Session/ErrorHandler.pm +++ b/lib/WebGUI/Session/ErrorHandler.pm @@ -386,19 +386,19 @@ sub showDebug { my $self = shift; my $text = $self->session->stow->get('debug_error'); $text =~ s/\n/\
\n/g; - my $output = 'beginDebug
'.$text."
\n"; + my $output = '
'.$text."
\n"; $text = $self->session->stow->get('debug_warn'); $text =~ s/\n/\
\n/g; - $output .= '
'.$text."
\n"; + $output .= '
'.$text."
\n"; $text = $self->session->stow->get('debug_info'); $text =~ s/\n/\
\n/g; - $output .= '
'.$text."
\n"; + $output .= '
'.$text."
\n"; $text = $self->session->stow->get('debug_debug'); $text =~ s/\n/\
\n/g; - $output .= '
'.$text."
\n"; + $output .= '
'.$text."
\n"; $text = $self->getSessionVars(); $text =~ s/\n/\
\n/g; - $output .= '
'.$text."
\n"; + $output .= '
'.$text."
\n"; return $output; } diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index a73ba2664..d0510f6b3 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1,6 +1,12 @@ package WebGUI::i18n::English::Asset; our $I18N = { + 'over max assets' => { + message => q|Your administrator has limited the number of assets you may place on your site, and you have exceeded the limit. Delete some old assets in order to add more.|, + lastUpdated => 0, + context => q|an error message that will be displayed if the number of assets is >= to the maximumAssets defined in the config file| + }, + 'confirm change url message' => { message => q|Setting this to 'Yes' confirms that you want to permanently change this URL, thusly deleteing all old revisions of this asset.|, lastUpdated => 0,