[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, support-coreroles-and-customroles, repushed

Craig Kaiser craig at bestpractical.com
Fri Feb 1 19:42:34 EST 2019


The branch support-coreroles-and-customroles was deleted and repushed:
       was 2efeba46f59567317692f4421d603fc17837ad1d
       now 58d8de272581c96391ded4febcb7fdb2d5ad804d

1:  ff81d7e ! 1:  79207b3 Support customroles for mandatoryontransition conditions
    @@ -127,7 +127,7 @@
          my @cfs  =  map { /^CF\.(.+)$/i; $1; }
                     grep { /^CF\./i } @$required;
     +    my @roles = map { /^(:?[CustomRole\.]?.+)$/i; $1; }
    -+               grep { /^CustomRole\.|^AdminCc|^Cc|^Requestor|^Owner/i } @$required;
    ++               grep { /^CustomRole\./i } @$required;
      
          # Pull out any must_be or must_not_be rules
          my %cf_must_values = ();
    @@ -142,28 +142,11 @@
      
      =head3 CheckMandatoryFields
     @@
    -     }
    - 
    -     # Some convenience variables set depending on what gets passed
    --    my ($CFs, $CurrentUser);
    -+    my ($CFs, $CRs, $CurrentUser);
    -     if ( $args{'Ticket'} ){
    -         $CFs = $args{'Ticket'}->CustomFields;
    -+        $CRs = $args{'Ticket'}->QueueObj->CustomRoles;
    -         $CurrentUser = $args{'Ticket'}->CurrentUser();
    -     }
    -     elsif ( $args{'Queue'} ){
    -         $CFs = $args{'Queue'}->TicketCustomFields;
    -+        $CRs = $args{'Queue'}->CustomRoles;
    -         $CurrentUser = $args{'Queue'}->CurrentUser();
    -     }
    -     else{
    -@@
              return \@errors;
          }
      
     -    my ($core, $cfs, $must_values) = $self->RequiredFields(
    -+    my ($core, $cfs, $roles, $cf_must_values) = $self->RequiredFields(
    ++    my ($core, $cfs, $roles, $must_values) = $self->RequiredFields(
              Ticket  => $args{'Ticket'},
              Queue   => $args{'Queue'} ? $args{'Queue'}->Name : undef,
              From    => $args{'From'},
    @@ -186,26 +169,16 @@
     +            my ( $role_arg, $role_full ) = ( $role, $role );
     +
     +            if ( $role =~ s/^CustomRole\.//i ) {
    -+                push @errors,
    -+                  $CurrentUser->loc(
    -+    'Custom Roles object required to process mandatory custom roles'
    -+                  ) unless $CRs;
    -+
    -+                my $role_object =
    -+                  RT::CustomRole->new( $args{Ticket}->CurrentUser );
    ++                my $role_object = RT::CustomRole->new( $args{Ticket}->CurrentUser );
     +
     +                my ( $ret, $msg ) = $role_object->Load($role);
    -+                push @errors,
    -+                  $CurrentUser->loc("Failed to load customrole $role:  $msg")
    -+                  unless $ret;
    ++                push @errors, $CurrentUser->loc("Failed to load custom role $role:  $msg") unless $ret;
     +                next unless $role_object->Id;
     +
     +                $role_arg = 'RT::CustomRole-' . $role_object->Id;
     +
    -+                ( $ret, $msg ) = $role_values =
    -+                  $args{Ticket}->RoleGroup( $role_object->GroupType );
    -+                push @errors, $CurrentUser->loc("Could not load current user")
    -+                  unless $ret;
    ++                ( $ret, $msg ) = $role_values = $args{Ticket}->RoleGroup( $role_object->GroupType );
    ++                push @errors, $CurrentUser->loc("Could not load current user") unless $ret;
     +            }
     +
     +            my $role_object = RT::CustomRole->new($args{Ticket}->CurrentUser);
    @@ -224,30 +197,25 @@
     +
     +            # Use this to keep track of input fields that use a count increment
     +            # example: WatcherAddressEmail1 or WatcherAddressEmail2
    -+            my @row_input_num = grep $role_arg eq $ARGSRef->{$_},
    -+              keys %{$ARGSRef};
    -+            map { push @role_values, $ARGSRef->{$_} if $ARGSRef->{$_} }
    -+              grep /$role_arg/, keys %{$ARGSRef};
    ++            my @row_input_num = grep $role_arg eq $ARGSRef->{$_}, keys %{$ARGSRef};
    ++            map { push @role_values, $ARGSRef->{$_} if $ARGSRef->{$_} } grep /$role_arg/, keys %{$ARGSRef};
     +
     +            # Grab our arguments for current role
     +            if (@row_input_num) {
    -+                map {
    -+                    push @role_values, $ARGSRef->{"WatcherAddressEmail$_"}
    ++                map { push @role_values, $ARGSRef->{"WatcherAddressEmail$_"}
     +                      if $ARGSRef->{"WatcherAddressEmail$_"}
     +                  }
    -+                  map { $_ =~ /^WatcherTypeEmail(\d*)$/; $1 } @row_input_num;
    ++                map { $_ =~ /^WatcherTypeEmail(\d*)$/; $1 } @row_input_num;
     +            }
     +            my @temp_array = $role_values->MemberEmailAddresses;
     +            push @role_values, @temp_array if scalar @temp_array;
     +
     +            if ( $args{'To'} && ( not scalar @role_values ) ) {
    -+                push @errors,
    -+                  $CurrentUser->loc(
    -+                    "[_1] is required when changing [_2] to [_3]",
    ++                push @errors, $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
     +                    $role,
     +                    $CurrentUser->loc($transition),
     +                    $CurrentUser->loc( $args{'To'} )
    -+                  );
    ++                );
     +                next;
     +            }
     +        }
    @@ -256,35 +224,4 @@
          return \@errors unless @$cfs;
      
          if ( not $CFs ){
    -@@
    -         }
    - 
    -         # Check for specific values
    --        if ( exists $must_values->{$cf->Name} ){
    -+        if ( exists $cf_must_values->{$cf->Name} ){
    -             my $cf_value = $value;
    - 
    -             if ( not defined $cf_value and $args{'Ticket'} ){
    -@@
    -                 $cf_value = $args{'Ticket'}->FirstCustomFieldValue($cf->Name);
    -             }
    - 
    --            if ( exists $must_values->{$cf->Name}{'must_be'} ){
    --                my @must_be = @{$must_values->{$cf->Name}{'must_be'}};
    -+            if ( exists $cf_must_values->{$cf->Name}{'must_be'} ){
    -+                my @must_be = @{$cf_must_values->{$cf->Name}{'must_be'}};
    - 
    -                 # OK if it's defined and is one of the specified values
    -                 next if defined $cf_value and grep { $cf_value eq $_ } @must_be;
    -@@
    -                 next;
    -             }
    - 
    --            if ( exists $must_values->{$cf->Name}{'must_not_be'} ){
    --                my @must_not_be = @{$must_values->{$cf->Name}{'must_not_be'}};
    -+            if ( exists $cf_must_values->{$cf->Name}{'must_not_be'} ){
    -+                my @must_not_be = @{$cf_must_values->{$cf->Name}{'must_not_be'}};
    - 
    -                 # OK if it's defined and _not_ in the list
    -                 next if defined $cf_value and !grep { $cf_value eq $_ } @must_not_be;
    -
    +
2:  8462a40 ! 2:  2d47a6b Support all core role fields as mandatory on transition fields
    @@ -63,6 +63,15 @@
      
      =head2 Methods
     @@
    +     my @cfs  =  map { /^CF\.(.+)$/i; $1; }
    +                grep { /^CF\./i } @$required;
    +     my @roles = map { /^(:?[CustomRole\.]?.+)$/i; $1; }
    +-               grep { /^CustomRole\./i } @$required;
    ++               grep { /^CustomRole\.|^AdminCc|^Cc|^Requestor|^Owner/i } @$required;
    + 
    +     # Pull out any must_be or must_not_be rules
    +     my %cf_must_values = ();
    +@@
                  : $CORE_FOR_CREATE{$field};
              next unless $arg;
      
    @@ -100,48 +109,31 @@
      
              # Do we have a value currently?
     @@
    -                 push @errors, $CurrentUser->loc("Could not load current user")
    -                   unless $ret;
    -             }
    -+            elsif ( $role eq 'Owner' ) {
    -+
    + 
    +                 ( $ret, $msg ) = $role_values = $args{Ticket}->RoleGroup( $role_object->GroupType );
    +                 push @errors, $CurrentUser->loc("Could not load current user") unless $ret;
    ++            } elsif ( $role eq 'Owner' ) {
     +                # There are 2 Owner fields on Jumbo page, copied the same handling from it.
     +                if ( ref $ARGSRef->{$role} ) {
     +                    foreach my $owner ( @{ $ARGSRef->{$role} } ) {
     +                        if ( defined($owner) && $owner =~ /\D/ ) {
    -+                            $owner_value = $owner
    -+                              unless (
    -+                                $args{'Ticket'}->OwnerObj->Name eq $owner );
    ++                            $owner_value = $owner unless ( $args{'Ticket'}->OwnerObj->Name eq $owner );
     +                        }
     +                        elsif ( length $owner ) {
    -+                            $owner_value = $owner
    -+                              unless (
    -+                                $args{'Ticket'}->OwnerObj->id == $owner );
    ++                            $owner_value = $owner unless ($args{'Ticket'}->OwnerObj->id == $owner );
     +                        }
     +                    }
     +                }
     +                else {
     +                    $owner_value = $ARGSRef->{$role};
     +                }
    - 
    -             my $role_object = RT::CustomRole->new($args{Ticket}->CurrentUser);
    - 
    -@@
    -             push @errors, $CurrentUser->loc("Failed to load custom role $role:  $msg") unless $ret;
    -             return \@errors unless $ret;
    - 
    --            $role_arg = 'RT::CustomRole-' . $role_object->Id;
    -+                my $user = RT::User->new( $args{Ticket}->CurrentUser );
    -+                $user->Load($owner_value);
    -+                push @errors,
    -+                  $CurrentUser->loc("Could not load user: $owner_value")
    -+                  unless $user->Id;
    - 
    --            ($ret, $msg) = $role_values = $args{Ticket}->RoleGroup($role_object->GroupType);
    --            push @errors, $CurrentUser->loc("$msg") unless $ret;
    --            return \@errors unless $ret;
    -+                $role_values = $user->EmailAddress if $user->Id;
    -+            }
    ++                if ( $owner_value ) {
    ++                    my $user = RT::User->new( $args{Ticket}->CurrentUser );
    ++                    $user->Load($owner_value);
    ++                    push @errors, $CurrentUser->loc("Could not load user: $owner_value") unless $user->Id;
    ++                    $role_values = $user->EmailAddress if $user->Id;
    ++                }
    +             }
     +            else {
     +                $role_values = RT::Group->new( $args{Ticket}->CurrentUser );
     +                my ( $ret, $msg ) = $role_values->LoadRoleGroup(
    @@ -149,38 +141,30 @@
     +                    Name   => $role
     +                );
      
    -+                push @errors,
    -+                  $CurrentUser->loc(
    -+                    "Failed to load role $role for ticket: $msg")
    -+                  unless $ret;
    +-            my $role_object = RT::CustomRole->new($args{Ticket}->CurrentUser);
    +-
    +-            my ($ret, $msg) = $role_object->Load($role);
    +-            push @errors, $CurrentUser->loc("Failed to load custom role $role:  $msg") unless $ret;
    +-            return \@errors unless $ret;
    +-
    +-            $role_arg = 'RT::CustomRole-' . $role_object->Id;
    +-
    +-            ($ret, $msg) = $role_values = $args{Ticket}->RoleGroup($role_object->GroupType);
    +-            push @errors, $CurrentUser->loc("$msg") unless $ret;
    +-            return \@errors unless $ret;
    +-
    ++                push @errors, $CurrentUser->loc("Failed to load role $role for ticket: $msg") unless $ret;
     +            }
                  my @role_values;
      
                  # Use this to keep track of input fields that use a count increment
     @@
                        }
    -                   map { $_ =~ /^WatcherTypeEmail(\d*)$/; $1 } @row_input_num;
    +                 map { $_ =~ /^WatcherTypeEmail(\d*)$/; $1 } @row_input_num;
                  }
     -            my @temp_array = $role_values->MemberEmailAddresses;
     -            push @role_values, @temp_array if scalar @temp_array;
      
    --            if ( $args{'To'} && ( not scalar @role_values ) ) {
    -+            # We could end up with a RT::Group option or a single value in the case of Owner
    -+            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 (
    -+                $args{'To'}
    -+                && ( not scalar @role_values
    -+                    or ( $owner_value && $owner_value == $RT::Nobody->id ) )
    -+              )
    -+            {
    -                 push @errors,
    -                   $CurrentUser->loc(
    -                     "[_1] is required when changing [_2] to [_3]",
    +             if ( $args{'To'} && ( not scalar @role_values ) ) {
    +                 push @errors, $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
     
3:  6be7907 < -:  ------- Support requiring a role to be a member of a group
-:  ------- > 3:  a6be1ff Support requiring a role to be a member of a group
4:  463c3ea ! 4:  92fb2f2 Create test file for roles
    @@ -199,7 +199,6 @@
     +    $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',
    @@ -329,7 +328,7 @@
     +
     +    my $group = RT::Group->new(RT->SystemUser);
     +    ($ret, $msg) = $group->CreateUserDefinedGroup(Name => 'Admins');
    -+    ok $ret, "Failed to create Amdins group: $msg";
    ++    ok $ret, "Failed to create Admins group: $msg";
     +
     +    $m->goto_ticket($t->id);
     +    $m->follow_link_ok({ text => 'Basics' }, 'Get Modify.html of ticket');
    @@ -357,7 +356,7 @@
     +    $m->text_contains("Status changed from 'open' to 'stalled'");
     +}
     +
    -+diag "Test customrole mandatory fields";
    ++diag "Test custom role mandatory fields";
     +{
     +    my $t = RT::Test->create_ticket(
     +        Queue   => 'General',
    @@ -370,17 +369,6 @@
     +
     +    my $id = $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 => 'deleted', },
    -+            button    => 'SubmitTicket',
    -+        },
    -+        "Submit deleted with customrole 'vip' created"
    -+    );
    -+    $m->text_contains("Failed to load customrole vip: Couldn't find row");
    -+
     +    my $customrole = RT::CustomRole->new(RT->SystemUser);
     +    ($ret, $msg) = $customrole->Create(Name => 'vip');
     +    ok $ret, $msg;
    @@ -398,7 +386,7 @@
     +            fields    => { Status => 'deleted', },
     +            button    => 'SubmitTicket',
     +        },
    -+        "Submit deleted with no value for required customrole"
    ++        "Submit deleted with no value for required custom role"
     +    );
     +    $m->text_contains("vip is required when changing Status to deleted");
     +
    @@ -412,7 +400,7 @@
     +            fields    => { Status => 'deleted', },
     +            button    => 'SubmitTicket',
     +        },
    -+        "Submit deleted with manatory customrole requirements met."
    ++        "Submit deleted with manatory custom role requirements met."
     +    );
     +    $m->text_contains("Ticket deleted");
     +}
