[Bps-public-commit] RT-Extension-CommandByMail branch add-custom-role-command created. 3.01-3-ga459786

BPS Git Server git at git.bestpractical.com
Fri Dec 22 13:15:55 UTC 2023


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-CommandByMail".

The branch, add-custom-role-command has been created
        at  a459786ec92e2f0ead3f7133d05954ab8f73061e (commit)

- Log -----------------------------------------------------------------
commit a459786ec92e2f0ead3f7133d05954ab8f73061e
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Thu Dec 21 15:27:28 2023 -0300

    Update POD with Custom Role support

diff --git a/README b/README
index 9d178f3..9699680 100644
--- a/README
+++ b/README
@@ -169,6 +169,20 @@ DESCRIPTION
         AddAdminCc: <address> Add new AdminCc watcher using the email address
         DelAdminCc: <address> Remove email address as AdminCc watcher
 
+   Custom Roles
+    Manage custom roles of the ticket. This commands can be used several
+    times and/or with Add and Del prefixes. If you have a Custom Role called
+    Customer for example, you can pass the command CustomRole.{Customer} to
+    set the members of that role. You can pass either a username or an email
+    address. For groups, you must prefix the group name with group:. For
+    example, CustomRole.{Customer}: group:MyGroupname.
+
+            CustomRole.{Customer}: set the members of the Customer Custom Role
+            AddCustomRole.{Customer}: add members to the Customer Custom Role
+            DelCustomRole.{Customer}: remove members from the Customer Custom Role
+
+    Replace Customer with the name of your Custom Role.
+
    Links
     Manage links. These commands are also could be used several times in one
     message.
diff --git a/lib/RT/Extension/CommandByMail.pm b/lib/RT/Extension/CommandByMail.pm
index 9051d13..42b63df 100644
--- a/lib/RT/Extension/CommandByMail.pm
+++ b/lib/RT/Extension/CommandByMail.pm
@@ -219,6 +219,22 @@ to the current list.
     AddAdminCc: <address> Add new AdminCc watcher using the email address
     DelAdminCc: <address> Remove email address as AdminCc watcher
 
+=head3 Custom Roles
+
+Manage custom roles of the ticket.
+This commands can be used several times and/or with C<Add> and C<Del>
+prefixes. If you have a Custom Role called C<Customer> for example, you can
+pass the command C<CustomRole.{Customer}> to set the members of that role.
+You can pass either a username or an email address.
+For groups, you must prefix the group name with C<group:>. For example,
+C<CustomRole.{Customer}: group:MyGroupname>.
+
+        CustomRole.{Customer}: set the members of the Customer Custom Role
+        AddCustomRole.{Customer}: add members to the Customer Custom Role
+        DelCustomRole.{Customer}: remove members from the Customer Custom Role
+
+Replace C<Customer> with the name of your Custom Role.
+
 =head3 Links
 
 Manage links. These commands are also could be used several times in one

commit c598517602f3450da01115e030138c378b7faaac
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Fri Dec 22 10:15:12 2023 -0300

    Add Custom Role update support
    
    Add new commands that allows do update ticket custom roles:
    - CustomRole
    - AddCustomRole
    - DelCustomRole

