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

BPS Git Server git at git.bestpractical.com
Fri Dec 22 18:27:18 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  6b3c85c32ab461b12078f0988cdea8292011f22e (commit)

- Log -----------------------------------------------------------------
commit 6b3c85c32ab461b12078f0988cdea8292011f22e
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
    
    Also update minimal version of RT to 5.0.4 since it's required for
    one of the new code blocks.

diff --git a/Makefile.PL b/Makefile.PL
index 8bd1a56..370e8e9 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -31,5 +31,8 @@ no_index package => 'RT::Extension::CommandByMail::Test';
 
 author_tests('xt');
 
+requires_rt '5.0.4';
+rt_too_new '6.2.0';
+
 sign;
 WriteAll();
diff --git a/lib/RT/Extension/CommandByMail.pm b/lib/RT/Extension/CommandByMail.pm
index 88111f5..7dbac68 100644
--- a/lib/RT/Extension/CommandByMail.pm
+++ b/lib/RT/Extension/CommandByMail.pm
@@ -420,6 +420,12 @@ 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' );
+
     # If we're updating.
     if ( $args{'Ticket'}->id ) {
         $ticket_as_user->Load( $args{'Ticket'}->id );
@@ -620,6 +626,59 @@ sub ProcessCommands {
             }
         }
 
+        $custom_roles->LimitToObjectId( $queue->id );
+        while ( my $custom_role = $custom_roles->Next ) {
+            my %tmp = _ParseAdditiveCommand( \%cmds, 0, "CustomRole{". $custom_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' ] )
+            _ReplaceUserAndGroupById( \%tmp );
+
+            my $role_group = $ticket_as_user->RoleGroup($custom_role->GroupType);
+            my $custom_role_members = $role_group->MembersObj( Recursively => 0 );
+
+            my @res;
+            while ( my $member = $custom_role_members->Next ) {
+                push @res, $member->MemberId;
+            }
+
+            $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  => $custom_role->GroupType,
+                    PrincipalId => $text,
+                );
+                push @{ $results{ 'Del'. "CustomRole{". $custom_role->Name ."}" } }, {
+                    value   => $text,
+                    result  => $val,
+                    message => $msg
+                };
+            }
+            foreach my $text ( @$add ) {
+                my ( $val, $msg ) = $ticket_as_user->AddWatcher(
+                    Type  => $custom_role->GroupType,
+                    $text =~ /\D/ ? (Email => $text) : (PrincipalId => $text),
+                );
+                push @{ $results{ 'Add'. "CustomRole{". $custom_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 +740,14 @@ sub ProcessCommands {
             $create_args{ 'CustomField-' . $cf->id } = [ _CompileAdditiveForCreate(%tmp) ];
         }
 
+        # Canonicalize custom roles
+        $custom_roles->LimitToObjectId( $queue->id );
+        while ( my $custom_role = $custom_roles->Next ) {
+            my %tmp = _ParseAdditiveCommand( \%cmds, 0, "CustomRole{". $custom_role->Name ."}" );
+            next unless keys %tmp;
+            $create_args{ $custom_role->GroupType } = [ _CompileAdditiveForCreate(%tmp) ];
+        }
+
         # Canonicalize watchers
         # First of all fetch default values
         foreach my $type ( @WATCHER_ATTRIBUTES ) {
@@ -771,6 +838,48 @@ sub ProcessCommands {
              Transaction => $transaction };
 }
 
+sub _ReplaceUserAndGroupById {
+    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");
+                    next;
+                }
+            }
+            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;
+            } else {
+                next unless $value =~ /\@/;
+                RT->Logger->warning("User '$value' not found");
+            }
+            # If no user or group found, keep the original value in case
+            # it contains an email address
+            push @new_values, $value;
+        }
+        $cmds->{$key} = \@new_values;
+    }
+}
+
 sub _ParseAdditiveCommand {
     my ($cmds, $plural_forms, $base) = @_;
     my (%res);
@@ -871,6 +980,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 +991,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