From 99c8ee286a0bc22fad8b029fa643378747145ece Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Wed, 1 Jul 2009 11:32:28 +0000 Subject: Bug 490333: Implement a method to get all attachment information from a given bug (Bug.attachments) Patch by Tiago Mello r=mkanat, a=mkanat --- Bugzilla/WebService/Bug.pm | 142 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 9835a315f..483b11ca7 100755 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -426,6 +426,24 @@ sub update_see_also { return { changes => \%changes }; } +sub attachments { + my ($self, $params) = validate(@_, 'bug_ids'); + + my $ids = $params->{bug_ids}; + defined $ids || ThrowCodeError('param_required', { param => 'bug_ids' }); + + my %attachments; + foreach my $bug_id (@$ids) { + my $bug = Bugzilla::Bug->check($bug_id); + $attachments{$bug->id} = []; + foreach my $attach (@{$bug->attachments}) { + push @{$attachments{$bug->id}}, + $self->_attachment_to_hash($attach, $params); + } + } + return { bugs => \%attachments }; +} + ############################## # Private Helper Subroutines # ############################## @@ -477,6 +495,30 @@ sub _bug_to_hash { return \%item; } +sub _attachment_to_hash { + my ($self, $attach, $filters) = @_; + + # Skipping attachment flags for now. + delete $attach->{flags}; + + my $attacher = new Bugzilla::User($attach->attacher->id); + + return filter $filters, { + creation_time => $self->type('dateTime', $attach->attached), + last_change_time => $self->type('dateTime', $attach->modification_time), + id => $self->type('int', $attach->id), + bug_id => $self->type('int', $attach->bug->id), + file_name => $self->type('string', $attach->filename), + description => $self->type('string', $attach->description), + content_type => $self->type('string', $attach->contenttype), + is_private => $self->type('int', $attach->isprivate), + is_obsolete => $self->type('int', $attach->isobsolete), + is_url => $self->type('int', $attach->isurl), + is_patch => $self->type('int', $attach->ispatch), + attacher => $self->type('string', $attacher->login) + }; +} + # Convert WebService API field names to internal DB field names. # Used by create() and search(). sub _map_fields { @@ -570,6 +612,106 @@ You specified a field that doesn't exist or isn't a drop-down field. =over +=item C + +B + +=over + +=item B + +Gets information about all attachments from a bug. + +B: Private attachments will only be returned if you are in the +insidergroup or if you are the submitter of the attachment. + +=item B + +=over + +=item C + +See the description of the C parameter in the L method. + +=back + +=item B + +A hash containing a single element, C. This is a hash of hashes. +Each hash has the numeric bug id as a key, and contains the following +items: + +=over + +=item C + +C The time the attachment was created. + +=item C + +C The last time the attachment was modified. + +=item C + +C The numeric id of the attachment. + +=item C + +C The numeric id of the bug that the attachment is attached to. + +=item C + +C The file name of the attachment. + +=item C + +C The description for the attachment. + +=item C + +C The MIME type of the attachment. + +=item C + +C True if the attachment is private (only visible to a certain +group called the "insidergroup"), False otherwise. + +=item C + +C True if the attachment is obsolete, False otherwise. + +=item C + +C True if the attachment is a URL instead of actual data, +False otherwise. Note that such attachments only happen when the +Bugzilla installation has at some point had the C +parameter enabled. + +=item C + +C True if the attachment is a patch, False otherwise. + +=item C + +C The login name of the user that created the attachment. + +=back + +=item B + +This method can throw all the same errors as L. + +=item B + +=over + +=item Added in Bugzilla B<3.6>. + +=back + +=back + + =item C B -- cgit v1.2.3-24-g4f1b