[Rt-commit] rt branch, 4.2/delete-template-that-has-overlay, created. rt-4.1.8-262-g110e6d7
Ruslan Zakirov
ruz at bestpractical.com
Wed May 8 17:51:29 EDT 2013
The branch, 4.2/delete-template-that-has-overlay has been created
at 110e6d75dad5b03d00b181fefbf9ead766284dac (commit)
- Log -----------------------------------------------------------------
commit 110e6d75dad5b03d00b181fefbf9ead766284dac
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu May 9 01:49:41 2013 +0400
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.
diff --git a/lib/RT/Template.pm b/lib/RT/Template.pm
index 47ad1e2..c0081f1 100644
--- a/lib/RT/Template.pm
+++ b/lib/RT/Template.pm
@@ -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
diff --git a/t/api/template.t b/t/api/template.t
index 8d9cc82..1baac44 100644
--- a/t/api/template.t
+++ b/t/api/template.t
@@ -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;
+ }
}
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list