1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 07:12:41 +01:00

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
This commit is contained in:
vrana 2012-05-17 17:21:07 -07:00
parent f1f43f0acf
commit 2476c872ff
5 changed files with 96 additions and 9 deletions

View file

@ -185,6 +185,7 @@ phutil_register_library_map(array(
'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_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_getcurrentstatus_Method' => 'applications/conduit/method/user/getcurrentstatus',
'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info', 'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info',
'ConduitAPI_user_query_Method' => 'applications/conduit/method/user/query', 'ConduitAPI_user_query_Method' => 'applications/conduit/method/user/query',
'ConduitAPI_user_removestatus_Method' => 'applications/conduit/method/user/removestatus', 'ConduitAPI_user_removestatus_Method' => 'applications/conduit/method/user/removestatus',
@ -1217,6 +1218,7 @@ phutil_register_library_map(array(
'ConduitAPI_user_Method' => 'ConduitAPIMethod', 'ConduitAPI_user_Method' => 'ConduitAPIMethod',
'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method',
'ConduitAPI_user_find_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_info_Method' => 'ConduitAPI_user_Method',
'ConduitAPI_user_query_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_query_Method' => 'ConduitAPI_user_Method',
'ConduitAPI_user_removestatus_Method' => 'ConduitAPI_user_Method', 'ConduitAPI_user_removestatus_Method' => 'ConduitAPI_user_Method',

View file

@ -73,19 +73,11 @@ final class ConduitAPI_user_addstatus_Method extends ConduitAPI_user_Method {
throw new ConduitException('ERR-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()) id(new PhabricatorUserStatus())
->setUserPHID($user_phid) ->setUserPHID($user_phid)
->setDateFrom($from) ->setDateFrom($from)
->setDateTo($to) ->setDateTo($to)
->setStatus($status) ->setTextStatus($request->getValue('status'))
->save(); ->save();
$table->endWriteLocking(); $table->endWriteLocking();

View file

@ -0,0 +1,64 @@
<?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_getcurrentstatus_Method
extends ConduitAPI_user_Method {
public function getMethodStatus() {
return self::METHOD_STATUS_UNSTABLE;
}
public function getMethodDescription() {
return "Get current status (away or sporadic) of specified users.";
}
public function defineParamTypes() {
return array(
'userPHIDs' => '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;
}
}

View file

@ -0,0 +1,15 @@
<?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/people/storage/userstatus');
phutil_require_module('phutil', 'utils');
phutil_require_source('ConduitAPI_user_getcurrentstatus_Method.php');

View file

@ -21,9 +21,23 @@ final class PhabricatorUserStatus extends PhabricatorUserDAO {
const STATUS_AWAY = 1; const STATUS_AWAY = 1;
const STATUS_SPORADIC = 2; const STATUS_SPORADIC = 2;
private static $statusTexts = array(
self::STATUS_AWAY => 'away',
self::STATUS_SPORADIC => 'sporadic',
);
protected $userPHID; protected $userPHID;
protected $dateFrom; protected $dateFrom;
protected $dateTo; protected $dateTo;
protected $status; protected $status;
public function getTextStatus() {
return self::$statusTexts[$this->status];
}
public function setTextStatus($status) {
$statuses = array_flip(self::$statusTexts);
return $this->setStatus($statuses[$status]);
}
} }