@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

vrana 416e4e7b 9b2ededd

+160
+11
resources/sql/patches/userstatus.sql
··· 1 + CREATE TABLE {$NAMESPACE}_user.user_status ( 2 + `id` int unsigned NOT NULL AUTO_INCREMENT, 3 + `userPHID` varchar(64) NOT NULL, 4 + `dateFrom` int unsigned NOT NULL, 5 + `dateTo` int unsigned NOT NULL, 6 + `status` tinyint unsigned NOT NULL, 7 + `dateCreated` int unsigned NOT NULL, 8 + `dateModified` int unsigned NOT NULL, 9 + PRIMARY KEY (`id`), 10 + INDEX `userPHID_dateFrom` (`userPHID`, `dateTo`) 11 + ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+4
src/__phutil_library_map__.php
··· 178 178 'ConduitAPI_remarkup_process_Method' => 'applications/conduit/method/remarkup/process', 179 179 'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info', 180 180 'ConduitAPI_user_Method' => 'applications/conduit/method/user/base', 181 + 'ConduitAPI_user_addstatus_Method' => 'applications/conduit/method/user/addstatus', 181 182 'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find', 182 183 'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info', 183 184 'ConduitAPI_user_whoami_Method' => 'applications/conduit/method/user/whoami', ··· 954 955 'PhabricatorUserSearchSettingsPanelController' => 'applications/people/controller/settings/panels/search', 955 956 'PhabricatorUserSettingsController' => 'applications/people/controller/settings', 956 957 'PhabricatorUserSettingsPanelController' => 'applications/people/controller/settings/panels/base', 958 + 'PhabricatorUserStatus' => 'applications/people/storage/userstatus', 957 959 'PhabricatorUserTestCase' => 'applications/people/storage/user/__tests__', 958 960 'PhabricatorWorker' => 'infrastructure/daemon/workers/worker', 959 961 'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/base', ··· 1196 1198 'ConduitAPI_remarkup_process_Method' => 'ConduitAPIMethod', 1197 1199 'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod', 1198 1200 'ConduitAPI_user_Method' => 'ConduitAPIMethod', 1201 + 'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method', 1199 1202 'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method', 1200 1203 'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method', 1201 1204 'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method', ··· 1819 1822 'PhabricatorUserSearchSettingsPanelController' => 'PhabricatorUserSettingsPanelController', 1820 1823 'PhabricatorUserSettingsController' => 'PhabricatorPeopleController', 1821 1824 'PhabricatorUserSettingsPanelController' => 'PhabricatorPeopleController', 1825 + 'PhabricatorUserStatus' => 'PhabricatorUserDAO', 1822 1826 'PhabricatorUserTestCase' => 'PhabricatorTestCase', 1823 1827 'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO', 1824 1828 'PhabricatorWorkerTask' => 'PhabricatorWorkerDAO',
+84
src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + /** 20 + * @group conduit 21 + */ 22 + final class ConduitAPI_user_addstatus_Method extends ConduitAPI_user_Method { 23 + 24 + public function getMethodDescription() { 25 + return "Add status information to the logged-in user."; 26 + } 27 + 28 + public function defineParamTypes() { 29 + return array( 30 + 'fromEpoch' => 'required int', 31 + 'toEpoch' => 'required int', 32 + 'status' => 'required enum<away, sporadic>', 33 + ); 34 + } 35 + 36 + public function defineReturnType() { 37 + return 'void'; 38 + } 39 + 40 + public function defineErrorTypes() { 41 + return array( 42 + 'ERR-BAD-EPOCH' => "'toEpoch' must be bigger than 'fromEpoch'.", 43 + 'ERR-OVERLAP' => 44 + 'There must be no status in any part of the specified epoch.', 45 + ); 46 + } 47 + 48 + protected function execute(ConduitAPIRequest $request) { 49 + $userPHID = $request->getUser()->getPHID(); 50 + $from = $request->getValue('fromEpoch'); 51 + $to = $request->getValue('toEpoch'); 52 + 53 + if ($to <= $from) { 54 + throw new ConduitException('ERR-BAD-EPOCH'); 55 + } 56 + 57 + // TODO: This SELECT should have LOCK IN SHARE MODE and be in transaction 58 + // with the next INSERT. 59 + $overlap = id(new PhabricatorUserStatus())->loadAllWhere( 60 + 'userPHID = %s AND dateFrom < %d AND dateTo > %d', 61 + $userPHID, 62 + $to, 63 + $from); 64 + if ($overlap) { 65 + throw new ConduitException('ERR-OVERLAP'); 66 + } 67 + 68 + switch ($request->getValue('status')) { 69 + case 'sporadic': 70 + $status = PhabricatorUserStatus::STATUS_SPORADIC; 71 + break; 72 + default: 73 + $status = PhabricatorUserStatus::STATUS_AWAY; 74 + break; 75 + } 76 + id(new PhabricatorUserStatus()) 77 + ->setUserPHID($userPHID) 78 + ->setDateFrom($from) 79 + ->setDateTo($to) 80 + ->setStatus($status) 81 + ->save(); 82 + } 83 + 84 + }
+16
src/applications/conduit/method/user/addstatus/__init__.php
··· 1 + <?php 2 + /** 3 + * This file is automatically generated. Lint this module to rebuild it. 4 + * @generated 5 + */ 6 + 7 + 8 + 9 + phutil_require_module('phabricator', 'applications/conduit/method/user/base'); 10 + phutil_require_module('phabricator', 'applications/conduit/protocol/exception'); 11 + phutil_require_module('phabricator', 'applications/people/storage/userstatus'); 12 + 13 + phutil_require_module('phutil', 'utils'); 14 + 15 + 16 + phutil_require_source('ConduitAPI_user_addstatus_Method.php');
+29
src/applications/people/storage/userstatus/PhabricatorUserStatus.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class PhabricatorUserStatus extends PhabricatorUserDAO { 20 + 21 + const STATUS_AWAY = 1; 22 + const STATUS_SPORADIC = 2; 23 + 24 + protected $userPHID; 25 + protected $dateFrom; 26 + protected $dateTo; 27 + protected $status; 28 + 29 + }
+12
src/applications/people/storage/userstatus/__init__.php
··· 1 + <?php 2 + /** 3 + * This file is automatically generated. Lint this module to rebuild it. 4 + * @generated 5 + */ 6 + 7 + 8 + 9 + phutil_require_module('phabricator', 'applications/people/storage/base'); 10 + 11 + 12 + phutil_require_source('PhabricatorUserStatus.php');
+4
src/infrastructure/setup/sql/phabricator/PhabricatorBuiltinPatchList.php
··· 855 855 'type' => 'sql', 856 856 'name' => $this->getPatchPath('holidays.sql'), 857 857 ), 858 + 'userstatus.sql' => array( 859 + 'type' => 'sql', 860 + 'name' => $this->getPatchPath('userstatus.sql'), 861 + ), 858 862 ); 859 863 } 860 864