From 416e4e7b672eac57d5b85d84cf3fd75cf6fa5b17 Mon Sep 17 00:00:00 2001 From: vrana Date: Thu, 3 May 2012 15:47:34 -0700 Subject: [PATCH] Allowing setting user status Summary: I will use it for highlighting users which are not currently available. Maybe I will also use it in the nagging tool. I don't plan creating a UI for it as API is currently enough for us. Maybe I will visualize it at /calendar/ later. I plan creating `user.deletestatus` method when this one will be done. Test Plan: `storage upgrade` Call Conduit `user.addstatus`. Verify DB. Reviewers: epriestley Reviewed By: epriestley CC: aran, Koolvin Differential Revision: https://secure.phabricator.com/D2382 --- resources/sql/patches/userstatus.sql | 11 +++ src/__phutil_library_map__.php | 4 + .../ConduitAPI_user_addstatus_Method.php | 84 +++++++++++++++++++ .../method/user/addstatus/__init__.php | 16 ++++ .../userstatus/PhabricatorUserStatus.php | 29 +++++++ .../people/storage/userstatus/__init__.php | 12 +++ .../PhabricatorBuiltinPatchList.php | 4 + 7 files changed, 160 insertions(+) create mode 100644 resources/sql/patches/userstatus.sql create mode 100644 src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php create mode 100644 src/applications/conduit/method/user/addstatus/__init__.php create mode 100644 src/applications/people/storage/userstatus/PhabricatorUserStatus.php create mode 100644 src/applications/people/storage/userstatus/__init__.php diff --git a/resources/sql/patches/userstatus.sql b/resources/sql/patches/userstatus.sql new file mode 100644 index 0000000000..a975b335bc --- /dev/null +++ b/resources/sql/patches/userstatus.sql @@ -0,0 +1,11 @@ +CREATE TABLE {$NAMESPACE}_user.user_status ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `userPHID` varchar(64) NOT NULL, + `dateFrom` int unsigned NOT NULL, + `dateTo` int unsigned NOT NULL, + `status` tinyint unsigned NOT NULL, + `dateCreated` int unsigned NOT NULL, + `dateModified` int unsigned NOT NULL, + PRIMARY KEY (`id`), + INDEX `userPHID_dateFrom` (`userPHID`, `dateTo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3dc80f1af8..fc35f0e32e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -178,6 +178,7 @@ phutil_register_library_map(array( 'ConduitAPI_remarkup_process_Method' => 'applications/conduit/method/remarkup/process', 'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info', '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_info_Method' => 'applications/conduit/method/user/info', 'ConduitAPI_user_whoami_Method' => 'applications/conduit/method/user/whoami', @@ -954,6 +955,7 @@ phutil_register_library_map(array( 'PhabricatorUserSearchSettingsPanelController' => 'applications/people/controller/settings/panels/search', 'PhabricatorUserSettingsController' => 'applications/people/controller/settings', 'PhabricatorUserSettingsPanelController' => 'applications/people/controller/settings/panels/base', + 'PhabricatorUserStatus' => 'applications/people/storage/userstatus', 'PhabricatorUserTestCase' => 'applications/people/storage/user/__tests__', 'PhabricatorWorker' => 'infrastructure/daemon/workers/worker', 'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/base', @@ -1196,6 +1198,7 @@ phutil_register_library_map(array( 'ConduitAPI_remarkup_process_Method' => 'ConduitAPIMethod', 'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod', 'ConduitAPI_user_Method' => 'ConduitAPIMethod', + 'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method', @@ -1819,6 +1822,7 @@ phutil_register_library_map(array( 'PhabricatorUserSearchSettingsPanelController' => 'PhabricatorUserSettingsPanelController', 'PhabricatorUserSettingsController' => 'PhabricatorPeopleController', 'PhabricatorUserSettingsPanelController' => 'PhabricatorPeopleController', + 'PhabricatorUserStatus' => 'PhabricatorUserDAO', 'PhabricatorUserTestCase' => 'PhabricatorTestCase', 'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO', 'PhabricatorWorkerTask' => 'PhabricatorWorkerDAO', 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 new file mode 100644 index 0000000000..318785bb84 --- /dev/null +++ b/src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php @@ -0,0 +1,84 @@ + 'required int', + 'toEpoch' => 'required int', + 'status' => 'required enum', + ); + } + + public function defineReturnType() { + return 'void'; + } + + public function defineErrorTypes() { + return array( + 'ERR-BAD-EPOCH' => "'toEpoch' must be bigger than 'fromEpoch'.", + 'ERR-OVERLAP' => + 'There must be no status in any part of the specified epoch.', + ); + } + + protected function execute(ConduitAPIRequest $request) { + $userPHID = $request->getUser()->getPHID(); + $from = $request->getValue('fromEpoch'); + $to = $request->getValue('toEpoch'); + + if ($to <= $from) { + throw new ConduitException('ERR-BAD-EPOCH'); + } + + // TODO: This SELECT should have LOCK IN SHARE MODE and be in transaction + // with the next INSERT. + $overlap = id(new PhabricatorUserStatus())->loadAllWhere( + 'userPHID = %s AND dateFrom < %d AND dateTo > %d', + $userPHID, + $to, + $from); + if ($overlap) { + 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($userPHID) + ->setDateFrom($from) + ->setDateTo($to) + ->setStatus($status) + ->save(); + } + +} diff --git a/src/applications/conduit/method/user/addstatus/__init__.php b/src/applications/conduit/method/user/addstatus/__init__.php new file mode 100644 index 0000000000..3ef3c367bf --- /dev/null +++ b/src/applications/conduit/method/user/addstatus/__init__.php @@ -0,0 +1,16 @@ + 'sql', 'name' => $this->getPatchPath('holidays.sql'), ), + 'userstatus.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('userstatus.sql'), + ), ); }