* Add new edit users interface to allow admins to search for users and to change change user passwords, email addresses, and other user data.

* Add automated testing authentication token to the user table -- to be used for future web services work.

* Create a fulltext index of user data to aid searching.
This commit is contained in:
zach%zachlipton.com 2006-06-16 17:27:54 +00:00
Родитель fe0887f519
Коммит 9c3af1bd90
11 изменённых файлов: 470 добавлений и 5 удалений

Просмотреть файл

@ -357,7 +357,19 @@ sub processLoginForm {
}
}
# Given a userobj, process the login and return a session cookie
sub changePassword {
my $userobj = shift;
my $password = shift;
$userobj->password(bz_crypt($password));
$userobj->update();
my @sessions = $userobj->sessions();
foreach my $session (@sessions) {
$session->makeExpire();
}
}
# Given a userobj, process the login and return a session object
sub makeSession {
my $userobj = shift;
my $c = Litmus->cgi();

Просмотреть файл

@ -38,7 +38,7 @@ use base 'Litmus::DBI';
Litmus::DB::User->table('users');
Litmus::DB::User->columns(All => qw/user_id bugzilla_uid email password realname irc_nickname enabled is_admin/);
Litmus::DB::User->columns(All => qw/user_id bugzilla_uid email password realname irc_nickname enabled is_admin authtoken/);
Litmus::DB::User->column_alias("is_trusted", "istrusted");
Litmus::DB::User->column_alias("is_admin", "is_trusted");
@ -66,6 +66,16 @@ __PACKAGE__->set_sql(TopTesters => qq{
LIMIT 15
});
# search by email, realname, or irc_nickname
__PACKAGE__->set_sql(FullTextMatches => qq{
SELECT *,
MATCH (email, realname, irc_nickname) AGAINST (?) AS relevance
FROM __TABLE__
WHERE MATCH (email, realname, irc_nickname) AGAINST (?) HAVING relevance > 0
ORDER BY relevance DESC, user_id ASC
LIMIT 100
});
#########################################################################
# returns the crypt'd password from a linked Bugzilla account if it
# exists or the Litmus user account

103
webtools/litmus/edit_users.cgi Executable file
Просмотреть файл

@ -0,0 +1,103 @@
#!/usr/bin/perl -w
# -*- 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 Litmus.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Zach Lipton <zach@zachlipton.com>
use strict;
use Litmus;
use Litmus::Error;
use Litmus::DB::Product;
use Litmus::DB::TestcaseSubgroup;
use Litmus::Auth;
use Litmus::Utils;
use CGI;
use Time::Piece::MySQL;
my $c = Litmus->cgi();
# obviously, you need to be an admin to edit users...
Litmus::Auth::requireAdmin('edit_users.cgi');
if ($c->param('search_string')) {
# search for users:
my $users = Litmus::DB::User->search_FullTextMatches(
$c->param('search_string'),
$c->param('search_string'));
my $vars = {
users => $users,
};
print $c->header();
Litmus->template()->process("admin/edit_users/search_results.html.tmpl", $vars) ||
internalError(Litmus->template()->error());
} elsif ($c->param('id')) {
# lookup a given user
my $uid = $c->param('id');
my $user = Litmus::DB::User->retrieve($uid);
print $c->header();
if (! $user) {
invalidInputError("Invalid user id: $uid");
}
my $vars = {
user => $user,
};
Litmus->template()->process("admin/edit_users/edit_user.html.tmpl", $vars) ||
internalError(Litmus->template()->error());
} elsif ($c->param('user_id')) {
# process changes to a user:
my $user = Litmus::DB::User->retrieve($c->param('user_id'));
print $c->header();
if (! $user) {
invalidInputError("Invalid user id: " . $c->param('user_id'));
}
$user->bugzilla_uid($c->param('bugzilla_uid'));
$user->email($c->param('email'));
if ($c->param('password') ne 'unchanged') {
# they changed the password, so let the auth folks know:
Litmus::Auth::changePassword($user, $c->param('password'));
}
$user->realname($c->param('realname'));
$user->irc_nickname($c->param('irc_nickname'));
if ($c->param('enabled')) {
$user->enabled(1);
}
if ($c->param('is_admin')) {
$user->is_admin(1);
}
$user->authtoken($c->param('authtoken'));
$user->update();
my $vars = {
user => $user,
};
Litmus->template()->process("admin/edit_users/user_edited.html.tmpl", $vars) ||
internalError(Litmus->template()->error());
} else {
# we're here for the first time, so display the search form
my $vars = {
};
print $c->header();
Litmus->template()->process("admin/edit_users/search_users.html.tmpl", $vars) ||
internalError(Litmus->template()->error());
}

Просмотреть файл

@ -229,6 +229,15 @@ $dbtool->AddKey("testcase_subgroups","sort_order","(sort_order)");
$dbtool->DropField("subgroups", "sort_order");
$dbtool->DropField("testcases", "sort_order");
$dbtool->AddField("users", "authtoken", "varchar(255)");
$dbtool->AddFullText("users", "key", "(email, realname, irc_nickname)");
# zll 2006-06-15: users.irc_nickname cannot have a unique index, since
# many users have a null nickname:
$dbtool->DropIndex("users", "irc_nickname");
$dbtool->AddKey("users", "irc_nickname", "(irc_nickname)");
print "Schema update complete.\n\n";
print <<EOS;
Due to the schema changes introduced, and depending on the when you last

Просмотреть файл

@ -341,11 +341,13 @@ $table{users} =
irc_nickname varchar(32),
enabled tinyint(1),
is_admin tinyint(1),
authtoken varchar(255),
index(bugzilla_uid),
unique index(email),
unique index(irc_nickname),
index(irc_nickname),
index(password),
index(realname),
index(enabled),
index(is_admin)';
index(is_admin),
fulltext key(email, realname, irc_nickname)';

Просмотреть файл

@ -0,0 +1,107 @@
[%# 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 Litmus.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Zach Lipton <zach@zachlipton.com>
#%]
[%# INTERFACE:
# $user - the user object to edit
#%]
[% PROCESS global/selects.none.tmpl %]
[% includeselects=1 %]
[% INCLUDE global/html_header.tmpl js_files=['js/SelectBoxes.js']
title='Edit User' %]
[% INCLUDE global/litmus_header.tmpl %]
<div id="page">
[% INCLUDE sidebar/sidebar.tmpl %]
<div id="content">
<h1 class="firstHeading">Edit User - [% user.email | html %]</h1>
<div class="section-full">
<form action="edit_users.cgi" method="post" name="form" id="form" autocomplete="off">
<input type="hidden" name="user_id" value="[% user.user_id | html %]" />
<table>
<tr>
<td><b>user id:</b></td> <td>[% user.user_id | html %]</td>
</tr>
<tr>
<td><b>bugzilla user id:</b></td>
<td><input name="bugzilla_uid" size="15" value="[% user.bugzilla_uid | html %]" /></td>
</tr>
<tr>
<td><b>email:</b></td>
<td><input name="email" size="30" value="[% user.email | html %]" /></td>
</tr>
<tr>
<td><b>password:</b></td>
<td><input name="password" type="password" size="30" value="unchanged" /></td>
</tr>
<tr>
<td><b>real name:</b></td>
<td><input name="realname" size="30" value="[% user.realname | html %]" /></td>
</tr>
<tr>
<td><b>irc nickname:</b></td>
<td><input name="irc_nickname" size="15" value="[% user.irc_nickname | html %]" /></td>
</tr>
</table>
<br />
<table>
<tr>
<td><b>enabled:</b></td>
<td><input name="enabled" type="checkbox" value="1"
[% IF user.enabled %] checked [% END %] /></td>
</tr>
<tr>
<td><b>is admin:</b></td>
<td><input name="is_admin" type="checkbox" value="1"
[% IF user.is_admin %] checked [% END %] /></td>
</tr>
</table>
<br />
<p>To enable this user to submit automated testing results through the web services
interface, you must enter a web services authentication token:</p>
<table>
<tr>
<td><b>web services auth token:</b></td>
<td><input name="authtoken" size="30" value="[% user.authtoken | html %]" /></td>
</tr>
</table>
<br />
<input type="submit" value="Submit changes" />
</form>
</div>
</div><!--END content-->
</div><!--END page-->
[% INCLUDE global/litmus_footer.tmpl %]
[% INCLUDE global/html_footer.tmpl %]

Просмотреть файл

@ -0,0 +1,84 @@
[%# 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 Litmus.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Zach Lipton <zach@zachlipton.com>
#%]
[%# INTERFACE:
# $users - iterator for the list of users to display
#%]
[% PROCESS global/selects.none.tmpl %]
[% includeselects=1 %]
[% INCLUDE global/html_header.tmpl js_files=['js/SelectBoxes.js']
title='Edit Users' %]
[% INCLUDE global/litmus_header.tmpl %]
<div id="page">
[% INCLUDE sidebar/sidebar.tmpl %]
<div id="content">
<h1 class="firstHeading">Edit Users - Search Results</h1>
<div class="section-full">
<table class="stats" style="width: 50% !important;">
<tr>
<td class="header"></td>
<td class="header">Email Address</td>
<td class="header">irc</td>
<td class="header">Name</td>
</tr>
[% resultsfound = 0 %]
[% WHILE (u = users.next) %]
[% resultsfound = 1 %]
<tr>
<td>
<a href="edit_users.cgi?id=[%u.user_id | html | uri %]">edit</a>
</td>
<td>
[% u.email | html %]
</td>
<td>
[% u.irc_nickname | html %]
</td>
<td>
[% u.realname | html %]
</td>
</tr>
[% END %]
</table>
[% IF resultsfound == 0 %]
<h1 class="errorHeading">No results found.</h1>
[% INCLUDE admin/edit_users/searchform.html.tmpl %]
[% END %]
</div>
</div><!--END content-->
</div><!--END page-->
[% INCLUDE global/litmus_footer.tmpl %]
[% INCLUDE global/html_footer.tmpl %]

Просмотреть файл

@ -0,0 +1,52 @@
[%# 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 Litmus.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Zach Lipton <zach@zachlipton.com>
#%]
[%# INTERFACE:
#
#%]
[% PROCESS global/selects.none.tmpl %]
[% includeselects=1 %]
[% INCLUDE global/html_header.tmpl js_files=['js/SelectBoxes.js']
title='Edit Users' %]
[% INCLUDE global/litmus_header.tmpl %]
<div id="page">
[% INCLUDE sidebar/sidebar.tmpl %]
<div id="content">
<h1 class="firstHeading">Edit Users</h1>
<div class="section-full">
[% INCLUDE admin/edit_users/searchform.html.tmpl %]
</div>
</div><!--END content-->
</div><!--END page-->
[% INCLUDE global/litmus_footer.tmpl %]
[% INCLUDE global/html_footer.tmpl %]

Просмотреть файл

@ -0,0 +1,30 @@
[%# 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 Litmus.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Zach Lipton <zach@zachlipton.com>
#%]
[%# INTERFACE:
#
#%]
<form action="edit_users.cgi" method="get" name="form" id="form">
List users matching
<input name="search_string" size="35" />
<input type="submit" name="submit" value="Search" />
</form>

Просмотреть файл

@ -0,0 +1,56 @@
[%# 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 Litmus.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Zach Lipton <zach@zachlipton.com>
#%]
[%# INTERFACE:
# $user - the edited user object
#%]
[% PROCESS global/selects.none.tmpl %]
[% includeselects=1 %]
[% INCLUDE global/html_header.tmpl js_files=['js/SelectBoxes.js']
title='Edit User' %]
[% INCLUDE global/litmus_header.tmpl %]
<div id="page">
[% INCLUDE sidebar/sidebar.tmpl %]
<div id="content">
<h1 class="firstHeading">User [% user.email | html %] edited</h1>
<h4><a href="edit_users.cgi?id=[% user.user_id | uri | html %]">Go back and
edit this user some more</a></h2>
<div class="section-full">
<h4>Edit another user:</h4>
[% INCLUDE admin/edit_users/searchform.html.tmpl %]
</div>
</div><!--END content-->
</div><!--END page-->
[% INCLUDE global/litmus_footer.tmpl %]
[% INCLUDE global/html_footer.tmpl %]

Просмотреть файл

@ -11,7 +11,7 @@
<li>Manage Testgroups</li>
<hr/>
<li>Manage Categories</li>
<li>Manage Users</li>
<li><a href="edit_users.cgi">Manage Users</a></li>
</ul>
</div>
</div>