[Bps-public-commit] rt-extension-rest2 branch custom-roles-on-update created. 1.14-2-g0c81b47
BPS Git Server
git at git.bestpractical.com
Fri Oct 15 18:52:59 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-extension-rest2".
The branch, custom-roles-on-update has been created
at 0c81b476238ee40ed188824f6f0da5ec9e05266b (commit)
- Log -----------------------------------------------------------------
commit 0c81b476238ee40ed188824f6f0da5ec9e05266b
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Oct 16 02:38:07 2021 +0800
Add tests for custom roles on ticket update
diff --git a/xt/ticket-customroles.t b/xt/ticket-customroles.t
index 51cf4f6..8d9701b 100644
--- a/xt/ticket-customroles.t
+++ b/xt/ticket-customroles.t
@@ -309,6 +309,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
@@ -449,6 +493,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 f28787e727f35a32e4d726b1ba265cf373378664
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Oct 16 02:27:43 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/Extension/REST2/Resource/Record/Writable.pm b/lib/RT/Extension/REST2/Resource/Record/Writable.pm
index aa8d8a4..f96b7c8 100644
--- a/lib/RT/Extension/REST2/Resource/Record/Writable.pm
+++ b/lib/RT/Extension/REST2/Resource/Record/Writable.pm
@@ -119,6 +119,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-extension-rest2
More information about the Bps-public-commit
mailing list