1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 01:10:58 +01:00

Move PhabricatorUser to new phid stuff

Summary: Ref T2715. Had to start loading status information in the query class. Debated trying to clean up some of the attach / load stuff but decided to just add status under the new paradigm for now.

Test Plan: phid.query  also made a status and checked that out. also played in conpherence.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6585
This commit is contained in:
Bob Trahan 2013-07-26 14:05:19 -07:00
parent 1457797c4a
commit 1cb0db8755
25 changed files with 116 additions and 90 deletions

View file

@ -1375,6 +1375,7 @@ phutil_register_library_map(array(
'PhabricatorPeopleListController' => 'applications/people/controller/PhabricatorPeopleListController.php',
'PhabricatorPeopleLogsController' => 'applications/people/controller/PhabricatorPeopleLogsController.php',
'PhabricatorPeoplePHIDTypeExternal' => 'applications/people/phid/PhabricatorPeoplePHIDTypeExternal.php',
'PhabricatorPeoplePHIDTypeUser' => 'applications/people/phid/PhabricatorPeoplePHIDTypeUser.php',
'PhabricatorPeopleProfileController' => 'applications/people/controller/PhabricatorPeopleProfileController.php',
'PhabricatorPeopleProfileEditController' => 'applications/people/controller/PhabricatorPeopleProfileEditController.php',
'PhabricatorPeopleProfilePictureController' => 'applications/people/controller/PhabricatorPeopleProfilePictureController.php',
@ -3410,6 +3411,7 @@ phutil_register_library_map(array(
),
'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController',
'PhabricatorPeoplePHIDTypeExternal' => 'PhabricatorPHIDType',
'PhabricatorPeoplePHIDTypeUser' => 'PhabricatorPHIDType',
'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController',
'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleController',
'PhabricatorPeopleProfilePictureController' => 'PhabricatorPeopleController',

View file

@ -219,7 +219,7 @@ final class PhabricatorAuditListController extends PhabricatorAuditController {
case 'active':
case 'user':
case 'author':
if ($type !== PhabricatorPHIDConstants::PHID_TYPE_USER) {
if ($type !== PhabricatorPeoplePHIDTypeUser::TYPECONST) {
throw new Exception("PHID must be a user PHID!");
}
break;

View file

@ -142,7 +142,7 @@ abstract class DifferentialMail extends PhabricatorMail {
continue;
}
$type = $reason_handles[$relation['reasonPHID']]->getType();
if ($type == PhabricatorPHIDConstants::PHID_TYPE_USER) {
if ($type == PhabricatorPeoplePHIDTypeUser::TYPECONST) {
$explicit_cc[] = $relation['objectPHID'];
}
}

View file

@ -41,7 +41,7 @@ final class DifferentialSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$rev->getAuthorPHID(),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$rev->getDateCreated());
if ($rev->getStatus() != ArcanistDifferentialRevisionStatus::CLOSED &&
@ -79,7 +79,7 @@ final class DifferentialSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_TOUCH,
$touch,
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$time);
}
@ -92,14 +92,14 @@ final class DifferentialSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_OWNER,
$phid,
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$rev->getDateModified()); // Bogus timestamp.
}
} else {
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_OWNER,
$rev->getAuthorPHID(),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$rev->getDateCreated());
}

View file

@ -105,7 +105,7 @@ abstract class ConduitAPI_maniphest_Method extends ConduitAPIMethod {
$owner_phid = $request->getValue('ownerPHID');
if ($owner_phid !== null) {
$this->validatePHIDList(array($owner_phid),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
'ownerPHID');
$changes[ManiphestTransactionType::TYPE_OWNER] = $owner_phid;
}
@ -113,7 +113,7 @@ abstract class ConduitAPI_maniphest_Method extends ConduitAPIMethod {
$ccs = $request->getValue('ccPHIDs');
if ($ccs !== null) {
$this->validatePHIDList($ccs,
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
'ccPHIDS');
$changes[ManiphestTransactionType::TYPE_CCS] = $ccs;
}

View file

@ -27,7 +27,7 @@ final class ManiphestSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$task->getAuthorPHID(),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$task->getDateCreated());
if ($task->getStatus() == ManiphestTaskStatus::STATUS_OPEN) {
@ -88,7 +88,7 @@ final class ManiphestSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_OWNER,
$owner->getNewValue(),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$owner->getDateCreated());
} else {
$doc->addRelationship(
@ -104,7 +104,7 @@ final class ManiphestSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_TOUCH,
$touch,
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$time);
}

View file

