[Bps-public-commit] rt-extension-rest2 branch, handle-absent-custom-role-groups, created. 1.09-6-gc872a55

? sunnavy sunnavy at bestpractical.com
Thu Nov 12 15:40:16 EST 2020


The branch, handle-absent-custom-role-groups has been created
        at  c872a559e24603e3b37f4517c627d4bc6ec1d006 (commit)

- Log -----------------------------------------------------------------
commit 0260bd08cd710a579045e0c26d80989d7bea92df
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Nov 13 03:30:50 2020 +0800

    In case lazy-created custom role groups don't exist
    
    Object's custom role groups don't always exist, e.g. if custom roles are
    created/applied after the object creation.
    
    Without this, the following $group->MembersObj would error out:
    
        couldn't execute the query 'SELECT main.* FROM GroupMembers main WHERE (main.GroupId = ) ORDER BY main.id ASC '

diff --git a/lib/RT/Extension/REST2/Util.pm b/lib/RT/Extension/REST2/Util.pm
index 6a2ba19..a34d373 100644
--- a/lib/RT/Extension/REST2/Util.pm
+++ b/lib/RT/Extension/REST2/Util.pm
@@ -116,6 +116,11 @@ sub serialize_record {
         for my $role ($record->Roles(ACLOnly => 0)) {
             my $members = $data{$role} = [];
             my $group = $record->RoleGroup($role);
+            if ( !$group->Id ) {
+                $data{$role} = expand_uid( RT->Nobody->UserObj->UID ) if $record->_ROLES->{$role}{Single};
+                next;
+            }
+
             my $gm = $group->MembersObj;
             while ($_ = $gm->Next) {
                 push @$members, expand_uid($_->MemberObj->Object->UID);

commit c872a559e24603e3b37f4517c627d4bc6ec1d006
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Nov 13 03:41:58 2020 +0800

    Test tickets with custom roles applied later

diff --git a/xt/ticket-customroles.t b/xt/ticket-customroles.t
index a2bc034..c390bf5 100644
--- a/xt/ticket-customroles.t
+++ b/xt/ticket-customroles.t
@@ -519,5 +519,49 @@ $user->PrincipalObj->GrantRight( Right => $_ )
     }), 'fetched group');
 }
 
+{
+    my $payload = {
+        Subject => 'Test custom rules applied later',
+        Queue   => 'General',
+    };
+
+    my $res = $mech->post_json("$rest_base_path/ticket",
+        $payload,
+        'Authorization' => $auth,
+    );
+    is($res->code, 201);
+    ok(my $ticket_url = $res->header('location'));
+    ok((my $ticket_id) = $ticket_url =~ qr[/ticket/(\d+)]);
+
+    my $later_single = RT::CustomRole->new(RT->SystemUser);
+    ($ok, $msg) = $later_single->Create(Name => 'Later Single Member', MaxValues => 1);
+    ok($ok, $msg);
+    my $later_single_id = $later_single->Id;
+
+    ($ok, $msg) = $later_single->AddToObject($queue->id);
+    ok($ok, $msg);
+
+    my $later_multi = RT::CustomRole->new(RT->SystemUser);
+    ($ok, $msg) = $later_multi->Create(Name => 'Later Multi Member');
+    ok($ok, $msg);
+    my $later_multi_id = $later_multi->Id;
+
+    ($ok, $msg) = $later_multi->AddToObject($queue->id);
+    ok($ok, $msg);
+
+    $res = $mech->get($ticket_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+
+    my $content = $mech->json_response;
+    cmp_deeply($content->{$later_multi->GroupType}, [], 'no Later Multi Member');
+    cmp_deeply($content->{$later_single->GroupType}, {
+        type => 'user',
+        id   => 'Nobody',
+        _url => re(qr{$rest_base_path/user/Nobody$}),
+    }, 'Later Single Member is Nobody');
+}
+
 done_testing;
 

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


More information about the Bps-public-commit mailing list