From b0642d67ae6a9a7e7bbb8b8dc7a832c26bb211af Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Mon, 1 Feb 2010 17:34:26 -0800 Subject: Bug 487508: Allow restricting the visibility of custom fields and values by component r=dkl, a=mkanat --- Bugzilla/Component.pm | 30 +++-- Bugzilla/Constants.pm | 9 ++ Bugzilla/Field.pm | 24 +++- Bugzilla/Field/Choice.pm | 140 ++------------------- Bugzilla/Migrate.pm | 4 +- Bugzilla/Product.pm | 17 +-- Bugzilla/Search.pm | 2 +- Bugzilla/Status.pm | 5 +- Bugzilla/WebService/Bug.pm | 4 +- editvalues.cgi | 10 +- report.cgi | 1 - .../en/default/admin/custom_fields/cf-js.js.tmpl | 9 +- .../en/default/admin/custom_fields/edit.html.tmpl | 5 +- .../en/default/admin/fieldvalues/create.html.tmpl | 3 + .../en/default/admin/fieldvalues/edit.html.tmpl | 5 +- template/en/default/bug/create/create.html.tmpl | 37 +++--- template/en/default/bug/edit.html.tmpl | 34 ++--- template/en/default/bug/field-events.js.tmpl | 1 + template/en/default/bug/field.html.tmpl | 17 +-- template/en/default/global/user-error.html.tmpl | 2 +- template/en/default/list/edit-multiple.html.tmpl | 2 + 21 files changed, 139 insertions(+), 222 deletions(-) diff --git a/Bugzilla/Component.pm b/Bugzilla/Component.pm index 194a3957c..5fb911031 100644 --- a/Bugzilla/Component.pm +++ b/Bugzilla/Component.pm @@ -17,11 +17,9 @@ # Max Kanat-Alexander # Akamai Technologies -use strict; - package Bugzilla::Component; - -use base qw(Bugzilla::Object); +use strict; +use base qw(Bugzilla::Field::ChoiceInterface Bugzilla::Object); use Bugzilla::Constants; use Bugzilla::Util; @@ -35,6 +33,8 @@ use Bugzilla::Series; ############################### use constant DB_TABLE => 'components'; +# This is mostly for the editfields.cgi case where ->get_all is called. +use constant LIST_ORDER => 'product_id, name'; use constant DB_COLUMNS => qw( id @@ -80,7 +80,7 @@ sub new { my $dbh = Bugzilla->dbh; my $product; - if (ref $param) { + if (ref $param and !defined $param->{id}) { $product = $param->{product}; my $name = $param->{name}; if (!defined $product) { @@ -156,6 +156,8 @@ sub remove_from_db { my $self = shift; my $dbh = Bugzilla->dbh; + $self->_check_if_controller(); # From ChoiceInterface + $dbh->bz_start_transaction(); if ($self->bug_count) { @@ -418,11 +420,25 @@ sub product { #### Accessors #### ############################### -sub id { return $_[0]->{'id'}; } -sub name { return $_[0]->{'name'}; } sub description { return $_[0]->{'description'}; } sub product_id { return $_[0]->{'product_id'}; } +############################################## +# Implement Bugzilla::Field::ChoiceInterface # +############################################## + +use constant FIELD_NAME => 'component'; +use constant is_default => 0; +use constant is_active => 1; + +sub is_set_on_bug { + my ($self, $bug) = @_; + # We treat it like a hash always, so that we don't have to check if it's + # a hash or an object. + return 0 if !defined $bug->{component_id}; + $bug->{component_id} == $self->id ? 1 : 0; +} + ############################### #### Subroutines #### ############################### diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm index 94d9f8bed..948ff5337 100644 --- a/Bugzilla/Constants.pm +++ b/Bugzilla/Constants.pm @@ -129,6 +129,8 @@ use File::Basename; FIELD_TYPE_BUG_ID FIELD_TYPE_BUG_URLS + ABNORMAL_SELECTS + TIMETRACKING_FIELDS USAGE_MODE_BROWSER @@ -368,6 +370,13 @@ use constant FIELD_TYPE_DATETIME => 5; use constant FIELD_TYPE_BUG_ID => 6; use constant FIELD_TYPE_BUG_URLS => 7; +# See the POD for Bugzilla::Field/is_abnormal to see why these are listed +# here. +use constant ABNORMAL_SELECTS => qw( + product + component +); + # The fields from fielddefs that are blocked from non-timetracking users. # work_time is sometimes called actual_time. use constant TIMETRACKING_FIELDS => diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm index 7b1569c52..2f14037ab 100644 --- a/Bugzilla/Field.pm +++ b/Bugzilla/Field.pm @@ -180,7 +180,7 @@ use constant DEFAULT_FIELDS => ( {name => 'priority', desc => 'Priority', in_new_bugmail => 1, type => FIELD_TYPE_SINGLE_SELECT, buglist => 1}, {name => 'component', desc => 'Component', in_new_bugmail => 1, - buglist => 1}, + type => FIELD_TYPE_SINGLE_SELECT, buglist => 1}, {name => 'assigned_to', desc => 'AssignedTo', in_new_bugmail => 1, buglist => 1}, {name => 'reporter', desc => 'ReportedBy', in_new_bugmail => 1, @@ -492,6 +492,28 @@ sub is_select { || $_[0]->type == FIELD_TYPE_MULTI_SELECT) ? 1 : 0 } +=over + +=item C + +Most fields that have a C diff --git a/template/en/default/admin/fieldvalues/create.html.tmpl b/template/en/default/admin/fieldvalues/create.html.tmpl index f1eec1a5a..019831489 100644 --- a/template/en/default/admin/fieldvalues/create.html.tmpl +++ b/template/en/default/admin/fieldvalues/create.html.tmpl @@ -75,6 +75,9 @@ [% FOREACH field_value = field.value_field.legal_values %] [% NEXT IF field_value.name == '' %] [% END %] diff --git a/template/en/default/admin/fieldvalues/edit.html.tmpl b/template/en/default/admin/fieldvalues/edit.html.tmpl index 5650ee87b..fb58e5784 100644 --- a/template/en/default/admin/fieldvalues/edit.html.tmpl +++ b/template/en/default/admin/fieldvalues/edit.html.tmpl @@ -73,7 +73,10 @@ [% END %] diff --git a/template/en/default/bug/create/create.html.tmpl b/template/en/default/bug/create/create.html.tmpl index 4b1745757..1f3380a29 100644 --- a/template/en/default/bug/create/create.html.tmpl +++ b/template/en/default/bug/create/create.html.tmpl @@ -168,14 +168,6 @@ TUI_hide_default('expert_fields'); --> -[% USE Bugzilla %] -[% SET select_fields = {} %] -[% FOREACH field = Bugzilla.get_fields( - { type => constants.FIELD_TYPE_SINGLE_SELECT, custom => 0 }) -%] - [% select_fields.${field.name} = field %] -[% END %] -
@@ -224,8 +216,8 @@ TUI_hide_default('expert_fields'); Component: - [%# Build the lists of assignees and QA contacts if "usemenuforusers" is enabled. %] [% IF Param("usemenuforusers") %] [% assignees_list = user.get_userlist.clone %] @@ -234,7 +226,13 @@ TUI_hide_default('expert_fields'); [%- FOREACH c = product.components %] [% IF Param("usemenuforusers") %] @@ -245,6 +243,13 @@ TUI_hide_default('expert_fields'); [% END %] [%- END %] + + @@ -276,19 +281,19 @@ TUI_hide_default('expert_fields'); [% INCLUDE bug/field.html.tmpl - bug = default, field = select_fields.bug_severity, editable = 1, + bug = default, field = bug_fields.bug_severity, editable = 1, value = default.bug_severity %] [% INCLUDE bug/field.html.tmpl - bug = default, field = select_fields.rep_platform, editable = 1, + bug = default, field = bug_fields.rep_platform, editable = 1, value = default.rep_platform %] [% INCLUDE bug/field.html.tmpl - bug = default, field = select_fields.op_sys, editable = 1, + bug = default, field = bug_fields.op_sys, editable = 1, value = default.op_sys %] @@ -304,7 +309,7 @@ TUI_hide_default('expert_fields'); [% IF Param('letsubmitterchoosepriority') %] [% INCLUDE bug/field.html.tmpl - bug = default, field = select_fields.priority, editable = 1, + bug = default, field = bug_fields.priority, editable = 1, value = default.priority %] [% ELSE %]   @@ -679,7 +684,7 @@ TUI_hide_default('expert_fields'); [% END %] diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 379370689..63b81d733 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -30,14 +30,6 @@ [% PROCESS bug/time.html.tmpl %] -[% USE Bugzilla %] -[% SET select_fields = {} %] -[% FOREACH field = Bugzilla.get_fields( - { type => constants.FIELD_TYPE_SINGLE_SELECT, custom => 0 }) -%] - [% select_fields.${field.name} = field %] -[% END %] -