[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, roles-2, repushed

Jim Brandt jbrandt at bestpractical.com
Fri Feb 15 16:15:07 EST 2019


The branch roles-2 was deleted and repushed:
       was 4f1f08e165fb4b306f6b302d602170e73a7a0490
       now b6c7f37dfcae6b21ad1c63722412ade6c99ac783

1:  3e86dc1 ! 1:  b52c9b9 Support custom roles as manadatory on transition
    @@ -55,13 +55,15 @@
     +    if ( $role =~ s/^CustomRole\.//i ) {
     +        my $role_object = RT::CustomRole->new($session{CurrentUser});
     +        my ($ret, $msg) = $role_object->Load($role);
    -+        RT::Logger->error($msg) unless $ret;
    -+
    -+        ($ret, $msg) = $role_group->LoadRoleGroup(Object => $Ticket->QueueObj, Name => $role_object->GroupType);
    -+        RT::Logger->error("Could not load group: " . $role_object->GroupType . " $msg") unless $role_group->Id;
    ++        RT::Logger->error("Unable to load custom role $role: $msg") unless $ret;
    ++
    ++        ($ret, $msg) = $role_group->LoadRoleGroup(
    ++            Object => $Ticket->QueueObj, Name => $role_object->GroupType);
    ++        RT::Logger->error("Unable to load role group: " . $role_object->GroupType . " $msg")
    ++            unless $role_group->Id;
     +        $crs{$role_group->Name} = { Id => $role_object->Id, Name => $role_object->Name };
     +
    -+        push @roles, $role_group if $ret;
    ++        push @roles, $role_group if $role_group->Id;
     +    }
     +}
      </%init>
    @@ -121,6 +123,20 @@
              '*' => {
                  '* -> resolved' => ['CF.Category'],
     @@
    + 
    + =head3 RequiredFields
    + 
    +-Returns two array refs of required fields for the described status transition.
    +-The first is core fields, the second is CF names.  Returns empty array refs
    +-on error or if nothing is required.
    ++Returns three array refs of required fields for the described status transition.
    ++The first is core fields, the second is CF names, the third is roles.  Returns
    ++empty array refs on error or if nothing is required. A forth parameter is a
    ++hashref of must-have values for custom fields.
    + 
    + Takes a paramhash with the keys Ticket, Queue, From, and To.  Ticket should be
    + an object.  Queue should be a name.  From and To should be statuses.  If you
    +@@
          my @core = grep { !/^CF\./i && $core_supported{$_} } @$required;
          my @cfs  =  map { /^CF\.(.+)$/i; $1; }
                     grep { /^CF\./i } @$required;
    @@ -170,20 +186,22 @@
     +                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") unless $ret;
    -+                RT::Logger->error($msg) unless $ret;
    ++                push @errors, $CurrentUser->loc("Could not load object for [_1]", $role) unless $ret;
    ++                RT::Logger->error("Unable to load custom role $role: $msg") unless $ret;
     +                next unless $role_object->Id;
     +
     +                $role_arg = 'RT::CustomRole-' . $role_object->Id;
     +
     +                $role_values = $args{Ticket}->RoleGroup( $role_object->GroupType );
    -+                push @errors, $CurrentUser->loc("Could not load current user") unless $role_values;
    ++                RT::Logger->error("Unable to load role group for " . $role_object->GroupType)
    ++                    unless $role_values;
     +            }
     +
     +            my @role_values;
     +            if ( ref $role_values eq 'RT::Group' ) {
    -+                my @temp_array = $role_values->MemberEmailAddresses;
    -+                push @role_values, @temp_array if scalar @temp_array;
    ++                push @role_values, $role_values->MemberEmailAddresses
    ++                    if $role_values->MemberEmailAddresses;
    ++            }
     +            push @role_values, $ARGSRef->{$role_arg} if $ARGSRef->{$role_arg};
     +
     +            if ( not scalar @role_values ) {
2:  102d016 ! 2:  673f20a Support making all core roles mandatory on transition
    @@ -1,4 +1,4 @@
    -Author: Craig Kaiser <craig at bestpractical.com>
    +Author: Jim Brandt <jbrandt at bestpractical.com>
     
         Support making all core roles mandatory on transition
     
    @@ -6,17 +6,17 @@
     --- a/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Update.html/AfterWorked
     +++ b/html/Callbacks/RT-Extension-MandatoryOnTransition/Ticket/Update.html/AfterWorked
     @@
    -         RT::Logger->error("Could not load group: " . $role_object->GroupType . " $msg") unless $role_group->Id;
              $crs{$role_group->Name} = { Id => $role_object->Id, Name => $role_object->Name };
      
    +         push @roles, $role_group if $role_group->Id;
    ++    } else {
    ++        # Handle core roles like Requestor, Cc, AdminCc
    ++        my ($ret, $msg) = $role_group->LoadRoleGroup(Object => $Ticket, Name => $role);
    ++        RT::Logger->error("Unable to load role $role: $msg") unless $ret;
     +        push @roles, $role_group if $ret;
    -+    } else {
    -+        my ($ret, $msg) = $role_group->LoadRoleGroup(Object => $Ticket, Name => $role);
    -+
    -+        RT::Logger->error($msg) unless $ret;
    -         push @roles, $role_group if $ret;
          }
      }
    + </%init>
     @@
      % }
      % if ( @$roles ) {
    @@ -56,10 +56,11 @@
     +        next unless $ARGSRef->{$role};
     +
     +        if ( $TicketObj->IsWatcher(Type => $role, Email => $ARGSRef->{$role}) ) {
    -+            RT::Logger->error($ARGSRef->{$role} . " is already a watcher for role: $role");
    ++            RT::Logger->debug($ARGSRef->{$role} . " is already a watcher for role: $role");
     +        } else {
     +            my ($ret, $msg) = $TicketObj->AddWatcher(Type => $role, Email => $ARGSRef->{$role});
    -+            RT::Logger->error($msg) unless $ret;
    ++            RT::Logger->error("Unable to add " . $ARGSRef->{$role} . " to role $role: $msg")
    ++                unless $ret;
     +        }
     +    }
      }
    @@ -154,9 +155,9 @@
      
                  if ( $role =~ s/^CustomRole\.//i ) {
     @@
    - 
                      $role_values = $args{Ticket}->RoleGroup( $role_object->GroupType );
    -                 push @errors, $CurrentUser->loc("Could not load current user") unless $role_values;
    +                 RT::Logger->error("Unable to load role group for " . $role_object->GroupType)
    +                     unless $role_values;
     +            } elsif ( $role eq 'Owner' ) {
     +                # There are 2 Owner fields on Jumbo page, copied the same handling from it.
     +                if ( ref $ARGSRef->{$role} ) {
    @@ -192,17 +193,18 @@
                  my @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;
    -+            }
    +                 push @role_values, $role_values->MemberEmailAddresses
    +                     if $role_values->MemberEmailAddresses;
    +             }
     +            else {
     +                push @role_values, $role_values;
     +            }
                  push @role_values, $ARGSRef->{$role_arg} if $ARGSRef->{$role_arg};
      
     -            if ( not scalar @role_values ) {
    -+            if ( not scalar @role_values or ($role eq 'Owner' and !$owner_value or
    -+                ( $owner_value && $owner_value == $RT::Nobody->id) ) ) {
    ++            if ( not scalar @role_values
    ++                    or ($role eq 'Owner' and !$owner_value or
    ++                    ( $owner_value && $owner_value == $RT::Nobody->id) ) ) {
                      push @errors, $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
                          $role,
                          $CurrentUser->loc($transition),
3:  6240749 ! 3:  9f0ed36 Support requiring a role to be a member of a group
    @@ -1,15 +1,28 @@
    -Author: Craig Kaiser <craig at bestpractical.com>
    +Author: Jim Brandt <jbrandt at bestpractical.com>
     
         Support requiring a role to be a member of a group
         
    -    Provide a group key for the role specific key in the
    -    mandatory-on-transition config hash to require at least one
    -    member of the role be a member of at least one of the groups
    -    in the groups array.
    +    Provide a group for the role specific key in the
    +    configuration hash to require a role to have
    +    a member in at least one of the groups.
     
     diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
     --- a/lib/RT/Extension/MandatoryOnTransition.pm
     +++ b/lib/RT/Extension/MandatoryOnTransition.pm
    +@@
    + 
    + Returns three array refs of required fields for the described status transition.
    + The first is core fields, the second is CF names, the third is roles.  Returns
    +-empty array refs on error or if nothing is required. A forth parameter is a
    +-hashref of must-have values for custom fields.
    ++empty array refs on error or if nothing is required.
    ++
    ++A fourth returned parameter is a hashref of must-have values for custom fields.
    ++
    ++The fifth parameter is a hashref of groups a role member must be in.
    + 
    + Takes a paramhash with the keys Ticket, Queue, From, and To.  Ticket should be
    + an object.  Queue should be a name.  From and To should be statuses.  If you
     @@
              }
          }
    @@ -60,6 +73,16 @@
              Queue   => $args{'Queue'} ? $args{'Queue'}->Name : undef,
              From    => $args{'From'},
     @@
    +             my @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' ) {
    +-                push @role_values, $role_values->MemberEmailAddresses
    +-                    if $role_values->MemberEmailAddresses;
    ++                my @member_emails = $role_values->MemberEmailAddresses;
    ++                push @role_values, @member_emails if @member_emails;
    +             }
    +             else {
    +                 push @role_values, $role_values;
                  }
                  push @role_values, $ARGSRef->{$role_arg} if $ARGSRef->{$role_arg};
      
    @@ -69,32 +92,31 @@
     +                my $has_valid_member;
     +
     +                foreach my $group_name ( @{ $role_group_values->{$role_full}->{group} } ) {
    -+                    next if $has_valid_member;
     +                    my $group = RT::Group->new( $args{Ticket}->CurrentUser );
     +
     +                    my ( $ret, $msg ) = $group->LoadUserDefinedGroup($group_name);
    -+                    push @errors, $CurrentUser->loc("Failed to load group: $group_name") unless $ret;
     +                    RT::Logger->error("Failed to load group: $group_name : $msg") unless $ret;
     +                    next unless $ret;
     +
    -+                    my $user = RT::User->new( $args{Ticket}->CurrentUser );
     +                    foreach my $member (@role_values) {
     +                        next unless $member;
     +
    ++                        my $user = RT::User->new( $args{Ticket}->CurrentUser );
     +                        $user->Load($member);
     +                        $user->LoadByEmail($member) unless $user->Id;
     +                        RT::Logger->error("Failed to load: $member") unless $user->Id;
     +                        next unless $user->Id;
     +
     +                        $has_valid_member = $group->HasMemberRecursively( $user->Id );
    ++                        last if $has_valid_member;
     +                    }
    ++                    last if $has_valid_member;
     +                }
     +                my $roles = join( ' or ', @{ $role_group_values->{$role_full}->{group} } );
     +                push @errors, $CurrentUser->loc("A member of group $roles is required for role: $role")
     +                    unless $has_valid_member;
    -+                next unless $has_valid_member;
     +            }
    -             if ( not scalar @role_values or ($role eq 'Owner' and !$owner_value or
    -                 ( $owner_value && $owner_value == $RT::Nobody->id) ) ) {
    -                 push @errors, $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
    +             if ( not scalar @role_values
    +                     or ($role eq 'Owner' and !$owner_value or
    +                     ( $owner_value && $owner_value == $RT::Nobody->id) ) ) {
     
4:  5e222b4 ! 4:  ec60133 Create test file for mandatory roles feature
    @@ -354,7 +354,7 @@
     +            fields    => { Status => 'stalled', },
     +            button    => 'SubmitTicket',
     +        },
    -+        "Try to stall ticket with $role and  group required"
    ++        "Try to stall ticket with $role and group required"
     +    );
     +    $m->text_contains("Status changed from 'open' to 'stalled'");
     +}
5:  4f1f08e = 5:  b6c7f37 Update README and Changelog



More information about the Bps-public-commit mailing list