[Rt-commit] rt branch 5.0/rest2-custom-roles-on-update created. rt-5.0.2-26-g59d720cd71
BPS Git Server
git at git.bestpractical.com
Mon Oct 18 17:33:43 UTC 2021
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 5.0/rest2-custom-roles-on-update has been created
at 59d720cd71133859eeb12bf453bac2a1fbc00eb0 (commit)
- Log -----------------------------------------------------------------
commit 59d720cd71133859eeb12bf453bac2a1fbc00eb0
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 19 01:23:24 2021 +0800
Add tests for custom roles on ticket update
diff --git a/t/rest2/ticket-customroles.t b/t/rest2/ticket-customroles.t
index 070d3d034e..8831c6869f 100644
--- a/t/rest2/ticket-customroles.t
+++ b/t/rest2/ticket-customroles.t
@@ -304,6 +304,50 @@ diag 'Create and view ticket with custom roles by name';
_url => re(qr{$rest_base_path/user/Nobody$}),
}, 'Single Member has changed to Nobody');
}
+
+ for my $identifier ($user->id, $user->Name) {
+ $payload = {
+ CustomRoles => { 'Single Member' => $identifier },
+ };
+
+ $res = $mech->put_json($ticket_url,
+ $payload,
+ 'Authorization' => $auth,
+ );
+ is_deeply($mech->json_response, ["Single Member changed from Nobody to test"], "updated Single Member with identifier $identifier");
+
+ $res = $mech->get($ticket_url,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 200);
+
+ cmp_deeply($mech->json_response->{$single->GroupType}, {
+ type => 'user',
+ id => 'test',
+ _url => re(qr{$rest_base_path/user/test$}),
+ }, 'Single Member has changed to test');
+
+ $payload = {
+ CustomRoles => { 'Single Member' => 'Nobody' },
+ };
+
+ $res = $mech->put_json($ticket_url,
+ $payload,
+ 'Authorization' => $auth,
+ );
+ is_deeply($mech->json_response, ["Single Member changed from test to Nobody"], 'updated Single Member');
+
+ $res = $mech->get($ticket_url,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 200);
+
+ cmp_deeply($mech->json_response->{$single->GroupType}, {
+ type => 'user',
+ id => 'Nobody',
+ _url => re(qr{$rest_base_path/user/Nobody$}),
+ }, 'Single Member has changed to Nobody');
+ }
}
# Modify multi-member roles
@@ -444,6 +488,32 @@ diag 'Create and view ticket with custom roles by name';
_url => re(qr{$rest_base_path/user/multi\@example\.com$}),
}), "preserved two Multi Members when $name");
}
+
+ $payload = { CustomRoles => { 'Multi Member' => [ 'test at localhost', 'multi at example.com' ] }, };
+ $res = $mech->put_json( $ticket_url, $payload, 'Authorization' => $auth, );
+ is_deeply(
+ $mech->json_response,
+ [ 'Added test at localhost as Multi Member for this ticket',
+ 'multi2 at example.com is no longer Multi Member for this ticket'
+ ],
+ "updated ticket watchers"
+ );
+ $res = $mech->get( $ticket_url, 'Authorization' => $auth, );
+ is( $res->code, 200 );
+ $content = $mech->json_response;
+ cmp_deeply(
+ $content->{ $multi->GroupType },
+ bag({ type => 'user',
+ id => 'test at localhost',
+ _url => re(qr{$rest_base_path/user/test\@localhost$}),
+ },
+ { type => 'user',
+ id => 'multi at example.com',
+ _url => re(qr{$rest_base_path/user/multi\@example\.com$}),
+ }
+ ),
+ 'two Multi Members'
+ );
}
# groups as members
commit d901a13dad80a0917cb2d4a653e06bae8fe4d070
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 19 01:21:53 2021 +0800
Support custom roles by name on ticket update
We previously supported custom roles on ticket update using syntax like
RT::CustomRole-2. This commit adds support for setting custom roles by
name, using the same syntax as comment/correspond.
With this, now we have consistent API on craete, update and
comment/correspond.
diff --git a/lib/RT/REST2/Resource/Record/Writable.pm b/lib/RT/REST2/Resource/Record/Writable.pm
index 3d81b25d5b..260e015975 100644
--- a/lib/RT/REST2/Resource/Record/Writable.pm
+++ b/lib/RT/REST2/Resource/Record/Writable.pm
@@ -152,6 +152,12 @@ sub update_record {
my $self = shift;
my $data = shift;
+ # update_role_members wants custom role IDs (like RT::CustomRole-ID)
+ # rather than role names.
+ if ( $data->{CustomRoles} ) {
+ %$data = ( %$data, %{ fix_custom_role_ids( $self->record, delete $data->{CustomRoles} ) } );
+ }
+
my @results = $self->record->Update(
ARGSRef => $data,
AttributesRef => [ $self->record->WritableAttributes ],
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list