1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 21:32:43 +01:00

Integrate user.getcurrentstatus into user.query

Summary: D2492#6

Test Plan:
`user.query` of user which is away.
`user.query` of user which is not away.
`user.whoami` - no information there.

Reviewers: epriestley

Reviewed By: epriestley

CC: btrahan, aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2502
This commit is contained in:
vrana 2012-05-19 09:38:34 -07:00
parent 18deff557e
commit fa36dd513c
6 changed files with 22 additions and 84 deletions

View file

@ -186,7 +186,6 @@ phutil_register_library_map(array(
'ConduitAPI_user_addstatus_Method' => 'applications/conduit/method/user/addstatus',
'ConduitAPI_user_disable_Method' => 'applications/conduit/method/user/disable',
'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',
@ -1220,7 +1219,6 @@ phutil_register_library_map(array(
'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method',
'ConduitAPI_user_disable_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',

View file

@ -21,14 +21,24 @@
*/
abstract class ConduitAPI_user_Method extends ConduitAPIMethod {
protected function buildUserInformationDictionary(PhabricatorUser $user) {
return array(
protected function buildUserInformationDictionary(
PhabricatorUser $user,
PhabricatorUserStatus $current_status = null) {
$return = array(
'phid' => $user->getPHID(),
'userName' => $user->getUserName(),
'realName' => $user->getRealName(),
'image' => $user->loadProfileImageURI(),
'uri' => PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'),
);
if ($current_status) {
$return['currentStatus'] = $current_status->getTextStatus();
$return['currentStatusUntil'] = $current_status->getDateTo();
}
return $return;
}
}

View file

@ -1,63 +0,0 @@
<?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())->loadCurrentStatuses(
$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

@ -1,15 +0,0 @@
<?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

@ -64,7 +64,7 @@ final class ConduitAPI_user_query_Method
$query->withUsernames($usernames);
}
if ($emails) {
// TODO -- validate emails and maybs
// TODO -- validate emails and maybe
// throw new ConduitException('ERR-INVALID-PARAMETER');
$query->withEmails($emails);
}
@ -85,9 +85,14 @@ final class ConduitAPI_user_query_Method
}
$users = $query->execute();
$statuses = id(new PhabricatorUserStatus())->loadCurrentStatuses(
mpull($users, 'getPHID'));
$results = array();
foreach ($users as $user) {
$results[] = $this->buildUserInformationDictionary($user);
$results[] = $this->buildUserInformationDictionary(
$user,
idx($statuses, $user->getPHID()));
}
return $results;
}

View file

@ -8,6 +8,9 @@
phutil_require_module('phabricator', 'applications/conduit/method/user/base');
phutil_require_module('phabricator', 'applications/people/query');
phutil_require_module('phabricator', 'applications/people/storage/userstatus');
phutil_require_module('phutil', 'utils');
phutil_require_source('ConduitAPI_user_query_Method.php');