diff options
author | David Lawrence <dkl@redhat.com> | 2010-03-23 20:52:16 +0100 |
---|---|---|
committer | David Lawrence <dkl@redhat.com> | 2010-03-23 20:52:16 +0100 |
commit | 455ab8384cc8a33be25c1a90087aca2673b96b69 (patch) | |
tree | 1de7daa7480ba5343a5b86d708a392ca0f69f357 /extensions/Example | |
parent | 7ff5e333473f712dadd2cecb80e1a0f431a29879 (diff) | |
download | bugzilla-455ab8384cc8a33be25c1a90087aca2673b96b69.tar.gz bugzilla-455ab8384cc8a33be25c1a90087aca2673b96b69.tar.xz |
Bug 544332 - New bug_check_can_change_field hook for Bugzilla/Bug.pm
r/a=mkanat
Diffstat (limited to 'extensions/Example')
-rw-r--r-- | extensions/Example/Extension.pm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm index 6acf3e135..398ddbd56 100644 --- a/extensions/Example/Extension.pm +++ b/extensions/Example/Extension.pm @@ -29,6 +29,7 @@ use Bugzilla::Error; use Bugzilla::Group; use Bugzilla::User; use Bugzilla::Util qw(diff_arrays html_quote); +use Bugzilla::Status qw(is_open_state); # This is extensions/Example/lib/Util.pm. I can load this here in my # Extension.pm only because I have a Config.pm. @@ -587,6 +588,44 @@ sub template_before_process { } } +sub bug_check_can_change_field { + my ($self, $args) = @_; + + my ($bug, $field, $new_value, $old_value, $priv_results) + = @$args{qw(bug field new_value old_value priv_results)}; + + my $user = Bugzilla->user; + + # Disallow a bug from being reopened if currently closed unless user + # is in 'admin' group + if ($field eq 'bug_status' && $bug->product_obj->name eq 'Example') { + if (!is_open_state($old_value) && is_open_state($new_value) + && !$user->in_group('admin')) + { + push(@$priv_results, PRIVILEGES_REQUIRED_EMPOWERED); + return; + } + } + + # Disallow a bug's keywords from being edited unless user is the + # reporter of the bug + if ($field eq 'keywords' && $bug->product_obj->name eq 'Example' + && $user->login ne $bug->reporter->login) + { + push(@$priv_results, PRIVILEGES_REQUIRED_REPORTER); + return; + } + + # Allow updating of priority even if user cannot normally edit the bug + # and they are in group 'engineering' + if ($field eq 'priority' && $bug->product_obj->name eq 'Example' + && $user->in_group('engineering')) + { + push(@$priv_results, PRIVILEGES_REQUIRED_NONE); + return; + } +} + sub webservice { my ($self, $args) = @_; |