Commit 2544c3a6 authored by Ruslan Zakirov's avatar Ruslan Zakirov
Browse files

make sure tmpl's name can't be set to empty or duplicate

parent 8bd0d450
......@@ -632,6 +632,30 @@ sub CurrentUserHasQueueRight {
return ( $self->QueueObj->CurrentUserHasRight(@_) );
}
=head2 SetName
Change name of the template.
=cut
sub SetName {
my $self = shift;
my $value = shift;
return ( undef, $self->loc('Name is required') )
unless $value;
return $self->_Set( Field => 'Name', Value => $value )
if lc($self->Name) eq lc($value);
my $tmp = $self->new( RT->SystemUser );
$tmp->LoadByCols( Name => $value, Queue => $self->Queue );
return ( undef, $self->loc('Template with that name already exist') )
if $tmp->id;
return $self->_Set( Field => 'Name', Value => $value );
}
=head2 SetType
If setting Type to Perl, require the ExecuteCode right.
......
......@@ -69,6 +69,30 @@ note "change template's name";
is $template->Name, 'Some';
}
note "can not change name to empty";
{
clean_templates( Queue => $queue->id );
my $template = RT::Template->new( RT->SystemUser );
my ($val,$msg) = $template->Create( Queue => $queue->id, Name => 'Test' );
ok($val,$msg);
($val,$msg) = $template->Create( Queue => $queue->id, Name => '' );
ok(!$val,$msg);
($val,$msg) = $template->Create( Queue => $queue->id, Name => undef );
ok(!$val,$msg);
}
note "can not change name to duplicate";
{
clean_templates( Queue => $queue->id );
my $template = RT::Template->new( RT->SystemUser );
my ($val,$msg) = $template->Create( Queue => $queue->id, Name => 'Test' );
ok($val,$msg);
($val,$msg) = $template->Create( Queue => $queue->id, Name => 'Some' );
ok($val,$msg);
}
{
my $t = RT::Template->new(RT->SystemUser);
$t->Create(Name => "Foo", Queue => $queue->id);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment