[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, master, updated. 0.16-2-g9cbe71c
? sunnavy
sunnavy at bestpractical.com
Fri Oct 26 11:19:31 EDT 2018
The branch, master has been updated
via 9cbe71c5add0b04c54eac247a8e2d7b09d1c1e66 (commit)
via d2fd0acfe730cdaf1f6786f73eb49ca1b2a05bab (commit)
from 741803edcc693fed6b27699f7d746c162e43ef62 (commit)
Summary of changes:
Changes | 3 +
MANIFEST | 1 +
META.yml | 2 +-
lib/RT/Extension/MandatoryOnTransition.pm | 39 +++++++++-
xt/require_owner_for_resolve.t | 122 ++++++++++++++++++++++++++++++
5 files changed, 163 insertions(+), 4 deletions(-)
create mode 100644 xt/require_owner_for_resolve.t
- Log -----------------------------------------------------------------
commit d2fd0acfe730cdaf1f6786f73eb49ca1b2a05bab
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Wed Oct 17 15:55:08 2018 +0200
Add support for Owner as a mandatory field
This makes it possible to require Owner to be set to anything but Nobody when
performing a transition. Typically, this would be used to require an owner to be
set before resolving a ticket.
Also added a test case for the new functionality.
Code mostly lifted from, with tweakings and the test case added:
https://forum.bestpractical.com/t/prevent-resolution-of-ticket-that-owner-is-nobody/30804/5
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index 993210d..8880d90 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -252,16 +252,18 @@ pair to %CORE_FOR_UPDATE and/or %CORE_FOR_CREATE.
=cut
-our @CORE_SUPPORTED = qw(Content TimeWorked TimeTaken);
-our @CORE_TICKET = qw(TimeWorked);
+our @CORE_SUPPORTED = qw(Content TimeWorked TimeTaken Owner);
+our @CORE_TICKET = qw(TimeWorked Owner);
our %CORE_FOR_UPDATE = (
TimeWorked => 'UpdateTimeWorked',
TimeTaken => 'UpdateTimeWorked',
Content => 'UpdateContent',
+ Owner => 'Owner',
);
our %CORE_FOR_CREATE = (
TimeWorked => 'TimeWorked',
Content => 'Content',
+ Owner => 'Owner',
);
=head2 Methods
@@ -449,6 +451,37 @@ sub CheckMandatoryFields {
? $CORE_FOR_UPDATE_COPY{$field}
: $CORE_FOR_CREATE{$field};
next unless $arg;
+
+ if ($field eq 'Owner') {
+ my $value;
+
+ # There are 2 Owner fields on Jumbo page, copied the same handling from it.
+ if (ref $ARGSRef->{$arg}) {
+ foreach my $owner (@{$ARGSRef->{$arg}}) {
+ if (defined($owner) && $owner =~ /\D/) {
+ $value = $owner unless ($args{'Ticket'}->OwnerObj->Name eq $owner);
+ }
+ elsif (length $owner) {
+ $value = $owner unless ($args{'Ticket'}->OwnerObj->id == $owner);
+ }
+ }
+ }
+ else {
+ $value = $ARGSRef->{$arg};
+ }
+
+ if (($value || $args{'Ticket'}->$field()) == $RT::Nobody->id) {
+ push @errors,
+ $CurrentUser->loc(
+ "[_1] is required when changing [_2] to [_3]",
+ $field,
+ $CurrentUser->loc($transition),
+ $CurrentUser->loc($field_label{$transition})
+ );
+ next;
+ }
+ }
+
next if defined $ARGSRef->{$arg} and length $ARGSRef->{$arg};
# Do we have a value currently?
diff --git a/xt/require_owner_for_resolve.t b/xt/require_owner_for_resolve.t
new file mode 100644
index 0000000..20fd377
--- /dev/null
+++ b/xt/require_owner_for_resolve.t
@@ -0,0 +1,122 @@
+use strict;
+use warnings;
+
+use RT::Extension::MandatoryOnTransition::Test tests => undef, config => <<CONFIG
+Set( %MandatoryOnTransition,
+ '*' => {
+ '* -> resolved' => ['Owner',],
+ }
+ );
+CONFIG
+ ;
+
+use_ok('RT::Extension::MandatoryOnTransition');
+
+my ($baseurl, $m) = RT::Test->started_ok();
+
+ok($m->login('root', 'password'), 'logged in');
+$m->get_ok($m->rt_base_url);
+
+my $root = RT::User->new(RT->SystemUser);
+$root->Load('root');
+ok($root->id, 'Loaded root');
+
+diag "Resolve ticket through Update with required Owner";
+{
+ my $t = RT::Test->create_ticket(
+ Queue => 'General',
+ Subject => 'Test Mandatory Owner On Resolve',
+ Content => 'Testing',
+ );
+
+ ok($t->id, 'Created test ticket: ' . $t->id);
+
+ $m->goto_ticket($t->id);
+
+ $m->follow_link_ok({ text => 'Resolve' }, 'Try to resolve ticket');
+ $m->text_contains('Test Mandatory Owner On Resolve');
+ $m->submit_form_ok(
+ { form_name => 'TicketUpdate',
+ button => 'SubmitTicket',
+ },
+ 'Submit resolve with no Owner set'
+ );
+ $m->text_contains('Owner is required when changing Status to resolved');
+ $m->submit_form_ok(
+ { form_name => 'TicketUpdate',
+ button => 'SubmitTicket',
+ fields => { Owner => $root->id }
+ },
+ 'Submit resolve with Owner set'
+ );
+ $m->text_lacks('Owner is required when changing Status to resolved');
+ $m->text_contains('Owner changed from Nobody to root');
+ $m->text_contains("Status changed from 'new' to 'resolved'");
+}
+
+diag "Resolve ticket through Basics with required Owner";
+{
+ my $t = RT::Test->create_ticket(
+ Queue => 'General',
+ Subject => 'Test Mandatory Owner On Resolve',
+ Content => 'Testing',
+ );
+ ok($t->id, 'Created ticket to resolve through Modify.html: ' . $t->id);
+
+ $m->goto_ticket($t->id);
+ $m->follow_link_ok({ text => 'Basics' }, 'Get Modify.html of ticket');
+ $m->submit_form_ok(
+ { form_name => 'TicketModify',
+ fields => { Status => 'resolved', },
+ button => 'SubmitTicket',
+ },
+ 'Submit resolve with no Owner set'
+ );
+ $m->text_contains('Owner is required when changing Status to resolved');
+
+ $m->submit_form_ok(
+ { form_name => 'TicketModify',
+ fields => { Status => 'resolved', Owner => $root->id, },
+ button => 'SubmitTicket',
+ },
+ 'Submit resolve with no Owner set'
+ );
+ $m->text_lacks('Owner is required when changing Status to resolved');
+ $m->text_contains('Owner changed from Nobody to root');
+ $m->text_contains("Status changed from 'new' to 'resolved'");
+}
+
+diag "Resolve ticket through Jumbo with required Owner";
+{
+ my $t = RT::Test->create_ticket(
+ Queue => 'General',
+ Subject => 'Test Mandatory Owner On Resolve',
+ Content => 'Testing',
+ );
+ ok($t->id, 'Created ticket to resolve through ModifyAll.html: ' . $t->id);
+
+ $m->goto_ticket($t->id);
+ $m->follow_link_ok({ text => 'Jumbo' }, 'Get ModifyAll.html of ticket');
+ $m->submit_form_ok(
+ { form_name => 'TicketModifyAll',
+ fields => { Status => 'resolved', },
+ button => 'SubmitTicket',
+ },
+ 'Submit resolve with no Owner set'
+ );
+ $m->text_contains('Owner is required when changing Status to resolved');
+
+ $m->submit_form_ok(
+ { form_name => 'TicketModifyAll',
+ fields => { Status => 'resolved', Owner => $root->id, },
+ button => 'SubmitTicket',
+ },
+ 'Submit resolve with no Owner set'
+ );
+ $m->text_lacks('Owner is required when changing Status to resolved');
+ $m->text_contains('Owner changed from Nobody to root');
+ $m->text_contains("Status changed from 'new' to 'resolved'");
+}
+
+undef $m;
+done_testing;
commit 9cbe71c5add0b04c54eac247a8e2d7b09d1c1e66
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Oct 26 23:05:43 2018 +0800
Release 0.17
diff --git a/Changes b/Changes
index b412fd5..5eb32fc 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+0.17 2018-10-26
+ - Add support for Owner as a mandatory field
+
0.16 2018-09-19
- Don't check permission to get queue name from ticket in RequiredFields
diff --git a/MANIFEST b/MANIFEST
index 308cbb0..0f57660 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -38,4 +38,5 @@ xt/basic.t
xt/immutable_core_for_update.t
xt/mandatory_on_create.t
xt/queue_change.t
+xt/require_owner_for_resolve.t
xt/required_fields.t
diff --git a/META.yml b/META.yml
index 84c7b6d..5463e30 100644
--- a/META.yml
+++ b/META.yml
@@ -27,6 +27,6 @@ requires:
resources:
license: http://opensource.org/licenses/gpl-license.php
repository: https://github.com/bestpractical/rt-extension-mandatoryontransition
-version: '0.16'
+version: '0.17'
x_module_install_rtx_version: '0.40'
x_requires_rt: 4.0.9
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index 8880d90..7c35df7 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -2,7 +2,7 @@ use strict;
use warnings;
package RT::Extension::MandatoryOnTransition;
-our $VERSION = '0.16';
+our $VERSION = '0.17';
=head1 NAME
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list