[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, accept-owner, created. 0.16-1-g47fcbf9

Gergely Nagy algernon at bestpractical.com
Wed Oct 17 09:59:46 EDT 2018


The branch, accept-owner has been created
        at  47fcbf91da67ede9d9d9806ea06c5eac13d9f6bb (commit)

- Log -----------------------------------------------------------------
commit 47fcbf91da67ede9d9d9806ea06c5eac13d9f6bb
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 minor modifications 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..b15c762 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
@@ -450,6 +452,12 @@ sub CheckMandatoryFields {
             : $CORE_FOR_CREATE{$field};
         next unless $arg;
         next if defined $ARGSRef->{$arg} and length $ARGSRef->{$arg};
+        if ($field eq 'Owner' and $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;
+        }
 
         # Do we have a value currently?
         # In Create the ticket hasn't been created yet.
diff --git a/xt/require_owner_for_resolve.t b/xt/require_owner_for_resolve.t
new file mode 100644
index 0000000..f154a57
--- /dev/null
+++ b/xt/require_owner_for_resolve.t
@@ -0,0 +1,46 @@
+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);
+
+diag "Test requiring an Owner to resolve tickets";
+{
+    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->content_contains('Test Mandatory Owner On Resolve');
+    $m->submit_form_ok( { form_name => 'TicketUpdate',
+                          button => 'SubmitTicket',},
+                        'Submit resolve with no Owner set');
+    $m->content_contains('Owner is required when changing Status to resolved');
+    $m->submit_form_ok( { form_name => 'TicketUpdate',
+                          button => 'SubmitTicket',
+                          fields => { Owner => RT->SystemUser->id }},
+                        'Submit resolve with Owner set');
+    $m->content_lacks('Owner is required when changing Status to resolved');
+}
+
+undef $m;
+done_testing;

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list