From 2476c872ffb459a599ee5bddaf7bc8a73dffc40d Mon Sep 17 00:00:00 2001 From: vrana Date: Thu, 17 May 2012 17:21:07 -0700 Subject: [PATCH] Add Conduit method for querying user status Summary: I want to use this to warn user if he specifies reviewers that are away. We can also implement a general query method but I think that this usage is the most useful not only for me but also in general case. Test Plan: Call the method for user which is away and which is not away. Add user status through Conduit. Reviewers: btrahan Reviewed By: btrahan CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D2492 --- src/__phutil_library_map__.php | 2 + .../ConduitAPI_user_addstatus_Method.php | 10 +-- ...onduitAPI_user_getcurrentstatus_Method.php | 64 +++++++++++++++++++ .../method/user/getcurrentstatus/__init__.php | 15 +++++ .../userstatus/PhabricatorUserStatus.php | 14 ++++ 5 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 src/applications/conduit/method/user/getcurrentstatus/ConduitAPI_user_getcurrentstatus_Method.php create mode 100644 src/applications/conduit/method/user/getcurrentstatus/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f502c55587..849bcc992f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -185,6 +185,7 @@ phutil_register_library_map(array( 'ConduitAPI_user_Method' => 'applications/conduit/method/user/base', 'ConduitAPI_user_addstatus_Method' => 'applications/conduit/method/user/addstatus', 'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find', + 'ConduitAPI_user_getcurrentstatus_Method' => 'applications/conduit/method/user/getcurrentstatus', 'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info', 'ConduitAPI_user_query_Method' => 'applications/conduit/method/user/query', 'ConduitAPI_user_removestatus_Method' => 'applications/conduit/method/user/removestatus', @@ -1217,6 +1218,7 @@ phutil_register_library_map(array( 'ConduitAPI_user_Method' => 'ConduitAPIMethod', 'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method', + 'ConduitAPI_user_getcurrentstatus_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_query_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_removestatus_Method' => 'ConduitAPI_user_Method', diff --git a/src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php b/src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php index 58d212687a..2789a00bff 100644 --- a/src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php +++ b/src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php @@ -73,19 +73,11 @@ final class ConduitAPI_user_addstatus_Method extends ConduitAPI_user_Method { throw new ConduitException('ERR-OVERLAP'); } - switch ($request->getValue('status')) { - case 'sporadic': - $status = PhabricatorUserStatus::STATUS_SPORADIC; - break; - default: - $status = PhabricatorUserStatus::STATUS_AWAY; - break; - } id(new PhabricatorUserStatus()) ->setUserPHID($user_phid) ->setDateFrom($from) ->setDateTo($to) - ->setStatus($status) + ->setTextStatus($request->getValue('status')) ->save(); $table->endWriteLocking(); diff --git a/src/applications/conduit/method/user/getcurrentstatus/ConduitAPI_user_getcurrentstatus_Method.php b/src/applications/conduit/method/user/getcurrentstatus/ConduitAPI_user_getcurrentstatus_Method.php new file mode 100644 index 0000000000..bae10f0f4e --- /dev/null +++ b/src/applications/conduit/method/user/getcurrentstatus/ConduitAPI_user_getcurrentstatus_Method.php @@ -0,0 +1,64 @@ + 'required list', + ); + } + + public function defineReturnType() { + return 'dict'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $statuses = id(new PhabricatorUserStatus())->loadAllWhere( + 'userPHID IN (%Ls) AND UNIX_TIMESTAMP() BETWEEN dateFrom AND dateTo', + $request->getValue('userPHIDs')); + + $return = array(); + foreach ($statuses as $status) { + $return[$status->getUserPHID()] = array( + 'fromEpoch' => $status->getDateFrom(), + 'toEpoch' => $status->getDateTo(), + 'status' => $status->getTextStatus(), + ); + } + return $return; + } + +} diff --git a/src/applications/conduit/method/user/getcurrentstatus/__init__.php b/src/applications/conduit/method/user/getcurrentstatus/__init__.php new file mode 100644 index 0000000000..66159193d6 --- /dev/null +++ b/src/applications/conduit/method/user/getcurrentstatus/__init__.php @@ -0,0 +1,15 @@ + 'away', + self::STATUS_SPORADIC => 'sporadic', + ); + protected $userPHID; protected $dateFrom; protected $dateTo; protected $status; + public function getTextStatus() { + return self::$statusTexts[$this->status]; + } + + public function setTextStatus($status) { + $statuses = array_flip(self::$statusTexts); + return $this->setStatus($statuses[$status]); + } + }