1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 20:40:56 +01:00

Remove ProjectProfile->loadProfileImageURI()

Summary: Ref T603. Gets rid of a sketchy, non-policy-aware, unbatched file query.

Test Plan: Looked at projects, typeahead, edited project profile images.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7253
This commit is contained in:
epriestley 2013-10-06 17:07:43 -07:00
parent 80f6d00940
commit c587b8a9c8
5 changed files with 47 additions and 15 deletions

View file

@ -26,8 +26,7 @@ final class PhabricatorProjectProfileController
}
$profile = $project->getProfile();
$picture = $profile->loadProfileImageURI();
$picture = $profile->getProfileImageURI();
require_celerity_resource('phabricator-profile-css');

View file

@ -29,7 +29,7 @@ final class PhabricatorProjectProfileEditController
}
$profile = $project->getProfile();
$img_src = $profile->loadProfileImageURI();
$img_src = $profile->getProfileImageURI();
$options = PhabricatorProjectStatus::getStatusMap();

View file

@ -120,11 +120,41 @@ final class PhabricatorProjectQuery
'projectPHID IN (%Ls)',
mpull($projects, 'getPHID'));
$profiles = mpull($profiles, null, 'getProjectPHID');
$default = null;
if ($profiles) {
$file_phids = mpull($profiles, 'getProfileImagePHID');
$files = id(new PhabricatorFileQuery())
->setViewer($this->getViewer())
->withPHIDs($file_phids)
->execute();
$files = mpull($files, null, 'getPHID');
foreach ($profiles as $profile) {
$file = idx($files, $profile->getProfileImagePHID());
if (!$file) {
if (!$default) {
$default = PhabricatorFile::loadBuiltin(
$this->getViewer(),
'profile.png');
}
$file = $default;
}
$profile->attachProfileImageFile($file);
}
}
foreach ($projects as $project) {
$profile = idx($profiles, $project->getPHID());
if (!$profile) {
if (!$default) {
$default = PhabricatorFile::loadBuiltin(
$this->getViewer(),
'profile.png');
}
$profile = id(new PhabricatorProjectProfile())
->setProjectPHID($project->getPHID());
->setProjectPHID($project->getPHID())
->attachProfileImageFile($default);
}
$project->attachProfile($profile);
}

View file

@ -6,16 +6,19 @@ final class PhabricatorProjectProfile extends PhabricatorProjectDAO {
protected $blurb;
protected $profileImagePHID;
public function loadProfileImageURI() {
$src_phid = $this->getProfileImagePHID();
private $profileImageFile = self::ATTACHABLE;
// TODO: (T603) Can we get rid of this and move it to a Query?
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid);
if ($file) {
return $file->getBestURI();
}
public function getProfileImageURI() {
return $this->getProfileImageFile()->getBestURI();
}
return PhabricatorUser::getDefaultProfileImageURI();
public function attachProfileImageFile(PhabricatorFile $file) {
$this->profileImageFile = $file;
return $this;
}
public function getProfileImageFile() {
return $this->assertAttached($this->profileImageFile);
}
}

View file

@ -231,10 +231,10 @@ final class PhabricatorTypeaheadCommonDatasourceController
->setDisplayType("Project")
->setURI('/project/view/'.$proj->getID().'/')
->setPHID($proj->getPHID());
$prof = $proj->getProfile();
if ($prof) {
$proj_result->setImageURI($prof->loadProfileImageURI());
}
$proj_result->setImageURI($prof->getProfileImageURI());
$results[] = $proj_result;
}
}