Skip to content

Commit

Permalink
Bug 1047131: enable "user story" field on all products
Browse files Browse the repository at this point in the history
  • Loading branch information
dklawren authored and globau committed Aug 6, 2014
1 parent b9b4791 commit ec10d05
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 77 deletions.
35 changes: 15 additions & 20 deletions extensions/UserStory/Extension.pm
Expand Up @@ -21,41 +21,36 @@ 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
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);
}
}
Expand Down
57 changes: 12 additions & 45 deletions extensions/UserStory/lib/Constants.pm
Expand Up @@ -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;
Expand Up @@ -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) %]

<div class="user_story">
Expand Down
Expand Up @@ -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) %]

</tbody>
<tbody id="cf_user_story_container" class="expert_fields bz_default_hidden">
Expand All @@ -33,15 +33,15 @@
%]
</div>
<script type="text/javascript">
var user_story_components = [];
[% FOREACH c = default.user_story_group.1 %]
user_story_components.push('[% c FILTER js %]');
var user_story_exclude_components = [];
[% FOREACH c = default.user_story_visible.1 %]
user_story_exclude_components.push('[% c FILTER js %]');
[% END %]
function toggleUserStory() {
if (YAHOO.util.Dom.get('user_story').value != '') {
hideUserStoryEdit();
}
if (user_story_components.length == 0) {
if (user_story_exclude_components.length == 0) {
YAHOO.util.Dom.removeClass('cf_user_story_container', 'bz_default_hidden');
YAHOO.util.Dom.get('user_story').disabled = false;
return;
Expand All @@ -55,15 +55,15 @@
index = 0;
}
if (index != -1) {
for (var i = 0, l = user_story_components.length; i < l; i++) {
if (user_story_components[i] == components[index]) {
YAHOO.util.Dom.removeClass('cf_user_story_container', 'bz_default_hidden');
YAHOO.util.Dom.get('user_story').disabled = false;
for (var i = 0, l = user_story_exclude_components.length; i < l; i++) {
if (user_story_exclude_components[i] == components[index]) {
YAHOO.util.Dom.addClass('cf_user_story_container', 'bz_default_hidden');
YAHOO.util.Dom.get('user_story').disabled = true;
return;
}
else {
YAHOO.util.Dom.addClass('cf_user_story_container', 'bz_default_hidden');
YAHOO.util.Dom.get('user_story').disabled = true;
YAHOO.util.Dom.removeClass('cf_user_story_container', 'bz_default_hidden');
YAHOO.util.Dom.get('user_story').disabled = false;
}
}
}
Expand Down

0 comments on commit ec10d05

Please sign in to comment.