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 +- 9 files changed, 75 insertions(+), 160 deletions(-) (limited to 'Bugzilla') 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