[Rt-commit] rt branch 5.0/template-split-headers-and-body created. rt-5.0.5-158-ga5c9728a0f
BPS Git Server
git at git.bestpractical.com
Fri Feb 9 19:06:46 UTC 2024
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 5.0/template-split-headers-and-body has been created
at a5c9728a0f80c6200e735065d7dd1f8473affdb9 (commit)
- Log -----------------------------------------------------------------
commit a5c9728a0f80c6200e735065d7dd1f8473affdb9
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Feb 9 12:31:32 2024 -0500
Abstract ProcessTemplateUpdate to reduce duplicate code
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index e47fa96069..49ddaf17d1 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -5887,6 +5887,44 @@ sub PreprocessTransactionSearchQuery {
return join ' AND ', @limits;
}
+
+=head2 ProcessTemplateUpdate ( TemplateObj => $Template, ARGSRef => \%ARGS );
+
+Returns an array of results messages.
+
+=cut
+
+sub ProcessTemplateUpdate {
+ my %args = (
+ ARGSRef => undef,
+ TemplateObj => undef,
+ @_
+ );
+
+ if ( !$args{ARGSRef}{Content} && ( $args{ARGSRef}{Headers} || $args{ARGSRef}{Body} ) ) {
+
+ if ( $args{ARGSRef}{Headers} =~ /\S/ ) {
+ $args{ARGSRef}{Headers} =~ s!^\s+!!;
+ $args{ARGSRef}{Headers} =~ s!\s+$!!;
+ $args{ARGSRef}{Content} = join "\n\n", $args{ARGSRef}{Headers}, $args{ARGSRef}{Body} // ();
+ }
+ elsif ( $args{ARGSRef}{Body} =~ /\S/ ) {
+ $args{ARGSRef}{Content} = "\n$args{ARGSRef}{Body}";
+ }
+ }
+
+ my @attribs = qw( Name Description Queue Type Content );
+ my @results = UpdateRecordObject(
+ AttributesRef => \@attribs,
+ Object => $args{TemplateObj},
+ ARGSRef => $args{ARGSRef},
+ );
+
+ my ( $ok, $msg ) = $args{TemplateObj}->CompileCheck;
+ push @results, $msg if !$ok;
+ return @results;
+}
+
package RT::Interface::Web;
RT::Base->_ImportOverlays();
diff --git a/share/html/Admin/Global/Template.html b/share/html/Admin/Global/Template.html
index 3f81b4dda0..e24efc6f45 100644
--- a/share/html/Admin/Global/Template.html
+++ b/share/html/Admin/Global/Template.html
@@ -87,27 +87,7 @@ if (!$Create) {
}
if ($TemplateObj->Id()) {
- my @attribs = qw( Name Description Queue Type Content );
-
- if ( !$ARGS{Content} && ( $ARGS{Headers} || $ARGS{Body} ) ) {
-
- if ( $ARGS{Headers} =~ /\S/ ) {
- $ARGS{Headers} =~ s!^\s+!!;
- $ARGS{Headers} =~ s!\s+$!!;
- $ARGS{Content} = join "\n\n", $ARGS{Headers}, $ARGS{Body} // ();
- }
- elsif ( $ARGS{Body} =~ /\S/ ) {
- $ARGS{Content} = "\n$ARGS{Body}";
- }
- }
-
- my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
- Object => $TemplateObj,
- ARGSRef => \%ARGS);
- push @results, @aresults;
-
- my ($ok, $msg) = $TemplateObj->CompileCheck;
- push @results, $msg if !$ok;
+ push @results, ProcessTemplateUpdate( TemplateObj => $TemplateObj, ARGSRef => \%ARGS );
} else {
$Create = 1;
}
diff --git a/share/html/Admin/Queues/Template.html b/share/html/Admin/Queues/Template.html
index 4b9c2b3b3e..5478a57c82 100644
--- a/share/html/Admin/Queues/Template.html
+++ b/share/html/Admin/Queues/Template.html
@@ -92,30 +92,7 @@ if ( !$Create ) {
}
if ( $TemplateObj->Id() ) {
- $Queue = $TemplateObj->Queue;
- $QueueObj = $TemplateObj->QueueObj;
-
- if ( !$ARGS{Content} && ( $ARGS{Headers} || $ARGS{Body} ) ) {
-
- if ( $ARGS{Headers} =~ /\S/ ) {
- $ARGS{Headers} =~ s!^\s+!!;
- $ARGS{Headers} =~ s!\s+$!!;
- $ARGS{Content} = join "\n\n", $ARGS{Headers}, $ARGS{Body} // ();
- }
- elsif ( $ARGS{Body} =~ /\S/ ) {
- $ARGS{Content} = "\n$ARGS{Body}";
- }
- }
-
- my @attribs = qw( Name Description Queue Type Content );
- my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
- Object => $TemplateObj,
- ARGSRef => \%ARGS
- );
- push @results, @aresults;
-
- my ( $ok, $msg ) = $TemplateObj->CompileCheck;
- push @results, $msg if !$ok;
+ push @results, ProcessTemplateUpdate( TemplateObj => $TemplateObj, ARGSRef => \%ARGS );
} else {
$Create = 1;
$QueueObj = RT::Queue->new( $session{'CurrentUser'} );
commit 651330ccb07b5d4da9aeab9fefcfbb31be64efc2
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Feb 9 11:19:01 2024 -0500
Split Headers and Body from Content to make template updates less confusing
It's a common mistake to forget the separator newline between headers and
body, especially when a template doesn't have any headers. By splitting
them, now we automatically add the separator.
diff --git a/share/html/Admin/Elements/ModifyTemplate b/share/html/Admin/Elements/ModifyTemplate
index 53ddc794cc..91beda1393 100644
--- a/share/html/Admin/Elements/ModifyTemplate
+++ b/share/html/Admin/Elements/ModifyTemplate
@@ -82,11 +82,20 @@
<div class="form-row">
<div class="label col-2">
- <&|/l&>Content</&>:
+ <&|/l&>Headers</&>:
</div>
<div class="value col-8">
- <textarea name="Content" class="form-control" rows="25" cols="80" wrap="soft">
-<%$Content||''%></textarea>
+ <textarea name="Headers" class="form-control" rows="10" cols="80" wrap="soft">
+<%$Headers||''%></textarea>
+ </div>
+</div>
+<div class="form-row">
+ <div class="label col-2">
+ <&|/l&>Body</&>:
+ </div>
+ <div class="value col-8">
+ <textarea name="Body" class="form-control" rows="25" cols="80" wrap="soft">
+<%$Body||''%></textarea>
</div>
</div>
</&>
@@ -98,6 +107,9 @@ unless ($Type) {
'Perl' : 'Simple';
}
+if ( $Content && !( $Headers && $Body ) ) {
+ ( $Headers, $Body ) = split( /^\r?\n/m, $Content, 2 );
+}
</%INIT>
<%ARGS>
@@ -105,4 +117,6 @@ $Name => ''
$Description => ''
$Content => ''
$Type => ''
+$Headers => ''
+$Body => ''
</%ARGS>
diff --git a/share/html/Admin/Global/Template.html b/share/html/Admin/Global/Template.html
index dedc21cc02..3f81b4dda0 100644
--- a/share/html/Admin/Global/Template.html
+++ b/share/html/Admin/Global/Template.html
@@ -88,6 +88,19 @@ if (!$Create) {
if ($TemplateObj->Id()) {
my @attribs = qw( Name Description Queue Type Content );
+
+ if ( !$ARGS{Content} && ( $ARGS{Headers} || $ARGS{Body} ) ) {
+
+ if ( $ARGS{Headers} =~ /\S/ ) {
+ $ARGS{Headers} =~ s!^\s+!!;
+ $ARGS{Headers} =~ s!\s+$!!;
+ $ARGS{Content} = join "\n\n", $ARGS{Headers}, $ARGS{Body} // ();
+ }
+ elsif ( $ARGS{Body} =~ /\S/ ) {
+ $ARGS{Content} = "\n$ARGS{Body}";
+ }
+ }
+
my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
Object => $TemplateObj,
ARGSRef => \%ARGS);
diff --git a/share/html/Admin/Queues/Template.html b/share/html/Admin/Queues/Template.html
index 86b1759634..4b9c2b3b3e 100644
--- a/share/html/Admin/Queues/Template.html
+++ b/share/html/Admin/Queues/Template.html
@@ -95,6 +95,18 @@ if ( $TemplateObj->Id() ) {
$Queue = $TemplateObj->Queue;
$QueueObj = $TemplateObj->QueueObj;
+ if ( !$ARGS{Content} && ( $ARGS{Headers} || $ARGS{Body} ) ) {
+
+ if ( $ARGS{Headers} =~ /\S/ ) {
+ $ARGS{Headers} =~ s!^\s+!!;
+ $ARGS{Headers} =~ s!\s+$!!;
+ $ARGS{Content} = join "\n\n", $ARGS{Headers}, $ARGS{Body} // ();
+ }
+ elsif ( $ARGS{Body} =~ /\S/ ) {
+ $ARGS{Content} = "\n$ARGS{Body}";
+ }
+ }
+
my @attribs = qw( Name Description Queue Type Content );
my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
Object => $TemplateObj,
diff --git a/t/web/template.t b/t/web/template.t
index 4bca733c65..1cec581a95 100644
--- a/t/web/template.t
+++ b/t/web/template.t
@@ -68,7 +68,7 @@ is($m->value('Type'), 'Perl', 'now that we have ExecuteCode we can update Type t
local $TODO = "WWW::Mechanize doesn't strip newline following <textarea> tag like browsers do";
# this test fails because earlier tests add newlines when using Mech
- like($content = $m->value('Content'), qr/^Subject: Resolved/, 'got expected Content');
+ like($content = $m->value('Headers'), qr/^Subject: Resolved/, 'got expected Content');
}
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list