fix for choosing uncommitted templates as a User Style Template

This commit is contained in:
Colin Kuskie 2007-10-18 23:17:18 +00:00
parent db3b2ba1b1
commit 598a0d0990
4 changed files with 51 additions and 18 deletions

View file

@ -191,7 +191,7 @@ sub getEditForm {
#-------------------------------------------------------------------
=head2 getList ( session, namespace )
=head2 getList ( session, namespace [,clause] )
Returns a hash reference containing template ids and template names of all the templates in the specified namespace.
@ -203,7 +203,12 @@ A reference to the current session.
=head3 namespace
Specify the namespace to build the list for.
Specify the namespace to build the list for. If no namespace is specified,
then an empty hash reference will be returned.
=head3 clause
An extra clause that can be used to further limit the list, such as "assetData.status='approved'
=cut
@ -211,8 +216,15 @@ sub getList {
my $class = shift;
my $session = shift;
my $namespace = shift;
my $sql = "select asset.assetId, assetData.revisionDate from template left join asset on asset.assetId=template.assetId left join assetData on assetData.revisionDate=template.revisionDate and assetData.assetId=template.assetId where template.namespace=".$session->db->quote($namespace)." and template.showInForms=1 and asset.state='published' and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId and (assetData.status='approved' or assetData.tagId=".$session->db->quote($session->scratch->get("versionTag")).")) order by assetData.title";
my $sth = $session->dbSlave->read($sql);
my $clause = shift;
if ($clause) {
$clause = ' and ' . $clause;
}
else {
$clause = '';
}
my $sql = "select asset.assetId, assetData.revisionDate from template left join asset on asset.assetId=template.assetId left join assetData on assetData.revisionDate=template.revisionDate and assetData.assetId=template.assetId where template.namespace=? and template.showInForms=1 and asset.state='published' and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId and (assetData.status='approved' or assetData.tagId=?)) $clause order by assetData.title";
my $sth = $session->dbSlave->read($sql, [$namespace, $session->scratch->get("versionTag")]);
my %templates;
tie %templates, 'Tie::IxHash';
while (my ($id, $version) = $sth->array) {

View file

@ -59,6 +59,10 @@ The namespace for the list of templates to return. If this is omitted, all templ
A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName().
=head4 onlyCommitted
If true, this will limit the list of template to only include templates that are committed.
=cut
sub definition {
@ -79,6 +83,9 @@ sub definition {
namespace=>{
defaultValue=>undef
},
onlyCommitted=>{
defaultValue=>''
},
dbDataType => {
defaultValue => "VARCHAR(22) BINARY",
},
@ -96,14 +103,15 @@ Renders a template picker control.
sub toHtml {
my $self = shift;
my $templateList = WebGUI::Asset::Template->getList($self->session, $self->get("namespace"));
#Remove entries from template list that the user does not have permission to view.
for my $assetId ( keys %{$templateList} ) {
my $asset = WebGUI::Asset::Template->new($self->session, $assetId);
if (!$asset->canView($self->session->user->userId)) {
delete $templateList->{$assetId};
}
my $onlyCommitted = $self->get('onlyCommitted') ? "assetData.status='approved'" : $self->get('onlyCommitted');
my $templateList = WebGUI::Asset::Template->getList($self->session, $self->get("namespace"), $onlyCommitted);
#Remove entries from template list that the user does not have permission to view.
for my $assetId ( keys %{$templateList} ) {
my $asset = WebGUI::Asset::Template->new($self->session, $assetId);
if (!$asset->canView($self->session->user->userId)) {
delete $templateList->{$assetId};
}
}
$self->set("options", $templateList);
return $self->SUPER::toHtml();
}

View file

@ -3138,8 +3138,8 @@ and tracked by WebGUI.|,
},
'user function style description' => {
message => q|Defines which style to be used to style WebGUI operations (profile editing, message log, etc.) when they are available to a user.|,
lastUpdated => 1120239343,
message => q|Defines which style to be used to style WebGUI operations (profile editing, message log, etc.) when they are available to a user. Only templates which have been committed are allowed.|,
lastUpdated => 1192735786,
},
'admin console template description' => {

View file

@ -15,12 +15,14 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset::Template;
use Test::More tests => 8; # increment this value for each test you create
use Test::More tests => 10; # increment this value for each test you create
use Test::Deep;
my $session = WebGUI::Test->session;
my $list = WebGUI::Asset::Template->getList($session);
ok(defined $list, "getList()");
cmp_deeply($list, {}, 'getList with no classname returns an empty hashref');
my $template = " <tmpl_var variable> <tmpl_if conditional>true</tmpl_if> <tmpl_loop loop>XY</tmpl_loop> ";
my %var = (
variable=>"AAAAA",
@ -31,11 +33,22 @@ my $output = WebGUI::Asset::Template->processRaw($session,$template,\%var);
ok($output =~ m/\bAAAAA\b/, "processRaw() - variables");
ok($output =~ m/true/, "processRaw() - conditionals");
ok($output =~ m/\s(?:XY){5}\s/, "processRaw() - loops");
my $importNode = WebGUI::Asset::Template->getImportNode($session);
my $template = $importNode->addChild({className=>"WebGUI::Asset::Template", title=>"test", url=>"testingtemplates", template=>$template});
ok(defined $template, "creating a template");
my $template = $importNode->addChild({className=>"WebGUI::Asset::Template", title=>"test", url=>"testingtemplates", template=>$template, namespace=>'WebGUI Test Template'});
isa_ok($template, 'WebGUI::Asset::Template', "creating a template");
$var{variable} = "BBBBB";
$output = $template->process(\%var);
ok($output =~ m/\bAAAAA\b/, "process() - variables");
ok($output =~ m/\bBBBBB\b/, "process() - variables");
ok($output =~ m/true/, "process() - conditionals");
ok($output =~ m/\s(?:XY){5}\s/, "process() - loops");
my $newList = WebGUI::Asset::Template->getList($session, 'WebGUI Test Template');
ok(exists $newList->{$template->getId}, 'Uncommitted template exists returned from getList');
my $newList2 = WebGUI::Asset::Template->getList($session, 'WebGUI Test Template', "assetData.status='approved'");
ok(!exists $newList2->{$template->getId}, 'extra clause to getList prevents uncommitted template from being displayed');
$template->purge;