1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

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
This commit is contained in:
epriestley 2012-04-27 17:44:10 -07:00
parent d27a751339
commit 8ed48a89f4
15 changed files with 26 additions and 45 deletions

View file

@ -31,10 +31,6 @@ return array(
// you through setting up Phabricator. // you through setting up Phabricator.
'phabricator.setup' => false, '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! Security! -------------------------------------------------- //
// IMPORTANT: By default, Phabricator serves files from the same domain the // IMPORTANT: By default, Phabricator serves files from the same domain the

View file

@ -22,20 +22,12 @@
abstract class ConduitAPI_user_Method extends ConduitAPIMethod { abstract class ConduitAPI_user_Method extends ConduitAPIMethod {
protected function buildUserInformationDictionary(PhabricatorUser $user) { 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( return array(
'phid' => $user->getPHID(), 'phid' => $user->getPHID(),
'userName' => $user->getUserName(), 'userName' => $user->getUserName(),
'realName' => $user->getRealName(), 'realName' => $user->getRealName(),
'email' => $user->getEmail(), 'email' => $user->getEmail(),
'image' => $picture, 'image' => $user->loadProfileImageURI(),
'uri' => PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'), 'uri' => PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'),
); );
} }

View file

@ -7,10 +7,7 @@
phutil_require_module('phabricator', 'applications/conduit/method/base'); 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('phabricator', 'infrastructure/env');
phutil_require_module('phutil', 'utils');
phutil_require_source('ConduitAPI_user_Method.php'); phutil_require_source('ConduitAPI_user_Method.php');

View file

@ -116,13 +116,7 @@ final class PhabricatorPeopleProfileController
throw new Exception("Unknown page '{$this->page}'!"); throw new Exception("Unknown page '{$this->page}'!");
} }
$src_phid = $user->getProfileImagePHID(); $picture = $user->loadProfileImageURI();
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid);
if ($file) {
$picture = $file->getBestURI();
} else {
$picture = null;
}
$header = new PhabricatorProfileHeaderView(); $header = new PhabricatorProfileHeaderView();
$header $header

View file

@ -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/auth/oauth/provider/base');
phutil_require_module('phabricator', 'applications/feed/builder/feed'); phutil_require_module('phabricator', 'applications/feed/builder/feed');
phutil_require_module('phabricator', 'applications/feed/query'); 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/markup/engine');
phutil_require_module('phabricator', 'applications/people/controller/base'); phutil_require_module('phabricator', 'applications/people/controller/base');
phutil_require_module('phabricator', 'applications/people/storage/profile'); phutil_require_module('phabricator', 'applications/people/storage/profile');

View file

@ -107,14 +107,7 @@ final class PhabricatorUserProfileSettingsPanelController
} }
} }
$file = id(new PhabricatorFile())->loadOneWhere( $img_src = $user->loadProfileImageURI();
'phid = %s',
$user->getProfileImagePHID());
if ($file) {
$img_src = $file->getBestURI();
} else {
$img_src = null;
}
$profile_uri = PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'); $profile_uri = PhabricatorEnv::getURI('/p/'.$user->getUsername().'/');
$sexes = array( $sexes = array(

View file

@ -45,10 +45,6 @@ final class PhabricatorUser extends PhabricatorUserDAO {
protected function readField($field) { protected function readField($field) {
switch ($field) { switch ($field) {
case 'profileImagePHID':
return nonempty(
$this->profileImagePHID,
PhabricatorEnv::getEnvConfig('user.default-profile-image-phid'));
case 'timezoneIdentifier': case 'timezoneIdentifier':
// If the user hasn't set one, guess the server's time. // If the user hasn't set one, guess the server's time.
return nonempty( return nonempty(
@ -523,4 +519,19 @@ EOBODY;
return (bool)preg_match('/^[a-zA-Z0-9]+$/', $username); 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();
}
} }

View file

@ -7,6 +7,7 @@
phutil_require_module('phabricator', 'aphront/writeguard'); 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/metamta/storage/mail');
phutil_require_module('phabricator', 'applications/people/storage/base'); phutil_require_module('phabricator', 'applications/people/storage/base');
phutil_require_module('phabricator', 'applications/people/storage/log'); 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/constants');
phutil_require_module('phabricator', 'applications/phid/storage/phid'); phutil_require_module('phabricator', 'applications/phid/storage/phid');
phutil_require_module('phabricator', 'applications/search/index/indexer/user'); 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/env');
phutil_require_module('phabricator', 'infrastructure/util/hash'); phutil_require_module('phabricator', 'infrastructure/util/hash');
phutil_require_module('phabricator', 'storage/qsprintf'); phutil_require_module('phabricator', 'storage/qsprintf');

View file

@ -169,6 +169,9 @@ final class PhabricatorObjectHandleData {
$img_uri = idx($images, $user->getProfileImagePHID()); $img_uri = idx($images, $user->getProfileImagePHID());
if ($img_uri) { if ($img_uri) {
$handle->setImageURI($img_uri); $handle->setImageURI($img_uri);
} else {
$handle->setImageURI(
PhabricatorUser::getDefaultProfileImageURI());
} }
} }
$handles[$phid] = $handle; $handles[$phid] = $handle;

View file

@ -11,6 +11,7 @@ phutil_require_module('arcanist', 'differential/constants/revisionstatus');
phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/files/storage/file');
phutil_require_module('phabricator', 'applications/maniphest/constants/owner'); phutil_require_module('phabricator', 'applications/maniphest/constants/owner');
phutil_require_module('phabricator', 'applications/maniphest/constants/status'); 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/constants');
phutil_require_module('phabricator', 'applications/phid/handle'); phutil_require_module('phabricator', 'applications/phid/handle');
phutil_require_module('phabricator', 'applications/phid/handle/const/status'); phutil_require_module('phabricator', 'applications/phid/handle/const/status');

View file

@ -49,7 +49,7 @@ final class PhabricatorProjectProfileController
if ($file) { if ($file) {
$picture = $file->getBestURI(); $picture = $file->getBestURI();
} else { } else {
$picture = null; $picture = PhabricatorUser::getDefaultProfileImageURI();
} }
$members = mpull($project->loadAffiliations(), null, 'getUserPHID'); $members = mpull($project->loadAffiliations(), null, 'getUserPHID');

View file

@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'applications/feed/query');
phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/files/storage/file');
phutil_require_module('phabricator', 'applications/maniphest/query'); phutil_require_module('phabricator', 'applications/maniphest/query');
phutil_require_module('phabricator', 'applications/maniphest/view/tasksummary'); 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/phid/handle/data');
phutil_require_module('phabricator', 'applications/project/controller/base'); phutil_require_module('phabricator', 'applications/project/controller/base');
phutil_require_module('phabricator', 'applications/project/storage/profile'); phutil_require_module('phabricator', 'applications/project/storage/profile');

View file

@ -22,9 +22,4 @@ final class PhabricatorProjectProfile extends PhabricatorProjectDAO {
protected $blurb; protected $blurb;
protected $profileImagePHID; protected $profileImagePHID;
public function getProfileImagePHID() {
return nonempty(
$this->profileImagePHID,
PhabricatorEnv::getEnvConfig('user.default-profile-image-phid'));
}
} }

View file

@ -7,9 +7,6 @@
phutil_require_module('phabricator', 'applications/project/storage/base'); phutil_require_module('phabricator', 'applications/project/storage/base');
phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorProjectProfile.php'); phutil_require_source('PhabricatorProjectProfile.php');

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 B