diff --git a/lib/RT/Extension/CommandByMail.pm b/lib/RT/Extension/CommandByMail.pm
index 88111f5..9051d13 100644
--- a/lib/RT/Extension/CommandByMail.pm
+++ b/lib/RT/Extension/CommandByMail.pm
@@ -420,6 +420,14 @@ sub ProcessCommands {
 
     my $transaction;
 
+    # Prepare Custom Roles. We will restrict also later to the ticket
+    # queue or to the creation queue according to the operation we are
+    # doing (create / update)
+    my $custom_roles = RT::CustomRoles->new( $args{'CurrentUser'} );
+    $custom_roles->LimitToLookupType( 'RT::Queue-RT::Ticket' );
+    # Global applied custom roles
+    $custom_roles->LimitToObjectId( 0 );
+
     # If we're updating.
     if ( $args{'Ticket'}->id ) {
         $ticket_as_user->Load( $args{'Ticket'}->id );
@@ -620,6 +628,70 @@ sub ProcessCommands {
             }
         }
 
+        $custom_roles->LimitToObjectId( $queue->id );
+        while ( my $role = $custom_roles->Next ) {
+            my %tmp = _ParseAdditiveCommand( \%cmds, 0, "CustomRole{". $role->Name ."}" );
+            next unless keys %tmp;
+
+            # Convert values to ID so we can better compare with the existing
+            # values when we are updating
+            # %tmp can be originally something like
+            #   ( 'Add' => [ 'user1 at example.com', 'group:group1', 'nonexistantuser at example.com' ] )
+            # after _ParseAdditiveCommand, found objects will be converted to
+            # PrincipalId's, so it will be turned into something like the following:
+            #   ( 'Add' => [ 1, 2, 'nonexistantuser at example' ] )
+            _replace_user_and_group_by_id( \%tmp );
+
+            my $custom_role = RT::CustomRole->new( $args{'CurrentUser'} );
+            my ($ret, $msg) = $custom_role->LoadByCols(Name => $role->Name);
+            RT::Logger->error("Could not load Custom Role: $msg") unless $ret;
+            next unless $ret;
+            my $role_group = $ticket_as_user->RoleGroup($custom_role->GroupType);
+            my $custom_role_group_members = $role_group->GroupMembersObj( Recursively => 0 );
+            my $custom_role_user_members = $role_group->UserMembersObj( Recursively => 0 );
+
+            my @res;
+            while ( my $member = $custom_role_group_members->Next ) {
+                push @res, $member->PrincipalId;
+            }
+            while ( my $member = $custom_role_user_members->Next ) {
+                push @res, $member->PrincipalId;
+            }
+
+            $tmp{'Default'} = [ @res ];
+            my ($add, $del) = _CompileAdditiveForUpdate( %tmp );
+
+            foreach my $text ( @$del ) {
+                # if we are removing a watcher, it is already has a user
+                # in the system, so emails will not be useful here
+                next if $text =~ /\@/;
+                my ( $val, $msg ) = $ticket_as_user->DeleteWatcher(
+                    Type  => $role->GroupType,
+                    PrincipalId => $text,
+                );
+                push @{ $results{ 'Del'. "CustomRole{". $role->Name ."}" } }, {
+                    value   => $text,
+                    result  => $val,
+                    message => $msg
+                };
+            }
+            foreach my $text ( @$add ) {
+                my ( $val, $msg ) = $ticket_as_user->AddWatcher(
+                    Type  => $role->GroupType,
+                    $text =~ /\@/
+                        ? (Email => $text)
+                        : (PrincipalId => $text)
+                    ,
+                );
+                push @{ $results{ 'Add'. "CustomRole{". $role->Name ."}" } }, {
+                    value   => $text,
+                    result  => $val,
+                    message => $msg
+                };
+
+            }
+        }
+
         foreach my $attribute (grep $_ eq 'Status', @REGULAR_ATTRIBUTES) {
             next unless defined $cmds{ lc $attribute };
             next if $ticket_as_user->$attribute() eq $cmds{ lc $attribute };
@@ -681,6 +753,14 @@ sub ProcessCommands {
             $create_args{ 'CustomField-' . $cf->id } = [ _CompileAdditiveForCreate(%tmp) ];
         }
 
+        # Canonicalize custom roles
+        $custom_roles->LimitToObjectId( $queue->id );
+        while ( my $role = $custom_roles->Next ) {
+            my %tmp = _ParseAdditiveCommand( \%cmds, 0, "CustomRole{". $role->Name ."}" );
+            next unless keys %tmp;
+            $create_args{ $role->GroupType } = [ _CompileAdditiveForCreate(%tmp) ];
+        }
+
         # Canonicalize watchers
         # First of all fetch default values
         foreach my $type ( @WATCHER_ATTRIBUTES ) {
@@ -771,6 +851,43 @@ sub ProcessCommands {
              Transaction => $transaction };
 }
 
+sub _replace_user_and_group_by_id {
+    my $cmds = shift;
+
+    foreach my $key (keys %$cmds) {
+        my @values = @{ $cmds->{$key} };
+        next unless @values;
+
+        my @new_values;
+        # Check each value and see if it can be a user or a group
+        foreach my $value (@values) {
+            if ($value =~ /^group\:(.*)/) {
+                my $group_name = $1;
+                $group_name =~ s/^\s+|\s+$//g;
+
+                my $group = RT::Group->new(RT->SystemUser);
+                $group->LoadUserDefinedGroup($group_name);
+                if ($group->id) {
+                    push @new_values, $group->id;
+                    next;
+                } else {
+                    RT->Logger->error("Group '$1' not found");
+                }
+            }
+            my $user = RT::User->new(RT->SystemUser);
+            $user->LoadByEmail($value) if $value =~ /\@/;
+            $user->Load($value) unless $user->id;
+            if ($user->id) {
+                push @new_values, $user->id;
+                next;
+            }
+            # If no user or group found, keep the original value
+            push @new_values, $value;
+        }
+        $cmds->{$key} = \@new_values;
+    }
+}
+
 sub _ParseAdditiveCommand {
     my ($cmds, $plural_forms, $base) = @_;
     my (%res);
@@ -871,6 +988,10 @@ sub _CanonicalizeCommand {
     # CustomField commands
     $key =~ s/^(add|del|)c(?:ustom)?-?f(?:ield)?\.?[({\[](.*)[)}\]]$/$1customfield{$2}/i;
     $key =~ s/^(?:transaction|txn)c(?:ustom)?-?f(?:ield)?\.?[({\[](.*)[)}\]]$/transactioncustomfield{$1}/i;
+
+    # CustomRole commands
+    $key =~ s/^(add|del|)c(?:ustom)?-?R(?:ole)?\.?[({\[](.*)[)}\]]$/$1customrole{$2}/i;
+
     return $key;
 }
 
@@ -878,6 +999,7 @@ sub _CheckCommand {
     my ($cmd, $val) = (lc shift, shift);
     return 1 if $cmd =~ /^(add|del|)customfield\{.*\}$/i;
     return 1 if $cmd =~ /^transactioncustomfield\{.*\}$/i;
+    return 1 if $cmd =~ /^(add|del|)customrole\{.*\}$/i;
     if ( grep $cmd eq lc $_, @REGULAR_ATTRIBUTES, @TIME_ATTRIBUTES, @DATE_ATTRIBUTES ) {
         return 1 unless ref $val;
         return (0, "Command '$cmd' doesn't support multiple values");

commit e9a90c41f8d4142ea4abdc0700c381aad9d64b4f
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Thu Dec 21 15:13:04 2023 -0300

    Update Module::Install

diff --git a/META.yml b/META.yml
index db25655..e97b2dd 100644
--- a/META.yml
+++ b/META.yml
@@ -10,7 +10,7 @@ configure_requires:
   ExtUtils::MakeMaker: 6.59
 distribution_type: module
 dynamic_config: 1
-generated_by: 'Module::Install version 1.19'
+generated_by: 'Module::Install version 1.21'
 license: gpl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -30,5 +30,5 @@ resources:
   license: http://opensource.org/licenses/gpl-license.php
   repository: https://github.com/bestpractical/rt-extension-commandbymail
 version: '3.01'
-x_module_install_rtx_version: '0.42'
+x_module_install_rtx_version: '0.43'
 x_requires_rt: 4.0.0
diff --git a/inc/Module/AutoInstall.pm b/inc/Module/AutoInstall.pm
index 8852e0b..b977d4d 100644
--- a/inc/Module/AutoInstall.pm
+++ b/inc/Module/AutoInstall.pm
@@ -8,7 +8,7 @@ use ExtUtils::MakeMaker ();
 
 use vars qw{$VERSION};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 }
 
 # special map on pre-defined feature sets
diff --git a/inc/Module/Install.pm b/inc/Module/Install.pm
index 7ba98c2..3dd721b 100644
--- a/inc/Module/Install.pm
+++ b/inc/Module/Install.pm
@@ -31,7 +31,7 @@ BEGIN {
 	# This is not enforced yet, but will be some time in the next few
 	# releases once we can make sure it won't clash with custom
 	# Module::Install extensions.
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 
 	# Storage for the pseudo-singleton
 	$MAIN    = undef;
diff --git a/inc/Module/Install/AutoInstall.pm b/inc/Module/Install/AutoInstall.pm
index 0e3dada..b771ef6 100644
--- a/inc/Module/Install/AutoInstall.pm
+++ b/inc/Module/Install/AutoInstall.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Base.pm b/inc/Module/Install/Base.pm
index 9fa42c2..67ce900 100644
--- a/inc/Module/Install/Base.pm
+++ b/inc/Module/Install/Base.pm
@@ -4,7 +4,7 @@ package Module::Install::Base;
 use strict 'vars';
 use vars qw{$VERSION};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 }
 
 # Suspend handler for "redefined" warnings
diff --git a/inc/Module/Install/Can.pm b/inc/Module/Install/Can.pm
index d65c753..93fc4f9 100644
--- a/inc/Module/Install/Can.pm
+++ b/inc/Module/Install/Can.pm
@@ -8,7 +8,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Fetch.pm b/inc/Module/Install/Fetch.pm
index 3072b08..3c9390a 100644
--- a/inc/Module/Install/Fetch.pm
+++ b/inc/Module/Install/Fetch.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Include.pm b/inc/Module/Install/Include.pm
index 13fdcd0..b9b926f 100644
--- a/inc/Module/Install/Include.pm
+++ b/inc/Module/Install/Include.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Makefile.pm b/inc/Module/Install/Makefile.pm
index 13a4464..1e214a0 100644
--- a/inc/Module/Install/Makefile.pm
+++ b/inc/Module/Install/Makefile.pm
@@ -8,7 +8,7 @@ use Fcntl qw/:flock :seek/;
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/Metadata.pm b/inc/Module/Install/Metadata.pm
index 11bf971..2ae8036 100644
--- a/inc/Module/Install/Metadata.pm
+++ b/inc/Module/Install/Metadata.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
@@ -455,12 +455,8 @@ sub author_from {
 my %license_urls = (
     perl         => 'http://dev.perl.org/licenses/',
     apache       => 'http://apache.org/licenses/LICENSE-2.0',
-    apache_1_1   => 'http://apache.org/licenses/LICENSE-1.1',
     artistic     => 'http://opensource.org/licenses/artistic-license.php',
-    artistic_2   => 'http://opensource.org/licenses/artistic-license-2.0.php',
     lgpl         => 'http://opensource.org/licenses/lgpl-license.php',
-    lgpl2        => 'http://opensource.org/licenses/lgpl-2.1.php',
-    lgpl3        => 'http://opensource.org/licenses/lgpl-3.0.html',
     bsd          => 'http://opensource.org/licenses/bsd-license.php',
     gpl          => 'http://opensource.org/licenses/gpl-license.php',
     gpl2         => 'http://opensource.org/licenses/gpl-2.0.php',
@@ -471,6 +467,12 @@ my %license_urls = (
     unrestricted => undef,
     restrictive  => undef,
     unknown      => undef,
+
+    # these are not actually allowed in meta-spec v1.4 but are left here for compatibility:
+    apache_1_1   => 'http://apache.org/licenses/LICENSE-1.1',
+    artistic_2   => 'http://opensource.org/licenses/artistic-license-2.0.php',
+    lgpl2        => 'http://opensource.org/licenses/lgpl-2.1.php',
+    lgpl3        => 'http://opensource.org/licenses/lgpl-3.0.html',
 );
 
 sub license {
diff --git a/inc/Module/Install/RTx.pm b/inc/Module/Install/RTx.pm
index 2dd9489..2889ece 100644
--- a/inc/Module/Install/RTx.pm
+++ b/inc/Module/Install/RTx.pm
@@ -9,7 +9,7 @@ no warnings 'once';
 use Term::ANSIColor qw(:constants);
 use Module::Install::Base;
 use base 'Module::Install::Base';
-our $VERSION = '0.42';
+our $VERSION = '0.43';
 
 use FindBin;
 use File::Glob     ();
@@ -134,7 +134,7 @@ lexicons ::
     if( $extra_args->{'remove_files'} ){
         $self->include('Module::Install::RTx::Remove');
         our @remove_files;
-        eval { require "etc/upgrade/remove_files" }
+        eval { require "./etc/upgrade/remove_files" }
           or print "No remove file located, no files to remove\n";
         $remove_files = join ",", map {"q(\$(DESTDIR)$plugin_path/$name/$_)"} @remove_files;
     }
diff --git a/inc/Module/Install/Win32.pm b/inc/Module/Install/Win32.pm
index f7aa615..b6c1d37 100644
--- a/inc/Module/Install/Win32.pm
+++ b/inc/Module/Install/Win32.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 	@ISA     = 'Module::Install::Base';
 	$ISCORE  = 1;
 }
diff --git a/inc/Module/Install/WriteAll.pm b/inc/Module/Install/WriteAll.pm
index 2db861a..d87eb9a 100644
--- a/inc/Module/Install/WriteAll.pm
+++ b/inc/Module/Install/WriteAll.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '1.19';
+	$VERSION = '1.21';
 	@ISA     = qw{Module::Install::Base};
 	$ISCORE  = 1;
 }
diff --git a/inc/YAML/Tiny.pm b/inc/YAML/Tiny.pm
index fb157a6..db3ae5c 100644
--- a/inc/YAML/Tiny.pm
+++ b/inc/YAML/Tiny.pm
@@ -2,12 +2,12 @@
 use 5.008001; # sane UTF-8 support
 use strict;
 use warnings;
-package YAML::Tiny; # git description: v1.72-7-g8682f63
+package YAML::Tiny; # git description: v1.73-12-ge02f827
 # XXX-INGY is 5.8.1 too old/broken for utf8?
 # XXX-XDG Lancaster consensus was that it was sufficient until
 # proven otherwise
 
-our $VERSION = '1.73';
+our $VERSION = '1.74';
 
 #####################################################################
 # The YAML::Tiny API.

-----------------------------------------------------------------------


hooks/post-receive
-- 
RT-Extension-CommandByMail


More information about the Bps-public-commit mailing list