From dfcccd4cb882a171d10ba8a5c2763dcc73654256 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Mon, 12 May 2014 09:51:40 -0700 Subject: [PATCH] Add config to require real name, respect config when creating new users, drop real name from full name if not provided. Summary: Fixes T4728, first pass, Make real name optional on user accounts Test Plan: Default real name config should be false (not required). Create new user, real name should not be required. Toggle config, real name should be required. Users with no real name should be always listed by their usernames. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4728 Differential Revision: https://secure.phabricator.com/D9027 --- .../auth/controller/PhabricatorAuthRegisterController.php | 6 ++++-- .../metamta/query/PhabricatorMetaMTAActorQuery.php | 3 ++- .../people/config/PhabricatorUserConfigOptions.php | 7 +++++++ .../people/controller/PhabricatorPeopleNewController.php | 5 +++-- .../controller/PhabricatorPeopleProfileController.php | 2 +- .../people/phid/PhabricatorPeoplePHIDTypeUser.php | 5 +++-- .../people/search/PhabricatorUserSearchIndexer.php | 2 +- src/applications/people/storage/PhabricatorUser.php | 6 +++++- 8 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/applications/auth/controller/PhabricatorAuthRegisterController.php b/src/applications/auth/controller/PhabricatorAuthRegisterController.php index 6f75a51555..563f256cc5 100644 --- a/src/applications/auth/controller/PhabricatorAuthRegisterController.php +++ b/src/applications/auth/controller/PhabricatorAuthRegisterController.php @@ -144,8 +144,10 @@ final class PhabricatorAuthRegisterController $errors = array(); + $require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name'); + $e_username = strlen($value_username) ? null : true; - $e_realname = strlen($value_realname) ? null : true; + $e_realname = $require_real_name ? true : null; $e_email = strlen($value_email) ? null : true; $e_password = true; $e_captcha = true; @@ -224,7 +226,7 @@ final class PhabricatorAuthRegisterController if ($can_edit_realname) { $value_realname = $request->getStr('realName'); - if (!strlen($value_realname)) { + if (!strlen($value_realname) && $require_real_name) { $e_realname = pht('Required'); $errors[] = pht('Real name is required.'); } else { diff --git a/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php b/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php index ad94b9ff31..ff5689d44e 100644 --- a/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php +++ b/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php @@ -177,7 +177,8 @@ final class PhabricatorMetaMTAActorQuery extends PhabricatorQuery { $name = $user->getUserName(); break; case 'real': - $name = $user->getRealName(); + $name = strlen($user->getRealName()) ? + $user->getRealName() : $user->getUserName(); break; case 'full': default: diff --git a/src/applications/people/config/PhabricatorUserConfigOptions.php b/src/applications/people/config/PhabricatorUserConfigOptions.php index 0795ba67e5..5c83312fcc 100644 --- a/src/applications/people/config/PhabricatorUserConfigOptions.php +++ b/src/applications/people/config/PhabricatorUserConfigOptions.php @@ -36,6 +36,13 @@ final class PhabricatorUserConfigOptions ->setDescription(pht("Select and reorder user profile fields.")), $this->newOption('user.custom-field-definitions', 'map', array()) ->setDescription(pht("Add new simple fields to user profiles.")), + $this->newOption('user.require-real-name', 'bool', true) + ->setDescription(pht("Always require real name for user profiles.")) + ->setBoolOptions( + array( + pht('Make real names required'), + pht('Make real names optional'), + )), ); } diff --git a/src/applications/people/controller/PhabricatorPeopleNewController.php b/src/applications/people/controller/PhabricatorPeopleNewController.php index c789747fff..5769c3aca7 100644 --- a/src/applications/people/controller/PhabricatorPeopleNewController.php +++ b/src/applications/people/controller/PhabricatorPeopleNewController.php @@ -25,9 +25,10 @@ final class PhabricatorPeopleNewController } $user = new PhabricatorUser(); + $require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name'); $e_username = true; - $e_realname = true; + $e_realname = $require_real_name ? true : null; $e_email = true; $errors = array(); @@ -64,7 +65,7 @@ final class PhabricatorPeopleNewController $e_username = null; } - if (!strlen($user->getRealName())) { + if (!strlen($user->getRealName()) && $require_real_name) { $errors[] = pht('Real name is required.'); $e_realname = pht('Required'); } else { diff --git a/src/applications/people/controller/PhabricatorPeopleProfileController.php b/src/applications/people/controller/PhabricatorPeopleProfileController.php index 0413127dce..c75ae8088e 100644 --- a/src/applications/people/controller/PhabricatorPeopleProfileController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileController.php @@ -33,7 +33,7 @@ final class PhabricatorPeopleProfileController $picture = $user->loadProfileImageURI(); $header = id(new PHUIHeaderView()) - ->setHeader($user->getUserName().' ('.$user->getRealName().')') + ->setHeader($user->getFullName()) ->setSubheader($profile->getTitle()) ->setImage($picture); diff --git a/src/applications/people/phid/PhabricatorPeoplePHIDTypeUser.php b/src/applications/people/phid/PhabricatorPeoplePHIDTypeUser.php index 49ddf01ed4..db6295006f 100644 --- a/src/applications/people/phid/PhabricatorPeoplePHIDTypeUser.php +++ b/src/applications/people/phid/PhabricatorPeoplePHIDTypeUser.php @@ -41,10 +41,11 @@ final class PhabricatorPeoplePHIDTypeUser extends PhabricatorPHIDType { foreach ($handles as $phid => $handle) { $user = $objects[$phid]; + $realname = $user->getRealName(); + $handle->setName($user->getUsername()); $handle->setURI('/p/'.$user->getUsername().'/'); - $handle->setFullName( - $user->getUsername().' ('.$user->getRealName().')'); + $handle->setFullName($user->getFullName()); $handle->setImageURI($user->loadProfileImageURI()); $handle->setDisabled(!$user->isUserActivated()); if ($user->hasStatus()) { diff --git a/src/applications/people/search/PhabricatorUserSearchIndexer.php b/src/applications/people/search/PhabricatorUserSearchIndexer.php index bb0a2a337c..da591d7f7d 100644 --- a/src/applications/people/search/PhabricatorUserSearchIndexer.php +++ b/src/applications/people/search/PhabricatorUserSearchIndexer.php @@ -13,7 +13,7 @@ final class PhabricatorUserSearchIndexer $doc = new PhabricatorSearchAbstractDocument(); $doc->setPHID($user->getPHID()); $doc->setDocumentType(PhabricatorPeoplePHIDTypeUser::TYPECONST); - $doc->setDocumentTitle($user->getUserName().' ('.$user->getRealName().')'); + $doc->setDocumentTitle($user->getFullName()); $doc->setDocumentCreated($user->getDateCreated()); $doc->setDocumentModified($user->getDateModified()); diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index 051a77f2b8..f5da21efd4 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -711,7 +711,11 @@ EOBODY; } public function getFullName() { - return $this->getUsername().' ('.$this->getRealName().')'; + if (strlen($this->getRealName())) { + return $this->getUsername().' ('.$this->getRealName().')'; + } else { + return $this->getUsername(); + } } public function __toString() {