summaryrefslogtreecommitdiffstats
path: root/extensions/Ember
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2013-09-26 07:48:59 +0200
committerByron Jones <bjones@mozilla.com>2013-09-26 07:48:59 +0200
commitdc20e895c1cbcf6d9d1eea80d99c82447867fc4f (patch)
treedfb0869cfb14c60075efa2864eda4db0e4c32d3a /extensions/Ember
parentac502fcd85596581fbb67f8493c8b32a0baf2124 (diff)
downloadbugzilla-dc20e895c1cbcf6d9d1eea80d99c82447867fc4f.tar.gz
bugzilla-dc20e895c1cbcf6d9d1eea80d99c82447867fc4f.tar.xz
Bug 920242: Ember.show's flags field isn't honouring inclusion/exclusion
Diffstat (limited to 'extensions/Ember')
-rw-r--r--extensions/Ember/lib/WebService.pm60
1 files changed, 53 insertions, 7 deletions
diff --git a/extensions/Ember/lib/WebService.pm b/extensions/Ember/lib/WebService.pm
index 57ce2fe36..e717e7579 100644
--- a/extensions/Ember/lib/WebService.pm
+++ b/extensions/Ember/lib/WebService.pm
@@ -16,6 +16,7 @@ use parent qw(Bugzilla::WebService
Bugzilla::WebService::Product);
use Bugzilla::Bug;
+use Bugzilla::Component;
use Bugzilla::Product;
use Bugzilla::Constants;
use Bugzilla::Error;
@@ -289,11 +290,25 @@ sub _get_fields {
});
# Add flag information as separate field
- my $flag_params = { is_active => 1 };
- $flag_params->{component_id} => $bug->component_obj->id if $bug->id;
- my $flag_hash = $bug->product_obj->flag_types($flag_params);
+ 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);
+ }
+ }
+ else {
+ my $flag_params = { is_active => 1 };
+ $flag_hash = $bug->product_obj->flag_types($flag_params);
+ }
my @flag_values;
- foreach my $flag_type ('bug','attachment') {
+ foreach my $flag_type ('bug', 'attachment') {
foreach my $flag (@{ $flag_hash->{$flag_type} }) {
push(@flag_values, $self->_flagtype_to_hash($flag, $bug));
}
@@ -471,8 +486,8 @@ sub _flag_to_hash {
id => $self->type('int', $flag->id),
name => $self->type('string', $flag->name),
type_id => $self->type('int', $flag->type_id),
- creation_date => $self->type('dateTime', $flag->creation_date),
- modification_date => $self->type('dateTime', $flag->modification_date),
+ creation_date => $self->type('dateTime', $flag->creation_date),
+ modification_date => $self->type('dateTime', $flag->modification_date),
status => $self->type('string', $flag->status)
};
@@ -488,7 +503,7 @@ sub _flag_to_hash {
}
sub _flagtype_to_hash {
- my ($self, $flagtype) = @_;
+ my ($self, $flagtype, $bug) = @_;
my $user = Bugzilla->user;
my $cansetflag = $user->can_set_flag($flagtype);
@@ -512,9 +527,40 @@ sub _flagtype_to_hash {
}
$data->{values} = \@values;
+ # if we're creating a bug, we need to return all valid flags for
+ # this product, as well as inclusions & exclusions so ember can
+ # display relevant flags once the component is selected
+ if (!$bug->id) {
+ my $inclusions = $self->_flagtype_clusions_to_hash($flagtype->inclusions, $bug->product_obj->id);
+ my $exclusions = $self->_flagtype_clusions_to_hash($flagtype->exclusions, $bug->product_obj->id);
+ # if we have both inclusions and exclusions, the exclusions are redundant
+ $exclusions = [] if @$inclusions && @$exclusions;
+ # no need to return anything if there's just "any component"
+ $data->{inclusions} = $inclusions if @$inclusions && $inclusions->[0] ne '';
+ $data->{exclusions} = $exclusions if @$exclusions && $exclusions->[0] ne '';
+ }
+
return $data;
}
+sub _flagtype_clusions_to_hash {
+ my ($self, $clusions, $product_id) = @_;
+ my $result = [];
+ foreach my $key (keys %$clusions) {
+ my ($prod_id, $comp_id) = split(/:/, $clusions->{$key}, 2);
+ if ($prod_id == 0 || $prod_id == $product_id) {
+ if ($comp_id) {
+ my $component = Bugzilla::Component->new({ id => $comp_id, cache => 1 });
+ push @$result, $component->name;
+ }
+ else {
+ return [ '' ];
+ }
+ }
+ }
+ return $result;
+}
+
sub rest_resources {
return [
# create page - single product name