diff options
author | Dave Lawrence <dlawrence@mozilla.com> | 2013-12-11 21:29:11 +0100 |
---|---|---|
committer | Dave Lawrence <dlawrence@mozilla.com> | 2013-12-11 21:29:11 +0100 |
commit | be917fc275079930abed04507159fb0cc719012c (patch) | |
tree | 753c988491ac0b802c543cc2c9eed7ec7180fbab | |
parent | 1221394e0533b3145c97a5d13c4463fb53f1dd9e (diff) | |
download | bugzilla-be917fc275079930abed04507159fb0cc719012c.tar.gz bugzilla-be917fc275079930abed04507159fb0cc719012c.tar.xz |
Bug 946353 - Attachments should include can_edit field
-rw-r--r-- | extensions/Ember/lib/WebService.pm | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/extensions/Ember/lib/WebService.pm b/extensions/Ember/lib/WebService.pm index 94990c881..9e07603b9 100644 --- a/extensions/Ember/lib/WebService.pm +++ b/extensions/Ember/lib/WebService.pm @@ -156,10 +156,8 @@ sub show { AND bug_id = ?', undef, ($last_updated, $last_updated, $bug->id)); if ($updated_attachments) { - $attachments = $self->attachments({ attachment_ids => $updated_attachments, - exclude_fields => ['data'] }); - $attachments = [ map { $attachments->{attachments}->{$_} } - keys %{ $attachments->{attachments} } ]; + $attachments = $self->_get_attachments({ attachment_ids => $updated_attachments, + exclude_fields => ['data'] }); } if (@$updated_fields || @$comments || @$updated_attachments) { @@ -174,10 +172,8 @@ sub show { @fields = $self->_get_fields($bug); $comments = $self->comments({ ids => $bug_id }); $comments = $comments->{bugs}->{$bug_id}->{comments}; - $attachments = $self->attachments({ ids => $bug_id, - exclude_fields => ['data'] }); - $attachments = $attachments->{bugs}->{$bug_id} || undef; - + $attachments = $self->_get_attachments({ ids => $bug_id, + exclude_fields => ['data'] }); } # Place the fields current value along with the field definition @@ -260,6 +256,29 @@ sub search { # Private Methods # ################### +sub _get_attachments { + my ($self, $params) = @_; + my $user = Bugzilla->user; + + my $attachments = $self->attachments($params); + + if ($params->{ids}) { + $attachments = [ map { @{ $attachments->{bugs}->{$_} } } + keys %{ $attachments->{bugs} } ]; + } + elsif ($params->{attachment_ids}) { + $attachments = [ map { $attachments->{attachments}->{$_} } + keys %{ $attachments->{attachments} } ]; + } + + foreach my $attachment (@$attachments) { + $attachment->{can_edit} + = ($user->login eq $attachment->{creator} || $user->in_group('editbugs')) ? 1 : 0; + } + + return $attachments; +} + sub _get_fields { my ($self, $bug, $field_ids) = @_; my $user = Bugzilla->user; |