From 3891b63a1eb52076337885487f251a10580a4a85 Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Wed, 27 Apr 2016 18:50:13 +0200 Subject: Bug 218917 - Allow the login name to be different from the email address Original patch by Gervase Markham r=gerv a=dkl --- Bugzilla/API/1_0/Util.pm | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'Bugzilla/API/1_0/Util.pm') diff --git a/Bugzilla/API/1_0/Util.pm b/Bugzilla/API/1_0/Util.pm index ce4487c1f..13c3eebac 100644 --- a/Bugzilla/API/1_0/Util.pm +++ b/Bugzilla/API/1_0/Util.pm @@ -33,9 +33,10 @@ our @EXPORT = qw( as_datetime as_double as_email - as_email_array as_int as_int_array + as_login + as_login_array as_name_array as_string as_string_array @@ -367,8 +368,8 @@ sub as_string { defined $_[0] ? $_[0] . '' : JSON::null } # array types -sub as_email_array { [ map { as_email($_) } @{ $_[0] // [] } ] } sub as_int_array { [ map { as_int($_) } @{ $_[0] // [] } ] } +sub as_login_array { [ map { as_login($_) } @{ $_[0] // [] } ] } sub as_name_array { [ map { as_string($_->name) } @{ $_[0] // [] } ] } sub as_string_array { [ map { as_string($_) } @{ $_[0] // [] } ] } @@ -380,10 +381,14 @@ sub as_datetime { : JSON::null; } -sub as_email { +sub as_login { defined $_[0] - ? ( Bugzilla->params->{webservice_email_filter} ? email_filter($_[0]) : $_[0] . '' ) - : JSON::null + ? ( Bugzilla->params->{use_email_as_login} ? email_filter($_[0]) : $_[0] . '' ) + : JSON::null; +} + +sub as_email { + defined($_[0]) && Bugzilla->user->in_group('editusers') ? $_[0] . '' : JSON::null; } sub as_base64 { @@ -496,13 +501,9 @@ double value. If parameter is undefined, returns JSON::null. =head2 as_email -Takes an email address as a parameter if filters it if C is -enabled in the system settings. If parameter is undefined, returns JSON::null. - -=head2 as_email_array - -Similar to C, but takes an array reference to a list of values and -returns an array reference with the converted values. +Takes an email address as a parameter. If the user is in the editusers group, +it returns the email address, unchanged. If the parameter is undefined or the +user is not in the editusers group, it returns JSON::null. =head2 as_int @@ -514,6 +515,18 @@ value. If parameter is undefined, returns JSON::null. Similar to C, but takes an array reference to a list of values and returns an array reference with the converted values. +=head2 as_login + +Takes a login name as a parameter. If C is enabled and the +user is logged out, it returns the local part of the email address (the part +before '@'). Else it returns the full login name. If parameter is undefined, +returns JSON::null. + +=head2 as_login_array + +Similar to C, but takes an array reference to a list of values and +returns an array reference with the converted values. + =head2 as_name_array Takes a list of L values and returns an array of new values -- cgit v1.2.3-24-g4f1b