[Rt-commit] rt branch, 5.0-trunk, updated. rt-5.0.0-116-g0f8e0e7942
? sunnavy
sunnavy at bestpractical.com
Mon Nov 16 19:47:08 EST 2020
The branch, 5.0-trunk has been updated
via 0f8e0e794202c3e964424dde42ff182498cbe8d8 (commit)
via cc2648df8cb4d6fbc92ae13f1b4c0b4c0e11dcc0 (commit)
via e790773efc4dd8d27d04c77be71dd4d075c019c3 (commit)
via 160f41a5e69a6e407945c1304cc681558e943b40 (commit)
from 9f2b9680451fc5b0d72e958a41987b161f9ef1fa (commit)
Summary of changes:
share/html/Admin/Lifecycles/Mappings.html | 8 +-
t/lifecycles/types.t | 10 +-
t/lifecycles/utils.pl | 18 +++
t/web/lifecycle_mappings.t | 184 ++++++++++++++++++++++++++++++
4 files changed, 211 insertions(+), 9 deletions(-)
create mode 100644 t/web/lifecycle_mappings.t
- Log -----------------------------------------------------------------
commit e790773efc4dd8d27d04c77be71dd4d075c019c3
Author: craig kaiser <craig at bestpractical.com>
Date: Mon Nov 16 14:37:45 2020 -0500
Update mapping form submission parsing to handle '-' in lifecycle name
When a lifecycle name has a dash in it the regex used to determine
mappings between lifecycles could break at the "-". Meaning if we have
one lifecycle named "sales" and one named "sales-engineering" the
Mappings.html submission will interpret mappings for the
"sales-engineering" lifecycle as a submission for the "sales" lifecycle,
which could also result in incorrect status names.
diff --git a/share/html/Admin/Lifecycles/Mappings.html b/share/html/Admin/Lifecycles/Mappings.html
index ce18f4cc8d..d487fedc3a 100644
--- a/share/html/Admin/Lifecycles/Mappings.html
+++ b/share/html/Admin/Lifecycles/Mappings.html
@@ -74,7 +74,7 @@
<% $OtherStatus %>:
</div>
<div class="col-8 value">
- <& /Elements/SelectStatus, Statuses => \@MyStatuses, Default => $FromMapping->{$OtherStatus}, Name => 'map-' . $Other->Name . '-' . $OtherStatus . '--' . $LifecycleObj->Name&>
+ <& /Elements/SelectStatus, Statuses => \@MyStatuses, Default => $FromMapping->{$OtherStatus}, Name => 'map-' . $Other->Name . '--' . $OtherStatus . '--' . $LifecycleObj->Name&>
</div>
</div>
% }
@@ -88,7 +88,7 @@
<% $MyStatus %>:
</div>
<div class="col-8 value">
- <& /Elements/SelectStatus, Statuses => \@OtherStatuses, Default => $ToMapping->{$MyStatus}, Name => 'map-' . $LifecycleObj->Name . '-' . $MyStatus . '--' . $Other->Name &>
+ <& /Elements/SelectStatus, Statuses => \@OtherStatuses, Default => $ToMapping->{$MyStatus}, Name => 'map-' . $LifecycleObj->Name . '--' . $MyStatus . '--' . $Other->Name &>
</div>
</div>
% }
@@ -128,7 +128,7 @@ if ($Update) {
my %maps;
my $lifecycle_re = join '|', map { quotemeta($_) } @lifecycle_names;
for my $key (keys %ARGS) {
- my ($from_lifecycle, $from_status, $to_lifecycle) = $key =~ /^map-($lifecycle_re)-(.*)--($lifecycle_re)$/ or next;
+ my ($from_lifecycle, $from_status, $to_lifecycle) = $key =~ /^map-($lifecycle_re)--(.*)--($lifecycle_re)$/ or next;
if (my $to_status = $ARGS{$key}) {
$maps{"$from_lifecycle -> $to_lifecycle"}{$from_status} = $to_status;
}
commit cc2648df8cb4d6fbc92ae13f1b4c0b4c0e11dcc0
Author: craig kaiser <craig at bestpractical.com>
Date: Tue Nov 3 16:41:49 2020 -0500
Add tests for the lifecycle Mappings.html page
diff --git a/t/lifecycles/types.t b/t/lifecycles/types.t
index 84cfd86277..ed8e0b572d 100644
--- a/t/lifecycles/types.t
+++ b/t/lifecycles/types.t
@@ -3,13 +3,13 @@ use warnings;
BEGIN {require './t/lifecycles/utils.pl'};
-is_deeply( [ RT::Lifecycle->ListAll ], [qw/ approvals default delivery /],
+is_deeply( [ RT::Lifecycle->ListAll ], [qw/ approvals default delivery sales sales-engineering/],
"Get the list of all lifecycles (implicitly for for tickets)");
-is_deeply( [ RT::Lifecycle->ListAll('ticket') ], [qw/ approvals default delivery /],
+is_deeply( [ RT::Lifecycle->ListAll('ticket') ], [qw/ approvals default delivery sales sales-engineering/],
"Get the list of all lifecycles for tickets");
-is_deeply( [ RT::Lifecycle->List], [qw/ default delivery /],
+is_deeply( [ RT::Lifecycle->List], [qw/ default delivery sales sales-engineering /],
"Get the list of lifecycles without approvals (implicitly for for tickets)");
-is_deeply( [ RT::Lifecycle->List('ticket') ], [qw/ default delivery /],
+is_deeply( [ RT::Lifecycle->List('ticket') ], [qw/ default delivery sales sales-engineering/],
"Get the list of lifecycles without approvals for tickets");
is_deeply( [ RT::Lifecycle->List('racecar') ], [qw/ racing /],
"Get the list of lifecycles for other types");
@@ -19,7 +19,7 @@ ok($tickets, "Got a generalized lifecycle for tickets");
isa_ok( $tickets, "RT::Lifecycle::Ticket", "Is the right subclass" );
is_deeply( [ sort $tickets->Valid ],
[ sort qw(new open stalled resolved rejected deleted ordered),
- 'on way', 'delayed', 'delivered' ],
+ 'on way', 'delayed', 'delivered', 'sales', 'engineering', 'initial', 'active', 'inactive'],
"Only gets ticket statuses" );
diff --git a/t/lifecycles/utils.pl b/t/lifecycles/utils.pl
index cd167d668e..f832828a51 100644
--- a/t/lifecycles/utils.pl
+++ b/t/lifecycles/utils.pl
@@ -66,6 +66,24 @@ Set(\%Lifecycles,
active => ['on-your-mark', 'get-set', 'go'],
inactive => ['first', 'second', 'third', 'no-place'],
},
+ "sales" => {
+ type => 'ticket',
+ initial => ['initial'],
+ active => ['active'],
+ inactive => ['inactive'],
+ },
+ "sales-engineering" => {
+ "initial" => ["sales"],
+ "active" => [
+ "engineering",
+ "stalled"
+ ],
+ "inactive" => [
+ "resolved",
+ "rejected",
+ "deleted"
+ ],
+ },
);
END
}
diff --git a/t/web/lifecycle_mappings.t b/t/web/lifecycle_mappings.t
new file mode 100644
index 0000000000..e4f5d101de
--- /dev/null
+++ b/t/web/lifecycle_mappings.t
@@ -0,0 +1,184 @@
+use strict;
+use warnings;
+
+BEGIN { require './t/lifecycles/utils.pl' }
+
+my ( $url, $m ) = RT::Test->started_ok;
+ok( $m->login(), 'logged in' );
+
+my $sales = RT::Lifecycle->new();
+my ( $ret, $msg ) = $sales->Load( Name => 'sales', Type => 'ticket' );
+ok $ret, "Loaded lifecycle sales successfully";
+
+my $default = RT::Lifecycle->new();
+( $ret, $msg ) = $default->Load( Name => 'default', Type => 'ticket' );
+ok $ret, "Loaded lifecycle default successfully";
+
+my $sales_engineering = RT::Lifecycle->new();
+( $ret, $msg ) = $sales_engineering->Load( Name => 'sales-engineering', Type => 'ticket' );
+ok $ret, "Loaded lifecycle sales_engineering successfully";
+
+diag "Test updating mappings";
+{
+ $m->get_ok( $url . '/Admin/Lifecycles/Mappings.html?Type=ticket&Name=default' );
+
+ my $form = $m->form_name('ModifyMappings');
+ $m->submit_form(
+ fields => {
+ "map-default--new--sales" => "initial",
+ "map-default--open--sales" => "active",
+ "map-default--resolved--sales" => "inactive",
+ "map-sales--initial--default" => "new",
+ "map-sales--active--default" => "open",
+ "map-sales--inactive--default" => "resolved",
+ "map-default--deleted--sales" => "inactive",
+ "map-default--rejected--sales" => "inactive",
+ "map-default--stalled--sales" => "active",
+ "Name" => "default",
+ "Type" => "ticket",
+ },
+ button => 'Update'
+ );
+ $m->content_contains('Lifecycle mappings updated');
+
+ reload_lifecycle();
+
+ my $from = {
+ deleted => "inactive",
+ new => "initial",
+ open => "active",
+ rejected => "inactive",
+ resolved => "inactive",
+ stalled => "active"
+ };
+
+ my $to = {
+ active => "open",
+ inactive => "resolved",
+ initial => "new",
+ };
+
+ is_deeply( $from, $default->MoveMap($sales), "Move map from default -> sales set correctly" );
+ is_deeply( $to, $sales->MoveMap($default), "Move map from sales -> default set correctly" );
+
+ $from->{'new'} = 'active';
+
+ $m->get_ok( $url . '/Admin/Lifecycles/Mappings.html?Type=ticket&Name=default' );
+ $form = $m->form_name('ModifyMappings');
+ $m->submit_form(
+ fields => {
+ "map-default--new--sales" => "active",
+ "map-default--open--sales" => "active",
+ "map-default--resolved--sales" => "inactive",
+ "map-sales--initial--default" => "new",
+ "map-sales--active--default" => "open",
+ "map-sales--inactive--default" => "resolved",
+ "map-default--deleted--sales" => "inactive",
+ "map-default--rejected--sales" => "inactive",
+ "map-default--stalled--sales" => "active",
+ "Name" => "default",
+ "Type" => "ticket",
+ },
+ button => 'Update'
+ );
+ $m->content_contains('Lifecycle mappings updated');
+
+ reload_lifecycle();
+
+ is_deeply( $from, $default->MoveMap($sales), "Move map from default -> sales updated correctly" );
+}
+
+diag "Confirm the web UI correctly displays mappings";
+{
+ $m->get_ok( $url . '/Admin/Lifecycles/Mappings.html?Type=ticket&Name=default' );
+ my $form = $m->form_name('ModifyMappings');
+
+ my $from = {
+ deleted => "inactive",
+ new => "active",
+ open => "active",
+ rejected => "inactive",
+ resolved => "inactive",
+ stalled => "active",
+ };
+
+ my $to = {
+ active => "open",
+ inactive => "resolved",
+ initial => "new",
+ };
+
+ my @inputs = $form->inputs;
+ foreach my $input (@inputs) {
+ my ( $default_from, $default_status, $default_to ) = $input->name =~ /^map-(default)--(.*)--(sales)$/;
+ my ( $sales_from, $sales_status, $sales_to ) = $input->name =~ /^map-(default)--(.*)--(sales)$/;
+
+ if ($default_from) {
+ is( $input->value,
+ $from->{$default_status},
+ "Mapping set correctly for default -> sales for status: $default_status"
+ );
+ }
+ elsif ($sales_from) {
+ is( $input->value, $to->{$sales_status},
+ "Mapping set correctly for sales -> default for status: $sales_status" );
+ }
+ }
+}
+
+diag "Test updating sales-engineering mappings";
+{
+ $m->get_ok( $url . '/Admin/Lifecycles/Mappings.html?Type=ticket&Name=sales-engineering' );
+
+ my $form = $m->form_name('ModifyMappings');
+ $m->submit_form(
+ fields => {
+ "map-sales-engineering--sales--default" => "new",
+ "map-sales-engineering--engineering--default" => "open",
+ "map-sales-engineering--rejected--default" => "rejected",
+ "map-sales-engineering--resolved--default" => "resolved",
+ "map-sales-engineering--stalled--default" => "stalled",
+ "map-sales-engineering--deleted--default" => "deleted",
+ "Name" => "sales-engineering",
+ "Type" => "ticket",
+ },
+ button => 'Update'
+ );
+ $m->content_contains('Lifecycle mappings updated');
+ $form = $m->form_name('ModifyMappings');
+
+ my $from = {
+ sales => "new",
+ engineering => "open",
+ stalled => "stalled",
+ rejected => "rejected",
+ resolved => "resolved",
+ deleted => "deleted",
+ };
+
+ for my $status ( keys %$from ) {
+ is( $form->value("map-sales-engineering--$status--default"),
+ $from->{$status}, "Mapping set correctly for sales-engineering -> default for status: $status" );
+ }
+
+ reload_lifecycle();
+
+ is_deeply(
+ $from,
+ $sales_engineering->MoveMap($default),
+ "Move map from sales_enginnering -> default updated correctly"
+ );
+}
+
+sub reload_lifecycle {
+ # to get rid of the warning of:
+ # you're changing config option in a test file when server is active
+
+ RT::Test->stop_server;
+ RT->Config->LoadConfigFromDatabase();
+ RT::Lifecycle->FillCache();
+ ( $url, $m ) = RT::Test->started_ok;
+ ok( $m->login(), 'logged in' );
+}
+
+done_testing;
commit 0f8e0e794202c3e964424dde42ff182498cbe8d8
Merge: 9f2b968045 cc2648df8c
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Nov 17 08:34:02 2020 +0800
Merge branch '5.0/lifecycle-ui-mappings-handle-dashes' into 5.0-trunk
-----------------------------------------------------------------------
More information about the rt-commit
mailing list