[Rt-commit] [rtir] 01/02: Fix "already granted" logic

Kevin Falcone falcone at bestpractical.com
Wed Apr 9 16:18:24 EDT 2014


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

falcone pushed a commit to branch 3.0/add-constituency-cf-rights
in repository rtir.

commit 78edc3a5583457afc9586f8f31ab7a283419ffbb
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed Apr 9 15:39:25 2014 -0400

    Fix "already granted" logic
    
    When the language for this changed in b29757e this stopped working.
    Rather than regexing the error message, just check if the right exists.
---
 etc/add_constituency.in | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/etc/add_constituency.in b/etc/add_constituency.in
index f5787b2..ef86cda 100644
--- a/etc/add_constituency.in
+++ b/etc/add_constituency.in
@@ -248,13 +248,14 @@ sub grant_group_queue_rights {
     foreach my $queue    (values %$queues) {
         debug "Granting rights for queue " .$queue->Name. " to group ". $group->Name;
         foreach my $right  (@rights) {
-            my ($val,$msg) =  $group->PrincipalObj->GrantRight(Right => $right, Object=>$queue);
             debug "\t$right\n";
+            if ( $group->PrincipalObj->HasRight( Right => $right, Object => $queue ) ) {
+                debug "\t...skipped, already granted";
+                next;
+            }
+            my ($val,$msg) =  $group->PrincipalObj->GrantRight(Right => $right, Object=>$queue);
             if ( $val ) {
                 debug "\t...done.";
-            }
-            elsif ( $msg =~ /That principal already has that right/i ) {
-                debug "\t...skipped, already granted.\n";
             } else {
                 die "Failed to grant $right to ". $group->Name ." for Queue ". $queue->Name;
             }
@@ -276,13 +277,14 @@ sub grant_group_cf_rights {
         debug "Granting rights for custom field ". $cf->Name . " to group ". $group->Name;
 
         foreach my $right  (@rights) {
-            my ($val,$msg) =  $group->PrincipalObj->GrantRight(Right => $right, Object=>$cf);
             debug "\t$right";
+            if ( $group->PrincipalObj->HasRight( Right => $right, Object => $cf ) ) {
+                debug "\t...skipped, already granted";
+                next;
+            }
+            my ($val,$msg) =  $group->PrincipalObj->GrantRight(Right => $right, Object=>$cf);
             if ( $val ) {
                 debug "\t...done.";
-            }
-            elsif ( $msg =~ /That principal already has that right/i ) {
-                debug "\t...skipped, already granted.\n";
             } else {
                 die "Failed to grant $right to ".$group->Name. " for Custom Field ". $cf->Name
                     .".\nError: $msg";

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list