GroupText macro now returns an error message if group cannot be found. includes test

This commit is contained in:
Colin Kuskie 2006-07-13 05:23:49 +00:00
parent 2555a7d5b4
commit 3dd45bad6d
4 changed files with 24 additions and 9 deletions

View file

@ -1,5 +1,6 @@
7.0.2 7.0.2
- fix: upgrade from 6.99.4-6.99-5 can fail if site contains groups tied to ldap with no users in it. - fix: upgrade from 6.99.4-6.99-5 can fail if site contains groups tied to ldap with no users in it.
- GroupText macro returns an error message if it can't find the group by the name the user supplies.
7.0.1 7.0.1

View file

@ -42,13 +42,17 @@ Text to be shown to someone not in the group.
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub process { sub process {
my $session = shift; my $session = shift;
my @param = @_; my ($groupName, $inGroupText, $outGroupText ) = @_;
my ($groupId) = $session->dbSlave->quickArray("select groupId from groups where groupName=".$session->db->quote($param[0])); my ($groupId) = $session->dbSlave->quickArray("select groupId from groups where groupName=?",[$groupName]);
$groupId = 3 if ($groupId eq ""); if ($groupId eq "") {
if ($session->user->isInGroup($groupId)) { my $i18n = WebGUI::International->new($session, 'Macro_GroupText');
return $param[1]; return sprintf $i18n->get('group not found'), $groupName
} else { }
return $param[2]; elsif ($session->user->isInGroup($groupId)) {
return $inGroupText;
}
else {
return $outGroupText;
} }
} }

View file

@ -7,6 +7,12 @@ our $I18N = {
lastUpdated => 1128838520, lastUpdated => 1128838520,
}, },
'group not found' => {
message => q|Group %s was not found|,
lastUpdated => 1112466408,
context => q|Error message when a group is not found during a by-name lookup of groups.|,
},
'group text title' => { 'group text title' => {
message => q|Group Text Macro|, message => q|Group Text Macro|,
lastUpdated => 1112466408, lastUpdated => 1112466408,

View file

@ -23,13 +23,13 @@ my $session = WebGUI::Test->session;
use Test::More; # increment this value for each test you create use Test::More; # increment this value for each test you create
plan tests => 2 + 4; plan tests => 4 + 4;
unless ($session->config->get('macros')->{'GroupText'}) { unless ($session->config->get('macros')->{'GroupText'}) {
Macro_Config::insert_macro($session, 'GroupText', 'GroupText'); Macro_Config::insert_macro($session, 'GroupText', 'GroupText');
} }
my $macroText = q!^GroupText("Admin","admin","visitor");!; my $macroText = q!^GroupText("Admins","admin","visitor");!;
my $output; my $output;
$session->user({userId => 1}); $session->user({userId => 1});
@ -42,6 +42,10 @@ $output = $macroText;
WebGUI::Macro::process($session, \$output); WebGUI::Macro::process($session, \$output);
is($output, 'admin', 'user is admin'); is($output, 'admin', 'user is admin');
$output = q!^GroupText("Not a Group","in group","outside group");!;
WebGUI::Macro::process($session, \$output);
is($output, 'Group Not a Group was not found', 'Non-existant group returns an error message');
##Bug test setup ##Bug test setup
##Create a small database ##Create a small database