[Rt-commit] rt branch, 5.0/rest2-handle-absent-custom-role-groups, created. rt-5.0.0-114-ge71f5796b8
? sunnavy
sunnavy at bestpractical.com
Thu Nov 12 15:38:17 EST 2020
The branch, 5.0/rest2-handle-absent-custom-role-groups has been created
at e71f5796b8a123e7df1146554f1bcdaaf79e2da7 (commit)
- Log -----------------------------------------------------------------
commit b9520faef5f3e3db9b322fe8e140cde218d7d8e0
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Nov 13 03:21:48 2020 +0800
Fix REST2 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/REST2/Util.pm b/lib/RT/REST2/Util.pm
index ccfca41d22..92a6736123 100644
--- a/lib/RT/REST2/Util.pm
+++ b/lib/RT/REST2/Util.pm
@@ -164,6 +164,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 e71f5796b8a123e7df1146554f1bcdaaf79e2da7
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Nov 13 03:38:41 2020 +0800
Test tickets with custom roles applied later
diff --git a/t/rest2/ticket-customroles.t b/t/rest2/ticket-customroles.t
index cad2992266..0433911ea6 100644
--- a/t/rest2/ticket-customroles.t
+++ b/t/rest2/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 rt-commit
mailing list