[Bps-public-commit] rt-extension-rest2 branch, collection-role-fields, repushed

? sunnavy sunnavy at bestpractical.com
Thu May 27 11:15:43 EDT 2021


The branch collection-role-fields was deleted and repushed:
       was 883aca81afa411538b109cb4d9bfb7a0027203c1
       now 878ba58dcfc0570aade26fee011f978eb5cbcaaa

1:  57e03e5 = 1:  57e03e5 Support core roles for ticket search result in REST2
2:  eb94229 = 2:  eb94229 Test core role fields for ticket search result in REST2
3:  8866c01 = 3:  8866c01 Support core roles for asset search result in REST2
4:  0f4488b = 4:  0f4488b Test core role fields for asset search result in REST2
5:  9e41bf6 ! 5:  b4cc6c1 Support custom roles for search result in REST2
    @@ -6,16 +6,16 @@
     --- a/lib/RT/Extension/REST2/Resource.pm
     +++ b/lib/RT/Extension/REST2/Resource.pm
     @@
    + 
                  push @{ $result }, values %values if %values;
              }
    - 
     +    } elsif ($field eq 'CustomRoles') {
     +        if ( $item->DOES("RT::Record::Role::Roles") ) {
     +            my %data;
     +            for my $role ( $item->Roles( ACLOnly => 0 ) ) {
     +                next unless $role =~ /^RT::CustomRole-/;
     +                $data{$role} = [];
    -+
    + 
     +                my $group = $item->RoleGroup($role);
     +                if ( !$group->Id ) {
     +                    $data{$role} = expand_uid( RT->Nobody->UserObj->UID ) if $item->_ROLES->{$role}{Single};
    @@ -32,6 +32,25 @@
     +            }
     +            return \%data;
     +        }
    ++    } elsif ($field =~ /^RT::CustomRole-\d+$/) {
    ++        if ( $item->DOES("RT::Record::Role::Roles") ) {
    ++            my $result = [];
    ++
    ++            my $group = $item->RoleGroup($field);
    ++            if ( !$group->Id ) {
    ++                $result = expand_uid( RT->Nobody->UserObj->UID ) if $item->_ROLES->{$field}{Single};
    ++                next;
    ++            }
    ++
    ++            my $gms = $group->MembersObj;
    ++            while ( my $gm = $gms->Next ) {
    ++                push @$result, expand_uid( $gm->MemberObj->Object->UID );
    ++            }
    ++
    ++            # Avoid the extra array ref for single member roles
    ++            $result = shift @$result if $group->SingleMemberRoleGroup;
    ++            return $result;
    ++        }
          } elsif ($item->can('_Accessible') && $item->_Accessible($field => 'read')) {
              # RT::Record derived object, so we can check access permissions.
      
6:  7cc6448 ! 6:  9c833eb Test custom role fields for ticket search result in REST2
    @@ -25,12 +25,25 @@
     +    ok( my $ticket_url = $res->header('location') );
     +    ok( my ($ticket_id) = $ticket_url =~ qr[/ticket/(\d+)] );
     +
    -+    $res = $mech->get( "$rest_base_path/tickets?query=id=$ticket_id&fields=CustomRoles", 'Authorization' => $auth, );
    ++    $res = $mech->get(
    ++        "$rest_base_path/tickets?query=id=$ticket_id&fields=" . join( ',', $single->GroupType, $multi->GroupType ),
    ++        'Authorization' => $auth,
    ++    );
     +    is( $res->code, 200 );
     +    my $content = $mech->json_response;
     +    is( scalar @{ $content->{items} }, 1 );
     +
     +    my $ticket = $content->{items}->[0];
    ++    is( $ticket->{ $single->GroupType }{id},   'single2 at example.com', 'Single Member id in search result' );
    ++    is( $ticket->{ $multi->GroupType }[0]{id}, 'multi at example.com',   'Multi Member id in search result' );
    ++    is( $ticket->{ $multi->GroupType }[1]{id}, 'multi2 at example.com',  'Multi Member id in search result' );
    ++
    ++    $res = $mech->get( "$rest_base_path/tickets?query=id=$ticket_id&fields=CustomRoles", 'Authorization' => $auth, );
    ++    is( $res->code, 200 );
    ++    $content = $mech->json_response;
    ++    is( scalar @{ $content->{items} }, 1 );
    ++
    ++    $ticket = $content->{items}->[0];
     +    is( $ticket->{CustomRoles}{ $single->GroupType }{id}, 'single2 at example.com',  'Single Member id in search result' );
     +    is( $ticket->{CustomRoles}{ $multi->GroupType }[0]{id}, 'multi at example.com',  'Multi Member id in search result' );
     +    is( $ticket->{CustomRoles}{ $multi->GroupType }[1]{id}, 'multi2 at example.com', 'Multi Member id in search result' );
7:  cac75c4 = 7:  dbc71d9 Fix typo in REST2 doc
8:  883aca8 ! 8:  878ba58 Document role fields for ticket search result
    @@ -10,7 +10,7 @@
      
          XX_RT_URL_XX/REST/2.0/tickets
     -      ?fields=Owner,Status,Created,Subject,Queue,CustomFields
    -+      ?fields=Owner,Status,Created,Subject,Queue,CustomFields,Requestor,Cc,AdminCc,CustomRoles
    ++      ?fields=Owner,Status,Created,Subject,Queue,CustomFields,Requestor,Cc,AdminCc,RT::CustomRole-1
            &fields[Queue]=Name,Description
      
      Says that in the result set for tickets, the extra fields for Owner, Status,
    @@ -29,7 +29,6 @@
                           "CustomField value"
                       ]
                   }
    --         ]
     +         ],
     +         "Requestor" : [
     +            {
    @@ -46,15 +45,12 @@
     +            }
     +         ],
     +         "AdminCc" : [],
    -+         "CustomRoles" : {
    -+            "RT::CustomRole-1" : [
    -+               {
    -+                  "_url" : "XX_RT_URL_XX/REST/2.0/user/foo at example.com",
    -+                  "type" : "user",
    -+                  "id" : "foo at example.com"
    -+               }
    -+            ]
    -+         }
    ++         "RT::CustomRole-1" : [
    ++            {
    ++               "_url" : "XX_RT_URL_XX/REST/2.0/user/foo at example.com",
    ++               "type" : "user",
    ++               "id" : "foo at example.com"
    ++            }
    +          ]
            }
            { … },
    -       …



More information about the Bps-public-commit mailing list