@ -33,7 +33,7 @@ final class PhabricatorMetaMTAActorQuery extends PhabricatorQuery {
foreach ($type_map as $type => $phids) {
switch ($type) {
case PhabricatorPHIDConstants::PHID_TYPE_USER:
case PhabricatorPeoplePHIDTypeUser::TYPECONST:
$this->loadUserActors($actors, $phids);
break;
case PhabricatorPeoplePHIDTypeExternal::TYPECONST:

View file

@ -280,7 +280,7 @@ EOBODY;
PhabricatorObjectHandle $handle,
$prefix) {
if ($handle->getType() != PhabricatorPHIDConstants::PHID_TYPE_USER) {
if ($handle->getType() != PhabricatorPeoplePHIDTypeUser::TYPECONST) {
// You must be a real user to get a private reply handler address.
return null;
}

View file

@ -44,7 +44,7 @@ final class ConduitAPI_owners_query_Method
protected static function queryByOwner($owner) {
$is_valid_phid =
phid_get_type($owner) == PhabricatorPHIDConstants::PHID_TYPE_USER ||
phid_get_type($owner) == PhabricatorPeoplePHIDTypeUser::TYPECONST ||
phid_get_type($owner) == PhabricatorProjectPHIDTypeProject::TYPECONST;
if (!$is_valid_phid) {

View file

@ -38,7 +38,7 @@ final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
$all_phids = phid_group_by_type(mpull($owners, 'getUserPHID'));
$user_phids = idx($all_phids,
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
array());
$users_in_project_phids = array();

View file

@ -0,0 +1,52 @@
<?php
final class PhabricatorPeoplePHIDTypeUser extends PhabricatorPHIDType {
const TYPECONST = 'USER';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Phabricator User');
}
public function newObject() {
return new PhabricatorUser();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorPeopleQuery())
->needProfileImage(true)
->needStatus(true)
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$user = $objects[$phid];
$handle->setName($user->getUsername());
$handle->setURI('/p/'.$user->getUsername().'/');
$handle->setFullName(
$user->getUsername().' ('.$user->getRealName().')');
$handle->setImageURI($user->loadProfileImageURI());
if ($user->hasStatus()) {
$status = $user->getStatus();
$handle->setStatus($status->getTextStatus());
$handle->setTitle($status->getTerseSummary($query->getViewer()));
}
}
}
}

View file

@ -18,6 +18,7 @@ final class PhabricatorPeopleQuery
private $needPrimaryEmail;
private $needProfile;
private $needProfileImage;
private $needStatus;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -89,6 +90,11 @@ final class PhabricatorPeopleQuery
return $this;
}
public function needStatus($need) {
$this->needStatus = $need;
return $this;
}
public function loadPage() {
$table = new PhabricatorUser();
$conn_r = $table->establishConnection('r');
@ -143,6 +149,18 @@ final class PhabricatorPeopleQuery
}
}
if ($this->needStatus) {
$user_list = mpull($users, null, 'getPHID');
$statuses = id(new PhabricatorUserStatus())->loadCurrentStatuses(
array_keys($user_list));
foreach ($user_list as $phid => $user) {
$status = idx($statuses, $phid);
if ($status) {
$user->attachStatus($status);
}
}
}
return $users;
}

View file

@ -12,7 +12,7 @@ final class PhabricatorUserSearchIndexer
$doc = new PhabricatorSearchAbstractDocument();
$doc->setPHID($user->getPHID());
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_USER);
$doc->setDocumentType(PhabricatorPeoplePHIDTypeUser::TYPECONST);
$doc->setDocumentTitle($user->getUserName().' ('.$user->getRealName().')');
$doc->setDocumentCreated($user->getDateCreated());
$doc->setDocumentModified($user->getDateModified());
@ -24,7 +24,7 @@ final class PhabricatorUserSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
$user->getPHID(),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
time());
}

View file

