Skip to content

Commit 39ca1e7

Browse files
author
epriestley
committed
Add user.info and phid.info Conduit methods
Summary: Allow user and arbitrary object lookup by PHID. Test Plan: Executed user.whoami, user.info, user.find and phid.info via Conduit console. Reviewers: jungejason, tuomaspelkonen, aran, nh Reviewed By: nh CC: skrul, aran, nh, jungejason, epriestley Differential Revision: 870
1 parent f7e136e commit 39ca1e7

15 files changed

+299
-13
lines changed

src/__phutil_library_map__.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@
120120
'ConduitAPI_paste_create_Method' => 'applications/conduit/method/paste/create',
121121
'ConduitAPI_paste_info_Method' => 'applications/conduit/method/paste/info',
122122
'ConduitAPI_path_getowners_Method' => 'applications/conduit/method/path/getowners',
123+
'ConduitAPI_phid_Method' => 'applications/conduit/method/phid/base',
124+
'ConduitAPI_phid_info_Method' => 'applications/conduit/method/phid/info',
123125
'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info',
126+
'ConduitAPI_user_Method' => 'applications/conduit/method/user/base',
124127
'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find',
128+
'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info',
125129
'ConduitAPI_user_whoami_Method' => 'applications/conduit/method/user/whoami',
126130
'ConduitException' => 'applications/conduit/protocol/exception',
127131
'DarkConsole' => 'aphront/console/api',
@@ -795,9 +799,13 @@
795799
'ConduitAPI_paste_create_Method' => 'ConduitAPI_paste_Method',
796800
'ConduitAPI_paste_info_Method' => 'ConduitAPI_paste_Method',
797801
'ConduitAPI_path_getowners_Method' => 'ConduitAPIMethod',
802+
'ConduitAPI_phid_Method' => 'ConduitAPIMethod',
803+
'ConduitAPI_phid_info_Method' => 'ConduitAPI_phid_Method',
798804
'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod',
799-
'ConduitAPI_user_find_Method' => 'ConduitAPIMethod',
800-
'ConduitAPI_user_whoami_Method' => 'ConduitAPIMethod',
805+
'ConduitAPI_user_Method' => 'ConduitAPIMethod',
806+
'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method',
807+
'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method',
808+
'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method',
801809
'DarkConsoleConfigPlugin' => 'DarkConsolePlugin',
802810
'DarkConsoleController' => 'PhabricatorController',
803811
'DarkConsoleErrorLogPlugin' => 'DarkConsolePlugin',
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 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+
abstract class ConduitAPI_phid_Method extends ConduitAPIMethod {
23+
24+
protected function buildHandleInformationDictionary(
25+
PhabricatorObjectHandle $handle) {
26+
27+
return array(
28+
'phid' => $handle->getPHID(),
29+
'uri' => PhabricatorEnv::getProductionURI($handle->getURI()),
30+
31+
'typeName' => $handle->getTypeName(),
32+
'type' => $handle->getType(),
33+
34+
'name' => $handle->getName(),
35+
'fullName' => $handle->getFullName(),
36+
37+
'status' => $handle->getStatus(),
38+
);
39+
}
40+
41+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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/base');
10+
phutil_require_module('phabricator', 'infrastructure/env');
11+
12+
13+
phutil_require_source('ConduitAPI_phid_Method.php');
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 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_phid_info_Method
23+
extends ConduitAPI_phid_Method {
24+
25+
public function getMethodDescription() {
26+
return "Retrieve information about an arbitrary PHID.";
27+
}
28+
29+
public function defineParamTypes() {
30+
return array(
31+
'phid' => 'required phid',
32+
);
33+
}
34+
35+
public function defineReturnType() {
36+
return 'nonempty dict<string, wild>';
37+
}
38+
39+
public function defineErrorTypes() {
40+
return array(
41+
'ERR-BAD-PHID' => 'No such object exists.',
42+
);
43+
}
44+
45+
protected function execute(ConduitAPIRequest $request) {
46+
47+
$phid = $request->getValue('phid');
48+
49+
$handles = id(new PhabricatorObjectHandleData(array($phid)))
50+
->loadHandles();
51+
52+
$handle = $handles[$phid];
53+
if (!$handle->isComplete()) {
54+
throw new ConduitException('ERR-BAD-PHID');
55+
}
56+
57+
return $this->buildHandleInformationDictionary($handle);
58+
}
59+
60+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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/phid/base');
10+
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
11+
phutil_require_module('phabricator', 'applications/phid/handle/data');
12+
13+
phutil_require_module('phutil', 'utils');
14+
15+
16+
phutil_require_source('ConduitAPI_phid_info_Method.php');
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 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+
abstract class ConduitAPI_user_Method extends ConduitAPIMethod {
23+
24+
protected function buildUserInformationDictionary(PhabricatorUser $user) {
25+
return array(
26+
'phid' => $user->getPHID(),
27+
'userName' => $user->getUserName(),
28+
'realName' => $user->getRealName(),
29+
);
30+
}
31+
32+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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/base');
10+
11+
12+
phutil_require_source('ConduitAPI_user_Method.php');

src/applications/conduit/method/user/find/ConduitAPI_user_find_Method.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
/**
2020
* @group conduit
2121
*/
22-
class ConduitAPI_user_find_Method extends ConduitAPIMethod {
22+
final class ConduitAPI_user_find_Method
23+
extends ConduitAPI_user_Method {
2324

2425
public function getMethodDescription() {
2526
return "Find user PHIDs which correspond to provided user aliases. ".

src/applications/conduit/method/user/find/__init__.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88

9-
phutil_require_module('phabricator', 'applications/conduit/method/base');
9+
phutil_require_module('phabricator', 'applications/conduit/method/user/base');
1010
phutil_require_module('phabricator', 'applications/people/storage/user');
1111

1212
phutil_require_module('phutil', 'utils');
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 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_info_Method
23+
extends ConduitAPI_user_Method {
24+
25+
public function getMethodDescription() {
26+
return "Retrieve information about a user by PHID.";
27+
}
28+
29+
public function defineParamTypes() {
30+
return array(
31+
'phid' => 'required phid',
32+
);
33+
}
34+
35+
public function defineReturnType() {
36+
return 'nonempty dict<string, wild>';
37+
}
38+
39+
public function defineErrorTypes() {
40+
return array(
41+
'ERR-BAD-USER' => 'No such user exists.',
42+
);
43+
}
44+
45+
protected function execute(ConduitAPIRequest $request) {
46+
47+
$user = id(new PhabricatorUser())->loadOneWhere(
48+
'phid = %s',
49+
$request->getValue('phid'));
50+
51+
if (!$user) {
52+
throw new ConduitException('ERR-BAD-USER');
53+
}
54+
55+
return $this->buildUserInformationDictionary($user);
56+
}
57+
58+
}

0 commit comments

Comments
 (0)