summaryrefslogtreecommitdiffstats
path: root/extensions/Ember
diff options
context:
space:
mode:
authorDave Lawrence <dlawrence@mozilla.com>2013-12-13 22:55:44 +0100
committerDave Lawrence <dlawrence@mozilla.com>2013-12-13 22:55:44 +0100
commit96814084690b9da9aaaf4b32a2091ddb51c4f7a0 (patch)
tree83019d02c0f76df553a08d843436fd9e2547963f /extensions/Ember
parent434a707542b27225fc957f21b2fa7b2177929a6c (diff)
downloadbugzilla-96814084690b9da9aaaf4b32a2091ddb51c4f7a0.tar.gz
bugzilla-96814084690b9da9aaaf4b32a2091ddb51c4f7a0.tar.xz
Bug 946457 - Add Ember.attachments API that includes possible flag values
Diffstat (limited to 'extensions/Ember')
-rw-r--r--extensions/Ember/lib/WebService.pm71
1 files changed, 61 insertions, 10 deletions
diff --git a/extensions/Ember/lib/WebService.pm b/extensions/Ember/lib/WebService.pm
index 9e07603b9..585079ac5 100644
--- a/extensions/Ember/lib/WebService.pm
+++ b/extensions/Ember/lib/WebService.pm
@@ -252,6 +252,28 @@ sub search {
return $result;
}
+sub get_attachments {
+ my ($self, $params) = @_;
+ my $attachments = $self->_get_attachments($params);
+ my $flag_types = [];
+ my $bug;
+ if ($params->{ids}) {
+ $bug = Bugzilla::Bug->check($params->{ids}->[0]);
+ $flag_types = $self->_get_flag_types_bug($bug, 'attachment');
+ }
+ elsif ($params->{attachment_ids} && @$attachments) {
+ $bug = Bugzilla::Bug->check($attachments->[0]->{bug_id});
+ $flag_types = $self->_get_flag_types_all($bug, 'attachment')->{attachment};
+ }
+ if (@$flag_types) {
+ @$flag_types = map { $self->_flagtype_to_hash($_, $bug) } @$flag_types;
+ }
+ return {
+ attachments => $attachments,
+ flag_types => $flag_types
+ };
+}
+
###################
# Private Methods #
###################
@@ -352,19 +374,11 @@ sub _get_fields {
my $flag_hash;
if ($bug->id) {
foreach my $flag_type ('bug', 'attachment') {
- my $flag_params = {
- target_type => $flag_type,
- product_id => $bug->product_obj->id,
- component_id => $bug->component_obj->id,
- bug_id => $bug->id,
- active_or_has_flags => $bug->id,
- };
- $flag_hash->{$flag_type} = Bugzilla::Flag->_flag_types($flag_params);
+ $flag_hash->{$flag_type} = $self->_get_flag_types_bug($bug, $flag_type);
}
}
else {
- my $flag_params = { is_active => 1 };
- $flag_hash = $bug->product_obj->flag_types($flag_params);
+ $flag_hash = $self->_get_flag_types_all($bug);
}
my @flag_values;
foreach my $flag_type ('bug', 'attachment') {
@@ -385,6 +399,25 @@ sub _get_fields {
return @fields;
}
+sub _get_flag_types_all {
+ my ($self, $bug, $type) = @_;
+ my $params = { is_active => 1 };
+ $params->{target_type} = $type if $type;
+ return $bug->product_obj->flag_types($params);
+}
+
+sub _get_flag_types_bug {
+ my ($self, $bug, $type) = @_;
+ my $params = {
+ target_type => $type,
+ product_id => $bug->product_obj->id,
+ component_id => $bug->component_obj->id,
+ bug_id => $bug->id,
+ active_or_has_flags => $bug->id,
+ };
+ return Bugzilla::Flag->_flag_types($params);
+}
+
sub _group_to_hash {
my ($self, $group, $bug) = @_;
@@ -666,6 +699,24 @@ sub rest_resources {
method => 'search',
},
},
+ # attachments - wrapper around SUPER::attachments that also includes
+ # can_edit attribute
+ qr{^/ember/bug/(\d+)/attachments$}, {
+ GET => {
+ method => 'get_attachments',
+ params => sub {
+ return { ids => $_[0] };
+ }
+ }
+ },
+ qr{^/ember/bug/attachments/(\d+)$}, {
+ GET => {
+ method => 'get_attachments',
+ params => sub {
+ return { attachment_ids => $_[0] };
+ }
+ }
+ }
];
};