@ -32,7 +32,7 @@ final class PhabricatorUser
private $profileImage = null;
private $profile = null;
private $status = null;
private $status = self::ATTACHABLE;
private $preferences = null;
private $omnipotent = false;
private $customFields = array();
@ -65,7 +65,7 @@ final class PhabricatorUser
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_USER);
PhabricatorPeoplePHIDTypeUser::TYPECONST);
}
public function setPassword(PhutilOpaqueEnvelope $envelope) {
@ -662,6 +662,20 @@ EOBODY;
return celerity_get_resource_uri('/rsrc/image/avatar.png');
}
public function attachStatus(PhabricatorUserStatus $status) {
$this->status = $status;
return $this;
}
public function getStatus() {
$this->assertAttached($this->status);
return $this->status;
}
public function hasStatus() {
return $this->status !== self::ATTACHABLE;
}
public function attachProfileImageURI($uri) {
$this->profileImage = $uri;
return $this;

View file

@ -8,7 +8,7 @@ final class PhabricatorUserTransaction
}
public function getApplicationTransactionType() {
return PhabricatorPHIDConstants::PHID_TYPE_USER;
return PhabricatorPeoplePHIDTypeUser::TYPECONST;
}
public function getApplicationTransactionCommentObject() {

View file

@ -107,11 +107,7 @@ final class PhabricatorObjectHandle
return $this->getPHIDType()->getTypeName();
}
static $map = array(
PhabricatorPHIDConstants::PHID_TYPE_USER => 'User',
);
return idx($map, $this->getType(), $this->getType());
return $this->getType();
}
@ -201,7 +197,7 @@ final class PhabricatorObjectHandle
public function getLinkName() {
switch ($this->getType()) {
case PhabricatorPHIDConstants::PHID_TYPE_USER:
case PhabricatorPeoplePHIDTypeUser::TYPECONST:
$name = $this->getName();
break;
default:

View file

@ -48,14 +48,6 @@ final class PhabricatorObjectHandleData {
switch ($type) {
case PhabricatorPHIDConstants::PHID_TYPE_USER:
// TODO: Update query + Batch User Images
$user_dao = new PhabricatorUser();
$users = $user_dao->loadAllWhere(
'phid in (%Ls)',
$phids);
return mpull($users, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
$project_dao = new PhabricatorRepositoryArcanistProject();
$projects = $project_dao->loadAllWhere(
@ -145,53 +137,6 @@ final class PhabricatorObjectHandleData {
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_USER:
$image_phids = mpull($objects, 'getProfileImagePHID');
$image_phids = array_unique(array_filter($image_phids));
$images = array();
if ($image_phids) {
$images = id(new PhabricatorFile())->loadAllWhere(
'phid IN (%Ls)',
$image_phids);
$images = mpull($images, 'getBestURI', 'getPHID');
}
$statuses = id(new PhabricatorUserStatus())->loadCurrentStatuses(
$phids);
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown User');
} else {
$user = $objects[$phid];
$handle->setName($user->getUsername());
$handle->setURI('/p/'.$user->getUsername().'/');
$handle->setFullName(
$user->getUsername().' ('.$user->getRealName().')');
$handle->setComplete(true);
if (isset($statuses[$phid])) {
$handle->setStatus($statuses[$phid]->getTextStatus());
$handle->setTitle(
$statuses[$phid]->getTerseSummary($this->viewer));
}
$handle->setDisabled($user->getIsDisabled());
$img_uri = idx($images, $user->getProfileImagePHID());
if ($img_uri) {
$handle->setImageURI($img_uri);
} else {
$handle->setImageURI(
PhabricatorUser::getDefaultProfileImageURI());
}
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();

View file

@ -26,7 +26,7 @@ final class PholioSearchIndexer extends PhabricatorSearchDocumentIndexer {
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$mock->getAuthorPHID(),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$mock->getDateCreated());
return $doc;

View file

@ -34,7 +34,7 @@ final class PhrictionSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$content->getAuthorPHID(),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$content->getDateCreated());
if ($document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS) {

View file

@ -209,7 +209,7 @@ final class PhabricatorPolicyFilter {
} else {
$this->rejectObject($object, $policy, $capability);
}
} else if ($type == PhabricatorPHIDConstants::PHID_TYPE_USER) {
} else if ($type == PhabricatorPeoplePHIDTypeUser::TYPECONST) {
if ($viewer->getPHID() == $policy) {
return true;
} else {
@ -271,7 +271,7 @@ final class PhabricatorPolicyFilter {
if ($type == PhabricatorProjectPHIDTypeProject::TYPECONST) {
$who = "To {$verb} this object, you must be a member of project ".
"'".$handle->getFullName()."'.";
} else if ($type == PhabricatorPHIDConstants::PHID_TYPE_USER) {
} else if ($type == PhabricatorPeoplePHIDTypeUser::TYPECONST) {
$who = "Only '".$handle->getFullName()."' can {$verb} this object.";
} else {
$who = "It is unclear who can {$verb} this object.";

View file

@ -26,7 +26,7 @@ final class PonderSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$question->getAuthorPHID(),
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$question->getDateCreated());
$comments = $question->getComments();

View file

@ -43,7 +43,7 @@ final class PhabricatorRepositoryCommitSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$author_phid,
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
$date_created);
}

View file

@ -19,7 +19,7 @@ final class PhabricatorSearchAbstractDocument {
PhabricatorRepositoryPHIDTypeCommit::TYPECONST => 'Repository Commits',
ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks',
PhrictionPHIDTypeDocument::TYPECONST => 'Phriction Documents',
PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users',
PhabricatorPeoplePHIDTypeUser::TYPECONST => 'Phabricator Users',
PonderPHIDTypeQuestion::TYPECONST => 'Ponder Questions',
);
}

View file

@ -53,7 +53,7 @@ final class PhabricatorHovercardExample extends PhabricatorUIExample {
$user_handle = $this->createBasicDummyHandle(
'gwashington',
PhabricatorPHIDConstants::PHID_TYPE_USER,
PhabricatorPeoplePHIDTypeUser::TYPECONST,
'George Washington');
$user_handle->setImageURI(
celerity_get_resource_uri('/rsrc/image/people/washington.png'));

View file

@ -154,7 +154,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
}
static $class_map = array(
PhabricatorPHIDConstants::PHID_TYPE_USER => 'PhabricatorUser',
PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject',
PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer',
PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount',