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

Policy - clean up access to user profile image uri

Summary: Ref T7094. We already had and were mostly using "needProfileImage" on the people query class. Only real trick in this diff is deleting a conduit end point that has been marked deprecated for the better part of 3 years.

Test Plan: clicked around the people action and profiles and calendars loaded nicely.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7094

Differential Revision: https://secure.phabricator.com/D11630
This commit is contained in:
Bob Trahan 2015-02-02 14:04:23 -08:00
parent 0fa31802e7
commit b2320c2e68
11 changed files with 21 additions and 81 deletions

View file

@ -3071,7 +3071,6 @@ phutil_register_library_map(array(
'UserDisableConduitAPIMethod' => 'applications/people/conduit/UserDisableConduitAPIMethod.php',
'UserEnableConduitAPIMethod' => 'applications/people/conduit/UserEnableConduitAPIMethod.php',
'UserFindConduitAPIMethod' => 'applications/people/conduit/UserFindConduitAPIMethod.php',
'UserInfoConduitAPIMethod' => 'applications/people/conduit/UserInfoConduitAPIMethod.php',
'UserQueryConduitAPIMethod' => 'applications/people/conduit/UserQueryConduitAPIMethod.php',
'UserRemoveStatusConduitAPIMethod' => 'applications/people/conduit/UserRemoveStatusConduitAPIMethod.php',
'UserWhoAmIConduitAPIMethod' => 'applications/people/conduit/UserWhoAmIConduitAPIMethod.php',
@ -6487,7 +6486,6 @@ phutil_register_library_map(array(
'UserDisableConduitAPIMethod' => 'UserConduitAPIMethod',
'UserEnableConduitAPIMethod' => 'UserConduitAPIMethod',
'UserFindConduitAPIMethod' => 'UserConduitAPIMethod',
'UserInfoConduitAPIMethod' => 'UserConduitAPIMethod',
'UserQueryConduitAPIMethod' => 'UserConduitAPIMethod',
'UserRemoveStatusConduitAPIMethod' => 'UserConduitAPIMethod',
'UserWhoAmIConduitAPIMethod' => 'UserConduitAPIMethod',

View file

@ -126,7 +126,12 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
$items = array();
if ($user->isLoggedIn() && $user->isUserActivated()) {
$image = $user->loadProfileImageURI();
$profile = id(new PhabricatorPeopleQuery())
->setViewer($user)
->needProfileImage(true)
->withPHIDs(array($user->getPHID()))
->executeOne();
$image = $profile->getProfileImageURI();
$item = id(new PHUIListItemView())
->setName($user->getUsername())

View file

@ -40,7 +40,7 @@ abstract class UserConduitAPIMethod extends ConduitAPIMethod {
'phid' => $user->getPHID(),
'userName' => $user->getUserName(),
'realName' => $user->getRealName(),
'image' => $user->loadProfileImageURI(),
'image' => $user->getProfileImageURI(),
'uri' => PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'),
'roles' => $roles,
);

View file

@ -1,49 +0,0 @@
<?php
final class UserInfoConduitAPIMethod extends UserConduitAPIMethod {
public function getAPIMethodName() {
return 'user.info';
}
public function getMethodStatus() {
return self::METHOD_STATUS_DEPRECATED;
}
public function getMethodStatusDescription() {
return "Replaced by 'user.query'.";
}
public function getMethodDescription() {
return 'Retrieve information about a user by PHID.';
}
public function defineParamTypes() {
return array(
'phid' => 'required phid',
);
}
public function defineReturnType() {
return 'nonempty dict<string, wild>';
}
public function defineErrorTypes() {
return array(
'ERR-BAD-USER' => 'No such user exists.',
);
}
protected function execute(ConduitAPIRequest $request) {
$user = id(new PhabricatorUser())->loadOneWhere(
'phid = %s',
$request->getValue('phid'));
if (!$user) {
throw new ConduitException('ERR-BAD-USER');
}
return $this->buildUserInformationDictionary($user);
}
}

View file

@ -41,8 +41,9 @@ final class UserQueryConduitAPIMethod extends UserConduitAPIMethod {
$offset = $request->getValue('offset', 0);
$limit = $request->getValue('limit', 100);
$query = new PhabricatorPeopleQuery();
$query->setViewer($request->getUser());
$query = id(new PhabricatorPeopleQuery())
->setViewer($request->getUser())
->needProfileImage(true);
if ($usernames) {
$query->withUsernames($usernames);

View file

@ -27,7 +27,13 @@ final class UserWhoAmIConduitAPIMethod extends UserConduitAPIMethod {
}
protected function execute(ConduitAPIRequest $request) {
return $this->buildUserInformationDictionary($request->getUser());
$person = id(new PhabricatorPeopleQuery())
->setViewer($request->getUser())
->needProfileImage(true)
->withPHIDs(array($request->getUser()->getPHID()))
->executeOne();
return $this->buildUserInformationDictionary($person);
}
}

View file

@ -25,7 +25,7 @@ final class PhabricatorPeopleCalendarController
return new Aphront404Response();
}
$picture = $user->loadProfileImageURI();
$picture = $user->getProfileImageURI();
$now = time();
$request = $this->getRequest();

View file

@ -18,7 +18,7 @@ final class PhabricatorPeopleLogsController
return $this->delegateToController($controller);
}
public function buildSideNavView() {
public function buildSideNavView($for_app = false) {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));

View file

@ -30,7 +30,7 @@ final class PhabricatorPeopleProfileController
$profile = $user->loadUserProfile();
$username = phutil_escape_uri($user->getUserName());
$picture = $user->loadProfileImageURI();
$picture = $user->getProfileImageURI();
$header = id(new PHUIHeaderView())
->setHeader($user->getFullName())

View file

@ -42,7 +42,7 @@ final class PhabricatorPeopleUserPHIDType extends PhabricatorPHIDType {
$handle->setName($user->getUsername());
$handle->setURI('/p/'.$user->getUsername().'/');
$handle->setFullName($user->getFullName());
$handle->setImageURI($user->loadProfileImageURI());
$handle->setImageURI($user->getProfileImageURI());
$handle->setDisabled(!$user->isUserActivated());
if ($user->hasStatus()) {
$status = $user->getStatus();

View file

@ -683,27 +683,6 @@ EOBODY;
return $this->assertAttached($this->profileImage);
}
public function loadProfileImageURI() {
if ($this->profileImage && ($this->profileImage !== self::ATTACHABLE)) {
return $this->profileImage;
}
$src_phid = $this->getProfileImagePHID();
if ($src_phid) {
// TODO: (T603) Can we get rid of this entirely and move it to
// PeopleQuery with attach/attachable?
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid);
if ($file) {
$this->profileImage = $file->getBestURI();
return $this->profileImage;
}
}
$this->profileImage = self::getDefaultProfileImageURI();
return $this->profileImage;
}
public function getFullName() {
if (strlen($this->getRealName())) {
return $this->getUsername().' ('.$this->getRealName().')';