summaryrefslogtreecommitdiffstats
path: root/Bugzilla/WebService
diff options
context:
space:
mode:
authorTiago Mello <timello@gmail.com>2012-04-14 19:07:36 +0200
committerTiago Mello <timello@gmail.com>2012-04-14 19:07:36 +0200
commit66b328c867fbc04b8f01650b7264d6837404610c (patch)
treeb242b329933059455f118afc5788e04d7931bdae /Bugzilla/WebService
parent778ea7db809b441b3efede0b135bae8fa128bcc7 (diff)
downloadbugzilla-66b328c867fbc04b8f01650b7264d6837404610c.tar.gz
bugzilla-66b328c867fbc04b8f01650b7264d6837404610c.tar.xz
Bug 616336: Add a Bug.update_tags WebService method to edit personal tags
r/a=LpSolit
Diffstat (limited to 'Bugzilla/WebService')
-rw-r--r--Bugzilla/WebService/Bug.pm102
1 files changed, 101 insertions, 1 deletions
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<UNSTABLE>
+
+=item B<Description>
+
+Adds or removes tags on bugs.
+
+=item B<Params>
+
+=over
+
+=item C<ids>
+
+B<Required> C<array> 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<tags>
+
+B<Required> C<hash> A hash representing tags to be added and/or removed.
+The hash has the following fields:
+
+=over
+
+=item C<add> An array of C<string>s 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<remove> An array of C<string>s 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<Returns>
+
+C<changes>, a hash containing bug IDs as keys and one single value
+name "tags" which is also a hash, with C<added> and C<removed> as keys.
+See L</update_see_also> for an example of how it looks like.
+
+=item B<Errors>
+
+This method can throw the same errors as L</get>.
+
+=back
+
+=item B<History>
+
+=over
+
+=item Added in Bugzilla B<4.4>.
+
+=back
+
+=back