diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 90fd0d5a44..36f9964370 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -120,8 +120,12 @@ phutil_register_library_map(array( 'ConduitAPI_paste_create_Method' => 'applications/conduit/method/paste/create', 'ConduitAPI_paste_info_Method' => 'applications/conduit/method/paste/info', 'ConduitAPI_path_getowners_Method' => 'applications/conduit/method/path/getowners', + 'ConduitAPI_phid_Method' => 'applications/conduit/method/phid/base', + 'ConduitAPI_phid_info_Method' => 'applications/conduit/method/phid/info', 'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info', + 'ConduitAPI_user_Method' => 'applications/conduit/method/user/base', 'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find', + 'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info', 'ConduitAPI_user_whoami_Method' => 'applications/conduit/method/user/whoami', 'ConduitException' => 'applications/conduit/protocol/exception', 'DarkConsole' => 'aphront/console/api', @@ -795,9 +799,13 @@ phutil_register_library_map(array( 'ConduitAPI_paste_create_Method' => 'ConduitAPI_paste_Method', 'ConduitAPI_paste_info_Method' => 'ConduitAPI_paste_Method', 'ConduitAPI_path_getowners_Method' => 'ConduitAPIMethod', + 'ConduitAPI_phid_Method' => 'ConduitAPIMethod', + 'ConduitAPI_phid_info_Method' => 'ConduitAPI_phid_Method', 'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod', - 'ConduitAPI_user_find_Method' => 'ConduitAPIMethod', - 'ConduitAPI_user_whoami_Method' => 'ConduitAPIMethod', + 'ConduitAPI_user_Method' => 'ConduitAPIMethod', + 'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method', + 'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method', + 'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method', 'DarkConsoleConfigPlugin' => 'DarkConsolePlugin', 'DarkConsoleController' => 'PhabricatorController', 'DarkConsoleErrorLogPlugin' => 'DarkConsolePlugin', diff --git a/src/applications/conduit/method/phid/base/ConduitAPI_phid_Method.php b/src/applications/conduit/method/phid/base/ConduitAPI_phid_Method.php new file mode 100644 index 0000000000..a9a0ab925d --- /dev/null +++ b/src/applications/conduit/method/phid/base/ConduitAPI_phid_Method.php @@ -0,0 +1,41 @@ + $handle->getPHID(), + 'uri' => PhabricatorEnv::getProductionURI($handle->getURI()), + + 'typeName' => $handle->getTypeName(), + 'type' => $handle->getType(), + + 'name' => $handle->getName(), + 'fullName' => $handle->getFullName(), + + 'status' => $handle->getStatus(), + ); + } + +} diff --git a/src/applications/conduit/method/phid/base/__init__.php b/src/applications/conduit/method/phid/base/__init__.php new file mode 100644 index 0000000000..275f895d18 --- /dev/null +++ b/src/applications/conduit/method/phid/base/__init__.php @@ -0,0 +1,13 @@ + 'required phid', + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + 'ERR-BAD-PHID' => 'No such object exists.', + ); + } + + protected function execute(ConduitAPIRequest $request) { + + $phid = $request->getValue('phid'); + + $handles = id(new PhabricatorObjectHandleData(array($phid))) + ->loadHandles(); + + $handle = $handles[$phid]; + if (!$handle->isComplete()) { + throw new ConduitException('ERR-BAD-PHID'); + } + + return $this->buildHandleInformationDictionary($handle); + } + +} diff --git a/src/applications/conduit/method/phid/info/__init__.php b/src/applications/conduit/method/phid/info/__init__.php new file mode 100644 index 0000000000..40c456cd50 --- /dev/null +++ b/src/applications/conduit/method/phid/info/__init__.php @@ -0,0 +1,16 @@ + $user->getPHID(), + 'userName' => $user->getUserName(), + 'realName' => $user->getRealName(), + ); + } + +} diff --git a/src/applications/conduit/method/user/base/__init__.php b/src/applications/conduit/method/user/base/__init__.php new file mode 100644 index 0000000000..c0f643620d --- /dev/null +++ b/src/applications/conduit/method/user/base/__init__.php @@ -0,0 +1,12 @@ + 'required phid', + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + 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); + } + +} diff --git a/src/applications/conduit/method/user/info/__init__.php b/src/applications/conduit/method/user/info/__init__.php new file mode 100644 index 0000000000..765fbb9cb4 --- /dev/null +++ b/src/applications/conduit/method/user/info/__init__.php @@ -0,0 +1,16 @@ +getUser(); - return array( - 'phid' => $user->getPHID(), - 'userName' => $user->getUserName(), - 'realName' => $user->getRealName(), - ); + return $this->buildUserInformationDictionary($request->getUser()); } } diff --git a/src/applications/conduit/method/user/whoami/__init__.php b/src/applications/conduit/method/user/whoami/__init__.php index 5b9ccec4ea..7ee715a1bd 100644 --- a/src/applications/conduit/method/user/whoami/__init__.php +++ b/src/applications/conduit/method/user/whoami/__init__.php @@ -6,7 +6,7 @@ -phutil_require_module('phabricator', 'applications/conduit/method/base'); +phutil_require_module('phabricator', 'applications/conduit/method/user/base'); phutil_require_source('ConduitAPI_user_whoami_Method.php'); diff --git a/src/applications/phid/handle/PhabricatorObjectHandle.php b/src/applications/phid/handle/PhabricatorObjectHandle.php index ab29065be4..050c5a2849 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandle.php +++ b/src/applications/phid/handle/PhabricatorObjectHandle.php @@ -28,7 +28,7 @@ class PhabricatorObjectHandle { private $timestamp; private $alternateID; private $status = 'open'; - + private $complete; public function setURI($uri) { $this->uri = $uri; @@ -135,6 +135,27 @@ class PhabricatorObjectHandle { return idx($map, $this->getType()); } + public function setComplete($complete) { + $this->complete = $complete; + return $this; + } + + /** + * Determine if the handle represents an object which was completely loaded + * (i.e., the underlying object exists) vs an object which could not be + * completely loaded (e.g., the type or data for the PHID could not be + * identified or located). + * + * Basically, @{class:PhabricatorObjectHandleData} gives you back a handle for + * any PHID you give it, but it gives you a complete handle only for valid + * PHIDs. + * + * @return bool True if the handle represents a complete object. + */ + public function isComplete() { + return $this->complete; + } + public function renderLink() { switch ($this->getType()) { diff --git a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php index 105d0f1200..d54eaecd7e 100644 --- a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php @@ -115,6 +115,7 @@ class PhabricatorObjectHandleData { case ManiphestTaskOwner::OWNER_UP_FOR_GRABS: $handle->setName('Up For Grabs'); $handle->setFullName('upforgrabs (Up For Grabs)'); + $handle->setComplete(true); break; default: $handle->setName('Foul Magicks'); @@ -145,6 +146,7 @@ class PhabricatorObjectHandleData { $handle->setFullName( $user->getUsername().' ('.$user->getRealName().')'); $handle->setAlternateID($user->getID()); + $handle->setComplete(true); $img_phid = $user->getProfileImagePHID(); if ($img_phid) { @@ -176,6 +178,7 @@ class PhabricatorObjectHandleData { $handle->setName($list->getName()); $handle->setURI($list->getURI()); $handle->setFullName($list->getName()); + $handle->setComplete(true); } $handles[$phid] = $handle; } @@ -199,6 +202,7 @@ class PhabricatorObjectHandleData { $handle->setName($rev->getTitle()); $handle->setURI('/D'.$rev->getID()); $handle->setFullName('D'.$rev->getID().': '.$rev->getTitle()); + $handle->setComplete(true); $status = $rev->getStatus(); if (($status == DifferentialRevisionStatus::COMMITTED) || @@ -256,6 +260,7 @@ class PhabricatorObjectHandleData { $handle->setURI('/r'.$callsign.$commit_identifier); $handle->setFullName('r'.$callsign.$commit_identifier); $handle->setTimestamp($commit->getEpoch()); + $handle->setComplete(true); } $handles[$phid] = $handle; } @@ -279,6 +284,7 @@ class PhabricatorObjectHandleData { $handle->setName($task->getTitle()); $handle->setURI('/T'.$task->getID()); $handle->setFullName('T'.$task->getID().': '.$task->getTitle()); + $handle->setComplete(true); if ($task->getStatus() != ManiphestTaskStatus::STATUS_OPEN) { $closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; $handle->setStatus($closed); @@ -305,6 +311,7 @@ class PhabricatorObjectHandleData { $file = $files[$phid]; $handle->setName($file->getName()); $handle->setURI($file->getViewURI()); + $handle->setComplete(true); } $handles[$phid] = $handle; } @@ -327,6 +334,7 @@ class PhabricatorObjectHandleData { $project = $projects[$phid]; $handle->setName($project->getName()); $handle->setURI('/project/view/'.$project->getID().'/'); + $handle->setComplete(true); } $handles[$phid] = $handle; } @@ -349,6 +357,7 @@ class PhabricatorObjectHandleData { $repository = $repositories[$phid]; $handle->setName($repository->getCallsign()); $handle->setURI('/diffusion/'.$repository->getCallsign().'/'); + $handle->setComplete(true); } $handles[$phid] = $handle; } @@ -371,6 +380,7 @@ class PhabricatorObjectHandleData { $package = $packages[$phid]; $handle->setName($package->getName()); $handle->setURI('/owners/package/'.$package->getID().'/'); + $handle->setComplete(true); } $handles[$phid] = $handle; } @@ -391,6 +401,7 @@ class PhabricatorObjectHandleData { } else { $project = $projects[$phid]; $handle->setName($project->getName()); + $handle->setComplete(true); } $handles[$phid] = $handle; } @@ -420,6 +431,7 @@ class PhabricatorObjectHandleData { $info = $documents[$phid]; $handle->setName($info['title']); $handle->setURI(PhrictionDocument::getSlugURI($info['slug'])); + $handle->setComplete(true); } $handles[$phid] = $handle; }