5:  2efeba4 ! 5:  58d8de2 Update README and Changelog
    @@ -32,19 +32,22 @@
     @@
      
              Set( %MandatoryOnTransition,
    -             'QueueName' => {
    --                'from -> to' => [ 'BasicField', 'CF.MyField', ],
    -+                'from -> to' => [ 'BasicField', 'CF.MyField', 'CustomRole.MyRole' ],
    +             Helpdesk => {
    +-                '* -> resolved' => ['TimeWorked', 'CF.Resolution', 'CustomRole.Analyst'],
    ++                '* -> resolved' => ['TimeWorked', 'CF.Resolution'],
    +             },
    +             '*' => {
    +                 '* -> resolved' => ['CF.Category'],
    +-                'CustomRole.Analyst' => {transition => '* -> open', group => 'Engineering'},
                  },
              );
      
    -@@
          The transition syntax is similar to that found in RT's Lifecycles. See
          perldoc /opt/rt4/etc/RT_Config.pm.
      
     +  Requiring role values
     +    You can require any core or custom role on a RT::Ticket object, below is
    -+    an example of requiring a customrole "customer" be set on transition
    ++    an example of requiring a custom role "customer" be set on transition
     +    from open and the owner also be set for the ticket on transition from a
     +    status of open.
     +



More information about the Bps-public-commit mailing list