From 4f6724b0f86ccffa091ca33c04e237b9dd5d4c4a Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 23 Oct 2013 15:25:27 +0800 Subject: Bug 895687: add UserStory extension --- extensions/UserStory/Config.pm | 21 ++++++ extensions/UserStory/Extension.pm | 88 ++++++++++++++++++++++ extensions/UserStory/lib/Constants.pm | 22 ++++++ .../hook/bug/comments-comment_banner.html.tmpl | 51 +++++++++++++ .../default/hook/bug/edit-custom_field.html.tmpl | 9 +++ .../en/default/hook/bug/show-header-end.html.tmpl | 9 +++ extensions/UserStory/web/style/user_story.css | 26 +++++++ 7 files changed, 226 insertions(+) create mode 100644 extensions/UserStory/Config.pm create mode 100644 extensions/UserStory/Extension.pm create mode 100644 extensions/UserStory/lib/Constants.pm create mode 100644 extensions/UserStory/template/en/default/hook/bug/comments-comment_banner.html.tmpl create mode 100644 extensions/UserStory/template/en/default/hook/bug/edit-custom_field.html.tmpl create mode 100644 extensions/UserStory/template/en/default/hook/bug/show-header-end.html.tmpl create mode 100644 extensions/UserStory/web/style/user_story.css (limited to 'extensions/UserStory') diff --git a/extensions/UserStory/Config.pm b/extensions/UserStory/Config.pm new file mode 100644 index 000000000..8649c71cf --- /dev/null +++ b/extensions/UserStory/Config.pm @@ -0,0 +1,21 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::UserStory; +use strict; + +use constant NAME => 'UserStory'; +use constant REQUIRED_MODULES => [ + { + package => 'Text-Diff', + module => 'Text::Diff', + version => 0, + }, +]; +use constant OPTIONAL_MODULES => []; + +__PACKAGE__->NAME; diff --git a/extensions/UserStory/Extension.pm b/extensions/UserStory/Extension.pm new file mode 100644 index 000000000..26f2c6bab --- /dev/null +++ b/extensions/UserStory/Extension.pm @@ -0,0 +1,88 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::UserStory; +use strict; +use warnings; + +use base qw(Bugzilla::Extension); +our $VERSION = '1'; + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Error; +use Bugzilla::Extension::UserStory::Constants; +use Text::Diff; + +BEGIN { + *Bugzilla::Product::user_story_group = \&_product_user_story_group; +} + +sub _product_user_story_group { + my ($self) = @_; + return USER_STORY_PRODUCTS->{$self->name}; +} + +# 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->product_obj->user_story_group() + || return; + if (!$user->in_group($group)) { + push (@$priv_results, PRIVILEGES_REQUIRED_EMPOWERED); + } +} + +# store just a diff of the changes in the bugs_activity table +sub bug_update_before_logging { + my ($self, $args) = @_; + my $changes = $args->{changes}; + return unless exists $changes->{cf_user_story}; + my $diff = diff( + \$changes->{cf_user_story}->[0], + \$changes->{cf_user_story}->[1], + { + CONTEXT => 0, + }, + ); + $changes->{cf_user_story} = [ '', $diff ]; +} + +# stop inline-history from displaying changes to the user story +sub inline_history_activtiy { + my ($self, $args) = @_; + foreach my $activity (@{ $args->{activity} }) { + foreach my $change (@{ $activity->{changes} }) { + if ($change->{fieldname} eq 'cf_user_story') { + $change->{removed} = ''; + $change->{added} = '(updated)'; + } + } + } +} + +# create cf_user_story field +sub install_update_db { + my ($self, $args) = @_; + return if Bugzilla::Field->new({ name => 'cf_user_story'}); + Bugzilla::Field->create({ + name => 'cf_user_story', + description => 'User Story', + type => FIELD_TYPE_TEXTAREA, + mailhead => 0, + enter_bug => 0, + obsolete => 0, + custom => 1, + buglist => 0, + }); +} + +__PACKAGE__->NAME; diff --git a/extensions/UserStory/lib/Constants.pm b/extensions/UserStory/lib/Constants.pm new file mode 100644 index 000000000..dca38154c --- /dev/null +++ b/extensions/UserStory/lib/Constants.pm @@ -0,0 +1,22 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::UserStory::Constants; + +use strict; +use warnings; + +use base qw(Exporter); + +our @EXPORT = qw( USER_STORY_PRODUCTS ); + +use constant USER_STORY_PRODUCTS => { + # product group required to edit + Tracking => 'editbugs', +}; + +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 new file mode 100644 index 000000000..f58c2fb8b --- /dev/null +++ b/extensions/UserStory/template/en/default/hook/bug/comments-comment_banner.html.tmpl @@ -0,0 +1,51 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% RETURN UNLESS bug.product_obj.user_story_group %] +[% can_edit_story = bug.check_can_change_field('cf_user_story', 0, 1) %] + +
+
+ User Story + [% IF can_edit_story %] + + (edit) + + [% END %] +
+ + [% IF bug.cf_user_story != "" %] +
+
+        [%- bug.cf_user_story FILTER quoteUrls(bug) -%]
+      
+
+ [% ELSE %] +
+ [% END %] + + [% IF can_edit_story %] +
+ [% INCLUDE global/textarea.html.tmpl + name = 'cf_user_story' + id = 'user_story' + minrows = 10 + maxrows = 10 + cols = constants.COMMENT_COLS + defaultcontent = bug.cf_user_story %] +
+ + [% END %] +
diff --git a/extensions/UserStory/template/en/default/hook/bug/edit-custom_field.html.tmpl b/extensions/UserStory/template/en/default/hook/bug/edit-custom_field.html.tmpl new file mode 100644 index 000000000..2f0f758a4 --- /dev/null +++ b/extensions/UserStory/template/en/default/hook/bug/edit-custom_field.html.tmpl @@ -0,0 +1,9 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% field.hidden = field.name == 'cf_user_story' %] diff --git a/extensions/UserStory/template/en/default/hook/bug/show-header-end.html.tmpl b/extensions/UserStory/template/en/default/hook/bug/show-header-end.html.tmpl new file mode 100644 index 000000000..abdbe865e --- /dev/null +++ b/extensions/UserStory/template/en/default/hook/bug/show-header-end.html.tmpl @@ -0,0 +1,9 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% style_urls.push("extensions/UserStory/web/style/user_story.css") %] diff --git a/extensions/UserStory/web/style/user_story.css b/extensions/UserStory/web/style/user_story.css new file mode 100644 index 000000000..51affd359 --- /dev/null +++ b/extensions/UserStory/web/style/user_story.css @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. */ + + +#user_story_readonly { + border: 1px solid black; + border-radius: 4px; +} + +.skin-standard #user_story_readonly { + padding: 2px; +} + +.skin-Mozilla #user_story_readonly { + border: none; + border-radius: 0px; +} + +.skin-Mozilla #user_story_readonly .bz_comment_text { + border: 1px solid darkgrey; + border-radius: 4px; +} -- cgit v1.2.3-24-g4f1b