From 66b328c867fbc04b8f01650b7264d6837404610c Mon Sep 17 00:00:00 2001 From: Tiago Mello Date: Sat, 14 Apr 2012 14:07:36 -0300 Subject: Bug 616336: Add a Bug.update_tags WebService method to edit personal tags r/a=LpSolit --- Bugzilla/WebService/Bug.pm | 102 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) (limited to 'Bugzilla/WebService/Bug.pm') diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index d163cf1a2..d0dda1466 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -18,7 +18,7 @@ use Bugzilla::WebService::Constants; use Bugzilla::WebService::Util qw(filter filter_wants validate); use Bugzilla::Bug; use Bugzilla::BugMail; -use Bugzilla::Util qw(trick_taint trim); +use Bugzilla::Util qw(trick_taint trim diff_arrays); use Bugzilla::Version; use Bugzilla::Milestone; use Bugzilla::Status; @@ -784,6 +784,44 @@ sub attachments { return { bugs => \%bugs, attachments => \%attachments }; } +sub update_tags { + my ($self, $params) = @_; + + Bugzilla->login(LOGIN_REQUIRED); + + my $ids = $params->{ids}; + my $tags = $params->{tags}; + + ThrowCodeError('param_required', + { function => 'Bug.update_tags', + param => 'ids' }) if !defined $ids; + + ThrowCodeError('param_required', + { function => 'Bug.update_tags', + param => 'tags' }) if !defined $tags; + + my %changes; + foreach my $bug_id (@$ids) { + my $bug = Bugzilla::Bug->check($bug_id); + my @old_tags = @{ $bug->tags }; + + $bug->remove_tag($_) foreach @{ $tags->{remove} || [] }; + $bug->add_tag($_) foreach @{ $tags->{add} || [] }; + + my ($removed, $added) = diff_arrays(\@old_tags, $bug->tags); + + my @removed = map { $self->type('string', $_) } @$removed; + my @added = map { $self->type('string', $_) } @$added; + + $changes{$bug->id}->{tags} = { + removed => \@removed, + added => \@added + }; + } + + return { changes => \%changes }; +} + ############################## # Private Helper Subroutines # ############################## @@ -3267,3 +3305,65 @@ this bug. =back =back + + +=head2 update_tags + +B + +=item B + +Adds or removes tags on bugs. + +=item B + +=over + +=item C + +B C An array of ints and/or strings--the ids +or aliases of bugs that you want to add or remove tags to. All the tags +will be added or removed to all these bugs. + +=item C + +B C A hash representing tags to be added and/or removed. +The hash has the following fields: + +=over + +=item C An array of Cs representing tag names +to be added to the bugs. + +It is safe to specify tags that are already associated with the +bugs--they will just be silently ignored. + +=item C An array of Cs representing tag names +to be removed from the bugs. + +It is safe to specify tags that are not associated with any +bugs--they will just be silently ignored. + +=back + +=item B + +C, a hash containing bug IDs as keys and one single value +name "tags" which is also a hash, with C and C as keys. +See L for an example of how it looks like. + +=item B + +This method can throw the same errors as L. + +=back + +=item B + +=over + +=item Added in Bugzilla B<4.4>. + +=back + +=back -- cgit v1.2.3-24-g4f1b