summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Group.pm
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2007-03-06 11:54:07 +0100
committermkanat%bugzilla.org <>2007-03-06 11:54:07 +0100
commitfd5be728fcf18479146aab4d52254c3475124154 (patch)
tree716b8f177abb39fb8dc8dbd0c8eb5b7f75f199bf /Bugzilla/Group.pm
parentb1a24eebebdab3a6fbae9bd8fd99736e130da0a9 (diff)
downloadbugzilla-fd5be728fcf18479146aab4d52254c3475124154.tar.gz
bugzilla-fd5be728fcf18479146aab4d52254c3475124154.tar.xz
Bug 354627: Improve the UI for adding/removing inheritance in editgroups.cgi
Patch By Max Kanat-Alexander <mkanat@bugzilla.org r=LpSolit, a=LpSolit
Diffstat (limited to 'Bugzilla/Group.pm')
-rw-r--r--Bugzilla/Group.pm123
1 files changed, 121 insertions, 2 deletions
diff --git a/Bugzilla/Group.pm b/Bugzilla/Group.pm
index c80d2333c..9e5a601c7 100644
--- a/Bugzilla/Group.pm
+++ b/Bugzilla/Group.pm
@@ -53,11 +53,23 @@ use constant VALIDATORS => {
name => \&_check_name,
description => \&_check_description,
userregexp => \&_check_user_regexp,
+ isactive => \&_check_is_active,
isbuggroup => \&_check_is_bug_group,
};
use constant REQUIRED_CREATE_FIELDS => qw(name description isbuggroup);
+use constant UPDATE_COLUMNS => qw(
+ name
+ description
+ userregexp
+ isactive
+);
+
+# Parameters that are lists of groups.
+use constant GROUP_PARAMS => qw(chartgroup insidergroup timetrackinggroup
+ querysharegroup);
+
###############################
#### Accessors ######
###############################
@@ -67,10 +79,112 @@ sub is_bug_group { return $_[0]->{'isbuggroup'}; }
sub user_regexp { return $_[0]->{'userregexp'}; }
sub is_active { return $_[0]->{'isactive'}; }
+sub members_direct {
+ my ($self) = @_;
+ return $self->{members_direct} if defined $self->{members_direct};
+ my $dbh = Bugzilla->dbh;
+ my $user_ids = $dbh->selectcol_arrayref(
+ "SELECT user_group_map.user_id
+ FROM user_group_map
+ WHERE user_group_map.group_id = ?
+ AND grant_type = " . GRANT_DIRECT . "
+ AND isbless = 0", undef, $self->id);
+ require Bugzilla::User;
+ $self->{members_direct} = Bugzilla::User->new_from_list($user_ids);
+ return $self->{members_direct};
+}
+
+sub grant_direct {
+ my ($self, $type) = @_;
+ $self->{grant_direct} ||= {};
+ return $self->{grant_direct}->{$type}
+ if defined $self->{members_direct}->{$type};
+ my $dbh = Bugzilla->dbh;
+
+ my $ids = $dbh->selectcol_arrayref(
+ "SELECT member_id FROM group_group_map
+ WHERE grantor_id = ? AND grant_type = $type",
+ undef, $self->id) || [];
+
+ $self->{grant_direct}->{$type} = $self->new_from_list($ids);
+ return $self->{grant_direct}->{$type};
+}
+
+sub granted_by_direct {
+ my ($self, $type) = @_;
+ $self->{granted_by_direct} ||= {};
+ return $self->{granted_by_direct}->{$type}
+ if defined $self->{granted_by_direct}->{$type};
+ my $dbh = Bugzilla->dbh;
+
+ my $ids = $dbh->selectcol_arrayref(
+ "SELECT grantor_id FROM group_group_map
+ WHERE member_id = ? AND grant_type = $type",
+ undef, $self->id) || [];
+
+ $self->{granted_by_direct}->{$type} = $self->new_from_list($ids);
+ return $self->{granted_by_direct}->{$type};
+}
+
###############################
#### Methods ####
###############################
+sub set_description { $_[0]->set('description', $_[1]); }
+sub set_is_active { $_[0]->set('isactive', $_[1]); }
+sub set_name { $_[0]->set('name', $_[1]); }
+sub set_user_regexp { $_[0]->set('userregexp', $_[1]); }
+
+sub update {
+ my $self = shift;
+ my $changes = $self->SUPER::update(@_);
+
+ if (exists $changes->{name}) {
+ my ($old_name, $new_name) = @{$changes->{name}};
+ my $update_params;
+ foreach my $group (GROUP_PARAMS) {
+ if ($old_name eq Bugzilla->params->{$group}) {
+ SetParam($group, $new_name);
+ $update_params = 1;
+ }
+ }
+ write_params() if $update_params;
+ }
+
+ # If we've changed this group to be active, fix any Mandatory groups.
+ $self->_enforce_mandatory if (exists $changes->{isactive}
+ && $changes->{isactive}->[1]);
+
+ $self->_rederive_regexp() if exists $changes->{userregexp};
+ return $changes;
+}
+
+# Add missing entries in bug_group_map for bugs created while
+# a mandatory group was disabled and which is now enabled again.
+sub _enforce_mandatory {
+ my ($self) = @_;
+ my $dbh = Bugzilla->dbh;
+ my $gid = $self->id;
+
+ my $bug_ids =
+ $dbh->selectcol_arrayref('SELECT bugs.bug_id
+ FROM bugs
+ INNER JOIN group_control_map
+ ON group_control_map.product_id = bugs.product_id
+ LEFT JOIN bug_group_map
+ ON bug_group_map.bug_id = bugs.bug_id
+ AND bug_group_map.group_id = group_control_map.group_id
+ WHERE group_control_map.group_id = ?
+ AND group_control_map.membercontrol = ?
+ AND bug_group_map.group_id IS NULL',
+ undef, ($gid, CONTROLMAPMANDATORY));
+
+ my $sth = $dbh->prepare('INSERT INTO bug_group_map (bug_id, group_id) VALUES (?, ?)');
+ foreach my $bug_id (@$bug_ids) {
+ $sth->execute($bug_id, $gid);
+ }
+}
+
sub is_active_bug_group {
my $self = shift;
return $self->is_active && $self->is_bug_group;
@@ -183,8 +297,11 @@ sub _check_name {
my ($invocant, $name) = @_;
$name = trim($name);
$name || ThrowUserError("empty_group_name");
- my $exists = new Bugzilla::Group({name => $name });
- ThrowUserError("group_exists", { name => $name }) if $exists;
+ # If we're creating a Group or changing the name...
+ if (!ref($invocant) || $invocant->name ne $name) {
+ my $exists = new Bugzilla::Group({name => $name });
+ ThrowUserError("group_exists", { name => $name }) if $exists;
+ }
return $name;
}
@@ -202,9 +319,11 @@ sub _check_user_regexp {
return $regex;
}
+sub _check_is_active { return $_[1] ? 1 : 0; }
sub _check_is_bug_group {
return $_[1] ? 1 : 0;
}
+
1;
__END__