Skip to content

Commit 3891b63

Browse files
committed
Bug 218917 - Allow the login name to be different from the email address
Original patch by Gervase Markham r=gerv a=dkl
1 parent c44470a commit 3891b63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1014
-598
lines changed

Bugzilla/API/1_0/Resource/Bug.pm

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ sub _translate_comment {
509509
my $comment_hash = {
510510
id => as_int($comment->id),
511511
bug_id => as_int($comment->bug_id),
512-
creator => as_email($comment->author->login),
512+
creator => as_login($comment->author->login),
513513
time => as_datetime($comment->creation_ts),
514514
creation_time => as_datetime($comment->creation_ts),
515515
is_private => as_boolean($comment->is_private),
@@ -1431,7 +1431,7 @@ sub _bug_to_hash {
14311431
$item{alias} = as_string_array($bug->alias);
14321432
}
14331433
if (filter_wants $params, 'assigned_to') {
1434-
$item{'assigned_to'} = as_email($bug->assigned_to->login);
1434+
$item{'assigned_to'} = as_login($bug->assigned_to->login);
14351435
$item{'assigned_to_detail'} = $self->_user_to_hash($bug->assigned_to, $params, undef, 'assigned_to');
14361436
}
14371437
if (filter_wants $params, 'blocks') {
@@ -1444,14 +1444,14 @@ sub _bug_to_hash {
14441444
$item{component} = as_string($bug->component);
14451445
}
14461446
if (filter_wants $params, 'cc') {
1447-
$item{'cc'} = as_email_array($bug->cc);
1447+
$item{'cc'} = as_login_array($bug->cc);
14481448
$item{'cc_detail'} = [ map { $self->_user_to_hash($_, $params, undef, 'cc') } @{ $bug->cc_users } ];
14491449
}
14501450
if (filter_wants $params, 'creation_time') {
14511451
$item{'creation_time'} = as_datetime($bug->creation_ts);
14521452
}
14531453
if (filter_wants $params, 'creator') {
1454-
$item{'creator'} = as_email($bug->reporter->login);
1454+
$item{'creator'} = as_login($bug->reporter->login);
14551455
$item{'creator_detail'} = $self->_user_to_hash($bug->reporter, $params, undef, 'creator');
14561456
}
14571457
if (filter_wants $params, 'depends_on') {
@@ -1477,7 +1477,7 @@ sub _bug_to_hash {
14771477
}
14781478
if (filter_wants $params, 'qa_contact') {
14791479
my $qa_login = $bug->qa_contact ? $bug->qa_contact->login : '';
1480-
$item{'qa_contact'} = as_email($qa_login);
1480+
$item{'qa_contact'} = as_login($qa_login);
14811481
if ($bug->qa_contact) {
14821482
$item{'qa_contact_detail'} = $self->_user_to_hash($bug->qa_contact, $params, undef, 'qa_contact');
14831483
}
@@ -1546,8 +1546,7 @@ sub _user_to_hash {
15461546
my $item = filter $filters, {
15471547
id => as_int($user->id),
15481548
real_name => as_string($user->name),
1549-
name => as_email($user->login),
1550-
email => as_email($user->email),
1549+
name => as_login($user->login),
15511550
}, $types, $prefix;
15521551
return $item;
15531552
}
@@ -1571,7 +1570,7 @@ sub _attachment_to_hash {
15711570
# creator requires an extra lookup, so we only send them if
15721571
# the filter wants them.
15731572
if (filter_wants $filters, 'creator', $types, $prefix) {
1574-
$item->{'creator'} = as_email($attach->attacher->login);
1573+
$item->{'creator'} = as_login($attach->attacher->login);
15751574
}
15761575

15771576
if (filter_wants $filters, 'data', $types, $prefix) {
@@ -1603,7 +1602,7 @@ sub _flag_to_hash {
16031602

16041603
foreach my $field (qw(setter requestee)) {
16051604
my $field_id = $field . "_id";
1606-
$item->{$field} = as_email($flag->$field->login)
1605+
$item->{$field} = as_login($flag->$field->login)
16071606
if $flag->$field_id;
16081607
}
16091608

@@ -2672,10 +2671,6 @@ C<string> The 'real' name for this user, if any.
26722671
26732672
C<string> The user's Bugzilla login.
26742673
2675-
=item C<email>
2676-
2677-
C<string> The user's email address. Currently this is the same value as the name.
2678-
26792674
=back
26802675
26812676
=back

Bugzilla/API/1_0/Resource/Bugzilla.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ use constant PARAMETERS_LOGGED_IN => qw(
6969
defaultseverity
7070
duplicate_or_move_bug_status
7171
emailregexpdesc
72-
emailsuffix
7372
letsubmitterchoosemilestone
7473
letsubmitterchoosepriority
7574
mailfrom
@@ -82,6 +81,7 @@ use constant PARAMETERS_LOGGED_IN => qw(
8281
requirelogin
8382
search_allow_no_criteria
8483
urlbase
84+
use_email_as_login
8585
use_see_also
8686
useclassification
8787
usemenuforusers
@@ -449,7 +449,6 @@ A logged-in user can access the following parameters (listed alphabetically):
449449
C<defaultseverity>,
450450
C<duplicate_or_move_bug_status>,
451451
C<emailregexpdesc>,
452-
C<emailsuffix>,
453452
C<letsubmitterchoosemilestone>,
454453
C<letsubmitterchoosepriority>,
455454
C<mailfrom>,
@@ -462,6 +461,7 @@ A logged-in user can access the following parameters (listed alphabetically):
462461
C<requirelogin>,
463462
C<search_allow_no_criteria>,
464463
C<urlbase>,
464+
C<use_email_as_login>,
465465
C<use_see_also>,
466466
C<useclassification>,
467467
C<usemenuforusers>,

Bugzilla/API/1_0/Resource/Group.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ sub _get_group_membership {
247247
map {{
248248
id => as_int($_->id),
249249
real_name => as_string($_->name),
250-
name => as_string($_->login),
251-
email => as_string($_->email),
250+
name => as_login($_->login),
251+
email => as_email($_->email),
252252
can_login => as_boolean($_->is_enabled),
253253
email_enabled => as_boolean($_->email_enabled),
254254
login_denied_text => as_string($_->disabledtext),
@@ -571,12 +571,12 @@ C<string> The actual name of the user.
571571
572572
=item email
573573
574-
C<string> The email address of the user.
574+
C<string> If you are in the editusers group, returns the email address of the
575+
user, else returns nothing.
575576
576577
=item name
577578
578-
C<string> The login name of the user. Note that in some situations this is
579-
different than their email.
579+
C<string> The login name of the user.
580580
581581
=item can_login
582582

Bugzilla/API/1_0/Resource/Product.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ sub _component_to_hash {
322322
name => as_string($component->name),
323323
description => as_string($component->description),
324324
default_assigned_to =>
325-
as_email($component->default_assignee->login),
325+
as_login($component->default_assignee->login),
326326
default_qa_contact =>
327-
as_email($component->default_qa_contact ?
327+
as_login($component->default_qa_contact ?
328328
$component->default_qa_contact->login : ""),
329329
sort_key => 0, # sort_key is returned to match Bug.fields
330330
is_active => as_boolean($component->is_active),

Bugzilla/API/1_0/Resource/User.pm

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ use constant PUBLIC_METHODS => qw(
5353
);
5454

5555
use constant MAPPED_FIELDS => {
56-
email => 'login',
5756
full_name => 'name',
5857
login_denied_text => 'disabledtext',
5958
};
6059

6160
use constant MAPPED_RETURNS => {
62-
login_name => 'email',
6361
realname => 'full_name',
6462
disabledtext => 'login_denied_text',
6563
};
@@ -158,8 +156,11 @@ sub offer_account_by_email {
158156
my $email = trim($params->{email})
159157
|| ThrowCodeError('param_required', { param => 'email' });
160158

159+
my $login = Bugzilla->params->{use_email_as_login} ? $email : trim($params->{login});
160+
$login or ThrowCodeError('param_required', { param => 'login' });
161+
161162
Bugzilla->user->check_account_creation_enabled;
162-
Bugzilla->user->check_and_send_account_creation_confirmation($email);
163+
Bugzilla->user->check_and_send_account_creation_confirmation($login, $email);
163164
return undef;
164165
}
165166

@@ -174,11 +175,16 @@ sub create {
174175

175176
my $email = trim($params->{email})
176177
|| ThrowCodeError('param_required', { param => 'email' });
178+
179+
my $login = Bugzilla->params->{use_email_as_login} ? $email : trim($params->{login});
180+
$login or ThrowCodeError('param_required', { param => 'login' });
181+
177182
my $realname = trim($params->{full_name});
178183
my $password = trim($params->{password}) || '*';
179184

180185
my $user = Bugzilla::User->create({
181-
login_name => $email,
186+
login_name => $login,
187+
email => $email,
182188
realname => $realname,
183189
cryptpassword => $password
184190
});
@@ -225,7 +231,7 @@ sub get {
225231
@users = map { filter $params, {
226232
id => as_int($_->id),
227233
real_name => as_string($_->name),
228-
name => as_email($_->login),
234+
name => as_login($_->login),
229235
} } @$in_group;
230236

231237
return { users => \@users };
@@ -277,12 +283,12 @@ sub get {
277283
my $user_info = filter $params, {
278284
id => as_int($user->id),
279285
real_name => as_string($user->name),
280-
name => as_email($user->login),
281-
email => as_email($user->email),
286+
name => as_login($user->login),
282287
can_login => as_boolean($user->is_enabled ? 1 : 0),
283288
};
284289

285290
if (Bugzilla->user->in_group('editusers')) {
291+
$user_info->{email} = as_email($user->email),
286292
$user_info->{email_enabled} = as_boolean($user->email_enabled);
287293
$user_info->{login_denied_text} = as_string($user->disabledtext);
288294
}
@@ -651,6 +657,8 @@ This is the recommended way to create a Bugzilla account.
651657
652658
=item C<email> (string) - the email to send the offer to.
653659
660+
=item C<login> (string) - the login of the user account.
661+
654662
=back
655663
656664
=item B<Returns> (nothing)
@@ -699,6 +707,11 @@ are the same as below.
699707
700708
=item C<email> (string) - The email address for the new user.
701709
710+
=item C<login> (string) - The login name for the new user.
711+
If the installation has the C<use_email_as_login> parameter switched on, then
712+
this parameter is ignored, and the value of the C<email> parameter will
713+
be used as the login name for the new account.
714+
702715
=item C<full_name> (string) B<Optional> - The user's full name. Will
703716
be set to empty if not specified.
704717
@@ -768,7 +781,7 @@ C<array> Contains ids of user to update.
768781
769782
=item C<names>
770783
771-
C<array> Contains email/login of user to update.
784+
C<array> Contains login of user to update.
772785
773786
=item C<full_name>
774787
@@ -996,8 +1009,7 @@ C<string> The email address of the user.
9961009
9971010
=item name
9981011
999-
C<string> The login name of the user. Note that in some situations this is
1000-
different than their email.
1012+
C<string> The login name of the user.
10011013
10021014
=item can_login
10031015
@@ -1083,7 +1095,7 @@ C<string> The CGI parameters for the saved report.
10831095
B<Note>: If you are not logged in to Bugzilla when you call this function, you
10841096
will only be returned the C<id>, C<name>, and C<real_name> items. If you are
10851097
logged in and not in editusers group, you will only be returned the C<id>, C<name>,
1086-
C<real_name>, C<email>, C<can_login>, and C<groups> items. The groups returned are
1098+
C<real_name>, C<can_login>, and C<groups> items. The groups returned are
10871099
filtered based on your permission to bless each group.
10881100
The C<saved_searches> and C<saved_reports> items are only returned if you are
10891101
querying your own account, even if you are in the editusers group.

Bugzilla/API/1_0/Util.pm

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ our @EXPORT = qw(
3333
as_datetime
3434
as_double
3535
as_email
36-
as_email_array
3736
as_int
3837
as_int_array
38+
as_login
39+
as_login_array
3940
as_name_array
4041
as_string
4142
as_string_array
@@ -367,8 +368,8 @@ sub as_string { defined $_[0] ? $_[0] . '' : JSON::null }
367368

368369
# array types
369370

370-
sub as_email_array { [ map { as_email($_) } @{ $_[0] // [] } ] }
371371
sub as_int_array { [ map { as_int($_) } @{ $_[0] // [] } ] }
372+
sub as_login_array { [ map { as_login($_) } @{ $_[0] // [] } ] }
372373
sub as_name_array { [ map { as_string($_->name) } @{ $_[0] // [] } ] }
373374
sub as_string_array { [ map { as_string($_) } @{ $_[0] // [] } ] }
374375

@@ -380,10 +381,14 @@ sub as_datetime {
380381
: JSON::null;
381382
}
382383

383-
sub as_email {
384+
sub as_login {
384385
defined $_[0]
385-
? ( Bugzilla->params->{webservice_email_filter} ? email_filter($_[0]) : $_[0] . '' )
386-
: JSON::null
386+
? ( Bugzilla->params->{use_email_as_login} ? email_filter($_[0]) : $_[0] . '' )
387+
: JSON::null;
388+
}
389+
390+
sub as_email {
391+
defined($_[0]) && Bugzilla->user->in_group('editusers') ? $_[0] . '' : JSON::null;
387392
}
388393

389394
sub as_base64 {
@@ -496,13 +501,9 @@ double value. If parameter is undefined, returns JSON::null.
496501
497502
=head2 as_email
498503
499-
Takes an email address as a parameter if filters it if C<webservice_email_filter> is
500-
enabled in the system settings. If parameter is undefined, returns JSON::null.
501-
502-
=head2 as_email_array
503-
504-
Similar to C<as_email>, but takes an array reference to a list of values and
505-
returns an array reference with the converted values.
504+
Takes an email address as a parameter. If the user is in the editusers group,
505+
it returns the email address, unchanged. If the parameter is undefined or the
506+
user is not in the editusers group, it returns JSON::null.
506507
507508
=head2 as_int
508509
@@ -514,6 +515,18 @@ value. If parameter is undefined, returns JSON::null.
514515
Similar to C<as_int>, but takes an array reference to a list of values and
515516
returns an array reference with the converted values.
516517
518+
=head2 as_login
519+
520+
Takes a login name as a parameter. If C<use_email_as_login> is enabled and the
521+
user is logged out, it returns the local part of the email address (the part
522+
before '@'). Else it returns the full login name. If parameter is undefined,
523+
returns JSON::null.
524+
525+
=head2 as_login_array
526+
527+
Similar to C<as_login>, but takes an array reference to a list of values and
528+
returns an array reference with the converted values.
529+
517530
=head2 as_name_array
518531
519532
Takes a list of L<Bugzilla::Object> values and returns an array of new values

Bugzilla/Auth.pm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ sub extern_id_used {
136136
|| $self->{_verifier}->extern_id_used;
137137
}
138138

139+
sub can_change_login {
140+
return $_[0]->user_can_create_account;
141+
}
142+
139143
sub can_change_email {
140144
return $_[0]->user_can_create_account;
141145
}
@@ -412,6 +416,14 @@ Returns: C<true> if users are allowed to create new Bugzilla accounts,
412416
413417
Description: Whether or not current login system uses extern_id.
414418
419+
=item C<can_change_login>
420+
421+
Description: Whether or not the current login system allows users to
422+
change their own login.
423+
Params: None
424+
Returns: C<true> if users can change their own login,
425+
C<false> otherwise.
426+
415427
=item C<can_change_email>
416428
417429
Description: Whether or not the current login system allows users to

0 commit comments

Comments
 (0)