Commit fd5be728 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 354627: Improve the UI for adding/removing inheritance in editgroups.cgi

Patch By Max Kanat-Alexander <mkanat@bugzilla.org r=LpSolit, a=LpSolit
parent b1a24eeb
......@@ -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__
......
[%# 1.0@bugzilla.org %]
[%# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Dave Miller <justdave@syndicomm.com>
# Joel Peshkin <bugreport@peshkin.net>
# Jacob Steenhagen <jake@bugzilla.org>
# Vlad Dascalu <jocuri@softhome.net>
# Max Kanat-Alexander <mkanat@bugzilla.org>
#%]
[%# INTERFACE:
# group: The Bugzilla::Group being changed.
# regexp: the regexp according to which the update is performed.
#%]
[% IF regexp %]
[% title = "Confirm: Remove Explicit Members in the Regular Expression?" %]
[% ELSE %]
[% title = "Confirm: Remove All Explicit Members?" %]
[% END %]
[% PROCESS global/header.html.tmpl %]
[% IF regexp %]
<p>This option will remove all users from '[% group.name FILTER html %]'
whose login names match the regular expression:
'[% regexp FILTER html %]'</p>
[% ELSE %]
<p>This option will remove all explicitly defined users
from '[% group.name FILTER html %].'</p>
[% END %]
<p>Generally, you will only need to do this when upgrading groups
created with [% terms.Bugzilla %] versions 2.16 and prior. Use
this option with <b>extreme care</b> and consult the documentation
for further information.
</p>
<form method="post" action="editgroups.cgi">
<input type="hidden" name="group_id" value="[% group.id FILTER html %]">
<input type="hidden" name="regexp" value="[% regexp FILTER html %]">
<input type="hidden" name="action" value="remove_regexp">
<input name="token" type="hidden" value="[% token FILTER html %]">
<input name="confirm" type="submit" value="Confirm">
<p>Or <a href="editgroups.cgi">return to the Edit Groups page</a>.</p>
</form>
<p>Back to the <a href="editgroups.cgi">group list</a>.</p>
[% PROCESS global/footer.html.tmpl %]
......@@ -20,36 +20,21 @@
# Joel Peshkin <bugreport@peshkin.net>
# Jacob Steenhagen <jake@bugzilla.org>
# Vlad Dascalu <jocuri@softhome.net>
# Max Kanat-Alexander <mkanat@bugzilla.org>
#%]
[%# INTERFACE:
# remove_all: boolean int. Is 1 if the action was remove_all,
# and 0 if the action was remove_all_regexp.
# name: string. The place where removal is performed.
# regexp: string. The regexp according to which the removal is performed.
# users: array with group objects having the properties:
# - login: string. The login which is removed.
# group: The Bugzilla::Group being modified.
# regexp: string. The regexp according to which the removal was performed.
# users: Array of Bugzilla::User objects who were removed from this group.
#%]
[% IF remove_all %]
[% title = BLOCK %]
Removing All Explicit Group Memberships from '[% name FILTER html %]'
[% END %]
[% ELSE %]
[% title = BLOCK %]
Removing All Explicit Group Memberships Matching Group RegExp from '[% name FILTER html %]'
[% END %]
[% END %]
[% PROCESS global/header.html.tmpl %]
[% PROCESS global/header.html.tmpl
title = "Removing Explicit Group Membership" %]
[% IF remove_all %]
<p><b>Removing explicit membership</b></p>
[% ELSE %]
<p><b>Removing explicit memberships of users matching
'[% regexp FILTER html %]'...</b></p>
[% END %]
<p><b>Removing explicit memberships[% IF regexp %] of users matching
'[% regexp FILTER html %]'[% END %]...</b></p>
[% FOREACH user = users %]
[% user.login FILTER html %] removed<br>
......
......@@ -209,6 +209,69 @@
An error occured while validating flags:
[%+ flag_creation_error FILTER none %]
[% ELSIF message_tag == "group_updated" %]
[% IF changes.keys.size %]
The following changes have been made to the '[% group.name FILTER html %]
group:
<ul>
[% FOREACH field = changes.keys.sort %]
[% SWITCH field %]
[% CASE 'name' %]
<li>The name was changed to '[% changes.name.1 FILTER html %]'</li>
[% CASE 'description' %]
<li>The description was updated.</li>
[% CASE 'userregexp' %]
<li>The regular expression was updated.</li>
[% CASE 'isactive' %]
[% IF changes.isactive.1 %]
<li>The group will now be used for [% terms.bugs %].</li>
[% ELSE %]
<li>The group will no longer be used for [% terms.bugs %].</li>
[% END %]
[% CASE 'members_add' %]
<li>The following groups are now members of this group:
[%+ changes.members_add.join(', ') FILTER html %]</li>
[% CASE 'members_remove' %]
<li>The following groups are no longer members of this group:
[%+ changes.members_remove.join(', ') FILTER html %]</li>
[% CASE 'member_of_add' %]
<li>This group is now a member of the following groups:
[%+ changes.member_of_add.join(', ') FILTER html %]</li>
[% CASE 'member_of_remove' %]
<li>This group is no longer a member of the following groups:
[%+ changes.member_of_remove.join(', ') FILTER html %]</li>
[% CASE 'bless_from_add' %]
<li>The following groups may now add users to this group:
[%+ changes.bless_from_add.join(', ') FILTER html %]</li>
[% CASE 'bless_from_remove' %]
<li>The following groups may no longer add users to this group:
[%+ changes.bless_from_remove.join(', ') FILTER html %]</li>
[% CASE 'bless_to_add' %]
<li>This group may now add users to the following groups:
[%+ changes.bless_to_add.join(', ') FILTER html %]</li>
[% CASE 'bless_to_remove' %]
<li>This group may no longer add users to the following groups:
[%+ changes.bless_to_remove.join(', ') FILTER html %]</li>
[% CASE 'visible_from_add' %]
<li>The following groups can now see users in this group:
[%+ changes.visible_from_add.join(', ') FILTER html %]</li>
[% CASE 'visible_from_remove' %]
<li>The following groups may no longer see users in this group:
[%+ changes.visible_from_remove.join(', ') FILTER html %]</li>
[% CASE 'visible_to_me_add' %]
<li>This group may now see users in the following groups:
[%+ changes.visible_to_me_add.join(', ') FILTER html %]</li>
[% CASE 'visible_to_me_remove' %]
<li>This group may no longer see users in the following groups:
[%+ changes.visible_to_me_remove.join(', ') FILTER html %]</li>
[% END %]
[% END %]
</ul>
[% ELSE %]
You didn't request any change for the '[% group.name FILTER html %]'
group.
[% END %]
[% ELSIF message_tag == "logged_out" %]
[% title = "Logged Out" %]
[% url = "index.cgi?GoAheadAndLogIn=1" %]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment