[Rt-commit] rt branch 5.0/rest2-custom-roles-on-create created. rt-5.0.1-609-gffab7276af
Gitolite
git at git.bestpractical.com
Fri Aug 13 15:19:01 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-create has been created
at ffab7276afeaa4affcc3a5baf945a2ec4efa9f89 (commit)
- Log -----------------------------------------------------------------
commit ffab7276afeaa4affcc3a5baf945a2ec4efa9f89
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Aug 13 22:58:11 2021 +0800
Add tests for custom roles on ticket create via REST2
This is the port of ef2cc3c3a2 in rt-extension-rest2.
diff --git a/t/rest2/ticket-customroles.t b/t/rest2/ticket-customroles.t
index 4a09314efb..070d3d034e 100644
--- a/t/rest2/ticket-customroles.t
+++ b/t/rest2/ticket-customroles.t
@@ -195,6 +195,46 @@ $user->PrincipalObj->GrantRight( Right => $_ )
}, 'one Single Member');
}
+diag 'Create and view ticket with custom roles by name';
+{
+ my $payload = {
+ Subject => 'Ticket with multiple watchers',
+ Queue => 'General',
+ CustomRoles => { 'Multi Member' => ['multi at example.com', 'multi2 at example.com'],
+ 'Single Member' => 'test at localhost' },
+ };
+
+ 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+)]);
+
+ $res = $mech->get($ticket_url,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 200);
+
+ my $content = $mech->json_response;
+ cmp_deeply($content->{$multi->GroupType}, [{
+ type => 'user',
+ id => 'multi at example.com',
+ _url => re(qr{$rest_base_path/user/multi\@example\.com$}),
+ }, {
+ type => 'user',
+ id => 'multi2 at example.com',
+ _url => re(qr{$rest_base_path/user/multi2\@example\.com$}),
+ }], 'two Multi Members');
+
+ cmp_deeply($content->{$single->GroupType}, {
+ type => 'user',
+ id => 'test at localhost',
+ _url => re(qr{$rest_base_path/user/test\@localhost}),
+ }, 'one Single Member');
+}
+
# Modify single-member role
{
my $payload = {
@@ -363,7 +403,7 @@ $user->PrincipalObj->GrantRight( Right => $_ )
my @stable_payloads = (
{
Subject => 'no changes to watchers',
- _messages => ["Ticket 5: Subject changed from 'Ticket for modifying watchers' to 'no changes to watchers'"],
+ _messages => ["Ticket 6: Subject changed from 'Ticket for modifying watchers' to 'no changes to watchers'"],
_name => 'no watcher keys',
},
{
commit 1c937574a2d5193a1345eaf53af24f2974949c9f
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Aug 13 22:58:01 2021 +0800
Support custom roles by name on ticket create via REST2
This is the port of 704bf19819 in rt-extension-rest2.
diff --git a/lib/RT/REST2.pm b/lib/RT/REST2.pm
index abeef7d3b0..d420af8ee3 100644
--- a/lib/RT/REST2.pm
+++ b/lib/RT/REST2.pm
@@ -537,10 +537,11 @@ curl for SSL like --cacert.
Below are some examples using the endpoints above.
- # Create a ticket, setting some custom fields
+ # Create a ticket, setting some custom fields and a custom role
curl -X POST -H "Content-Type: application/json" -u 'root:password'
-d '{ "Queue": "General", "Subject": "Create ticket test",
"Requestor": "user1 at example.com", "Cc": "user2 at example.com",
+ "CustomRoles": {"My Role": "staff1 at example.com"},
"Content": "Testing a create",
"CustomFields": {"Severity": "Low"}}'
'https://myrt.com/REST/2.0/ticket'
diff --git a/lib/RT/REST2/Resource/Record/Writable.pm b/lib/RT/REST2/Resource/Record/Writable.pm
index e31f6d52a7..3d81b25d5b 100644
--- a/lib/RT/REST2/Resource/Record/Writable.pm
+++ b/lib/RT/REST2/Resource/Record/Writable.pm
@@ -53,7 +53,7 @@ use warnings;
use Moose::Role;
use namespace::autoclean;
use JSON ();
-use RT::REST2::Util qw( deserialize_record error_as_json expand_uid update_custom_fields process_uploads update_role_members );
+use RT::REST2::Util qw( deserialize_record error_as_json expand_uid update_custom_fields process_uploads update_role_members fix_custom_role_ids );
use List::MoreUtils 'uniq';
with 'RT::REST2::Resource::Role::RequestBodyIsJSON'
@@ -357,6 +357,13 @@ sub create_record {
}
}
+ if ( $args{CustomRoles} ) {
+ # RT::Ticket::Create wants custom role IDs (like RT::CustomRole-ID)
+ # rather than role names.
+ %args = ( %args, %{ fix_custom_role_ids( $record, delete $args{CustomRoles} ) } );
+ }
+
+
my $method = $record->isa('RT::Group') ? 'CreateUserDefinedGroup' : 'Create';
my ($ok, @rest) = $record->$method(%args);
diff --git a/lib/RT/REST2/Util.pm b/lib/RT/REST2/Util.pm
index e750715e32..f9bc8e5fa9 100644
--- a/lib/RT/REST2/Util.pm
+++ b/lib/RT/REST2/Util.pm
@@ -224,7 +224,7 @@ sub deserialize_record {
# Sanitize input for the Perl API
for my $field (sort keys %$data) {
- my $skip_regex = join '|', 'CustomFields', 'Attachments',
+ my $skip_regex = join '|', 'CustomFields', 'CustomRoles', 'Attachments',
$record->DOES("RT::Record::Role::Links") ? ( sort keys %RT::Link::TYPEMAP ) : ();
next if $field =~ /$skip_regex/;
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list