1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 16:00:59 +01:00

Auto-generate profile images for sad psyducks

Summary: Fixes T10319. This looks for custom profile image, then falls back to a generated profile image.

Test Plan: Create a new user, log in, and see new profile image. Note this seems to break `bin/lipsum generate user`

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T10319

Differential Revision: https://secure.phabricator.com/D17467
This commit is contained in:
Chad Little 2017-03-05 08:20:35 -08:00
parent 8e26916f7f
commit eb73c50e87
4 changed files with 61 additions and 36 deletions

View file

@ -24,8 +24,43 @@ final class PhabricatorUserProfileImageCacheType
public function newValueForUsers($key, array $users) {
$viewer = $this->getViewer();
$file_phids = mpull($users, 'getProfileImagePHID');
$file_phids = array_filter($file_phids);
$file_phids = array();
$generate_users = array();
foreach ($users as $user) {
$user_phid = $user->getPHID();
$custom_phid = $user->getProfileImagePHID();
$default_phid = $user->getDefaultProfileImagePHID();
$version = $user->getDefaultProfileImageVersion();
if ($custom_phid) {
$file_phids[$user_phid] = $custom_phid;
continue;
}
if ($default_phid) {
if ($version == PhabricatorFilesComposeAvatarBuiltinFile::VERSION) {
$file_phids[$user_phid] = $default_phid;
continue;
}
}
$generate_users[] = $user;
}
// Generate Files for anyone without a default
foreach ($generate_users as $generate_user) {
$generate_user_phid = $generate_user->getPHID();
$generate_username = $generate_user->getUsername();
$generate_version = PhabricatorFilesComposeAvatarBuiltinFile::VERSION;
$generate_file = id(new PhabricatorFilesComposeAvatarBuiltinFile())
->getUserProfileImageFile($generate_username);
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$generate_user->setDefaultProfileImagePHID($generate_file->getPHID());
$generate_user->setDefaultProfileImageVersion($generate_version);
$generate_user->save();
unset($unguarded);
$file_phids[$generate_user_phid] = $generate_file->getPHID();
}
if ($file_phids) {
$files = id(new PhabricatorFileQuery())
@ -40,8 +75,11 @@ final class PhabricatorUserProfileImageCacheType
$results = array();
foreach ($users as $user) {
$image_phid = $user->getProfileImagePHID();
$default_phid = $user->getDefaultProfileImagePHID();
if (isset($files[$image_phid])) {
$image_uri = $files[$image_phid]->getBestURI();
} else if (isset($files[$default_phid])) {
$image_uri = $files[$default_phid]->getBestURI();
} else {
$image_uri = PhabricatorUser::getDefaultProfileImageURI();
}

View file

@ -30,22 +30,12 @@ final class PhabricatorPeopleProfilePictureController
$e_file = true;
$errors = array();
// Verify install has GD extension, otherwise default to avatar.png
$gd = function_exists('imagecreatefromstring');
if ($request->isFormPost()) {
$phid = $request->getStr('phid');
$is_default = false;
if ($phid == PhabricatorPHIDConstants::PHID_VOID) {
// Compose the builtin unique image
if ($gd) {
$file = id(new PhabricatorFilesComposeAvatarBuiltinFile())
->getUserProfileImageFile($name);
} else {
$phid = null;
$is_default = true;
}
$phid = null;
$is_default = true;
} else if ($phid) {
$file = id(new PhabricatorFileQuery())
->setViewer($viewer)
@ -96,13 +86,15 @@ final class PhabricatorPeopleProfilePictureController
$form = id(new PHUIFormLayoutView())
->setUser($viewer);
if ($gd) {
$unique_default = id(new PhabricatorFilesComposeAvatarBuiltinFile())
->getUniqueProfileImage($name);
$default_image = PhabricatorFile::loadBuiltin(
$viewer, $unique_default['icon']);
} else {
$unique_default = null;
$default_image = $user->getDefaultProfileImagePHID();
if ($default_image) {
$default_image = id(new PhabricatorFileQuery())
->setViewer($viewer)
->withPHIDs(array($default_image))
->executeOne();
}
if (!$default_image) {
$default_image = PhabricatorFile::loadBuiltin($viewer, 'profile.png');
}
@ -181,21 +173,9 @@ final class PhabricatorPeopleProfilePictureController
}
}
$default_style = array();
if ($unique_default) {
$border_color = implode(', ', $unique_default['border']);
$default_style = array(
'background-color: '.$unique_default['color'].';',
'border: 4px solid rgba('.$border_color.');',
'height: 42px;',
'width: 42px',
);
}
$images[PhabricatorPHIDConstants::PHID_VOID] = array(
'uri' => $default_image->getBestURI(),
'tip' => pht('Default Picture'),
'style' => implode(' ', $default_style),
);
require_celerity_resource('people-profile-css');
@ -223,7 +203,6 @@ final class PhabricatorPeopleProfilePictureController
'height' => 50,
'width' => 50,
'src' => $spec['uri'],
'style' => $style,
)));
$button = array(

View file

@ -55,8 +55,14 @@ final class PhabricatorPeopleProfileImageWorkflow
foreach ($iterator as $user) {
$username = $user->getUsername();
$default_phid = $user->getDefaultProfileImagePHID();
$gen_version = $user->getDefaultProfileImageVersion();
if ($default_phid == null || $is_force) {
$generate = false;
if ($gen_version != $version) {
$generate = true;
}
if ($default_phid == null || $is_force || $generate) {
$file = id(new PhabricatorFilesComposeAvatarBuiltinFile())
->getUserProfileImageFile($username);
$user->setDefaultProfileImagePHID($file->getPHID());

View file

@ -13,7 +13,9 @@ final class PhabricatorUserProfile extends PhabricatorUserDAO {
return id(new self())
->setUserPHID($user->getPHID())
->setIcon($default_icon);
->setIcon($default_icon)
->setTitle('')
->setBlurb('');
}
protected function getConfiguration() {