From 351b399991094e57e890a9291484c4ab69ca628b Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Wed, 18 Jul 2018 22:42:56 -0400 Subject: Bug 1476288 - Replace moz_nick with (new, revised) nick and also attempt to disallow duplicate nicks --- Bugzilla/User.pm | 10 ++++++--- extensions/BugModal/lib/MonkeyPatches.pm | 25 ---------------------- .../en/default/bug_modal/activity_stream.html.tmpl | 6 +++--- .../template/en/default/bug_modal/edit.html.tmpl | 4 ++-- .../template/en/default/bug_modal/user.html.tmpl | 6 +++--- template/en/default/global/messages.html.tmpl | 2 ++ 6 files changed, 17 insertions(+), 36 deletions(-) diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 9faed25cc..4a58043a0 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -482,11 +482,15 @@ sub set_login { } sub _generate_nickname { - my ($name, $login) = @_; + my ($name, $login, $id) = @_; my ($nick) = extract_nicks($name); if (!$nick) { $nick = ""; } + my ($count) = Bugzilla->dbh->selectrow_array('SELECT COUNT(*) FROM profiles WHERE nickname = ? AND userid != ?', undef, $nick, $id); + if ($count) { + $nick = ""; + } return $nick; } @@ -494,7 +498,7 @@ sub set_name { my ($self, $name) = @_; $self->set('realname', $name); delete $self->{identity}; - $self->set('nickname', _generate_nickname($name, $self->login)); + $self->set('nickname', _generate_nickname($name, $self->login, $self->id)); } sub set_nick { @@ -2532,7 +2536,7 @@ sub create { my $dbh = Bugzilla->dbh; $dbh->bz_start_transaction(); - $params->{nickname} = _generate_nickname($params->{realname}, $params->{login_name}); + $params->{nickname} = _generate_nickname($params->{realname}, $params->{login_name}, 0); my $user = $class->SUPER::create($params); # Turn on all email for the new user diff --git a/extensions/BugModal/lib/MonkeyPatches.pm b/extensions/BugModal/lib/MonkeyPatches.pm index 88fce11af..54bd6e560 100644 --- a/extensions/BugModal/lib/MonkeyPatches.pm +++ b/extensions/BugModal/lib/MonkeyPatches.pm @@ -40,31 +40,6 @@ sub active_attachments { 1; -package Bugzilla::User; - -use 5.10.1; -use strict; -use warnings; - -sub moz_nick { - my ($self) = @_; - if (!exists $self->{moz_nick}) { - if ($self->name =~ /:?:(\S+?)\b/) { - $self->{moz_nick} = $1; - } - elsif ($self->name) { - $self->{moz_nick} = $self->name; - } - else { - $self->login =~ /^([^\@]+)\@/; - $self->{moz_nick} = $1; - } - } - return $self->{moz_nick}; -} - -1; - package Bugzilla::Attachment; use 5.10.1; diff --git a/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl index 883393fba..af2077e00 100644 --- a/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl @@ -146,7 +146,7 @@ [% END %] [% END %] @@ -184,9 +184,9 @@ + title="[% comment.author.nick FILTER html %] [[% comment.creation_ts FILTER time("%Y-%m-%d %H:%M %Z") FILTER html %]]"> [% ELSE %] - title="[% comment.author.moz_nick FILTER html %] [[% comment.creation_ts FILTER time_duration FILTER html %]]"> + title="[% comment.author.nick FILTER html %] [[% comment.creation_ts FILTER time_duration FILTER html %]]"> [% END %] Comment hidden ([% comment.collapsed_reason FILTER html %]) diff --git a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl index d82e1a684..e2c8bba26 100644 --- a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl @@ -565,8 +565,8 @@ [% sub = []; - sub.push("Reporter: " _ bug.reporter.moz_nick); - sub.push(unassigned ? "Unassigned" : "Assigned: " _ bug.assigned_to.moz_nick); + sub.push("Reporter: " _ bug.reporter.nick); + sub.push(unassigned ? "Unassigned" : "Assigned: " _ bug.assigned_to.nick); IF bug.mentors.size; sub.push("Mentored"); END; diff --git a/extensions/BugModal/template/en/default/bug_modal/user.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/user.html.tmpl index 9eda7b936..6a0ce4e24 100644 --- a/extensions/BugModal/template/en/default/bug_modal/user.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/user.html.tmpl @@ -30,9 +30,9 @@ END; [% IF simple %] [% IF user.id %] - [% u.moz_nick FILTER html %] + [% u.nick FILTER html %] [% ELSE %] - [% u.moz_nick FILTER html %] + [% u.nick FILTER html %] [% END %] [% ELSE %] @@ -52,7 +52,7 @@ END; href="user_profile?user_id=[% u.id FILTER none %]" [% END %] > - [% nick_only ? u.moz_nick : (u.name || u.nick) FILTER html %] + [% nick_only ? u.nick : (u.name || u.nick) FILTER html %] [%~~%] [% END %] diff --git a/template/en/default/global/messages.html.tmpl b/template/en/default/global/messages.html.tmpl index b2430b7ed..591617f3e 100644 --- a/template/en/default/global/messages.html.tmpl +++ b/template/en/default/global/messages.html.tmpl @@ -56,6 +56,8 @@ The login is now [% otheruser.login FILTER html %]. [% ELSIF field == 'realname' %] The real name has been updated. + [% ELSIF field == 'nickname' %] + The nickname is now [% otheruser.nick FILTER html %]. [% ELSIF field == 'cryptpassword' %] A new password has been set. [% ELSIF field == 'disabledtext' %] -- cgit v1.2.3-24-g4f1b