2004-05-23 11:07:50 +04:00
|
|
|
#!/usr/bin/perl -wT
|
2000-04-26 23:35:51 +04:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2001-04-17 06:26:16 +04:00
|
|
|
# Contributor(s): Dave Miller <justdave@syndicomm.com>
|
2002-09-22 21:15:13 +04:00
|
|
|
# Joel Peshkin <bugreport@peshkin.net>
|
2002-08-27 08:28:05 +04:00
|
|
|
# Jacob Steenhagen <jake@bugzilla.org>
|
2003-11-10 00:07:26 +03:00
|
|
|
# Vlad Dascalu <jocuri@softhome.net>
|
2000-04-26 23:35:51 +04:00
|
|
|
|
|
|
|
# Code derived from editowners.cgi and editusers.cgi
|
|
|
|
|
|
|
|
use strict;
|
2002-04-29 23:32:29 +04:00
|
|
|
use lib ".";
|
2000-04-26 23:35:51 +04:00
|
|
|
|
2004-03-26 18:18:07 +03:00
|
|
|
use Bugzilla;
|
2002-11-24 22:56:34 +03:00
|
|
|
use Bugzilla::Constants;
|
2000-04-26 23:35:51 +04:00
|
|
|
require "CGI.pl";
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
|
2003-11-10 00:07:26 +03:00
|
|
|
use vars qw($template $vars);
|
|
|
|
|
2004-03-27 06:51:44 +03:00
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
2000-04-26 23:35:51 +04:00
|
|
|
|
2003-05-05 05:15:38 +04:00
|
|
|
print Bugzilla->cgi->header();
|
2000-04-26 23:35:51 +04:00
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
ThrowUserError("auth_cant_edit_groups") unless UserInGroup("creategroups");
|
2000-04-26 23:35:51 +04:00
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
my $action = trim($cgi->param('action') || '');
|
2000-04-26 23:35:51 +04:00
|
|
|
|
2004-06-16 09:04:48 +04:00
|
|
|
# RederiveRegexp: update user_group_map with regexp-based grants
|
|
|
|
sub RederiveRegexp ($$)
|
|
|
|
{
|
|
|
|
my $regexp = shift;
|
|
|
|
my $gid = shift;
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
my $sth = $dbh->prepare("SELECT userid, login_name FROM profiles");
|
|
|
|
my $sthadd = $dbh->prepare("INSERT IGNORE INTO user_group_map
|
|
|
|
(user_id, group_id, grant_type, isbless)
|
|
|
|
VALUES (?, ?, ?, 0)");
|
|
|
|
my $sthdel = $dbh->prepare("DELETE FROM user_group_map
|
|
|
|
WHERE user_id = ? AND group_id = ?
|
|
|
|
AND grant_type = ? and isbless = 0");
|
|
|
|
$sth->execute();
|
|
|
|
while (my ($uid, $login) = $sth->fetchrow_array()) {
|
2004-07-07 09:10:55 +04:00
|
|
|
if (($regexp =~ /\S+/) && ($login =~ m/$regexp/i))
|
2004-06-16 09:04:48 +04:00
|
|
|
{
|
|
|
|
$sthadd->execute($uid, $gid, GRANT_REGEXP);
|
|
|
|
} else {
|
|
|
|
$sthdel->execute($uid, $gid, GRANT_REGEXP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-26 23:35:51 +04:00
|
|
|
# TestGroup: check if the group name exists
|
|
|
|
sub TestGroup ($)
|
|
|
|
{
|
|
|
|
my $group = shift;
|
|
|
|
|
|
|
|
# does the group exist?
|
|
|
|
SendSQL("SELECT name
|
2001-10-13 05:36:17 +04:00
|
|
|
FROM groups
|
|
|
|
WHERE name=" . SqlQuote($group));
|
2000-04-26 23:35:51 +04:00
|
|
|
return FetchOneColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='' -> No action specified, get a list.
|
|
|
|
#
|
|
|
|
|
|
|
|
unless ($action) {
|
2004-07-13 09:12:33 +04:00
|
|
|
my @groups;
|
2000-04-26 23:35:51 +04:00
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT id,name,description,userregexp,isactive,isbuggroup " .
|
2000-04-26 23:35:51 +04:00
|
|
|
"FROM groups " .
|
2002-09-22 21:15:13 +04:00
|
|
|
"ORDER BY isbuggroup, name");
|
2000-04-26 23:35:51 +04:00
|
|
|
|
|
|
|
while (MoreSQLData()) {
|
2004-07-13 09:12:33 +04:00
|
|
|
my ($id, $name, $description, $regexp, $isactive, $isbuggroup)
|
|
|
|
= FetchSQLData();
|
|
|
|
my $group = {};
|
|
|
|
$group->{'id'} = $id;
|
|
|
|
$group->{'name'} = $name;
|
|
|
|
$group->{'description'} = $description;
|
|
|
|
$group->{'regexp'} = $regexp;
|
|
|
|
$group->{'isactive'} = $isactive;
|
|
|
|
$group->{'isbuggroup'} = $isbuggroup;
|
|
|
|
|
|
|
|
push(@groups, $group);
|
2000-04-26 23:35:51 +04:00
|
|
|
}
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
$vars->{'groups'} = \@groups;
|
|
|
|
|
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
$template->process("admin/groups/list.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
exit;
|
|
|
|
}
|
2000-04-26 23:35:51 +04:00
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
#
|
|
|
|
# action='changeform' -> present form for altering an existing group
|
|
|
|
#
|
|
|
|
# (next action will be 'postchanges')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'changeform') {
|
2004-07-13 09:12:33 +04:00
|
|
|
my $gid = trim($cgi->param('group') || '');
|
|
|
|
ThrowUserError("group_not_specified") unless ($gid);
|
2004-05-23 11:07:50 +04:00
|
|
|
detaint_natural($gid);
|
2002-09-22 21:15:13 +04:00
|
|
|
|
|
|
|
SendSQL("SELECT id, name, description, userregexp, isactive, isbuggroup
|
2004-07-13 09:12:33 +04:00
|
|
|
FROM groups WHERE id = $gid");
|
2002-09-22 21:15:13 +04:00
|
|
|
my ($group_id, $name, $description, $rexp, $isactive, $isbuggroup)
|
|
|
|
= FetchSQLData();
|
|
|
|
|
2003-01-11 02:51:38 +03:00
|
|
|
# For each group, we use left joins to establish the existence of
|
2002-09-22 21:15:13 +04:00
|
|
|
# a record making that group a member of this group
|
2003-01-11 02:51:38 +03:00
|
|
|
# and the existence of a record permitting that group to bless
|
2002-09-22 21:15:13 +04:00
|
|
|
# this one
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my @groups;
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT groups.id, groups.name, groups.description," .
|
2004-07-31 13:36:18 +04:00
|
|
|
" CASE WHEN group_group_map.member_id IS NOT NULL THEN 1 ELSE 0 END," .
|
|
|
|
" CASE WHEN B.member_id IS NOT NULL THEN 1 ELSE 0 END," .
|
|
|
|
" CASE WHEN C.member_id IS NOT NULL THEN 1 ELSE 0 END" .
|
2002-09-22 21:15:13 +04:00
|
|
|
" FROM groups" .
|
|
|
|
" LEFT JOIN group_group_map" .
|
|
|
|
" ON group_group_map.member_id = groups.id" .
|
|
|
|
" AND group_group_map.grantor_id = $group_id" .
|
2004-07-27 20:33:41 +04:00
|
|
|
" AND group_group_map.grant_type = " . GROUP_MEMBERSHIP .
|
2002-09-22 21:15:13 +04:00
|
|
|
" LEFT JOIN group_group_map as B" .
|
|
|
|
" ON B.member_id = groups.id" .
|
|
|
|
" AND B.grantor_id = $group_id" .
|
2004-07-27 20:33:41 +04:00
|
|
|
" AND B.grant_type = " . GROUP_BLESS .
|
|
|
|
" LEFT JOIN group_group_map as C" .
|
|
|
|
" ON C.member_id = groups.id" .
|
|
|
|
" AND C.grantor_id = $group_id" .
|
|
|
|
" AND C.grant_type = " . GROUP_VISIBLE .
|
2002-09-22 21:15:13 +04:00
|
|
|
" WHERE groups.id != $group_id ORDER by name");
|
2000-04-26 23:35:51 +04:00
|
|
|
|
|
|
|
while (MoreSQLData()) {
|
2004-07-27 20:33:41 +04:00
|
|
|
my ($grpid, $grpnam, $grpdesc, $grpmember, $blessmember, $membercansee)
|
|
|
|
= FetchSQLData();
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my $group = {};
|
|
|
|
$group->{'grpid'} = $grpid;
|
|
|
|
$group->{'grpnam'} = $grpnam;
|
|
|
|
$group->{'grpdesc'} = $grpdesc;
|
|
|
|
$group->{'grpmember'} = $grpmember;
|
|
|
|
$group->{'blessmember'} = $blessmember;
|
2004-07-27 20:33:41 +04:00
|
|
|
$group->{'membercansee'}= $membercansee;
|
2004-07-13 09:12:33 +04:00
|
|
|
push(@groups, $group);
|
2000-04-26 23:35:51 +04:00
|
|
|
}
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
$vars->{'group_id'} = $group_id;
|
|
|
|
$vars->{'name'} = $name;
|
|
|
|
$vars->{'description'} = $description;
|
|
|
|
$vars->{'rexp'} = $rexp;
|
|
|
|
$vars->{'isactive'} = $isactive;
|
|
|
|
$vars->{'isbuggroup'} = $isbuggroup;
|
|
|
|
$vars->{'groups'} = \@groups;
|
|
|
|
|
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
$template->process("admin/groups/edit.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2000-04-26 23:35:51 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='add' -> present form for parameters for new group
|
|
|
|
#
|
|
|
|
# (next action will be 'new')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'add') {
|
2003-11-10 00:07:26 +03:00
|
|
|
print Bugzilla->cgi->header();
|
2003-11-19 09:42:09 +03:00
|
|
|
$template->process("admin/groups/create.html.tmpl", $vars)
|
2003-11-10 00:07:26 +03:00
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2000-04-26 23:35:51 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='new' -> add group entered in the 'action=add' screen
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'new') {
|
|
|
|
# Cleanups and valididy checks
|
2004-07-13 09:12:33 +04:00
|
|
|
my $name = trim($cgi->param('name') || '');
|
|
|
|
my $desc = trim($cgi->param('desc') || '');
|
|
|
|
my $regexp = trim($cgi->param('regexp') || '');
|
2001-06-06 07:16:52 +04:00
|
|
|
# convert an undefined value in the inactive field to zero
|
|
|
|
# (this occurs when the inactive checkbox is not checked
|
|
|
|
# and the browser does not send the field to the server)
|
2004-07-13 09:12:33 +04:00
|
|
|
my $isactive = $cgi->param('isactive') ? 1 : 0;
|
|
|
|
|
|
|
|
# At this point $isactive is either 0 or 1 so we can mark it safe
|
|
|
|
trick_taint($isactive);
|
|
|
|
|
|
|
|
ThrowUserError("empty_group_name") unless $name;
|
|
|
|
ThrowUserError("empty_group_description") unless $desc;
|
2000-04-26 23:35:51 +04:00
|
|
|
|
|
|
|
if (TestGroup($name)) {
|
2004-07-13 09:12:33 +04:00
|
|
|
ThrowUserError("group_exists", { name => $name });
|
2000-04-26 23:35:51 +04:00
|
|
|
}
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
ThrowUserError("invalid_regexp") unless (eval {qr/$regexp/});
|
|
|
|
|
|
|
|
# We use SqlQuote and FILTER html on name, description and regexp.
|
|
|
|
# So they are safe to be detaint
|
|
|
|
trick_taint($name);
|
|
|
|
trick_taint($desc);
|
|
|
|
trick_taint($regexp);
|
2000-04-26 23:35:51 +04:00
|
|
|
|
|
|
|
# Add the new group
|
|
|
|
SendSQL("INSERT INTO groups ( " .
|
2002-09-22 21:15:13 +04:00
|
|
|
"name, description, isbuggroup, userregexp, isactive, last_changed " .
|
2000-04-26 23:35:51 +04:00
|
|
|
" ) VALUES ( " .
|
2002-09-22 21:15:13 +04:00
|
|
|
SqlQuote($name) . ", " .
|
|
|
|
SqlQuote($desc) . ", " .
|
2000-04-26 23:35:51 +04:00
|
|
|
"1," .
|
2002-09-22 21:15:13 +04:00
|
|
|
SqlQuote($regexp) . ", " .
|
|
|
|
$isactive . ", NOW())" );
|
|
|
|
SendSQL("SELECT last_insert_id()");
|
|
|
|
my $gid = FetchOneColumn();
|
|
|
|
my $admin = GroupNameToId('admin');
|
2004-07-27 20:33:41 +04:00
|
|
|
# Since we created a new group, give the "admin" group all privileges
|
|
|
|
# initially.
|
|
|
|
SendSQL("INSERT INTO group_group_map (member_id, grantor_id, grant_type)
|
|
|
|
VALUES ($admin, $gid, " . GROUP_MEMBERSHIP . ")");
|
|
|
|
SendSQL("INSERT INTO group_group_map (member_id, grantor_id, grant_type)
|
|
|
|
VALUES ($admin, $gid, " . GROUP_BLESS . ")");
|
|
|
|
SendSQL("INSERT INTO group_group_map (member_id, grantor_id, grant_type)
|
|
|
|
VALUES ($admin, $gid, " . GROUP_VISIBLE . ")");
|
2002-11-24 22:56:34 +03:00
|
|
|
# Permit all existing products to use the new group if makeproductgroups.
|
2004-07-13 09:12:33 +04:00
|
|
|
if ($cgi->param('insertnew')) {
|
2002-11-24 22:56:34 +03:00
|
|
|
SendSQL("INSERT INTO group_control_map " .
|
|
|
|
"(group_id, product_id, entry, membercontrol, " .
|
|
|
|
"othercontrol, canedit) " .
|
|
|
|
"SELECT $gid, products.id, 0, " .
|
|
|
|
CONTROLMAPSHOWN . ", " .
|
|
|
|
CONTROLMAPNA . ", 0 " .
|
|
|
|
"FROM products");
|
|
|
|
}
|
2004-06-16 09:04:48 +04:00
|
|
|
RederiveRegexp($regexp, $gid);
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
$template->process("admin/groups/created.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-04-26 23:35:51 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='del' -> ask if user really wants to delete
|
|
|
|
#
|
|
|
|
# (next action would be 'delete')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'del') {
|
2004-07-13 09:12:33 +04:00
|
|
|
my $gid = trim($cgi->param('group') || '');
|
|
|
|
ThrowUserError("group_not_specified") unless ($gid);
|
2004-05-23 11:07:50 +04:00
|
|
|
detaint_natural($gid);
|
2004-07-13 09:12:33 +04:00
|
|
|
|
2004-05-23 11:07:50 +04:00
|
|
|
SendSQL("SELECT id FROM groups WHERE id=$gid");
|
2004-07-13 09:12:33 +04:00
|
|
|
ThrowUserError("invalid_group_ID") unless FetchOneColumn();
|
|
|
|
|
2000-04-26 23:35:51 +04:00
|
|
|
SendSQL("SELECT name,description " .
|
|
|
|
"FROM groups " .
|
2004-07-13 09:12:33 +04:00
|
|
|
"WHERE id = $gid");
|
2000-04-26 23:35:51 +04:00
|
|
|
|
|
|
|
my ($name, $desc) = FetchSQLData();
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my $hasusers = 0;
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT user_id FROM user_group_map
|
|
|
|
WHERE group_id = $gid AND isbless = 0");
|
2004-07-13 09:12:33 +04:00
|
|
|
if (FetchOneColumn()) {
|
|
|
|
$hasusers = 1;
|
2000-06-23 22:03:47 +04:00
|
|
|
}
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my $hasbugs = 0;
|
|
|
|
my $buglist = "";
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT bug_id FROM bug_group_map WHERE group_id = $gid");
|
2004-07-13 09:12:33 +04:00
|
|
|
|
2000-06-23 22:03:47 +04:00
|
|
|
if (MoreSQLData()) {
|
2004-07-13 09:12:33 +04:00
|
|
|
$hasbugs = 1;
|
2002-09-22 21:15:13 +04:00
|
|
|
my $buglist = "0";
|
2004-07-13 09:12:33 +04:00
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
while (MoreSQLData()) {
|
|
|
|
my ($bug) = FetchSQLData();
|
|
|
|
$buglist .= "," . $bug;
|
|
|
|
}
|
2000-06-23 22:03:47 +04:00
|
|
|
}
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my $hasproduct = 0;
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("SELECT name FROM products WHERE name=" . SqlQuote($name));
|
2000-06-23 22:03:47 +04:00
|
|
|
if (MoreSQLData()) {
|
2004-07-13 09:12:33 +04:00
|
|
|
$hasproduct = 1;
|
2000-06-23 22:03:47 +04:00
|
|
|
}
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
$vars->{'gid'} = $gid;
|
|
|
|
$vars->{'name'} = $name;
|
|
|
|
$vars->{'description'} = $desc;
|
|
|
|
$vars->{'hasusers'} = $hasusers;
|
|
|
|
$vars->{'hasbugs'} = $hasbugs;
|
|
|
|
$vars->{'hasproduct'} = $hasproduct;
|
|
|
|
$vars->{'buglist'} = $buglist;
|
2000-04-26 23:35:51 +04:00
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
$template->process("admin/groups/delete.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2000-04-26 23:35:51 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='delete' -> really delete the group
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'delete') {
|
2004-07-13 09:12:33 +04:00
|
|
|
my $gid = trim($cgi->param('group') || '');
|
|
|
|
ThrowUserError("group_not_specified") unless ($gid);
|
2004-05-23 11:07:50 +04:00
|
|
|
detaint_natural($gid);
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
SendSQL("SELECT name FROM groups WHERE id = $gid");
|
2000-06-23 22:03:47 +04:00
|
|
|
my ($name) = FetchSQLData();
|
|
|
|
|
|
|
|
my $cantdelete = 0;
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT user_id FROM user_group_map
|
|
|
|
WHERE group_id = $gid AND isbless = 0");
|
2000-06-23 22:03:47 +04:00
|
|
|
if (FetchOneColumn()) {
|
2004-07-13 09:12:33 +04:00
|
|
|
if (!defined $cgi->param('removeusers')) {
|
|
|
|
$cantdelete = 1;
|
|
|
|
}
|
2000-06-23 22:03:47 +04:00
|
|
|
}
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT bug_id FROM bug_group_map WHERE group_id = $gid");
|
2000-06-23 22:03:47 +04:00
|
|
|
if (FetchOneColumn()) {
|
2004-07-13 09:12:33 +04:00
|
|
|
if (!defined $cgi->param('removebugs')) {
|
|
|
|
$cantdelete = 1;
|
|
|
|
}
|
2000-06-23 22:03:47 +04:00
|
|
|
}
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("SELECT name FROM products WHERE name=" . SqlQuote($name));
|
2000-06-23 22:03:47 +04:00
|
|
|
if (FetchOneColumn()) {
|
2004-07-13 09:12:33 +04:00
|
|
|
if (!defined $cgi->param('unbind')) {
|
|
|
|
$cantdelete = 1;
|
|
|
|
}
|
2000-06-23 22:03:47 +04:00
|
|
|
}
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
if (!$cantdelete) {
|
|
|
|
SendSQL("DELETE FROM user_group_map WHERE group_id = $gid");
|
|
|
|
SendSQL("DELETE FROM group_group_map WHERE grantor_id = $gid");
|
|
|
|
SendSQL("DELETE FROM bug_group_map WHERE group_id = $gid");
|
|
|
|
SendSQL("DELETE FROM group_control_map WHERE group_id = $gid");
|
|
|
|
SendSQL("DELETE FROM groups WHERE id = $gid");
|
2000-06-23 22:03:47 +04:00
|
|
|
}
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
$vars->{'gid'} = $gid;
|
|
|
|
$vars->{'name'} = $name;
|
|
|
|
$vars->{'cantdelete'} = $cantdelete;
|
2002-09-22 21:15:13 +04:00
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
$template->process("admin/groups/deleted.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-04-26 23:35:51 +04:00
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2002-09-22 21:15:13 +04:00
|
|
|
# action='postchanges' -> update the groups
|
2000-04-26 23:35:51 +04:00
|
|
|
#
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
if ($action eq 'postchanges') {
|
2004-03-26 18:18:07 +03:00
|
|
|
# ZLL: Bug 181589: we need to have something to remove explictly listed users from
|
|
|
|
# groups in order for the conversion to 2.18 groups to work
|
2004-07-13 09:12:33 +04:00
|
|
|
my $action;
|
|
|
|
|
|
|
|
if ($cgi->param('remove_explicit_members')) {
|
|
|
|
$action = 1;
|
|
|
|
} elsif ($cgi->param('remove_explicit_members_regexp')) {
|
|
|
|
$action = 2;
|
|
|
|
} else {
|
|
|
|
$action = 3;
|
2004-03-26 18:18:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
my ($gid, $chgs) = doGroupChanges();
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
$vars->{'action'} = $action;
|
|
|
|
$vars->{'changes'} = $chgs;
|
|
|
|
$vars->{'gid'} = $gid;
|
|
|
|
$vars->{'name'} = $cgi->param('name');
|
|
|
|
if ($action == 2) {
|
|
|
|
$vars->{'regexp'} = $cgi->param("rexp");
|
2004-03-26 18:18:07 +03:00
|
|
|
}
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
$template->process("admin/groups/change.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2004-03-26 18:18:07 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($action eq 'remove_all_regexp') || ($action eq 'remove_all')) {
|
2004-07-13 09:12:33 +04:00
|
|
|
# remove all explicit users from the group with gid $cgi->param('group')
|
|
|
|
# that match the regexp stored in the DB for that group
|
2004-03-26 18:18:07 +03:00
|
|
|
# or all of them period
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my $gid = $cgi->param('group');
|
|
|
|
ThrowUserError("group_not_specified") unless ($gid);
|
2004-05-23 11:07:50 +04:00
|
|
|
detaint_natural($gid);
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2004-03-26 18:18:07 +03:00
|
|
|
my $sth = $dbh->prepare("SELECT name, userregexp FROM groups
|
|
|
|
WHERE id = ?");
|
|
|
|
$sth->execute($gid);
|
|
|
|
my ($name, $regexp) = $sth->fetchrow_array();
|
|
|
|
$dbh->do("LOCK TABLES
|
|
|
|
groups WRITE,
|
|
|
|
profiles READ,
|
|
|
|
user_group_map WRITE");
|
|
|
|
$sth = $dbh->prepare("SELECT user_group_map.user_id, profiles.login_name
|
|
|
|
FROM user_group_map, profiles
|
|
|
|
WHERE user_group_map.user_id = profiles.userid
|
|
|
|
AND user_group_map.group_id = ?
|
2004-06-16 09:04:48 +04:00
|
|
|
AND grant_type = ?
|
2004-03-26 18:18:07 +03:00
|
|
|
AND isbless = 0");
|
2004-06-16 09:04:48 +04:00
|
|
|
$sth->execute($gid, GRANT_DIRECT);
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my @users;
|
2004-03-26 18:18:07 +03:00
|
|
|
my $sth2 = $dbh->prepare("DELETE FROM user_group_map
|
|
|
|
WHERE user_id = ?
|
|
|
|
AND isbless = 0
|
|
|
|
AND group_id = ?");
|
|
|
|
while ( my ($userid, $userlogin) = $sth->fetchrow_array() ) {
|
|
|
|
if ((($regexp =~ /\S/) && ($userlogin =~ m/$regexp/i))
|
|
|
|
|| ($action eq 'remove_all'))
|
|
|
|
{
|
|
|
|
$sth2->execute($userid,$gid);
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my $user = {};
|
|
|
|
$user->{'login'} = $userlogin;
|
|
|
|
push(@users, $user);
|
2004-03-26 18:18:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sth = $dbh->prepare("UPDATE groups
|
|
|
|
SET last_changed = NOW()
|
|
|
|
WHERE id = ?");
|
|
|
|
$sth->execute($gid);
|
|
|
|
$dbh->do("UNLOCK TABLES");
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
$vars->{'users'} = \@users;
|
|
|
|
$vars->{'name'} = $name;
|
|
|
|
$vars->{'regexp'} = $regexp;
|
|
|
|
$vars->{'remove_all'} = ($action eq 'remove_all');
|
|
|
|
$vars->{'gid'} = $gid;
|
|
|
|
|
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
$template->process("admin/groups/remove.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2004-03-26 18:18:07 +03:00
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
exit;
|
|
|
|
}
|
2004-03-26 18:18:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# No valid action found
|
|
|
|
#
|
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
ThrowCodeError("action_unrecognized", $vars);
|
2004-03-26 18:18:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Helper sub to handle the making of changes to a group
|
|
|
|
sub doGroupChanges {
|
2004-07-13 09:12:33 +04:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
|
|
|
|
my $gid = trim($cgi->param('group') || '');
|
|
|
|
ThrowUserError("group_not_specified") unless ($gid);
|
2004-05-23 11:07:50 +04:00
|
|
|
detaint_natural($gid);
|
2004-07-13 09:12:33 +04:00
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT isbuggroup FROM groups WHERE id = $gid");
|
|
|
|
my ($isbuggroup) = FetchSQLData();
|
2000-04-26 23:35:51 +04:00
|
|
|
my $chgs = 0;
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
if (($isbuggroup == 1) && ($cgi->param('oldname') ne $cgi->param("name"))) {
|
2002-09-22 21:15:13 +04:00
|
|
|
$chgs = 1;
|
|
|
|
SendSQL("UPDATE groups SET name = " .
|
2004-07-13 09:12:33 +04:00
|
|
|
SqlQuote($cgi->param("name")) . " WHERE id = $gid");
|
2002-09-22 21:15:13 +04:00
|
|
|
}
|
2004-07-13 09:12:33 +04:00
|
|
|
if (($isbuggroup == 1) && ($cgi->param('olddesc') ne $cgi->param("desc"))) {
|
2002-09-22 21:15:13 +04:00
|
|
|
$chgs = 1;
|
|
|
|
SendSQL("UPDATE groups SET description = " .
|
2004-07-13 09:12:33 +04:00
|
|
|
SqlQuote($cgi->param("desc")) . " WHERE id = $gid");
|
2002-09-22 21:15:13 +04:00
|
|
|
}
|
2004-07-13 09:12:33 +04:00
|
|
|
if ($cgi->param("oldrexp") ne $cgi->param("rexp")) {
|
2002-09-22 21:15:13 +04:00
|
|
|
$chgs = 1;
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
my $rexp = $cgi->param('rexp');
|
|
|
|
ThrowUserError("invalid_regexp") unless (eval {qr/$rexp/});
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("UPDATE groups SET userregexp = " .
|
2004-07-13 09:12:33 +04:00
|
|
|
SqlQuote($rexp) . " WHERE id = $gid");
|
2004-06-16 09:04:48 +04:00
|
|
|
RederiveRegexp($::FORM{"rexp"}, $gid);
|
2002-09-22 21:15:13 +04:00
|
|
|
}
|
2004-07-13 09:12:33 +04:00
|
|
|
if (($isbuggroup == 1) && ($cgi->param("oldisactive") ne $cgi->param("isactive"))) {
|
2002-09-22 21:15:13 +04:00
|
|
|
$chgs = 1;
|
|
|
|
SendSQL("UPDATE groups SET isactive = " .
|
2004-07-13 09:12:33 +04:00
|
|
|
SqlQuote($cgi->param("isactive")) . " WHERE id = $gid");
|
2002-09-22 21:15:13 +04:00
|
|
|
}
|
2004-07-13 09:12:33 +04:00
|
|
|
|
|
|
|
foreach my $b (grep {/^oldgrp-\d*$/} $cgi->param()) {
|
|
|
|
if (defined($cgi->param($b))) {
|
|
|
|
$b =~ /^oldgrp-(\d+)$/;
|
|
|
|
my $v = $1;
|
|
|
|
my $grp = $cgi->param("grp-$v") || 0;
|
|
|
|
if ($cgi->param("oldgrp-$v") != $grp) {
|
2000-04-26 23:35:51 +04:00
|
|
|
$chgs = 1;
|
2002-09-22 21:15:13 +04:00
|
|
|
if ($grp != 0) {
|
|
|
|
SendSQL("INSERT INTO group_group_map
|
2004-07-27 20:33:41 +04:00
|
|
|
(member_id, grantor_id, grant_type)
|
|
|
|
VALUES ($v, $gid," . GROUP_MEMBERSHIP . ")");
|
2000-04-26 23:35:51 +04:00
|
|
|
} else {
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("DELETE FROM group_group_map
|
|
|
|
WHERE member_id = $v AND grantor_id = $gid
|
2004-07-27 20:33:41 +04:00
|
|
|
AND grant_type = " . GROUP_MEMBERSHIP);
|
2000-04-26 23:35:51 +04:00
|
|
|
}
|
|
|
|
}
|
2002-09-22 21:15:13 +04:00
|
|
|
|
2004-07-13 09:12:33 +04:00
|
|
|
my $bless = $cgi->param("bless-$v") || 0;
|
|
|
|
if ($cgi->param("oldbless-$v") != $bless) {
|
2001-06-06 07:16:52 +04:00
|
|
|
$chgs = 1;
|
2002-09-22 21:15:13 +04:00
|
|
|
if ($bless != 0) {
|
|
|
|
SendSQL("INSERT INTO group_group_map
|
2004-07-27 20:33:41 +04:00
|
|
|
(member_id, grantor_id, grant_type)
|
|
|
|
VALUES ($v, $gid," . GROUP_BLESS . ")");
|
|
|
|
} else {
|
|
|
|
SendSQL("DELETE FROM group_group_map
|
|
|
|
WHERE member_id = $v AND grantor_id = $gid
|
|
|
|
AND grant_type = " . GROUP_BLESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $cansee = $cgi->param("cansee-$v") || 0;
|
|
|
|
if (Param("usevisibilitygroups")
|
|
|
|
&& ($cgi->param("oldcansee-$v") != $cansee)) {
|
|
|
|
$chgs = 1;
|
|
|
|
if ($cansee != 0) {
|
|
|
|
SendSQL("INSERT INTO group_group_map
|
|
|
|
(member_id, grantor_id, grant_type)
|
|
|
|
VALUES ($v, $gid," . GROUP_VISIBLE . ")");
|
2001-06-06 07:16:52 +04:00
|
|
|
} else {
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("DELETE FROM group_group_map
|
|
|
|
WHERE member_id = $v AND grantor_id = $gid
|
2004-07-27 20:33:41 +04:00
|
|
|
AND grant_type = " . GROUP_VISIBLE);
|
2001-06-06 07:16:52 +04:00
|
|
|
}
|
|
|
|
}
|
2002-09-22 21:15:13 +04:00
|
|
|
|
2000-04-26 23:35:51 +04:00
|
|
|
}
|
|
|
|
}
|
2004-03-26 18:18:07 +03:00
|
|
|
|
|
|
|
if ($chgs) {
|
|
|
|
# mark the changes
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("UPDATE groups SET last_changed = NOW() WHERE id = $gid");
|
2000-04-26 23:35:51 +04:00
|
|
|
}
|
2004-07-13 09:12:33 +04:00
|
|
|
return $gid, $chgs;
|
2000-04-26 23:35:51 +04:00
|
|
|
}
|