From a404e6c3e3d777f09ef2ab8100ad01a20a3c885c Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sat, 12 Jan 2008 22:23:10 +0000 Subject: Bug 401965: Move groups updating from process_bug.cgi to Bugzilla::Bug Patch By Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Product.pm | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'Bugzilla/Product.pm') diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm index 728bd0652..45c489973 100644 --- a/Bugzilla/Product.pm +++ b/Bugzilla/Product.pm @@ -21,6 +21,7 @@ package Bugzilla::Product; use Bugzilla::Version; use Bugzilla::Milestone; +use Bugzilla::Constants; use Bugzilla::Util; use Bugzilla::Group; use Bugzilla::Error; @@ -101,6 +102,39 @@ sub group_controls { return $self->{group_controls}; } +sub groups_mandatory_for { + my ($self, $user) = @_; + my $groups = $user->groups_as_string; + my $mandatory = CONTROLMAPMANDATORY; + # For membercontrol we don't check group_id IN, because if membercontrol + # is Mandatory, the group is Mandatory for everybody, regardless of their + # group membership. + my $ids = Bugzilla->dbh->selectcol_arrayref( + "SELECT group_id FROM group_control_map + WHERE product_id = ? + AND (membercontrol = $mandatory + OR (othercontrol = $mandatory + AND group_id NOT IN ($groups)))", + undef, $self->id); + return Bugzilla::Group->new_from_list($ids); +} + +sub groups_valid { + my ($self) = @_; + return $self->{groups_valid} if defined $self->{groups_valid}; + + # Note that we don't check OtherControl below, because there is no + # valid NA/* combination. + my $ids = Bugzilla->dbh->selectcol_arrayref( + "SELECT DISTINCT group_id + FROM group_control_map AS gcm + INNER JOIN groups ON gcm.group_id = groups.id + WHERE product_id = ? AND isbuggroup = 1 + AND membercontrol != " . CONTROLMAPNA, undef, $self->id); + $self->{groups_valid} = Bugzilla::Group->new_from_list($ids); + return $self->{groups_valid}; +} + sub versions { my $self = shift; my $dbh = Bugzilla->dbh; @@ -285,6 +319,42 @@ below. Returns: A hash with group id as key and hash containing a Bugzilla::Group object and the properties of group relative to the product. + +=item C + +=over + +=item B + +Tells you what groups are mandatory for bugs in this product. + +=item B + +C<$user> - The user who you want to check. + +=item B An arrayref of C objects. + +=back + +=item C + +=over + +=item B + +Returns an arrayref of L objects, representing groups +that bugs could validly be restricted to within this product. Used mostly +by L to assure that you're adding valid groups to a bug. + +B: This doesn't check whether or not the current user can add/remove +bugs to/from these groups. It just tells you that bugs I these +groups, in this product. + +=item B (none) + +=item B An arrayref of L objects. + +=back =item C -- cgit v1.2.3-24-g4f1b