Commit d3395fe6 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 314039: editusers.cgi edits user 0 if you don't pass a userid - Patch by…

Bug 314039: editusers.cgi edits user 0 if you don't pass a userid - Patch by Frédéric Buclin <LpSolit@gmail.com> r=wurblzap a=justdave
parent 36246089
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# #
# Contributor(s): Marc Schumann <wurblzap@gmail.com> # Contributor(s): Marc Schumann <wurblzap@gmail.com>
# Lance Larsh <lance.larsh@oracle.com> # Lance Larsh <lance.larsh@oracle.com>
# Frédéric Buclin <LpSolit@gmail.com>
use strict; use strict;
use lib "."; use lib ".";
...@@ -29,14 +30,14 @@ use Bugzilla::Config; ...@@ -29,14 +30,14 @@ use Bugzilla::Config;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Field; use Bugzilla::Field;
use Bugzilla::Group;
Bugzilla->login(LOGIN_REQUIRED); my $user = Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $user = Bugzilla->user;
my $userid = $user->id; my $userid = $user->id;
my $editusers = $user->in_group('editusers'); my $editusers = $user->in_group('editusers');
...@@ -48,19 +49,12 @@ $editusers ...@@ -48,19 +49,12 @@ $editusers
action => "edit", action => "edit",
object => "users"}); object => "users"});
print Bugzilla->cgi->header(); print $cgi->header();
# Common CGI params # Common CGI params
my $action = $cgi->param('action') || 'search'; my $action = $cgi->param('action') || 'search';
my $login = $cgi->param('login'); my $otherUserID = $cgi->param('userid');
my $password = $cgi->param('password'); my $otherUserLogin = $cgi->param('user');
my $groupid = $cgi->param('groupid');
my $otherUser = new Bugzilla::User($cgi->param('userid'));
my $realname = trim($cgi->param('name') || '');
my $disabledtext = trim($cgi->param('disabledtext') || '');
# Directly from common CGI params derived values
my $otherUserID = $otherUser->id();
# Prefill template vars with data used in all or nearly all templates # Prefill template vars with data used in all or nearly all templates
$vars->{'editusers'} = $editusers; $vars->{'editusers'} = $editusers;
...@@ -84,6 +78,13 @@ if ($action eq 'search') { ...@@ -84,6 +78,13 @@ if ($action eq 'search') {
my $nextCondition; my $nextCondition;
my $visibleGroups; my $visibleGroups;
# 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');
}
if (!$editusers && Param('usevisibilitygroups')) { if (!$editusers && Param('usevisibilitygroups')) {
# Show only users in visible groups. # Show only users in visible groups.
$visibleGroups = $user->visible_groups_as_string(); $visibleGroups = $user->visible_groups_as_string();
...@@ -134,9 +135,8 @@ if ($action eq 'search') { ...@@ -134,9 +135,8 @@ if ($action eq 'search') {
# Handle selection by group. # Handle selection by group.
if ($grouprestrict eq '1') { if ($grouprestrict eq '1') {
detaint_natural($groupid);
my $grouplist = join(',', my $grouplist = join(',',
@{Bugzilla::User->flatten_group_membership($groupid)}); @{Bugzilla::User->flatten_group_membership($group->id)});
$query .= " $nextCondition profiles.userid = ugm.user_id " . $query .= " $nextCondition profiles.userid = ugm.user_id " .
"AND ugm.group_id IN($grouplist)"; "AND ugm.group_id IN($grouplist)";
} }
...@@ -149,9 +149,9 @@ if ($action eq 'search') { ...@@ -149,9 +149,9 @@ if ($action eq 'search') {
} }
if ($matchtype eq 'exact' && scalar(@{$vars->{'users'}}) == 1) { if ($matchtype eq 'exact' && scalar(@{$vars->{'users'}}) == 1) {
$otherUserID = $vars->{'users'}[0]->{'userid'}; my $match_user_id = $vars->{'users'}[0]->{'userid'};
$otherUser = new Bugzilla::User($otherUserID); my $match_user = check_user($match_user_id);
edit_processing(); edit_processing($match_user);
} else { } else {
$template->process('admin/users/list.html.tmpl', $vars) $template->process('admin/users/list.html.tmpl', $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
...@@ -172,6 +172,11 @@ if ($action eq 'search') { ...@@ -172,6 +172,11 @@ if ($action eq 'search') {
action => "add", action => "add",
object => "users"}); object => "users"});
my $login = $cgi->param('login');
my $password = $cgi->param('password');
my $realname = trim($cgi->param('name') || '');
my $disabledtext = trim($cgi->param('disabledtext') || '');
# Lock tables during the check+creation session. # Lock tables during the check+creation session.
$dbh->bz_lock_tables('profiles WRITE', $dbh->bz_lock_tables('profiles WRITE',
'profiles_activity WRITE', 'profiles_activity WRITE',
...@@ -196,11 +201,11 @@ if ($action eq 'search') { ...@@ -196,11 +201,11 @@ if ($action eq 'search') {
trick_taint($disabledtext); trick_taint($disabledtext);
insert_new_user($login, $realname, $password, $disabledtext); insert_new_user($login, $realname, $password, $disabledtext);
$otherUserID = $dbh->bz_last_key('profiles', 'userid'); my $new_user_id = $dbh->bz_last_key('profiles', 'userid');
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
my $newprofile = new Bugzilla::User($otherUserID); my $newprofile = new Bugzilla::User($new_user_id);
$newprofile->derive_regexp_groups(); $newprofile->derive_regexp_groups();
userDataToVars($otherUserID); userDataToVars($new_user_id);
$vars->{'message'} = 'account_created'; $vars->{'message'} = 'account_created';
$template->process('admin/users/edit.html.tmpl', $vars) $template->process('admin/users/edit.html.tmpl', $vars)
...@@ -208,13 +213,14 @@ if ($action eq 'search') { ...@@ -208,13 +213,14 @@ if ($action eq 'search') {
########################################################################### ###########################################################################
} elsif ($action eq 'edit') { } elsif ($action eq 'edit') {
my $otherUser = check_user($otherUserID, $otherUserLogin);
edit_processing(); edit_processing($otherUser);
########################################################################### ###########################################################################
} elsif ($action eq 'update') { } elsif ($action eq 'update') {
$otherUser my $otherUser = check_user($otherUserID, $otherUserLogin);
|| ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')}); $otherUserID = $otherUser->id;
my $logoutNeeded = 0; my $logoutNeeded = 0;
my @changedFields; my @changedFields;
...@@ -240,9 +246,13 @@ if ($action eq 'search') { ...@@ -240,9 +246,13 @@ if ($action eq 'search') {
# Cleanups # Cleanups
my $loginold = $cgi->param('loginold') || ''; my $loginold = $cgi->param('loginold') || '';
my $realnameold = $cgi->param('nameold') || ''; my $realnameold = $cgi->param('nameold') || '';
my $password = $cgi->param('password') || '';
my $disabledtextold = $cgi->param('disabledtextold') || ''; my $disabledtextold = $cgi->param('disabledtextold') || '';
my $login = $cgi->param('login');
my $password = $cgi->param('password');
my $realname = trim($cgi->param('name') || '');
my $disabledtext = trim($cgi->param('disabledtext') || '');
# Update profiles table entry; silently skip doing this if the user # Update profiles table entry; silently skip doing this if the user
# is not authorized. # is not authorized.
if ($editusers) { if ($editusers) {
...@@ -289,7 +299,7 @@ if ($action eq 'search') { ...@@ -289,7 +299,7 @@ if ($action eq 'search') {
} }
if (@changedFields) { if (@changedFields) {
push (@values, $otherUserID); push (@values, $otherUserID);
$logoutNeeded && Bugzilla->logout_user_by_id($otherUserID); $logoutNeeded && Bugzilla->logout_user($otherUser);
$dbh->do('UPDATE profiles SET ' . $dbh->do('UPDATE profiles SET ' .
join(' = ?,', @changedFields).' = ? ' . join(' = ?,', @changedFields).' = ? ' .
'WHERE userid = ?', 'WHERE userid = ?',
...@@ -401,8 +411,8 @@ if ($action eq 'search') { ...@@ -401,8 +411,8 @@ if ($action eq 'search') {
########################################################################### ###########################################################################
} elsif ($action eq 'del') { } elsif ($action eq 'del') {
$otherUser my $otherUser = check_user($otherUserID, $otherUserLogin);
|| ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')}); $otherUserID = $otherUser->id;
Param('allowuserdeletion') || ThrowUserError('users_deletion_disabled'); Param('allowuserdeletion') || ThrowUserError('users_deletion_disabled');
$editusers || ThrowUserError('auth_failure', {group => "editusers", $editusers || ThrowUserError('auth_failure', {group => "editusers",
...@@ -469,9 +479,8 @@ if ($action eq 'search') { ...@@ -469,9 +479,8 @@ if ($action eq 'search') {
########################################################################### ###########################################################################
} elsif ($action eq 'delete') { } elsif ($action eq 'delete') {
$otherUser my $otherUser = check_user($otherUserID, $otherUserLogin);
|| ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')}); $otherUserID = $otherUser->id;
my $otherUserLogin = $otherUser->login();
# Cache for user accounts. # Cache for user accounts.
my %usercache = (0 => new Bugzilla::User()); my %usercache = (0 => new Bugzilla::User());
...@@ -516,7 +525,7 @@ if ($action eq 'search') { ...@@ -516,7 +525,7 @@ if ($action eq 'search') {
@{$otherUser->product_responsibilities()} @{$otherUser->product_responsibilities()}
&& ThrowUserError('user_has_responsibility'); && ThrowUserError('user_has_responsibility');
Bugzilla->logout_user_by_id($otherUserID); Bugzilla->logout_user($otherUser);
# Get the timestamp for LogActivityEntry. # Get the timestamp for LogActivityEntry.
my $timestamp = $dbh->selectrow_array('SELECT NOW()'); my $timestamp = $dbh->selectrow_array('SELECT NOW()');
...@@ -679,7 +688,7 @@ if ($action eq 'search') { ...@@ -679,7 +688,7 @@ if ($action eq 'search') {
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
$vars->{'message'} = 'account_deleted'; $vars->{'message'} = 'account_deleted';
$vars->{'otheruser'}{'login'} = $otherUserLogin; $vars->{'otheruser'}{'login'} = $otherUser->login;
$vars->{'restrictablegroups'} = $user->bless_groups(); $vars->{'restrictablegroups'} = $user->bless_groups();
$template->process('admin/users/search.html.tmpl', $vars) $template->process('admin/users/search.html.tmpl', $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
...@@ -702,6 +711,27 @@ exit; ...@@ -702,6 +711,27 @@ exit;
# Helpers # Helpers
########################################################################### ###########################################################################
# 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;
}
# Copy incoming list selection values from CGI params to template variables. # Copy incoming list selection values from CGI params to template variables.
sub mirrorListSelectionValues { sub mirrorListSelectionValues {
if (defined($cgi->param('matchtype'))) { if (defined($cgi->param('matchtype'))) {
...@@ -770,19 +800,16 @@ sub userDataToVars { ...@@ -770,19 +800,16 @@ sub userDataToVars {
} }
} }
sub edit_processing sub edit_processing {
{ my $otherUser = shift;
$otherUser
|| ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')});
$editusers || $user->can_see_user($otherUser) $editusers || $user->can_see_user($otherUser)
|| ThrowUserError('auth_failure', {reason => "not_visible", || ThrowUserError('auth_failure', {reason => "not_visible",
action => "modify", action => "modify",
object => "user"}); object => "user"});
userDataToVars($otherUserID); userDataToVars($otherUser->id);
$template->process('admin/users/edit.html.tmpl', $vars) $template->process('admin/users/edit.html.tmpl', $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
} }
...@@ -227,9 +227,16 @@ ...@@ -227,9 +227,16 @@
The keyword ID <em>[% id FILTER html %]</em> couldn't be The keyword ID <em>[% id FILTER html %]</em> couldn't be
found. found.
[% ELSIF error == "invalid_user_id" %] [% ELSIF error == "invalid_user" %]
[% title = "Invalid User ID" %] [% title = "Invalid User" %]
There is no user account with ID <em>[% userid FILTER html %]</em>. There is no user account
[% IF user_id %]
with ID <em>[% user_id FILTER html %]</em>.
[% ELSIF user_login %]
with login name <em>[% user_login FILTER html %]</em>.
[% ELSE %]
given.
[% END %]
[% ELSIF error == "missing_bug_id" %] [% ELSIF error == "missing_bug_id" %]
No [% terms.bug %] ID was given. No [% terms.bug %] ID was given.
......
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