[Rt-commit] rt branch, 4.4/rest-watcher-id, created. rt-4.4.1-1-ge4ca6e1

Shawn Moore shawn at bestpractical.com
Thu May 25 14:12:08 EDT 2017


The branch, 4.4/rest-watcher-id has been created
        at  e4ca6e12a8296f07a7052bfc6492269152b05ac0 (commit)

- Log -----------------------------------------------------------------
commit e4ca6e12a8296f07a7052bfc6492269152b05ac0
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu May 4 18:40:37 2017 +0000

    Support managing groups as watchers in REST
    
    By specifying a numeric ID rather than an email address, you can now
    add/remove a group as a ticket watcher over REST 1.0
    
    Fixes: T#185062

diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index d4dbd9c..2f68555 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -361,20 +361,37 @@ else {
             my ($p, @msgs);
 
             my %new  = map {$_=>1} @{ vsplit($val) };
-            my %old  = map {$_=>1} $ticket->$key->MemberEmailAddresses;
+            my %old;
+
+            my $members = $ticket->$key->MembersObj;
+            while (my $member = $members->Next) {
+                my $principal = $member->MemberObj;
+                if ($principal->IsGroup) {
+                    $old{ $principal->Id } = 1;
+                }
+                else {
+                    $old{ $principal->Object->EmailAddress } = 1;
+                }
+            }
+
             my $type = $key eq 'Requestors' ? 'Requestor' : $key;
 
             foreach $p (keys %old) {
                 unless (exists $new{$p}) {
+                    my $key = "Email";
+                    $key = "PrincipalId" if $p =~ /^\d+$/;
+
                     ($s, $n) = $ticket->DeleteWatcher(Type => $type,
-                                                      Email => $p);
+                                                      $key => $p);
                     push @msgs, [ $s, $n ];
                 }
             }
             foreach $p (keys %new) {
-                unless ($ticket->IsWatcher(Type => $type, Email => $p)) {
+                my $key = "Email";
+                $key = "PrincipalId" if $p =~ /^\d+$/;
+                unless ($ticket->IsWatcher(Type => $type, $key => $p)) {
                     ($s, $n) = $ticket->AddWatcher(Type => $type,
-                                                   Email => $p);
+                                                   $key => $p);
                     push @msgs, [ $s, $n ];
                 }
             }

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


More information about the rt-commit mailing list