Commit 0df76bb7 authored by travis%sedsystems.ca's avatar travis%sedsystems.ca

Bug 284262 : Bundle of small editusers.cgi post-checkin fixes

Patch by Marc Schumann <wurblzap@gmail.com> r=mkanat a=justdave
parent f03496f5
...@@ -149,6 +149,8 @@ sub id { $_[0]->{id}; } ...@@ -149,6 +149,8 @@ sub id { $_[0]->{id}; }
sub login { $_[0]->{login}; } sub login { $_[0]->{login}; }
sub email { $_[0]->{login} . Param('emailsuffix'); } sub email { $_[0]->{login} . Param('emailsuffix'); }
sub name { $_[0]->{name}; } sub name { $_[0]->{name}; }
sub disabledtext { $_[0]->{'disabledtext'}; }
sub is_disabled { $_[0]->disabledtext ? 1 : 0; }
sub showmybugslink { $_[0]->{showmybugslink}; } sub showmybugslink { $_[0]->{showmybugslink}; }
sub set_flags { sub set_flags {
...@@ -1277,6 +1279,9 @@ Params: $username (scalar, string) - The login name for the new user. ...@@ -1277,6 +1279,9 @@ Params: $username (scalar, string) - The login name for the new user.
generated. generated.
$disabledtext (scalar, string) - Optional. The disable text for the new $disabledtext (scalar, string) - Optional. The disable text for the new
user; if not given, it will be empty. user; if not given, it will be empty.
If given, the user will be disabled,
meaning the account will be
unavailable for login.
Returns: The password for this user, in plain text, so it can be included Returns: The password for this user, in plain text, so it can be included
in an e-mail sent to the user. in an e-mail sent to the user.
......
...@@ -1073,12 +1073,13 @@ Reason: %reason% ...@@ -1073,12 +1073,13 @@ Reason: %reason%
{ {
name => 'allowuserdeletion', name => 'allowuserdeletion',
desc => 'The pages to edit users can also let you delete a user. ' . desc => q{The user editing pages are capable of letting you delete user
'Bugzilla will issue a warning in case you\'d run into ' . accounts.
'inconsistencies when you\'re about to do so, ' . Bugzilla will issue a warning in case you'd run into
'but such deletions remain kinda scary. ' . inconsistencies when you're about to do so,
'So, you have to turn on this option before any such deletions ' . but such deletions remain kinda scary.
'will ever happen.', So, you have to turn on this option before any such deletions
will ever happen.},
type => 'b', type => 'b',
default => 0 default => 0
}, },
......
...@@ -23,19 +23,21 @@ require "globals.pl"; ...@@ -23,19 +23,21 @@ require "globals.pl";
use vars qw( $vars ); use vars qw( $vars );
use Bugzilla;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::Config;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Auth; use Bugzilla::Auth;
use Bugzilla::Util;
Bugzilla->login(LOGIN_REQUIRED); Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi(); my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template(); my $template = Bugzilla->template;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $user = Bugzilla->user(); my $user = Bugzilla->user;
my $userid = $user->id(); my $userid = $user->id;
my $editusers = UserInGroup('editusers'); my $editusers = $user->in_group('editusers');
my $action = $cgi->param('action') || 'search';
# Reject access if there is no sense in continuing. # Reject access if there is no sense in continuing.
$editusers $editusers
...@@ -47,6 +49,19 @@ $editusers ...@@ -47,6 +49,19 @@ $editusers
print Bugzilla->cgi->header(); print Bugzilla->cgi->header();
# Common CGI params
my $action = $cgi->param('action') || 'search';
my $login = $cgi->param('login');
my $password = $cgi->param('password');
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
$vars->{'editusers'} = $editusers; $vars->{'editusers'} = $editusers;
mirrorListSelectionValues(); mirrorListSelectionValues();
...@@ -62,7 +77,6 @@ if ($action eq 'search') { ...@@ -62,7 +77,6 @@ if ($action eq 'search') {
my $matchstr = $cgi->param('matchstr'); my $matchstr = $cgi->param('matchstr');
my $matchtype = $cgi->param('matchtype'); my $matchtype = $cgi->param('matchtype');
my $grouprestrict = $cgi->param('grouprestrict') || '0'; my $grouprestrict = $cgi->param('grouprestrict') || '0';
my $groupid = $cgi->param('groupid');
my $query = 'SELECT DISTINCT userid, login_name, realname, disabledtext ' . my $query = 'SELECT DISTINCT userid, login_name, realname, disabledtext ' .
'FROM profiles'; 'FROM profiles';
my @bindValues; my @bindValues;
...@@ -136,13 +150,6 @@ if ($action eq 'search') { ...@@ -136,13 +150,6 @@ if ($action eq 'search') {
action => "add", action => "add",
object => "users"}); object => "users"});
my $login = $cgi->param('login');
my $password = $cgi->param('password');
# Cleanups
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',
...@@ -175,9 +182,8 @@ if ($action eq 'search') { ...@@ -175,9 +182,8 @@ if ($action eq 'search') {
########################################################################### ###########################################################################
} elsif ($action eq 'edit') { } elsif ($action eq 'edit') {
my $otherUser = new Bugzilla::User($cgi->param('userid')) $otherUser
|| ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')}); || ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')});
my $otherUserID = $otherUser->id();
canSeeUser($otherUserID) canSeeUser($otherUserID)
|| ThrowUserError('auth_failure', {reason => "not_visible", || ThrowUserError('auth_failure', {reason => "not_visible",
...@@ -191,9 +197,8 @@ if ($action eq 'search') { ...@@ -191,9 +197,8 @@ if ($action eq 'search') {
########################################################################### ###########################################################################
} elsif ($action eq 'update') { } elsif ($action eq 'update') {
my $otherUser = new Bugzilla::User($cgi->param('userid')) $otherUser
|| ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')}); || ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')});
my $otherUserID = $otherUser->id();
my $logoutNeeded = 0; my $logoutNeeded = 0;
my @changedFields; my @changedFields;
...@@ -215,13 +220,10 @@ if ($action eq 'search') { ...@@ -215,13 +220,10 @@ if ($action eq 'search') {
object => "user"}); object => "user"});
# Cleanups # Cleanups
my $login = trim($cgi->param('login') || ''); my $loginold = $cgi->param('loginold') || '';
my $loginold = $cgi->param('loginold') || ''; my $realnameold = $cgi->param('nameold') || '';
my $realname = trim($cgi->param('name') || ''); my $password = $cgi->param('password') || '';
my $realnameold = $cgi->param('nameold') || ''; my $disabledtextold = $cgi->param('disabledtextold') || '';
my $password = $cgi->param('password') || '';
my $disabledtext = trim($cgi->param('disabledtext') || '');
my $disabledtextold = $cgi->param('disabledtextold') || '';
# 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.
...@@ -272,7 +274,7 @@ if ($action eq 'search') { ...@@ -272,7 +274,7 @@ if ($action eq 'search') {
join(' = ?,', @changedFields).' = ? ' . join(' = ?,', @changedFields).' = ? ' .
'WHERE userid = ?', 'WHERE userid = ?',
undef, @values); undef, @values);
# FIXME: should create profiles_activity entries. # XXX: should create profiles_activity entries.
} }
} }
...@@ -301,8 +303,8 @@ if ($action eq 'search') { ...@@ -301,8 +303,8 @@ if ($action eq 'search') {
# Regard only groups the user is allowed to bless and skip all others # Regard only groups the user is allowed to bless and skip all others
# silently. # silently.
# FIXME: checking for existence of each user_group_map entry # XXX: checking for existence of each user_group_map entry
# would allow to display a friendlier error message on page reloads. # would allow to display a friendlier error message on page reloads.
foreach (@{groupsUserMayBless($user, 'id')}) { foreach (@{groupsUserMayBless($user, 'id')}) {
my $id = $$_{'id'}; my $id = $$_{'id'};
...@@ -355,11 +357,11 @@ if ($action eq 'search') { ...@@ -355,11 +357,11 @@ if ($action eq 'search') {
$dbh->do('UPDATE profiles SET refreshed_when=? WHERE userid = ?', $dbh->do('UPDATE profiles SET refreshed_when=? WHERE userid = ?',
undef, ('1900-01-01 00:00:00', $otherUserID)); undef, ('1900-01-01 00:00:00', $otherUserID));
} }
# FIXME: should create profiles_activity entries for blesser changes. # XXX: should create profiles_activity entries for blesser changes.
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
# FIXME: userDataToVars may be off when editing ourselves. # XXX: userDataToVars may be off when editing ourselves.
userDataToVars($otherUserID); userDataToVars($otherUserID);
$vars->{'message'} = 'account_updated'; $vars->{'message'} = 'account_updated';
...@@ -374,9 +376,8 @@ if ($action eq 'search') { ...@@ -374,9 +376,8 @@ if ($action eq 'search') {
########################################################################### ###########################################################################
} elsif ($action eq 'del') { } elsif ($action eq 'del') {
my $otherUser = new Bugzilla::User($cgi->param('userid')) $otherUser
|| ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')}); || ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')});
my $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",
...@@ -415,15 +416,6 @@ if ($action eq 'search') { ...@@ -415,15 +416,6 @@ if ($action eq 'search') {
$vars->{'flags'}{'setter'} = $dbh->selectrow_array( $vars->{'flags'}{'setter'} = $dbh->selectrow_array(
'SELECT COUNT(*) FROM flags WHERE setter_id = ?', 'SELECT COUNT(*) FROM flags WHERE setter_id = ?',
undef, $otherUserID); undef, $otherUserID);
$vars->{'groups'} = $dbh->selectall_arrayref(
qq{SELECT name
FROM groups, user_group_map
WHERE id = group_id
AND user_id = ?
AND isbless = 0
ORDER BY name
},
{'Slice' => {}}, $otherUserID);
$vars->{'longdescs'} = $dbh->selectrow_array( $vars->{'longdescs'} = $dbh->selectrow_array(
'SELECT COUNT(*) FROM longdescs WHERE who = ?', 'SELECT COUNT(*) FROM longdescs WHERE who = ?',
undef, $otherUserID); undef, $otherUserID);
...@@ -461,15 +453,14 @@ if ($action eq 'search') { ...@@ -461,15 +453,14 @@ if ($action eq 'search') {
########################################################################### ###########################################################################
} elsif ($action eq 'delete') { } elsif ($action eq 'delete') {
my $otherUser = new Bugzilla::User($cgi->param('userid')) $otherUser
|| ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')}); || ThrowCodeError('invalid_user_id', {'userid' => $cgi->param('userid')});
my $otherUserID = $otherUser->id();
my $otherUserLogin = $otherUser->login(); my $otherUserLogin = $otherUser->login();
# Lock tables during the check+removal session. # Lock tables during the check+removal session.
# FIXME: if there was some change on these tables after the deletion # XXX: if there was some change on these tables after the deletion
# confirmation checks, we may do something here we haven't warned # confirmation checks, we may do something here we haven't warned
# about. # about.
$dbh->bz_lock_tables('products READ', $dbh->bz_lock_tables('products READ',
'components READ', 'components READ',
'logincookies WRITE', 'logincookies WRITE',
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
# editusers: is viewing user member of editusers? # editusers: is viewing user member of editusers?
# editcomponents: is viewing user member of editcomponents? # editcomponents: is viewing user member of editcomponents?
# otheruser: Bugzilla::User object of the viewed user. # otheruser: Bugzilla::User object of the viewed user.
# groups: array of Group names the viewed user is a member
# of.
# product_responsibilities: list of hashes, one entry per Bugzilla component. # product_responsibilities: list of hashes, one entry per Bugzilla component.
# productname: Name of the product. # productname: Name of the product.
# componentname: Name of the component. # componentname: Name of the component.
...@@ -78,8 +76,8 @@ ...@@ -78,8 +76,8 @@
<td> <td>
[% IF groups.size %] [% IF groups.size %]
<ul> <ul>
[% FOREACH group = groups %] [% FOREACH group = otheruser.groups.keys %]
<li>[% group.name FILTER html %]</li> <li>[% group FILTER html %]</li>
[% END %] [% END %]
</ul> </ul>
[% ELSE %] [% ELSE %]
...@@ -96,7 +94,7 @@ ...@@ -96,7 +94,7 @@
<li> <li>
[% andstring = '' %] [% andstring = '' %]
[% FOREACH responsibility = ['initialowner', 'initialqacontact'] %] [% FOREACH responsibility = ['initialowner', 'initialqacontact'] %]
[% IF component.$responsibility == userid %] [% IF component.$responsibility == otheruser.id %]
[% andstring %] [% responsibilityterms.$responsibility %] [% andstring %] [% responsibilityterms.$responsibility %]
[% andstring = ' and ' %] [% andstring = ' and ' %]
[% END %] [% END %]
......
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