aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJochen Wiedmann <jochen.wiedmann@gmail.com>2011-04-27 15:20:55 -0700
committerMax Kanat-Alexander <mkanat@bugzilla.org>2011-04-27 15:20:55 -0700
commit645ebe3d40e6a148dca52054e91483253b3d7568 (patch)
treedf9a0bdb22479b789668a051397a3f5cb658c7ab
parent6233375db2f69e79f2fa7ba3030956aa2a6eafbe (diff)
downloadbugs-645ebe3d40e6a148dca52054e91483253b3d7568.tar
bugs-645ebe3d40e6a148dca52054e91483253b3d7568.tar.gz
bugs-645ebe3d40e6a148dca52054e91483253b3d7568.tar.bz2
bugs-645ebe3d40e6a148dca52054e91483253b3d7568.tar.xz
bugs-645ebe3d40e6a148dca52054e91483253b3d7568.zip
Bug 423612 - Allow editing extern_id for users from the admin interface
r=mkanat, a=mkanat
-rw-r--r--Bugzilla/Auth.pm10
-rw-r--r--Bugzilla/Auth/Login.pm9
-rw-r--r--Bugzilla/Auth/Login/Env.pm1
-rw-r--r--Bugzilla/Auth/Login/Stack.pm6
-rw-r--r--Bugzilla/Auth/Verify.pm9
-rw-r--r--Bugzilla/Auth/Verify/Stack.pm5
-rw-r--r--Bugzilla/Template.pm1
-rw-r--r--Bugzilla/User.pm27
-rwxr-xr-xeditusers.cgi6
-rw-r--r--template/en/default/admin/users/userdata.html.tmpl13
-rw-r--r--template/en/default/global/messages.html.tmpl2
-rw-r--r--template/en/default/global/user-error.html.tmpl8
12 files changed, 96 insertions, 1 deletions
diff --git a/Bugzilla/Auth.pm b/Bugzilla/Auth.pm
index 782953878..e6127d32a 100644
--- a/Bugzilla/Auth.pm
+++ b/Bugzilla/Auth.pm
@@ -134,6 +134,12 @@ sub user_can_create_account {
&& $getter->user_can_create_account;
}
+sub extern_id_used {
+ my ($self) = @_;
+ return $self->{_info_getter}->extern_id_used
+ || $self->{_verifier}->extern_id_used;
+}
+
sub can_change_email {
return $_[0]->user_can_create_account;
}
@@ -397,6 +403,10 @@ Params: None
Returns: C<true> if users are allowed to create new Bugzilla accounts,
C<false> otherwise.
+=item C<extern_id_used>
+
+Description: Whether or not current login system uses extern_id.
+
=item C<can_change_email>
Description: Whether or not the current login system allows users to
diff --git a/Bugzilla/Auth/Login.pm b/Bugzilla/Auth/Login.pm
index b3add7365..42ce51c62 100644
--- a/Bugzilla/Auth/Login.pm
+++ b/Bugzilla/Auth/Login.pm
@@ -28,6 +28,7 @@ use constant requires_persistence => 1;
use constant requires_verification => 1;
use constant user_can_create_account => 0;
use constant is_automatic => 0;
+use constant extern_id_used => 0;
sub new {
my ($class) = @_;
@@ -131,4 +132,12 @@ just passes us an environment variable on most page requests, and does not
ask the user for authentication information directly in Bugzilla.) Defaults
to C<false>.
+=item C<extern_id_used>
+
+Whether or not this login method uses the extern_id field. If
+used, users with editusers permission will be be allowed to
+edit the extern_id for all users.
+
+The default value is C<0>.
+
=back
diff --git a/Bugzilla/Auth/Login/Env.pm b/Bugzilla/Auth/Login/Env.pm
index f93034ef3..76227f18b 100644
--- a/Bugzilla/Auth/Login/Env.pm
+++ b/Bugzilla/Auth/Login/Env.pm
@@ -32,6 +32,7 @@ use constant can_login => 0;
use constant requires_persistence => 0;
use constant requires_verification => 0;
use constant is_automatic => 1;
+use constant extern_id_used => 1;
sub get_login_info {
my ($self) = @_;
diff --git a/Bugzilla/Auth/Login/Stack.pm b/Bugzilla/Auth/Login/Stack.pm
index f490d243b..0f3661954 100644
--- a/Bugzilla/Auth/Login/Stack.pm
+++ b/Bugzilla/Auth/Login/Stack.pm
@@ -28,6 +28,7 @@ use fields qw(
);
use Hash::Util qw(lock_keys);
use Bugzilla::Hook;
+use List::MoreUtils qw(any);
sub new {
my $class = shift;
@@ -97,4 +98,9 @@ sub user_can_create_account {
return 0;
}
+sub extern_id_used {
+ my ($self) = @_;
+ return any { $_->extern_id_used } @{ $self->{_stack} };
+}
+
1;
diff --git a/Bugzilla/Auth/Verify.pm b/Bugzilla/Auth/Verify.pm
index b293e2583..a8cd0af2c 100644
--- a/Bugzilla/Auth/Verify.pm
+++ b/Bugzilla/Auth/Verify.pm
@@ -25,6 +25,7 @@ use Bugzilla::User;
use Bugzilla::Util;
use constant user_can_create_account => 1;
+use constant extern_id_used => 0;
sub new {
my ($class, $login_type) = @_;
@@ -232,4 +233,12 @@ C<false>.
Whether or not users can manually create accounts in this type of
account source. Defaults to C<true>.
+=item C<extern_id_used>
+
+Whether or not this verifier method uses the extern_id field. If
+used, users with editusers permission will be be allowed to
+edit the extern_id for all users.
+
+The default value is C<false>.
+
=back
diff --git a/Bugzilla/Auth/Verify/Stack.pm b/Bugzilla/Auth/Verify/Stack.pm
index 2df3fcd25..dfc920420 100644
--- a/Bugzilla/Auth/Verify/Stack.pm
+++ b/Bugzilla/Auth/Verify/Stack.pm
@@ -86,4 +86,9 @@ sub user_can_create_account {
return 0;
}
+sub extern_id_used {
+ my ($self) = @_;
+ return any { $_->extern_id_used } @{ $self->{_stack} };
+}
+
1;
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index 93c318456..612291ceb 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -955,6 +955,7 @@ sub create {
}
return \@optional;
},
+ 'default_authorizer' => new Bugzilla::Auth(),
},
};
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index f23873991..89cd7ce72 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -97,6 +97,7 @@ use constant DB_COLUMNS => (
'profiles.mybugslink AS showmybugslink',
'profiles.disabledtext',
'profiles.disable_mail',
+ 'profiles.extern_id',
);
use constant NAME_FIELD => 'login_name';
use constant ID_FIELD => 'userid';
@@ -108,6 +109,7 @@ use constant VALIDATORS => {
disabledtext => \&_check_disabledtext,
login_name => \&check_login_name_for_creation,
realname => \&_check_realname,
+ extern_id => \&_check_extern_id,
};
sub UPDATE_COLUMNS {
@@ -117,6 +119,7 @@ sub UPDATE_COLUMNS {
disabledtext
login_name
realname
+ extern_id
);
push(@cols, 'cryptpassword') if exists $self->{cryptpassword};
return @cols;
@@ -135,6 +138,12 @@ sub new {
bless ($user, $class);
return $user unless $param;
+ if (ref($param) eq 'HASH') {
+ if (defined $param->{extern_id}) {
+ $param = { condition => 'extern_id = ?' , values => [$param->{extern_id}] };
+ $_[0] = $param;
+ }
+ }
return $class->SUPER::new(@_);
}
@@ -180,6 +189,22 @@ sub update {
sub _check_disable_mail { return $_[1] ? 1 : 0; }
sub _check_disabledtext { return trim($_[1]) || ''; }
+# Check whether the extern_id is unique.
+sub _check_extern_id {
+ my ($invocant, $extern_id) = @_;
+ $extern_id = trim($extern_id);
+ return undef unless defined($extern_id) && $extern_id ne "";
+ if (!ref($invocant) || $invocant->extern_id ne $extern_id) {
+ my $existing_login = $invocant->new({ extern_id => $extern_id });
+ if ($existing_login) {
+ ThrowUserError( 'extern_id_exists',
+ { extern_id => $extern_id,
+ existing_login_name => $existing_login->login });
+ }
+ }
+ return $extern_id;
+}
+
# This is public since createaccount.cgi needs to use it before issuing
# a token for account creation.
sub check_login_name_for_creation {
@@ -219,6 +244,7 @@ sub _check_realname { return trim($_[1]) || ''; }
sub set_disabledtext { $_[0]->set('disabledtext', $_[1]); }
sub set_disable_mail { $_[0]->set('disable_mail', $_[1]); }
+sub set_extern_id { $_[0]->set('extern_id', $_[1]); }
sub set_login {
my ($self, $login) = @_;
@@ -243,6 +269,7 @@ sub set_password { $_[0]->set('cryptpassword', $_[1]); }
# Accessors for user attributes
sub name { $_[0]->{realname}; }
sub login { $_[0]->{login_name}; }
+sub extern_id { $_[0]->{extern_id}; }
sub email { $_[0]->login . Bugzilla->params->{'emailsuffix'}; }
sub disabledtext { $_[0]->{'disabledtext'}; }
sub is_disabled { $_[0]->disabledtext ? 1 : 0; }
diff --git a/editusers.cgi b/editusers.cgi
index f53fde985..ad70e08a8 100755
--- a/editusers.cgi
+++ b/editusers.cgi
@@ -213,7 +213,9 @@ if ($action eq 'search') {
cryptpassword => $password,
realname => scalar $cgi->param('name'),
disabledtext => scalar $cgi->param('disabledtext'),
- disable_mail => scalar $cgi->param('disable_mail')});
+ disable_mail => scalar $cgi->param('disable_mail'),
+ extern_id => scalar $cgi->param('extern_id'),
+ });
userDataToVars($new_user->id);
@@ -256,6 +258,8 @@ if ($action eq 'search') {
if $cgi->param('password');
$otherUser->set_disabledtext($cgi->param('disabledtext'));
$otherUser->set_disable_mail($cgi->param('disable_mail'));
+ $otherUser->set_extern_id($cgi->param('extern_id'))
+ if defined($cgi->param('extern_id'));
$changes = $otherUser->update();
}
diff --git a/template/en/default/admin/users/userdata.html.tmpl b/template/en/default/admin/users/userdata.html.tmpl
index 5df1f7c8c..f3f0e5aa9 100644
--- a/template/en/default/admin/users/userdata.html.tmpl
+++ b/template/en/default/admin/users/userdata.html.tmpl
@@ -38,6 +38,19 @@
[% END %]
</td>
</tr>
+[% IF default_authorizer.extern_id_used %]
+ <tr>
+ <th><label for="extern_id">External Login ID:</label></th>
+ <td>
+ [% IF editusers %]
+ <input size="64" maxlength="64" name="extern_id"
+ id="extern_id" value="[% otheruser.extern_id FILTER html %]">
+ [% ELSE %]
+ [% otheruser.extern_id FILTER html %]
+ [% END %]
+ </td>
+ </tr>
+[% END %]
<tr>
<th><label for="name">Real name:</label></th>
<td>
diff --git a/template/en/default/global/messages.html.tmpl b/template/en/default/global/messages.html.tmpl
index 5583a961e..0b20be869 100644
--- a/template/en/default/global/messages.html.tmpl
+++ b/template/en/default/global/messages.html.tmpl
@@ -60,6 +60,8 @@
A new password has been set.
[% ELSIF field == 'disabledtext' %]
The disable text has been modified.
+ [% ELSIF field == 'extern_id' %]
+ The user's External Login ID has been modified.
[% ELSIF field == 'disable_mail' %]
[% IF otheruser.email_disabled %]
[% terms.Bug %]mail has been disabled.
diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl
index 16b66ca84..071599bf8 100644
--- a/template/en/default/global/user-error.html.tmpl
+++ b/template/en/default/global/user-error.html.tmpl
@@ -1696,6 +1696,14 @@
[% title = "Illegal User ID" %]
User ID '[% userid FILTER html %]' is not valid integer.
+ [% ELSIF error == "extern_id_exists" %]
+ [% title = "Account Already Exists" %]
+ There is already an account
+ [% IF existing_login_name %]
+ ([% existing_login_name FILTER html %])
+ [% END %]
+ with the External Login ID "[% extern_id FILTER html %]".
+
[% ELSE %]
[%# Try to find hooked error messages %]