[Bps-public-commit] rt-extension-rest2 01/02: Support custom roles by name on ticket create

Jim Brandt jbrandt at bestpractical.com
Fri Aug 6 15:10:44 UTC 2021


This is an automated email from the git hooks/post-receive script.

jbrandt pushed a commit to branch custom-roles-on-create
in repository rt-extension-rest2.

commit 0d55b7bb8e143f09f16c0333ea68b40f1e3bf232
Author: Jim Brandt <jbrandt at bestpractical.com>
AuthorDate: Fri Aug 6 11:04:04 2021 -0400

    Support custom roles by name on ticket create
    
    We previously supported custom roles on ticket create using
    syntax like RT::CustomRole-2. Add support for setting custom roles
    by name, using the same syntax as update. Using the name visible
    in the web UI is much easier for users.
---
 lib/RT/Extension/REST2.pm                          | 3 ++-
 lib/RT/Extension/REST2/Resource/Record/Writable.pm | 9 ++++++++-
 lib/RT/Extension/REST2/Util.pm                     | 1 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/RT/Extension/REST2.pm b/lib/RT/Extension/REST2.pm
index b60494c..025a46e 100644
--- a/lib/RT/Extension/REST2.pm
+++ b/lib/RT/Extension/REST2.pm
@@ -511,10 +511,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/Extension/REST2/Resource/Record/Writable.pm b/lib/RT/Extension/REST2/Resource/Record/Writable.pm
index d8e7068..81c3552 100644
--- a/lib/RT/Extension/REST2/Resource/Record/Writable.pm
+++ b/lib/RT/Extension/REST2/Resource/Record/Writable.pm
@@ -5,7 +5,7 @@ use warnings;
 use Moose::Role;
 use namespace::autoclean;
 use JSON ();
-use RT::Extension::REST2::Util qw( deserialize_record error_as_json expand_uid update_custom_fields update_role_members);
+use RT::Extension::REST2::Util qw( deserialize_record error_as_json expand_uid update_custom_fields update_role_members fix_custom_role_ids );
 use List::MoreUtils 'uniq';
 
 with 'RT::Extension::REST2::Resource::Role::RequestBodyIsJSON'
@@ -260,6 +260,13 @@ sub create_record {
         update_custom_fields($record, $cfs);
     }
 
+    if ($ok && $args{CustomRoles}) {
+        # update_role_members wants custom role IDs (like RT::CustomRole-ID)
+        # rather than role names.
+        %args = ( %args, %{ fix_custom_role_ids( $record, $args{CustomRoles} ) } ) if $args{CustomRoles};
+        update_role_members($record, \%args);
+    }
+
     return ($ok, @rest);
 }
 
diff --git a/lib/RT/Extension/REST2/Util.pm b/lib/RT/Extension/REST2/Util.pm
index 429901a..4b6d1d3 100644
--- a/lib/RT/Extension/REST2/Util.pm
+++ b/lib/RT/Extension/REST2/Util.pm
@@ -176,6 +176,7 @@ sub deserialize_record {
     # Sanitize input for the Perl API
     for my $field (sort keys %$data) {
         next if $field eq 'CustomFields';
+        next if $field eq 'CustomRoles';
 
         my $value = $data->{$field};
         next unless ref $value;

-- 
To stop receiving notification emails like this one, please contact
sysadmin at bestpractical.com.


More information about the Bps-public-commit mailing list