mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
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
This commit is contained in:
parent
9b2ededd48
commit
416e4e7b67
7 changed files with 160 additions and 0 deletions
11
resources/sql/patches/userstatus.sql
Normal file
11
resources/sql/patches/userstatus.sql
Normal file
|
@ -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;
|
|
@ -178,6 +178,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_remarkup_process_Method' => 'applications/conduit/method/remarkup/process',
|
'ConduitAPI_remarkup_process_Method' => 'applications/conduit/method/remarkup/process',
|
||||||
'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info',
|
'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info',
|
||||||
'ConduitAPI_user_Method' => 'applications/conduit/method/user/base',
|
'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_find_Method' => 'applications/conduit/method/user/find',
|
||||||
'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info',
|
'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info',
|
||||||
'ConduitAPI_user_whoami_Method' => 'applications/conduit/method/user/whoami',
|
'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',
|
'PhabricatorUserSearchSettingsPanelController' => 'applications/people/controller/settings/panels/search',
|
||||||
'PhabricatorUserSettingsController' => 'applications/people/controller/settings',
|
'PhabricatorUserSettingsController' => 'applications/people/controller/settings',
|
||||||
'PhabricatorUserSettingsPanelController' => 'applications/people/controller/settings/panels/base',
|
'PhabricatorUserSettingsPanelController' => 'applications/people/controller/settings/panels/base',
|
||||||
|
'PhabricatorUserStatus' => 'applications/people/storage/userstatus',
|
||||||
'PhabricatorUserTestCase' => 'applications/people/storage/user/__tests__',
|
'PhabricatorUserTestCase' => 'applications/people/storage/user/__tests__',
|
||||||
'PhabricatorWorker' => 'infrastructure/daemon/workers/worker',
|
'PhabricatorWorker' => 'infrastructure/daemon/workers/worker',
|
||||||
'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/base',
|
'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/base',
|
||||||
|
@ -1196,6 +1198,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_remarkup_process_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_remarkup_process_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_user_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_user_Method' => 'ConduitAPIMethod',
|
||||||
|
'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method',
|
||||||
'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method',
|
'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method',
|
||||||
'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method',
|
'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method',
|
||||||
'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method',
|
'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method',
|
||||||
|
@ -1819,6 +1822,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorUserSearchSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
|
'PhabricatorUserSearchSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
|
||||||
'PhabricatorUserSettingsController' => 'PhabricatorPeopleController',
|
'PhabricatorUserSettingsController' => 'PhabricatorPeopleController',
|
||||||
'PhabricatorUserSettingsPanelController' => 'PhabricatorPeopleController',
|
'PhabricatorUserSettingsPanelController' => 'PhabricatorPeopleController',
|
||||||
|
'PhabricatorUserStatus' => 'PhabricatorUserDAO',
|
||||||
'PhabricatorUserTestCase' => 'PhabricatorTestCase',
|
'PhabricatorUserTestCase' => 'PhabricatorTestCase',
|
||||||
'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorWorkerTask' => 'PhabricatorWorkerDAO',
|
'PhabricatorWorkerTask' => 'PhabricatorWorkerDAO',
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group conduit
|
||||||
|
*/
|
||||||
|
final class ConduitAPI_user_addstatus_Method extends ConduitAPI_user_Method {
|
||||||
|
|
||||||
|
public function getMethodDescription() {
|
||||||
|
return "Add status information to the logged-in user.";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineParamTypes() {
|
||||||
|
return array(
|
||||||
|
'fromEpoch' => 'required int',
|
||||||
|
'toEpoch' => 'required int',
|
||||||
|
'status' => 'required enum<away, sporadic>',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/applications/conduit/method/user/addstatus/__init__.php
Normal file
16
src/applications/conduit/method/user/addstatus/__init__.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is automatically generated. Lint this module to rebuild it.
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('phabricator', 'applications/conduit/method/user/base');
|
||||||
|
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
|
||||||
|
phutil_require_module('phabricator', 'applications/people/storage/userstatus');
|
||||||
|
|
||||||
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_source('ConduitAPI_user_addstatus_Method.php');
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
final class PhabricatorUserStatus extends PhabricatorUserDAO {
|
||||||
|
|
||||||
|
const STATUS_AWAY = 1;
|
||||||
|
const STATUS_SPORADIC = 2;
|
||||||
|
|
||||||
|
protected $userPHID;
|
||||||
|
protected $dateFrom;
|
||||||
|
protected $dateTo;
|
||||||
|
protected $status;
|
||||||
|
|
||||||
|
}
|
12
src/applications/people/storage/userstatus/__init__.php
Normal file
12
src/applications/people/storage/userstatus/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is automatically generated. Lint this module to rebuild it.
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('phabricator', 'applications/people/storage/base');
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_source('PhabricatorUserStatus.php');
|
|
@ -855,6 +855,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'name' => $this->getPatchPath('holidays.sql'),
|
'name' => $this->getPatchPath('holidays.sql'),
|
||||||
),
|
),
|
||||||
|
'userstatus.sql' => array(
|
||||||
|
'type' => 'sql',
|
||||||
|
'name' => $this->getPatchPath('userstatus.sql'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue