2006-02-22 23:54:13 +00:00
|
|
|
#!/usr/bin/perl -wT
|
1999-10-12 23:00:35 +00:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-01 23:33:56 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2005-02-28 20:41:45 +00:00
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
1999-11-01 23:33:56 +00:00
|
|
|
#
|
2005-02-28 20:41:45 +00:00
|
|
|
# Contributor(s): Marc Schumann <wurblzap@gmail.com>
|
2005-08-31 08:00:25 +00:00
|
|
|
# Lance Larsh <lance.larsh@oracle.com>
|
2005-11-30 12:00:54 +00:00
|
|
|
# Frédéric Buclin <LpSolit@gmail.com>
|
2006-02-21 22:25:52 +00:00
|
|
|
# David Lawrence <dkl@redhat.com>
|
2006-02-25 23:40:30 +00:00
|
|
|
# Vlad Dascalu <jocuri@softhome.net>
|
|
|
|
# Gavin Shelley <bugzilla@chimpychompy.org>
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
use strict;
|
2002-04-29 19:32:29 +00:00
|
|
|
use lib ".";
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-03-07 18:11:37 +00:00
|
|
|
use Bugzilla;
|
2006-06-21 00:44:48 +00:00
|
|
|
use Bugzilla::Constants;
|
|
|
|
use Bugzilla::Util;
|
|
|
|
use Bugzilla::Error;
|
2003-06-03 09:48:15 +00:00
|
|
|
use Bugzilla::User;
|
2005-08-26 10:28:07 +00:00
|
|
|
use Bugzilla::Bug;
|
|
|
|
use Bugzilla::Flag;
|
2005-09-05 20:41:21 +00:00
|
|
|
use Bugzilla::Field;
|
2005-11-30 12:00:54 +00:00
|
|
|
use Bugzilla::Group;
|
2003-06-03 09:48:15 +00:00
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
my $user = Bugzilla->login(LOGIN_REQUIRED);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-03-07 18:11:37 +00:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
my $template = Bugzilla->template;
|
2005-02-28 20:41:45 +00:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-03-07 18:11:37 +00:00
|
|
|
my $userid = $user->id;
|
|
|
|
my $editusers = $user->in_group('editusers');
|
2006-07-06 06:12:05 +00:00
|
|
|
local our $vars = {};
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
# Reject access if there is no sense in continuing.
|
|
|
|
$editusers
|
2005-09-15 22:01:56 +00:00
|
|
|
|| $user->can_bless()
|
2005-02-28 20:41:45 +00:00
|
|
|
|| ThrowUserError("auth_failure", {group => "editusers",
|
|
|
|
reason => "cant_bless",
|
|
|
|
action => "edit",
|
|
|
|
object => "users"});
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
print $cgi->header();
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-03-07 18:11:37 +00:00
|
|
|
# Common CGI params
|
2005-11-30 12:00:54 +00:00
|
|
|
my $action = $cgi->param('action') || 'search';
|
|
|
|
my $otherUserID = $cgi->param('userid');
|
|
|
|
my $otherUserLogin = $cgi->param('user');
|
2005-03-07 18:11:37 +00:00
|
|
|
|
|
|
|
# Prefill template vars with data used in all or nearly all templates
|
2005-02-28 20:41:45 +00:00
|
|
|
$vars->{'editusers'} = $editusers;
|
|
|
|
mirrorListSelectionValues();
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
if ($action eq 'search') {
|
|
|
|
# Allow to restrict the search to any group the user is allowed to bless.
|
2005-08-13 20:22:12 +00:00
|
|
|
$vars->{'restrictablegroups'} = $user->bless_groups();
|
2005-02-28 20:41:45 +00:00
|
|
|
$template->process('admin/users/search.html.tmpl', $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
} elsif ($action eq 'list') {
|
2006-02-21 22:25:52 +00:00
|
|
|
my $matchvalue = $cgi->param('matchvalue') || '';
|
2005-02-28 20:41:45 +00:00
|
|
|
my $matchstr = $cgi->param('matchstr');
|
|
|
|
my $matchtype = $cgi->param('matchtype');
|
|
|
|
my $grouprestrict = $cgi->param('grouprestrict') || '0';
|
|
|
|
my $query = 'SELECT DISTINCT userid, login_name, realname, disabledtext ' .
|
|
|
|
'FROM profiles';
|
|
|
|
my @bindValues;
|
|
|
|
my $nextCondition;
|
2005-04-16 16:55:32 +00:00
|
|
|
my $visibleGroups;
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
# If a group ID is given, make sure it is a valid one.
|
|
|
|
my $group;
|
|
|
|
if ($grouprestrict) {
|
|
|
|
$group = new Bugzilla::Group(scalar $cgi->param('groupid'));
|
|
|
|
$group || ThrowUserError('invalid_group_ID');
|
|
|
|
}
|
|
|
|
|
2006-07-03 21:26:22 +00:00
|
|
|
if (!$editusers && Bugzilla->params->{'usevisibilitygroups'}) {
|
2005-02-28 20:41:45 +00:00
|
|
|
# Show only users in visible groups.
|
2005-07-25 07:56:38 +00:00
|
|
|
$visibleGroups = $user->visible_groups_as_string();
|
2005-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
if ($visibleGroups) {
|
|
|
|
$query .= qq{, user_group_map AS ugm
|
|
|
|
WHERE ugm.user_id = profiles.userid
|
|
|
|
AND ugm.isbless = 0
|
|
|
|
AND ugm.group_id IN ($visibleGroups)
|
|
|
|
};
|
|
|
|
$nextCondition = 'AND';
|
|
|
|
}
|
2000-02-17 05:15:23 +00:00
|
|
|
} else {
|
2005-04-16 16:55:32 +00:00
|
|
|
$visibleGroups = 1;
|
2005-02-28 20:41:45 +00:00
|
|
|
if ($grouprestrict eq '1') {
|
2006-01-03 08:40:45 +00:00
|
|
|
$query .= qq{, user_group_map AS ugm
|
|
|
|
WHERE ugm.user_id = profiles.userid
|
|
|
|
AND ugm.isbless = 0
|
|
|
|
};
|
|
|
|
$nextCondition = 'AND';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$nextCondition = 'WHERE';
|
2005-02-28 20:41:45 +00:00
|
|
|
}
|
2000-02-17 05:15:23 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:55:32 +00:00
|
|
|
if (!$visibleGroups) {
|
|
|
|
$vars->{'users'} = {};
|
2004-03-21 14:26:58 +00:00
|
|
|
}
|
2005-04-16 16:55:32 +00:00
|
|
|
else {
|
2006-02-21 22:25:52 +00:00
|
|
|
# Handle selection by login name, real name, or userid.
|
2005-04-16 16:55:32 +00:00
|
|
|
if (defined($matchtype)) {
|
2005-08-31 08:00:25 +00:00
|
|
|
$query .= " $nextCondition ";
|
2006-02-21 22:25:52 +00:00
|
|
|
my $expr = "";
|
|
|
|
if ($matchvalue eq 'userid') {
|
|
|
|
if ($matchstr) {
|
|
|
|
my $stored_matchstr = $matchstr;
|
|
|
|
detaint_natural($matchstr)
|
|
|
|
|| ThrowUserError('illegal_user_id', {userid => $stored_matchstr});
|
|
|
|
}
|
|
|
|
$expr = "profiles.userid";
|
|
|
|
} elsif ($matchvalue eq 'realname') {
|
|
|
|
$expr = "profiles.realname";
|
|
|
|
} else {
|
|
|
|
$expr = "profiles.login_name";
|
|
|
|
}
|
2005-04-16 16:55:32 +00:00
|
|
|
if ($matchtype eq 'regexp') {
|
2005-08-31 08:00:25 +00:00
|
|
|
$query .= $dbh->sql_regexp($expr, '?');
|
2005-04-16 16:55:32 +00:00
|
|
|
$matchstr = '.' unless $matchstr;
|
|
|
|
} elsif ($matchtype eq 'notregexp') {
|
2005-08-31 08:00:25 +00:00
|
|
|
$query .= $dbh->sql_not_regexp($expr, '?');
|
2005-04-16 16:55:32 +00:00
|
|
|
$matchstr = '.' unless $matchstr;
|
2005-09-04 18:45:11 +00:00
|
|
|
} elsif ($matchtype eq 'exact') {
|
|
|
|
$query .= $expr . ' = ?';
|
|
|
|
$matchstr = '.' unless $matchstr;
|
2005-04-16 16:55:32 +00:00
|
|
|
} else { # substr or unknown
|
2005-11-04 10:04:47 +00:00
|
|
|
$query .= $dbh->sql_istrcmp($expr, '?', 'LIKE');
|
2005-04-16 16:55:32 +00:00
|
|
|
$matchstr = "%$matchstr%";
|
|
|
|
}
|
|
|
|
$nextCondition = 'AND';
|
|
|
|
# We can trick_taint because we use the value in a SELECT only,
|
|
|
|
# using a placeholder.
|
|
|
|
trick_taint($matchstr);
|
|
|
|
push(@bindValues, $matchstr);
|
|
|
|
}
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-04-16 16:55:32 +00:00
|
|
|
# Handle selection by group.
|
|
|
|
if ($grouprestrict eq '1') {
|
2005-08-22 20:59:56 +00:00
|
|
|
my $grouplist = join(',',
|
2005-11-30 12:00:54 +00:00
|
|
|
@{Bugzilla::User->flatten_group_membership($group->id)});
|
2006-01-03 08:40:45 +00:00
|
|
|
$query .= " $nextCondition ugm.group_id IN($grouplist) ";
|
2005-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
$query .= ' ORDER BY profiles.login_name';
|
|
|
|
|
|
|
|
$vars->{'users'} = $dbh->selectall_arrayref($query,
|
|
|
|
{'Slice' => {}},
|
|
|
|
@bindValues);
|
2005-09-04 18:45:11 +00:00
|
|
|
|
2003-07-19 20:37:20 +00:00
|
|
|
}
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2005-09-04 18:45:11 +00:00
|
|
|
if ($matchtype eq 'exact' && scalar(@{$vars->{'users'}}) == 1) {
|
2005-11-30 12:00:54 +00:00
|
|
|
my $match_user_id = $vars->{'users'}[0]->{'userid'};
|
|
|
|
my $match_user = check_user($match_user_id);
|
|
|
|
edit_processing($match_user);
|
2005-09-04 18:45:11 +00:00
|
|
|
} else {
|
|
|
|
$template->process('admin/users/list.html.tmpl', $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
} elsif ($action eq 'add') {
|
|
|
|
$editusers || ThrowUserError("auth_failure", {group => "editusers",
|
|
|
|
action => "add",
|
|
|
|
object => "users"});
|
|
|
|
|
|
|
|
$template->process('admin/users/create.html.tmpl', $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
} elsif ($action eq 'new') {
|
|
|
|
$editusers || ThrowUserError("auth_failure", {group => "editusers",
|
|
|
|
action => "add",
|
|
|
|
object => "users"});
|
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
my $login = $cgi->param('login');
|
|
|
|
my $password = $cgi->param('password');
|
|
|
|
my $realname = trim($cgi->param('name') || '');
|
|
|
|
my $disabledtext = trim($cgi->param('disabledtext') || '');
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# Lock tables during the check+creation session.
|
2006-06-07 20:31:10 +00:00
|
|
|
$dbh->bz_lock_tables('profiles WRITE', 'profiles_activity WRITE',
|
|
|
|
'email_setting WRITE', 'user_group_map WRITE',
|
|
|
|
'groups READ', 'tokens READ', 'fielddefs READ');
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
# Validity checks
|
|
|
|
$login || ThrowUserError('user_login_required');
|
2005-08-15 17:43:38 +00:00
|
|
|
validate_email_syntax($login)
|
|
|
|
|| ThrowUserError('illegal_email_address', {addr => $login});
|
|
|
|
is_available_username($login)
|
|
|
|
|| ThrowUserError('account_exists', {email => $login});
|
2006-05-07 20:13:49 +00:00
|
|
|
validate_password($password);
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
# Login and password are validated now, and realname and disabledtext
|
|
|
|
# are allowed to contain anything
|
|
|
|
trick_taint($login);
|
|
|
|
trick_taint($realname);
|
|
|
|
trick_taint($password);
|
|
|
|
trick_taint($disabledtext);
|
|
|
|
|
|
|
|
insert_new_user($login, $realname, $password, $disabledtext);
|
2005-11-30 12:00:54 +00:00
|
|
|
my $new_user_id = $dbh->bz_last_key('profiles', 'userid');
|
2005-02-28 20:41:45 +00:00
|
|
|
$dbh->bz_unlock_tables();
|
2005-11-30 12:00:54 +00:00
|
|
|
userDataToVars($new_user_id);
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
$vars->{'message'} = 'account_created';
|
|
|
|
$template->process('admin/users/edit.html.tmpl', $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
} elsif ($action eq 'edit') {
|
2005-11-30 12:00:54 +00:00
|
|
|
my $otherUser = check_user($otherUserID, $otherUserLogin);
|
|
|
|
edit_processing($otherUser);
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
} elsif ($action eq 'update') {
|
2005-11-30 12:00:54 +00:00
|
|
|
my $otherUser = check_user($otherUserID, $otherUserLogin);
|
|
|
|
$otherUserID = $otherUser->id;
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
my $logoutNeeded = 0;
|
|
|
|
my @changedFields;
|
|
|
|
|
|
|
|
# Lock tables during the check+update session.
|
|
|
|
$dbh->bz_lock_tables('profiles WRITE',
|
|
|
|
'profiles_activity WRITE',
|
|
|
|
'fielddefs READ',
|
|
|
|
'tokens WRITE',
|
|
|
|
'logincookies WRITE',
|
|
|
|
'groups READ',
|
|
|
|
'user_group_map WRITE',
|
2005-04-19 17:36:25 +00:00
|
|
|
'group_group_map READ',
|
|
|
|
'group_group_map AS ggm READ');
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2005-09-25 20:51:52 +00:00
|
|
|
$editusers || $user->can_see_user($otherUser)
|
2005-02-28 20:41:45 +00:00
|
|
|
|| ThrowUserError('auth_failure', {reason => "not_visible",
|
|
|
|
action => "modify",
|
2005-03-05 00:18:48 +00:00
|
|
|
object => "user"});
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
# Cleanups
|
2005-03-07 18:11:37 +00:00
|
|
|
my $loginold = $cgi->param('loginold') || '';
|
|
|
|
my $realnameold = $cgi->param('nameold') || '';
|
|
|
|
my $disabledtextold = $cgi->param('disabledtextold') || '';
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
my $login = $cgi->param('login');
|
|
|
|
my $password = $cgi->param('password');
|
|
|
|
my $realname = trim($cgi->param('name') || '');
|
|
|
|
my $disabledtext = trim($cgi->param('disabledtext') || '');
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# Update profiles table entry; silently skip doing this if the user
|
|
|
|
# is not authorized.
|
|
|
|
if ($editusers) {
|
|
|
|
my @values;
|
|
|
|
|
|
|
|
if ($login ne $loginold) {
|
|
|
|
# Validate, then trick_taint.
|
2005-03-05 00:18:48 +00:00
|
|
|
$login || ThrowUserError('user_login_required');
|
2005-08-15 17:43:38 +00:00
|
|
|
validate_email_syntax($login)
|
|
|
|
|| ThrowUserError('illegal_email_address', {addr => $login});
|
|
|
|
is_available_username($login)
|
|
|
|
|| ThrowUserError('account_exists', {email => $login});
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
trick_taint($login);
|
|
|
|
push(@changedFields, 'login_name');
|
|
|
|
push(@values, $login);
|
|
|
|
$logoutNeeded = 1;
|
|
|
|
|
|
|
|
# Since we change the login, silently delete any tokens.
|
|
|
|
$dbh->do('DELETE FROM tokens WHERE userid = ?', {}, $otherUserID);
|
2001-10-13 01:36:17 +00:00
|
|
|
}
|
2005-02-28 20:41:45 +00:00
|
|
|
if ($realname ne $realnameold) {
|
|
|
|
# The real name may be anything; we use a placeholder for our
|
|
|
|
# INSERT, and we rely on displaying code to FILTER html.
|
|
|
|
trick_taint($realname);
|
|
|
|
push(@changedFields, 'realname');
|
|
|
|
push(@values, $realname);
|
2001-10-13 01:36:17 +00:00
|
|
|
}
|
2005-02-28 20:41:45 +00:00
|
|
|
if ($password) {
|
|
|
|
# Validate, then trick_taint.
|
2006-05-07 20:13:49 +00:00
|
|
|
validate_password($password) if $password;
|
2005-02-28 20:41:45 +00:00
|
|
|
trick_taint($password);
|
|
|
|
push(@changedFields, 'cryptpassword');
|
|
|
|
push(@values, bz_crypt($password));
|
|
|
|
$logoutNeeded = 1;
|
2001-10-13 01:36:17 +00:00
|
|
|
}
|
2005-02-28 20:41:45 +00:00
|
|
|
if ($disabledtext ne $disabledtextold) {
|
|
|
|
# The disable text may be anything; we use a placeholder for our
|
|
|
|
# INSERT, and we rely on displaying code to FILTER html.
|
|
|
|
trick_taint($disabledtext);
|
|
|
|
push(@changedFields, 'disabledtext');
|
|
|
|
push(@values, $disabledtext);
|
|
|
|
$logoutNeeded = 1;
|
2000-01-18 22:41:26 +00:00
|
|
|
}
|
2005-02-28 20:41:45 +00:00
|
|
|
if (@changedFields) {
|
|
|
|
push (@values, $otherUserID);
|
2005-11-30 12:00:54 +00:00
|
|
|
$logoutNeeded && Bugzilla->logout_user($otherUser);
|
2005-02-28 20:41:45 +00:00
|
|
|
$dbh->do('UPDATE profiles SET ' .
|
|
|
|
join(' = ?,', @changedFields).' = ? ' .
|
|
|
|
'WHERE userid = ?',
|
|
|
|
undef, @values);
|
2005-03-07 18:11:37 +00:00
|
|
|
# XXX: should create profiles_activity entries.
|
2005-08-18 20:09:37 +00:00
|
|
|
#
|
|
|
|
# We create a new user object here because it needs to
|
|
|
|
# read information that may have changed since this
|
|
|
|
# script started.
|
|
|
|
my $newprofile = new Bugzilla::User($otherUserID);
|
|
|
|
$newprofile->derive_regexp_groups();
|
2000-01-18 18:34:01 +00:00
|
|
|
}
|
2000-02-17 05:15:23 +00:00
|
|
|
}
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# Update group settings.
|
|
|
|
my $sth_add_mapping = $dbh->prepare(
|
|
|
|
qq{INSERT INTO user_group_map (
|
|
|
|
user_id, group_id, isbless, grant_type
|
|
|
|
) VALUES (
|
|
|
|
?, ?, ?, ?
|
|
|
|
)
|
|
|
|
});
|
|
|
|
my $sth_remove_mapping = $dbh->prepare(
|
|
|
|
qq{DELETE FROM user_group_map
|
|
|
|
WHERE user_id = ?
|
|
|
|
AND group_id = ?
|
|
|
|
AND isbless = ?
|
|
|
|
AND grant_type = ?
|
|
|
|
});
|
|
|
|
|
|
|
|
my @groupsAddedTo;
|
|
|
|
my @groupsRemovedFrom;
|
|
|
|
my @groupsGrantedRightsToBless;
|
|
|
|
my @groupsDeniedRightsToBless;
|
|
|
|
|
|
|
|
# Regard only groups the user is allowed to bless and skip all others
|
|
|
|
# silently.
|
2005-03-07 18:11:37 +00:00
|
|
|
# XXX: checking for existence of each user_group_map entry
|
|
|
|
# would allow to display a friendlier error message on page reloads.
|
2005-08-13 20:22:12 +00:00
|
|
|
foreach (@{$user->bless_groups()}) {
|
2005-02-28 20:41:45 +00:00
|
|
|
my $id = $$_{'id'};
|
2005-04-12 18:08:21 +00:00
|
|
|
my $name = $$_{'name'};
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
# Change memberships.
|
|
|
|
my $oldgroupid = $cgi->param("oldgroup_$id") || '0';
|
|
|
|
my $groupid = $cgi->param("group_$id") || '0';
|
|
|
|
if ($groupid ne $oldgroupid) {
|
|
|
|
if ($groupid eq '0') {
|
|
|
|
$sth_remove_mapping->execute(
|
|
|
|
$otherUserID, $id, 0, GRANT_DIRECT);
|
2005-04-12 18:08:21 +00:00
|
|
|
push(@groupsRemovedFrom, $name);
|
2005-02-28 20:41:45 +00:00
|
|
|
} else {
|
|
|
|
$sth_add_mapping->execute(
|
|
|
|
$otherUserID, $id, 0, GRANT_DIRECT);
|
2005-04-12 18:08:21 +00:00
|
|
|
push(@groupsAddedTo, $name);
|
2005-02-28 20:41:45 +00:00
|
|
|
}
|
|
|
|
}
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# Only members of the editusers group may change bless grants.
|
|
|
|
# Skip silently if this is not the case.
|
|
|
|
if ($editusers) {
|
|
|
|
my $oldgroupid = $cgi->param("oldbless_$id") || '0';
|
|
|
|
my $groupid = $cgi->param("bless_$id") || '0';
|
|
|
|
if ($groupid ne $oldgroupid) {
|
|
|
|
if ($groupid eq '0') {
|
|
|
|
$sth_remove_mapping->execute(
|
|
|
|
$otherUserID, $id, 1, GRANT_DIRECT);
|
2005-04-12 18:08:21 +00:00
|
|
|
push(@groupsDeniedRightsToBless, $name);
|
2005-02-28 20:41:45 +00:00
|
|
|
} else {
|
|
|
|
$sth_add_mapping->execute(
|
|
|
|
$otherUserID, $id, 1, GRANT_DIRECT);
|
2005-04-12 18:08:21 +00:00
|
|
|
push(@groupsGrantedRightsToBless, $name);
|
2005-02-28 20:41:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-12 23:00:35 +00:00
|
|
|
}
|
2005-02-28 20:41:45 +00:00
|
|
|
if (@groupsAddedTo || @groupsRemovedFrom) {
|
|
|
|
$dbh->do(qq{INSERT INTO profiles_activity (
|
|
|
|
userid, who,
|
|
|
|
profiles_when, fieldid,
|
|
|
|
oldvalue, newvalue
|
|
|
|
) VALUES (
|
|
|
|
?, ?, now(), ?, ?, ?
|
|
|
|
)
|
|
|
|
},
|
|
|
|
undef,
|
|
|
|
($otherUserID, $userid,
|
2005-09-05 20:41:21 +00:00
|
|
|
get_field_id('bug_group'),
|
2005-02-28 20:41:45 +00:00
|
|
|
join(', ', @groupsRemovedFrom), join(', ', @groupsAddedTo)));
|
|
|
|
$dbh->do('UPDATE profiles SET refreshed_when=? WHERE userid = ?',
|
|
|
|
undef, ('1900-01-01 00:00:00', $otherUserID));
|
1999-10-12 23:00:35 +00:00
|
|
|
}
|
2005-03-07 18:11:37 +00:00
|
|
|
# XXX: should create profiles_activity entries for blesser changes.
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
$dbh->bz_unlock_tables();
|
|
|
|
|
2005-03-07 18:11:37 +00:00
|
|
|
# XXX: userDataToVars may be off when editing ourselves.
|
2005-02-28 20:41:45 +00:00
|
|
|
userDataToVars($otherUserID);
|
|
|
|
|
|
|
|
$vars->{'message'} = 'account_updated';
|
|
|
|
$vars->{'loginold'} = $loginold;
|
|
|
|
$vars->{'changed_fields'} = \@changedFields;
|
|
|
|
$vars->{'groups_added_to'} = \@groupsAddedTo;
|
|
|
|
$vars->{'groups_removed_from'} = \@groupsRemovedFrom;
|
|
|
|
$vars->{'groups_granted_rights_to_bless'} = \@groupsGrantedRightsToBless;
|
|
|
|
$vars->{'groups_denied_rights_to_bless'} = \@groupsDeniedRightsToBless;
|
|
|
|
$template->process('admin/users/edit.html.tmpl', $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
} elsif ($action eq 'del') {
|
2005-11-30 12:00:54 +00:00
|
|
|
my $otherUser = check_user($otherUserID, $otherUserLogin);
|
|
|
|
$otherUserID = $otherUser->id;
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2006-07-03 21:26:22 +00:00
|
|
|
Bugzilla->params->{'allowuserdeletion'}
|
|
|
|
|| ThrowUserError('users_deletion_disabled');
|
2005-02-28 20:41:45 +00:00
|
|
|
$editusers || ThrowUserError('auth_failure', {group => "editusers",
|
|
|
|
action => "delete",
|
|
|
|
object => "users"});
|
|
|
|
$vars->{'otheruser'} = $otherUser;
|
|
|
|
$vars->{'editcomponents'} = UserInGroup('editcomponents');
|
|
|
|
|
|
|
|
# Find other cross references.
|
2005-08-04 18:24:09 +00:00
|
|
|
$vars->{'assignee_or_qa'} = $dbh->selectrow_array(
|
2005-02-28 20:41:45 +00:00
|
|
|
qq{SELECT COUNT(*)
|
|
|
|
FROM bugs
|
2005-08-04 18:24:09 +00:00
|
|
|
WHERE assigned_to = ? OR qa_contact = ?},
|
|
|
|
undef, ($otherUserID, $otherUserID));
|
|
|
|
$vars->{'reporter'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM bugs WHERE reporter = ?',
|
|
|
|
undef, $otherUserID);
|
2005-02-28 20:41:45 +00:00
|
|
|
$vars->{'cc'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM cc WHERE who = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
$vars->{'bugs_activity'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM bugs_activity WHERE who = ?',
|
|
|
|
undef, $otherUserID);
|
2005-12-13 20:20:13 +00:00
|
|
|
$vars->{'email_setting'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM email_setting WHERE user_id = ?',
|
|
|
|
undef, $otherUserID);
|
2005-02-28 20:41:45 +00:00
|
|
|
$vars->{'flags'}{'requestee'} = $dbh->selectrow_array(
|
2006-04-14 16:50:47 +00:00
|
|
|
'SELECT COUNT(*) FROM flags WHERE requestee_id = ?',
|
2005-02-28 20:41:45 +00:00
|
|
|
undef, $otherUserID);
|
|
|
|
$vars->{'flags'}{'setter'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM flags WHERE setter_id = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
$vars->{'longdescs'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM longdescs WHERE who = ?',
|
|
|
|
undef, $otherUserID);
|
2006-07-13 20:08:00 +00:00
|
|
|
$vars->{'namedqueries'} = $dbh->selectcol_arrayref(
|
|
|
|
'SELECT id FROM namedqueries WHERE userid = ?',
|
|
|
|
undef,
|
|
|
|
$otherUserID);
|
|
|
|
if (@{$vars->{'namedqueries'}}) {
|
|
|
|
$vars->{'namedquery_group_map'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM namedquery_group_map WHERE namedquery_id IN' .
|
|
|
|
' (' . join(', ', @{$vars->{'namedqueries'}}) . ')');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$vars->{'namedquery_group_map'} = 0;
|
|
|
|
}
|
2005-12-13 20:20:13 +00:00
|
|
|
$vars->{'profile_setting'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM profile_setting WHERE user_id = ?',
|
|
|
|
undef, $otherUserID);
|
2005-02-28 20:41:45 +00:00
|
|
|
$vars->{'profiles_activity'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM profiles_activity WHERE who = ? AND userid != ?',
|
|
|
|
undef, ($otherUserID, $otherUserID));
|
|
|
|
$vars->{'series'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM series WHERE creator = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
$vars->{'votes'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM votes WHERE who = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
$vars->{'watch'}{'watched'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM watch WHERE watched = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
$vars->{'watch'}{'watcher'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM watch WHERE watcher = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
$vars->{'whine_events'} = $dbh->selectrow_array(
|
|
|
|
'SELECT COUNT(*) FROM whine_events WHERE owner_userid = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
$vars->{'whine_schedules'} = $dbh->selectrow_array(
|
|
|
|
qq{SELECT COUNT(distinct eventid)
|
|
|
|
FROM whine_schedules
|
|
|
|
WHERE mailto = ?
|
|
|
|
AND mailto_type = ?
|
|
|
|
},
|
|
|
|
undef, ($otherUserID, MAILTO_USER));
|
|
|
|
|
|
|
|
$template->process('admin/users/confirm-delete.html.tmpl', $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
} elsif ($action eq 'delete') {
|
2005-11-30 12:00:54 +00:00
|
|
|
my $otherUser = check_user($otherUserID, $otherUserLogin);
|
|
|
|
$otherUserID = $otherUser->id;
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2005-08-26 10:28:07 +00:00
|
|
|
# Cache for user accounts.
|
|
|
|
my %usercache = (0 => new Bugzilla::User());
|
|
|
|
my %updatedbugs;
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# Lock tables during the check+removal session.
|
2005-03-07 18:11:37 +00:00
|
|
|
# XXX: if there was some change on these tables after the deletion
|
|
|
|
# confirmation checks, we may do something here we haven't warned
|
|
|
|
# about.
|
2005-08-26 10:28:07 +00:00
|
|
|
$dbh->bz_lock_tables('bugs WRITE',
|
|
|
|
'bugs_activity WRITE',
|
|
|
|
'attachments READ',
|
|
|
|
'fielddefs READ',
|
|
|
|
'products READ',
|
2005-02-28 20:41:45 +00:00
|
|
|
'components READ',
|
|
|
|
'logincookies WRITE',
|
|
|
|
'profiles WRITE',
|
|
|
|
'profiles_activity WRITE',
|
2005-12-13 20:20:13 +00:00
|
|
|
'email_setting WRITE',
|
|
|
|
'profile_setting WRITE',
|
2005-08-26 10:28:07 +00:00
|
|
|
'bug_group_map READ',
|
2005-02-28 20:41:45 +00:00
|
|
|
'user_group_map WRITE',
|
|
|
|
'flags WRITE',
|
2005-08-26 10:28:07 +00:00
|
|
|
'flagtypes READ',
|
2005-02-28 20:41:45 +00:00
|
|
|
'cc WRITE',
|
|
|
|
'namedqueries WRITE',
|
2006-07-13 20:08:00 +00:00
|
|
|
'namedqueries_link_in_footer WRITE',
|
|
|
|
'namedquery_group_map WRITE',
|
2005-02-28 20:41:45 +00:00
|
|
|
'tokens WRITE',
|
|
|
|
'votes WRITE',
|
|
|
|
'watch WRITE',
|
|
|
|
'series WRITE',
|
|
|
|
'series_data WRITE',
|
|
|
|
'whine_schedules WRITE',
|
|
|
|
'whine_queries WRITE',
|
2005-08-26 10:28:07 +00:00
|
|
|
'whine_events WRITE');
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2006-07-03 21:26:22 +00:00
|
|
|
Bugzilla->params->{'allowuserdeletion'}
|
2005-03-05 00:18:48 +00:00
|
|
|
|| ThrowUserError('users_deletion_disabled');
|
2005-02-28 20:41:45 +00:00
|
|
|
$editusers || ThrowUserError('auth_failure',
|
|
|
|
{group => "editusers",
|
|
|
|
action => "delete",
|
2005-03-05 00:18:48 +00:00
|
|
|
object => "users"});
|
2005-06-24 22:33:05 +00:00
|
|
|
@{$otherUser->product_responsibilities()}
|
2005-03-05 00:18:48 +00:00
|
|
|
&& ThrowUserError('user_has_responsibility');
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
Bugzilla->logout_user($otherUser);
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2006-07-13 20:08:00 +00:00
|
|
|
# Get the named query list so we can delete namedquery_group_map entries.
|
|
|
|
my $namedqueries_as_string = join(', ', $dbh->selectcol_arrayref(
|
|
|
|
'SELECT id FROM namedqueries WHERE userid = ?',
|
|
|
|
undef,
|
|
|
|
$otherUserID));
|
|
|
|
|
2005-08-26 10:28:07 +00:00
|
|
|
# Get the timestamp for LogActivityEntry.
|
|
|
|
my $timestamp = $dbh->selectrow_array('SELECT NOW()');
|
|
|
|
|
|
|
|
# When we update a bug_activity entry, we update the bug timestamp, too.
|
|
|
|
my $sth_set_bug_timestamp =
|
|
|
|
$dbh->prepare('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?');
|
|
|
|
|
|
|
|
# Reference removals which need LogActivityEntry.
|
|
|
|
my $statement_flagupdate = 'UPDATE flags set requestee_id = NULL
|
|
|
|
WHERE bug_id = ?
|
|
|
|
AND attach_id %s
|
|
|
|
AND requestee_id = ?';
|
|
|
|
my $sth_flagupdate_attachment =
|
|
|
|
$dbh->prepare(sprintf($statement_flagupdate, '= ?'));
|
|
|
|
my $sth_flagupdate_bug =
|
|
|
|
$dbh->prepare(sprintf($statement_flagupdate, 'IS NULL'));
|
|
|
|
|
|
|
|
my $buglist = $dbh->selectall_arrayref('SELECT DISTINCT bug_id, attach_id
|
|
|
|
FROM flags
|
|
|
|
WHERE requestee_id = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
|
|
|
|
foreach (@$buglist) {
|
|
|
|
my ($bug_id, $attach_id) = @$_;
|
|
|
|
my @old_summaries = Bugzilla::Flag::snapshot($bug_id, $attach_id);
|
|
|
|
if ($attach_id) {
|
|
|
|
$sth_flagupdate_attachment->execute($bug_id, $attach_id, $otherUserID);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sth_flagupdate_bug->execute($bug_id, $otherUserID);
|
|
|
|
}
|
|
|
|
my @new_summaries = Bugzilla::Flag::snapshot($bug_id, $attach_id);
|
|
|
|
# Let update_activity do all the dirty work, including setting
|
|
|
|
# the bug timestamp.
|
2006-05-16 22:49:14 +00:00
|
|
|
Bugzilla::Flag::update_activity($bug_id, $attach_id, $timestamp,
|
2005-08-26 10:28:07 +00:00
|
|
|
\@old_summaries, \@new_summaries);
|
|
|
|
$updatedbugs{$bug_id} = 1;
|
|
|
|
}
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
# Simple deletions in referred tables.
|
2005-12-13 20:20:13 +00:00
|
|
|
$dbh->do('DELETE FROM email_setting WHERE user_id = ?', undef,
|
|
|
|
$otherUserID);
|
2005-02-28 20:41:45 +00:00
|
|
|
$dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $otherUserID);
|
|
|
|
$dbh->do('DELETE FROM namedqueries WHERE userid = ?', undef, $otherUserID);
|
2006-07-13 20:08:00 +00:00
|
|
|
$dbh->do('DELETE FROM namedqueries_link_in_footer WHERE user_id = ?', undef,
|
|
|
|
$otherUserID);
|
|
|
|
if ($namedqueries_as_string) {
|
|
|
|
$dbh->do('DELETE FROM namedquery_group_map WHERE namedquery_id IN ' .
|
|
|
|
"($namedqueries_as_string)");
|
|
|
|
}
|
2005-12-13 20:20:13 +00:00
|
|
|
$dbh->do('DELETE FROM profile_setting WHERE user_id = ?', undef,
|
|
|
|
$otherUserID);
|
2005-02-28 20:41:45 +00:00
|
|
|
$dbh->do('DELETE FROM profiles_activity WHERE userid = ? OR who = ?', undef,
|
|
|
|
($otherUserID, $otherUserID));
|
|
|
|
$dbh->do('DELETE FROM tokens WHERE userid = ?', undef, $otherUserID);
|
|
|
|
$dbh->do('DELETE FROM user_group_map WHERE user_id = ?', undef,
|
|
|
|
$otherUserID);
|
|
|
|
$dbh->do('DELETE FROM votes WHERE who = ?', undef, $otherUserID);
|
|
|
|
$dbh->do('DELETE FROM watch WHERE watcher = ? OR watched = ?', undef,
|
|
|
|
($otherUserID, $otherUserID));
|
|
|
|
|
2005-08-26 10:28:07 +00:00
|
|
|
# Deletions in referred tables which need LogActivityEntry.
|
|
|
|
$buglist = $dbh->selectcol_arrayref('SELECT bug_id FROM cc
|
|
|
|
WHERE who = ?',
|
|
|
|
undef, $otherUserID);
|
|
|
|
$dbh->do('DELETE FROM cc WHERE who = ?', undef, $otherUserID);
|
|
|
|
foreach my $bug_id (@$buglist) {
|
|
|
|
LogActivityEntry($bug_id, 'cc', $otherUser->login, '', $userid,
|
|
|
|
$timestamp);
|
|
|
|
$sth_set_bug_timestamp->execute($timestamp, $bug_id);
|
|
|
|
$updatedbugs{$bug_id} = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Even more complex deletions in referred tables.
|
2005-02-28 20:41:45 +00:00
|
|
|
my $id;
|
|
|
|
|
|
|
|
# 1) Series
|
|
|
|
my $sth_seriesid = $dbh->prepare(
|
|
|
|
'SELECT series_id FROM series WHERE creator = ?');
|
|
|
|
my $sth_deleteSeries = $dbh->prepare(
|
|
|
|
'DELETE FROM series WHERE series_id = ?');
|
|
|
|
my $sth_deleteSeriesData = $dbh->prepare(
|
|
|
|
'DELETE FROM series_data WHERE series_id = ?');
|
|
|
|
|
|
|
|
$sth_seriesid->execute($otherUserID);
|
|
|
|
while ($id = $sth_seriesid->fetchrow_array()) {
|
|
|
|
$sth_deleteSeriesData->execute($id);
|
|
|
|
$sth_deleteSeries->execute($id);
|
1999-10-12 23:00:35 +00:00
|
|
|
}
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# 2) Whines
|
|
|
|
my $sth_whineidFromSchedules = $dbh->prepare(
|
|
|
|
qq{SELECT eventid FROM whine_schedules
|
|
|
|
WHERE mailto = ? AND mailto_type = ?});
|
|
|
|
my $sth_whineidFromEvents = $dbh->prepare(
|
|
|
|
'SELECT id FROM whine_events WHERE owner_userid = ?');
|
|
|
|
my $sth_deleteWhineEvent = $dbh->prepare(
|
|
|
|
'DELETE FROM whine_events WHERE id = ?');
|
|
|
|
my $sth_deleteWhineQuery = $dbh->prepare(
|
|
|
|
'DELETE FROM whine_queries WHERE eventid = ?');
|
|
|
|
my $sth_deleteWhineSchedule = $dbh->prepare(
|
|
|
|
'DELETE FROM whine_schedules WHERE eventid = ?');
|
|
|
|
|
|
|
|
$sth_whineidFromSchedules->execute($otherUserID, MAILTO_USER);
|
|
|
|
while ($id = $sth_whineidFromSchedules->fetchrow_array()) {
|
|
|
|
$sth_deleteWhineQuery->execute($id);
|
|
|
|
$sth_deleteWhineSchedule->execute($id);
|
|
|
|
$sth_deleteWhineEvent->execute($id);
|
|
|
|
}
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
$sth_whineidFromEvents->execute($otherUserID);
|
|
|
|
while ($id = $sth_whineidFromEvents->fetchrow_array()) {
|
|
|
|
$sth_deleteWhineQuery->execute($id);
|
|
|
|
$sth_deleteWhineSchedule->execute($id);
|
|
|
|
$sth_deleteWhineEvent->execute($id);
|
1999-10-12 23:00:35 +00:00
|
|
|
}
|
|
|
|
|
2005-08-04 18:24:09 +00:00
|
|
|
# 3) Bugs
|
|
|
|
# 3.1) fall back to the default assignee
|
2005-08-26 10:28:07 +00:00
|
|
|
$buglist = $dbh->selectall_arrayref(
|
2005-08-04 18:24:09 +00:00
|
|
|
'SELECT bug_id, initialowner
|
|
|
|
FROM bugs
|
|
|
|
INNER JOIN components ON components.id = bugs.component_id
|
|
|
|
WHERE assigned_to = ?', undef, $otherUserID);
|
|
|
|
|
|
|
|
my $sth_updateAssignee = $dbh->prepare(
|
2005-08-26 10:28:07 +00:00
|
|
|
'UPDATE bugs SET assigned_to = ?, delta_ts = ? WHERE bug_id = ?');
|
2005-08-04 18:24:09 +00:00
|
|
|
|
|
|
|
foreach my $bug (@$buglist) {
|
2005-08-26 10:28:07 +00:00
|
|
|
my ($bug_id, $default_assignee_id) = @$bug;
|
|
|
|
$sth_updateAssignee->execute($default_assignee_id,
|
|
|
|
$timestamp, $bug_id);
|
|
|
|
$updatedbugs{$bug_id} = 1;
|
|
|
|
$default_assignee_id ||= 0;
|
|
|
|
$usercache{$default_assignee_id} ||=
|
|
|
|
new Bugzilla::User($default_assignee_id);
|
|
|
|
LogActivityEntry($bug_id, 'assigned_to', $otherUser->login,
|
|
|
|
$usercache{$default_assignee_id}->login,
|
|
|
|
$userid, $timestamp);
|
2005-08-04 18:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# 3.2) fall back to the default QA contact
|
|
|
|
$buglist = $dbh->selectall_arrayref(
|
|
|
|
'SELECT bug_id, initialqacontact
|
|
|
|
FROM bugs
|
|
|
|
INNER JOIN components ON components.id = bugs.component_id
|
|
|
|
WHERE qa_contact = ?', undef, $otherUserID);
|
|
|
|
|
|
|
|
my $sth_updateQAcontact = $dbh->prepare(
|
2005-08-26 10:28:07 +00:00
|
|
|
'UPDATE bugs SET qa_contact = ?, delta_ts = ? WHERE bug_id = ?');
|
2005-08-04 18:24:09 +00:00
|
|
|
|
|
|
|
foreach my $bug (@$buglist) {
|
2005-08-26 10:28:07 +00:00
|
|
|
my ($bug_id, $default_qa_contact_id) = @$bug;
|
|
|
|
$sth_updateQAcontact->execute($default_qa_contact_id,
|
|
|
|
$timestamp, $bug_id);
|
|
|
|
$updatedbugs{$bug_id} = 1;
|
|
|
|
$default_qa_contact_id ||= 0;
|
|
|
|
$usercache{$default_qa_contact_id} ||=
|
|
|
|
new Bugzilla::User($default_qa_contact_id);
|
|
|
|
LogActivityEntry($bug_id, 'qa_contact', $otherUser->login,
|
|
|
|
$usercache{$default_qa_contact_id}->login,
|
|
|
|
$userid, $timestamp);
|
2005-08-04 18:24:09 +00:00
|
|
|
}
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# Finally, remove the user account itself.
|
|
|
|
$dbh->do('DELETE FROM profiles WHERE userid = ?', undef, $otherUserID);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
$dbh->bz_unlock_tables();
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
$vars->{'message'} = 'account_deleted';
|
2005-11-30 12:00:54 +00:00
|
|
|
$vars->{'otheruser'}{'login'} = $otherUser->login;
|
2005-08-13 20:22:12 +00:00
|
|
|
$vars->{'restrictablegroups'} = $user->bless_groups();
|
2005-02-28 20:41:45 +00:00
|
|
|
$template->process('admin/users/search.html.tmpl', $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-08-26 10:28:07 +00:00
|
|
|
# Send mail about what we've done to bugs.
|
|
|
|
# The deleted user is not notified of the changes.
|
|
|
|
foreach (keys(%updatedbugs)) {
|
|
|
|
Bugzilla::BugMail::Send($_);
|
|
|
|
}
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
###########################################################################
|
2006-02-25 23:40:30 +00:00
|
|
|
} elsif ($action eq 'activity') {
|
|
|
|
my $otherUser = check_user($otherUserID, $otherUserLogin);
|
|
|
|
|
|
|
|
$vars->{'profile_changes'} = $dbh->selectall_arrayref(
|
|
|
|
"SELECT profiles.login_name AS who, " .
|
|
|
|
$dbh->sql_date_format('profiles_activity.profiles_when') . " AS activity_when,
|
|
|
|
fielddefs.description AS what,
|
|
|
|
profiles_activity.oldvalue AS removed,
|
|
|
|
profiles_activity.newvalue AS added
|
|
|
|
FROM profiles_activity
|
|
|
|
INNER JOIN profiles ON profiles_activity.who = profiles.userid
|
2006-07-25 23:20:42 +00:00
|
|
|
INNER JOIN fielddefs ON fielddefs.id = profiles_activity.fieldid
|
2006-02-25 23:40:30 +00:00
|
|
|
WHERE profiles_activity.userid = ?
|
|
|
|
ORDER BY profiles_activity.profiles_when",
|
|
|
|
{'Slice' => {}},
|
|
|
|
$otherUser->id);
|
|
|
|
|
|
|
|
$vars->{'otheruser'} = $otherUser;
|
|
|
|
|
|
|
|
$template->process("account/profile-activity.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
|
|
###########################################################################
|
2005-02-28 20:41:45 +00:00
|
|
|
} else {
|
|
|
|
$vars->{'action'} = $action;
|
|
|
|
ThrowCodeError('action_unrecognized', $vars);
|
1999-10-12 23:00:35 +00:00
|
|
|
}
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
exit;
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
###########################################################################
|
|
|
|
# Helpers
|
|
|
|
###########################################################################
|
1999-10-12 23:00:35 +00:00
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
# Try to build a user object using its ID, else its login name, and throw
|
|
|
|
# an error if the user does not exist.
|
|
|
|
sub check_user {
|
|
|
|
my ($otherUserID, $otherUserLogin) = @_;
|
|
|
|
|
|
|
|
my $otherUser;
|
|
|
|
my $vars = {};
|
|
|
|
|
|
|
|
if ($otherUserID) {
|
|
|
|
$otherUser = Bugzilla::User->new($otherUserID);
|
|
|
|
$vars->{'user_id'} = $otherUserID;
|
|
|
|
}
|
|
|
|
elsif ($otherUserLogin) {
|
|
|
|
$otherUser = Bugzilla::User->new_from_login($otherUserLogin);
|
|
|
|
$vars->{'user_login'} = $otherUserLogin;
|
|
|
|
}
|
|
|
|
($otherUser && $otherUser->id) || ThrowCodeError('invalid_user', $vars);
|
|
|
|
|
|
|
|
return $otherUser;
|
|
|
|
}
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# Copy incoming list selection values from CGI params to template variables.
|
|
|
|
sub mirrorListSelectionValues {
|
2006-07-06 06:12:05 +00:00
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-02-28 20:41:45 +00:00
|
|
|
if (defined($cgi->param('matchtype'))) {
|
2006-02-21 22:25:52 +00:00
|
|
|
foreach ('matchvalue', 'matchstr', 'matchtype', 'grouprestrict', 'groupid') {
|
2005-02-28 20:41:45 +00:00
|
|
|
$vars->{'listselectionvalues'}{$_} = $cgi->param($_);
|
|
|
|
}
|
|
|
|
}
|
1999-10-12 23:00:35 +00:00
|
|
|
}
|
|
|
|
|
2005-02-28 20:41:45 +00:00
|
|
|
# Retrieve user data for the user editing form. User creation and user
|
|
|
|
# editing code rely on this to call derive_groups().
|
|
|
|
sub userDataToVars {
|
2005-07-25 07:56:38 +00:00
|
|
|
my $otheruserid = shift;
|
|
|
|
my $otheruser = new Bugzilla::User($otheruserid);
|
2005-02-28 20:41:45 +00:00
|
|
|
my $query;
|
2006-07-06 06:12:05 +00:00
|
|
|
my $user = Bugzilla->user;
|
2005-03-16 00:27:15 +00:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2005-08-18 20:09:37 +00:00
|
|
|
my $grouplist = $otheruser->groups_as_string;
|
2005-02-28 20:41:45 +00:00
|
|
|
|
2005-07-25 07:56:38 +00:00
|
|
|
$vars->{'otheruser'} = $otheruser;
|
2005-08-13 20:22:12 +00:00
|
|
|
$vars->{'groups'} = $user->bless_groups();
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
$vars->{'permissions'} = $dbh->selectall_hashref(
|
|
|
|
qq{SELECT id,
|
|
|
|
COUNT(directmember.group_id) AS directmember,
|
|
|
|
COUNT(regexpmember.group_id) AS regexpmember,
|
2005-08-22 20:59:56 +00:00
|
|
|
(CASE WHEN (groups.id IN ($grouplist)
|
|
|
|
AND COUNT(directmember.group_id) = 0
|
|
|
|
AND COUNT(regexpmember.group_id) = 0
|
|
|
|
) THEN 1 ELSE 0 END)
|
|
|
|
AS derivedmember,
|
2005-02-28 20:41:45 +00:00
|
|
|
COUNT(directbless.group_id) AS directbless
|
|
|
|
FROM groups
|
|
|
|
LEFT JOIN user_group_map AS directmember
|
|
|
|
ON directmember.group_id = id
|
|
|
|
AND directmember.user_id = ?
|
|
|
|
AND directmember.isbless = 0
|
|
|
|
AND directmember.grant_type = ?
|
|
|
|
LEFT JOIN user_group_map AS regexpmember
|
|
|
|
ON regexpmember.group_id = id
|
|
|
|
AND regexpmember.user_id = ?
|
|
|
|
AND regexpmember.isbless = 0
|
|
|
|
AND regexpmember.grant_type = ?
|
|
|
|
LEFT JOIN user_group_map AS directbless
|
|
|
|
ON directbless.group_id = id
|
|
|
|
AND directbless.user_id = ?
|
|
|
|
AND directbless.isbless = 1
|
|
|
|
AND directbless.grant_type = ?
|
2005-03-16 00:27:15 +00:00
|
|
|
} . $dbh->sql_group_by('id'),
|
2005-02-28 20:41:45 +00:00
|
|
|
'id', undef,
|
2005-07-25 07:56:38 +00:00
|
|
|
($otheruserid, GRANT_DIRECT,
|
|
|
|
$otheruserid, GRANT_REGEXP,
|
|
|
|
$otheruserid, GRANT_DIRECT));
|
2005-02-28 20:41:45 +00:00
|
|
|
|
|
|
|
# Find indirect bless permission.
|
|
|
|
$query = qq{SELECT groups.id
|
2005-08-18 20:09:37 +00:00
|
|
|
FROM groups, group_group_map AS ggm
|
|
|
|
WHERE groups.id = ggm.grantor_id
|
|
|
|
AND ggm.member_id IN ($grouplist)
|
2005-02-28 20:41:45 +00:00
|
|
|
AND ggm.grant_type = ?
|
2005-03-16 00:27:15 +00:00
|
|
|
} . $dbh->sql_group_by('id');
|
2005-07-25 07:56:38 +00:00
|
|
|
foreach (@{$dbh->selectall_arrayref($query, undef,
|
2005-08-18 20:09:37 +00:00
|
|
|
(GROUP_BLESS))}) {
|
2005-02-28 20:41:45 +00:00
|
|
|
# Merge indirect bless permissions into permission variable.
|
|
|
|
$vars->{'permissions'}{${$_}[0]}{'indirectbless'} = 1;
|
|
|
|
}
|
|
|
|
}
|
2005-09-04 18:45:11 +00:00
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
sub edit_processing {
|
|
|
|
my $otherUser = shift;
|
2006-07-06 06:12:05 +00:00
|
|
|
my $user = Bugzilla->user;
|
|
|
|
my $template = Bugzilla->template;
|
2005-09-04 18:45:11 +00:00
|
|
|
|
2006-07-06 06:12:05 +00:00
|
|
|
$user->in_group('editusers') || $user->can_see_user($otherUser)
|
2005-09-04 18:45:11 +00:00
|
|
|
|| ThrowUserError('auth_failure', {reason => "not_visible",
|
|
|
|
action => "modify",
|
|
|
|
object => "user"});
|
|
|
|
|
2005-11-30 12:00:54 +00:00
|
|
|
userDataToVars($otherUser->id);
|
2005-09-04 18:45:11 +00:00
|
|
|
|
|
|
|
$template->process('admin/users/edit.html.tmpl', $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|