Commit 110e6d75 authored by Ruslan Zakirov's avatar Ruslan Zakirov
Browse files

allow to delete templates with backup

If queue specific template has global template
with the same name then it should be allowed to
delete it. Scrips will use global template.
parent abfda12b
......@@ -313,7 +313,7 @@ sub Delete {
return ( 0, $self->loc('Permission Denied') );
}
if ( $self->UsedBy->Count ) {
if ( !$self->IsOverride && $self->UsedBy->Count ) {
return ( 0, $self->loc('Template is in use') );
}
......@@ -349,6 +349,23 @@ sub IsEmpty {
return 1;
}
=head2 IsOverride
Returns true if it's queue specific template and there is global
template with the same name.
=cut
sub IsOverride {
my $self = shift;
return 0 unless $self->Queue;
my $template = RT::Template->new( $self->CurrentUser );
$template->LoadGlobalTemplate( $self->Name );
return $template->id;
}
=head2 MIMEObj
Returns L<MIME::Entity> object parsed using L</Parse> method. Returns
......
......@@ -2,7 +2,7 @@
use warnings;
use strict;
use RT::Test tests => 29;
use RT::Test tests => 37;
use_ok('RT::Template');
......@@ -127,6 +127,54 @@ note "make sure template can not be deleted if it has scrips";
ok(!$val,$msg);
}
note "make sure template can be deleted if it's an override";
{
clean_templates( Queue => $queue->id );
my $template = RT::Template->new( RT->SystemUser );
my ($val,$msg) = $template->Create( Queue => $queue->id, Name => 'Overrided' );
ok($val,$msg);
$template = RT::Template->new( RT->SystemUser );
($val,$msg) = $template->Create( Queue => 0, Name => 'Overrided' );
ok($val,$msg);
my $scrip = RT::Scrip->new( RT->SystemUser );
($val,$msg) = $scrip->Create(
Queue => $queue->id,
ScripCondition => "On Create",
ScripAction => 'Autoreply To Requestors',
Template => $template->Name,
);
ok($val, $msg);
($val, $msg) = $template->Delete;
ok($val,$msg);
}
note "make sure template can be deleted if it has an override";
{
clean_templates( Queue => $queue->id );
my $template = RT::Template->new( RT->SystemUser );
my ($val,$msg) = $template->Create( Queue => 0, Name => 'Overrided' );
ok($val,$msg);
$template = RT::Template->new( RT->SystemUser );
($val,$msg) = $template->Create( Queue => $queue->id, Name => 'Overrided' );
ok($val,$msg);
my $scrip = RT::Scrip->new( RT->SystemUser );
($val,$msg) = $scrip->Create(
Queue => $queue->id,
ScripCondition => "On Create",
ScripAction => 'Autoreply To Requestors',
Template => $template->Name,
);
ok($val, $msg);
($val, $msg) = $template->Delete;
ok($val,$msg);
}
{
my $t = RT::Template->new(RT->SystemUser);
......@@ -145,7 +193,11 @@ sub clean_templates {
$templates->Limit( FIELD => 'Name', VALUE => $_ )
foreach ref $args{'Name'}? @{$args{'Name'}} : ($args{'Name'}||());
while ( my $t = $templates->Next ) {
$t->Delete;
my ($status) = $t->Delete;
unless ( $status ) {
$_->Delete foreach @{ $t->UsedBy->ItemsArrayRef };
$t->Delete;
}
}
}
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