[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, support-coreroles-and-customroles, updated. 0.17-3-g9b18d25

Craig Kaiser craig at bestpractical.com
Mon Jan 7 08:39:03 EST 2019


The branch, support-coreroles-and-customroles has been updated
       via  9b18d2564f6b96ae363610f60f4129677e4ba0e6 (commit)
      from  609d0c3d66ddd2615a7e81b23aab21ad37355bcc (commit)

Summary of changes:
 lib/RT/Extension/MandatoryOnTransition.pm | 74 +++++++++++++++----------------
 1 file changed, 35 insertions(+), 39 deletions(-)

- Log -----------------------------------------------------------------
commit 9b18d2564f6b96ae363610f60f4129677e4ba0e6
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon Jan 7 08:37:09 2019 -0500

    Move Owner code into the roles code block
    
    Since owner is a ticket role it makes logical sense to move the code
    handling the owner value on a ticket into the same code block as
    the other role handling code.

diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index 661e923..425999c 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -258,18 +258,16 @@ pair to %CORE_FOR_UPDATE and/or %CORE_FOR_CREATE.
 
 =cut
 
-our @CORE_SUPPORTED  = qw(Content TimeWorked TimeTaken Owner);
-our @CORE_TICKET     = qw(TimeWorked Owner);
+our @CORE_SUPPORTED  = qw(Content TimeWorked TimeTaken);
+our @CORE_TICKET     = qw(TimeWorked);
 our %CORE_FOR_UPDATE = (
     TimeWorked  => 'UpdateTimeWorked',
     TimeTaken   => 'UpdateTimeWorked',
-    Content     => 'UpdateContent',
-    Owner       => 'Owner',
+    Content     => 'UpdateContent'
 );
 our %CORE_FOR_CREATE = (
     TimeWorked  => 'TimeWorked',
     Content     => 'Content',
-    Owner       => 'Owner',
 );
 
 =head2 Methods
@@ -342,7 +340,7 @@ sub RequiredFields {
     my @cfs  =  map { /^CF\.(.+)$/i; $1; }
                grep { /^CF\./i } @$required;
     my @roles = map { /^(:?[CustomRole\.]?.+)$/i; $1; }
-               grep { /^CustomRole\.||AdminCc||Cc||Requestor/i } @$required;
+               grep { /^CustomRole\.||AdminCc||Cc||Requestor||Owner/i } @$required;
 
     # Pull out any must_be or must_not_be rules
     my %cf_must_values = ();
@@ -480,36 +478,6 @@ sub CheckMandatoryFields {
             : $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?
@@ -548,21 +516,49 @@ sub CheckMandatoryFields {
                 ($ret, $msg) = $role_values = $args{Ticket}->RoleGroup($role_object->GroupType);
                 push @errors, $CurrentUser->loc("$msg") unless $ret;
                 return \@errors unless $ret;
+            } elsif ( $role =~ 'Owner' ) {
+                my $value;
+                foreach my $owner (@{$ARGSRef->{$role}}) {
+                    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);
+                    }
+                }
+                if (($value || $args{'Ticket'}->$role()) == $RT::Nobody->id) {
+                    push @errors,
+                    $CurrentUser->loc(
+                        "[_1] is required when changing [_2] to [_3]",
+                        $role,
+                        $CurrentUser->loc($args{From}),
+                        $CurrentUser->loc($args{To})
+                    );
+                }
+                my $user = RT::User->new($args{Ticket}->CurrentUser);
+                my ($ret, $msg) = $user->Load($value);
+                push @errors, $CurrentUser->loc("$msg") unless $ret;
+                return \@errors unless $ret;
+
+                $role_values = $user->EmailAddress;
             } else {
                 $role_values = RT::Group->new($args{Ticket}->CurrentUser);
                 my ($ret, $msg) = $role_values->LoadRoleGroup(Object => $args{Ticket}, Name => $role);
                 push @errors, $CurrentUser->loc("Failed to load role $role for ticket: $msg") unless $ret;
                 return \@errors unless $ret;
             }
-
             my @role_values;
             my @row_input_id = grep $role_arg eq $ARGSRef->{$_}, keys %{$ARGSRef};
             if ( @row_input_id ) {
                 map {push @role_values, $ARGSRef->{"WatcherAddressEmail$_"} } grep { $_ =~ qr/WatcherTypeEmail(.+)/ } @row_input_id;
             }
 
-            my @temp_array = $role_values->MemberEmailAddresses;
-            push @role_values, @temp_array if scalar @temp_array;
+            if ( ref $role_values eq 'RT::Group' ) {
+                my @temp_array = $role_values->MemberEmailAddresses;
+                push @role_values, @temp_array if scalar @temp_array;
+            } else {
+                push @role_values, $role_values;
+            }
 
             if ( not scalar @role_values ) {
                     push @errors, "Requires value for $role to perform action.";

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


More information about the Bps-public-commit mailing list