From ec10d05697c5e8b89d4a76374563bacaf4238d02 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Wed, 6 Aug 2014 14:47:15 +0800 Subject: Bug 1047131: enable "user story" field on all products --- extensions/UserStory/Extension.pm | 35 ++++++------- extensions/UserStory/lib/Constants.pm | 57 +++++----------------- .../hook/bug/comments-comment_banner.html.tmpl | 2 +- .../create/create-after_custom_fields.html.tmpl | 22 ++++----- 4 files changed, 39 insertions(+), 77 deletions(-) (limited to 'extensions/UserStory') diff --git a/extensions/UserStory/Extension.pm b/extensions/UserStory/Extension.pm index e70b86f5a..2053a0097 100644 --- a/extensions/UserStory/Extension.pm +++ b/extensions/UserStory/Extension.pm @@ -21,29 +21,28 @@ use Bugzilla::Extension::BMO::FakeBug; use Text::Diff; BEGIN { - *Bugzilla::Bug::user_story_group = \&_bug_user_story_group; - *Bugzilla::Extension::BMO::FakeBug::user_story_group = \&_bug_user_story_group; + *Bugzilla::Bug::user_story_visible = \&_bug_user_story_visible; + *Bugzilla::Extension::BMO::FakeBug::user_story_visible = \&_bug_user_story_visible; } -sub _bug_user_story_group { +sub _bug_user_story_visible { my ($self) = @_; - if (!exists $self->{user_story_group}) { + if (!exists $self->{user_story_visible}) { + # Visible by default + $self->{user_story_visible} = 1; my ($product, $component) = ($self->product, $self->component); - my $edit_group = ''; - my $components = []; - if (exists USER_STORY->{$product}) { - $components = USER_STORY->{$product}->{components}; - if (!$component - || scalar(@$components) == 0 - || grep { $_ eq $component } @$components) + my $exclude_components = []; + if (exists USER_STORY_EXCLUDE->{$product}) { + $exclude_components = USER_STORY_EXCLUDE->{$product}; + if (scalar(@$exclude_components) == 0 + || ($component && grep { $_ eq $component } @$exclude_components)) { - $edit_group = USER_STORY->{$product}->{group}; + $self->{user_story_visible} = 0; } } - $self->{user_story_group} = $edit_group; - $self->{user_story_components} = $components; + $self->{user_story_exclude_components} = $exclude_components; } - return ($self->{user_story_group}, $self->{user_story_components}); + return ($self->{user_story_visible}, $self->{user_story_exclude_components}); } # ensure user is allowed to edit the story @@ -51,11 +50,7 @@ sub bug_check_can_change_field { my ($self, $args) = @_; my ($bug, $field, $priv_results) = @$args{qw(bug field priv_results)}; return unless $field eq 'cf_user_story'; - - my $user = Bugzilla->user; - my ($group) = $bug->user_story_group(); - $group || return; - if (!$user->in_group($group)) { + if (!Bugzilla->user->in_group(USER_STORY_GROUP)) { push (@$priv_results, PRIVILEGES_REQUIRED_EMPOWERED); } } diff --git a/extensions/UserStory/lib/Constants.pm b/extensions/UserStory/lib/Constants.pm index c59a9d5a6..d09b28fef 100644 --- a/extensions/UserStory/lib/Constants.pm +++ b/extensions/UserStory/lib/Constants.pm @@ -12,51 +12,18 @@ use warnings; use base qw(Exporter); -our @EXPORT = qw( USER_STORY ); +our @EXPORT = qw( USER_STORY_EXCLUDE USER_STORY_GROUP ); -use constant USER_STORY => { - # note - an empty components array means all components - Loop => { - group => 'editbugs', - components => [], - }, - Tracking => { - group => 'editbugs', - components => [], - }, - Firefox => { - group => 'editbugs', - components => [ - "Developer Tools", - "Developer Tools: 3D View", - "Developer Tools: Canvas Debugger", - "Developer Tools: Console", - "Developer Tools: Debugger", - "Developer Tools: Framework", - "Developer Tools: Graphic Commandline and Toolbar", - "Developer Tools: Inspector", - "Developer Tools: Memory", - "Developer Tools: Netmonitor", - "Developer Tools: Object Inspector", - "Developer Tools: Profiler", - "Developer Tools: Responsive Mode", - "Developer Tools: Scratchpad", - "Developer Tools: Source Editor", - "Developer Tools: Style Editor", - "Developer Tools: User Stories", - "Developer Tools: Web Audio Editor", - "Developer Tools: WebGL Shader Editor", - "Developer Tools: WebIDE", - ], - }, - 'Firefox OS' => { - group => 'editbugs', - components => [], - }, - 'support.mozilla.org' => { - group => 'editbugs', - components => [], - } -}; +# Group allowed to set/edit the user story field +use constant USER_STORY_GROUP => 'editbugs'; + +# Exclude showing the user story field for these products/components. +# Examples: +# Don't show User Story on any Firefox OS component: +# 'Firefox OS' => [], +# Don't show User Story on Developer Tools component, visible on all other +# Firefox components +# 'Firefox' => ['Developer Tools'], +use constant USER_STORY_EXCLUDE => { }; 1; diff --git a/extensions/UserStory/template/en/default/hook/bug/comments-comment_banner.html.tmpl b/extensions/UserStory/template/en/default/hook/bug/comments-comment_banner.html.tmpl index dcb95524e..c7c202d62 100644 --- a/extensions/UserStory/template/en/default/hook/bug/comments-comment_banner.html.tmpl +++ b/extensions/UserStory/template/en/default/hook/bug/comments-comment_banner.html.tmpl @@ -6,7 +6,7 @@ # defined by the Mozilla Public License, v. 2.0. #%] -[% RETURN UNLESS bug.user_story_group.0 %] +[% RETURN UNLESS bug.user_story_visible.0 %] [% can_edit_story = bug.check_can_change_field('cf_user_story', 0, 1) %]
diff --git a/extensions/UserStory/template/en/default/hook/bug/create/create-after_custom_fields.html.tmpl b/extensions/UserStory/template/en/default/hook/bug/create/create-after_custom_fields.html.tmpl index a0c904fe0..04c7f3c04 100644 --- a/extensions/UserStory/template/en/default/hook/bug/create/create-after_custom_fields.html.tmpl +++ b/extensions/UserStory/template/en/default/hook/bug/create/create-after_custom_fields.html.tmpl @@ -6,7 +6,7 @@ # defined by the Mozilla Public License, v. 2.0. #%] -[% RETURN UNLESS default.user_story_group.0 && default.check_can_change_field('cf_user_story', 0, 1) %] +[% RETURN UNLESS default.user_story_visible.0 && default.check_can_change_field('cf_user_story', 0, 1) %] @@ -33,15 +33,15 @@ %]