From 8ed48a89f4512ff6e2f0840632ac78ee5ed1d9e1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 27 Apr 2012 17:44:10 -0700 Subject: [PATCH] Use a disk-based default avatar, not a database-based one Summary: This is mostly in an effort to simplify D2323. Currently, we load one image into the database by default. This is a weird special case that makes things more complicated than necessary. Instead, use a disk-based default avatar. Test Plan: Verified that a user without an image appears with the default avatar as a handle, in profile settings, and on their person page. Reviewers: btrahan, vrana, edward, jungejason Reviewed By: vrana CC: aran Maniphest Tasks: T345 Differential Revision: https://secure.phabricator.com/D2331 --- conf/default.conf.php | 4 ---- .../user/base/ConduitAPI_user_Method.php | 10 +-------- .../conduit/method/user/base/__init__.php | 3 --- .../PhabricatorPeopleProfileController.php | 8 +------- .../people/controller/profile/__init__.php | 1 - ...atorUserProfileSettingsPanelController.php | 9 +-------- .../people/storage/user/PhabricatorUser.php | 19 ++++++++++++++---- .../people/storage/user/__init__.php | 2 ++ .../data/PhabricatorObjectHandleData.php | 3 +++ .../phid/handle/data/__init__.php | 1 + .../PhabricatorProjectProfileController.php | 2 +- .../project/controller/profile/__init__.php | 1 + .../profile/PhabricatorProjectProfile.php | 5 ----- .../project/storage/profile/__init__.php | 3 --- webroot/rsrc/image/avatar.png | Bin 0 -> 959 bytes 15 files changed, 26 insertions(+), 45 deletions(-) create mode 100644 webroot/rsrc/image/avatar.png diff --git a/conf/default.conf.php b/conf/default.conf.php index 334e0a12b9..98b7d9ca7f 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -31,10 +31,6 @@ return array( // you through setting up Phabricator. 'phabricator.setup' => false, - // The default PHID for users who haven't uploaded a profile image. It should - // be 50x50px. - 'user.default-profile-image-phid' => 'PHID-FILE-4d61229816cfe6f2b2a3', - // -- IMPORTANT! Security! -------------------------------------------------- // // IMPORTANT: By default, Phabricator serves files from the same domain the diff --git a/src/applications/conduit/method/user/base/ConduitAPI_user_Method.php b/src/applications/conduit/method/user/base/ConduitAPI_user_Method.php index ec73278b95..c74029b021 100644 --- a/src/applications/conduit/method/user/base/ConduitAPI_user_Method.php +++ b/src/applications/conduit/method/user/base/ConduitAPI_user_Method.php @@ -22,20 +22,12 @@ abstract class ConduitAPI_user_Method extends ConduitAPIMethod { protected function buildUserInformationDictionary(PhabricatorUser $user) { - $src_phid = $user->getProfileImagePHID(); - $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid); - if ($file) { - $picture = $file->getBestURI(); - } else { - $picture = null; - } - return array( 'phid' => $user->getPHID(), 'userName' => $user->getUserName(), 'realName' => $user->getRealName(), 'email' => $user->getEmail(), - 'image' => $picture, + 'image' => $user->loadProfileImageURI(), 'uri' => PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'), ); } diff --git a/src/applications/conduit/method/user/base/__init__.php b/src/applications/conduit/method/user/base/__init__.php index 1780cf774f..a91e4dcbd1 100644 --- a/src/applications/conduit/method/user/base/__init__.php +++ b/src/applications/conduit/method/user/base/__init__.php @@ -7,10 +7,7 @@ phutil_require_module('phabricator', 'applications/conduit/method/base'); -phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'infrastructure/env'); -phutil_require_module('phutil', 'utils'); - phutil_require_source('ConduitAPI_user_Method.php'); diff --git a/src/applications/people/controller/profile/PhabricatorPeopleProfileController.php b/src/applications/people/controller/profile/PhabricatorPeopleProfileController.php index 111795f2df..ff91c71758 100644 --- a/src/applications/people/controller/profile/PhabricatorPeopleProfileController.php +++ b/src/applications/people/controller/profile/PhabricatorPeopleProfileController.php @@ -116,13 +116,7 @@ final class PhabricatorPeopleProfileController throw new Exception("Unknown page '{$this->page}'!"); } - $src_phid = $user->getProfileImagePHID(); - $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid); - if ($file) { - $picture = $file->getBestURI(); - } else { - $picture = null; - } + $picture = $user->loadProfileImageURI(); $header = new PhabricatorProfileHeaderView(); $header diff --git a/src/applications/people/controller/profile/__init__.php b/src/applications/people/controller/profile/__init__.php index 110a677ab4..a4f50fdc45 100644 --- a/src/applications/people/controller/profile/__init__.php +++ b/src/applications/people/controller/profile/__init__.php @@ -10,7 +10,6 @@ phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'applications/auth/oauth/provider/base'); phutil_require_module('phabricator', 'applications/feed/builder/feed'); phutil_require_module('phabricator', 'applications/feed/query'); -phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/markup/engine'); phutil_require_module('phabricator', 'applications/people/controller/base'); phutil_require_module('phabricator', 'applications/people/storage/profile'); diff --git a/src/applications/people/controller/settings/panels/profile/PhabricatorUserProfileSettingsPanelController.php b/src/applications/people/controller/settings/panels/profile/PhabricatorUserProfileSettingsPanelController.php index 8c8e75c859..4856a04d5a 100644 --- a/src/applications/people/controller/settings/panels/profile/PhabricatorUserProfileSettingsPanelController.php +++ b/src/applications/people/controller/settings/panels/profile/PhabricatorUserProfileSettingsPanelController.php @@ -107,14 +107,7 @@ final class PhabricatorUserProfileSettingsPanelController } } - $file = id(new PhabricatorFile())->loadOneWhere( - 'phid = %s', - $user->getProfileImagePHID()); - if ($file) { - $img_src = $file->getBestURI(); - } else { - $img_src = null; - } + $img_src = $user->loadProfileImageURI(); $profile_uri = PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'); $sexes = array( diff --git a/src/applications/people/storage/user/PhabricatorUser.php b/src/applications/people/storage/user/PhabricatorUser.php index b5d495ac53..4612b0456a 100644 --- a/src/applications/people/storage/user/PhabricatorUser.php +++ b/src/applications/people/storage/user/PhabricatorUser.php @@ -45,10 +45,6 @@ final class PhabricatorUser extends PhabricatorUserDAO { protected function readField($field) { switch ($field) { - case 'profileImagePHID': - return nonempty( - $this->profileImagePHID, - PhabricatorEnv::getEnvConfig('user.default-profile-image-phid')); case 'timezoneIdentifier': // If the user hasn't set one, guess the server's time. return nonempty( @@ -523,4 +519,19 @@ EOBODY; return (bool)preg_match('/^[a-zA-Z0-9]+$/', $username); } + public static function getDefaultProfileImageURI() { + return celerity_get_resource_uri('/rsrc/image/avatar.png'); + } + + public function loadProfileImageURI() { + $src_phid = $this->getProfileImagePHID(); + + $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid); + if ($file) { + return $file->getBestURI(); + } + + return self::getDefaultProfileImageURI(); + } + } diff --git a/src/applications/people/storage/user/__init__.php b/src/applications/people/storage/user/__init__.php index 910e09c634..3201c0f2e1 100644 --- a/src/applications/people/storage/user/__init__.php +++ b/src/applications/people/storage/user/__init__.php @@ -7,6 +7,7 @@ phutil_require_module('phabricator', 'aphront/writeguard'); +phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/metamta/storage/mail'); phutil_require_module('phabricator', 'applications/people/storage/base'); phutil_require_module('phabricator', 'applications/people/storage/log'); @@ -14,6 +15,7 @@ phutil_require_module('phabricator', 'applications/people/storage/preferences'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/storage/phid'); phutil_require_module('phabricator', 'applications/search/index/indexer/user'); +phutil_require_module('phabricator', 'infrastructure/celerity/api'); phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'infrastructure/util/hash'); phutil_require_module('phabricator', 'storage/qsprintf'); diff --git a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php index a50a106b4d..de1ca5f562 100644 --- a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php @@ -169,6 +169,9 @@ final class PhabricatorObjectHandleData { $img_uri = idx($images, $user->getProfileImagePHID()); if ($img_uri) { $handle->setImageURI($img_uri); + } else { + $handle->setImageURI( + PhabricatorUser::getDefaultProfileImageURI()); } } $handles[$phid] = $handle; diff --git a/src/applications/phid/handle/data/__init__.php b/src/applications/phid/handle/data/__init__.php index 3cfb40dbf3..c2df9169cd 100644 --- a/src/applications/phid/handle/data/__init__.php +++ b/src/applications/phid/handle/data/__init__.php @@ -11,6 +11,7 @@ phutil_require_module('arcanist', 'differential/constants/revisionstatus'); phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/maniphest/constants/owner'); phutil_require_module('phabricator', 'applications/maniphest/constants/status'); +phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/handle'); phutil_require_module('phabricator', 'applications/phid/handle/const/status'); diff --git a/src/applications/project/controller/profile/PhabricatorProjectProfileController.php b/src/applications/project/controller/profile/PhabricatorProjectProfileController.php index 22c03f7a08..9a7528810d 100644 --- a/src/applications/project/controller/profile/PhabricatorProjectProfileController.php +++ b/src/applications/project/controller/profile/PhabricatorProjectProfileController.php @@ -49,7 +49,7 @@ final class PhabricatorProjectProfileController if ($file) { $picture = $file->getBestURI(); } else { - $picture = null; + $picture = PhabricatorUser::getDefaultProfileImageURI(); } $members = mpull($project->loadAffiliations(), null, 'getUserPHID'); diff --git a/src/applications/project/controller/profile/__init__.php b/src/applications/project/controller/profile/__init__.php index 8447952294..88f55e9312 100644 --- a/src/applications/project/controller/profile/__init__.php +++ b/src/applications/project/controller/profile/__init__.php @@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'applications/feed/query'); phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/maniphest/query'); phutil_require_module('phabricator', 'applications/maniphest/view/tasksummary'); +phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phabricator', 'applications/project/controller/base'); phutil_require_module('phabricator', 'applications/project/storage/profile'); diff --git a/src/applications/project/storage/profile/PhabricatorProjectProfile.php b/src/applications/project/storage/profile/PhabricatorProjectProfile.php index f14d070138..2fc6d0403c 100644 --- a/src/applications/project/storage/profile/PhabricatorProjectProfile.php +++ b/src/applications/project/storage/profile/PhabricatorProjectProfile.php @@ -22,9 +22,4 @@ final class PhabricatorProjectProfile extends PhabricatorProjectDAO { protected $blurb; protected $profileImagePHID; - public function getProfileImagePHID() { - return nonempty( - $this->profileImagePHID, - PhabricatorEnv::getEnvConfig('user.default-profile-image-phid')); - } } diff --git a/src/applications/project/storage/profile/__init__.php b/src/applications/project/storage/profile/__init__.php index 7049de11cc..da02c73032 100644 --- a/src/applications/project/storage/profile/__init__.php +++ b/src/applications/project/storage/profile/__init__.php @@ -7,9 +7,6 @@ phutil_require_module('phabricator', 'applications/project/storage/base'); -phutil_require_module('phabricator', 'infrastructure/env'); - -phutil_require_module('phutil', 'utils'); phutil_require_source('PhabricatorProjectProfile.php'); diff --git a/webroot/rsrc/image/avatar.png b/webroot/rsrc/image/avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..755d19cd2ef2467e93a7fb1fee14978bf2ac866e GIT binary patch literal 959 zcmV;w13>(VP)QPui1bI*-?emZemqRR;kx zA0=Etj0ThSLfXlyscPm%G0cOlYKPtapc}`@T;>I3CaQ&FLBGx3{OMI_^%mkTpP zC1nb2$gNWx#>-d;#B`ygV>j8LZ&bZOge<9QZe{zNROq1xsTmXj6g!+IkrzV?Y&cmUNveC8D^FC4XcTG+=k40d?(2UTV3tED}j|;-u>(*Vm1W^uh zgt9Y>z(O~MVT2M#A{G|1--zE9fdzS0s3nqyRe7A|n^DgutTg&zq-krwu8Lp^P9l$1 zhf=x8+G=ENv;H*4^>o8RkB^oW;~EBClDwj^@Yg?|cvP_*nS#0P09T#UA^1q4jK)Hi ze|*WmCVn=IlSqxpf{2gkzDdO~p}}u<=ZUrDV-1%DF?pVMu`H6b#iBQI(hgyC!*GzY zREMgU3rO+2pv39uX?Y8-&YdY!cY0nq)_q2st1 zj?srPwJ}qFztY9Jt&Z^-^pONU%jXW_WBD61K{-Mp3$B(UBK|xSq3-!oMMJCUzS~sI z#8d~|KD$D*fI}VsmWw9&uX_h~-Q>@B_Z&U|4KXMy!2vA&z9-K^@)=jU{}L3Am2v&Y hO0s?d009600{~U%*wRS4HSz!e002ovPDHLkV1h=g&Gi5P literal 0 HcmV?d00001