forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConduitAPI_user_disable_Method.php
53 lines (42 loc) · 1.12 KB
/
ConduitAPI_user_disable_Method.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* @group conduit
*/
final class ConduitAPI_user_disable_Method
extends ConduitAPI_user_Method {
public function getMethodDescription() {
return "Permanently disable specified users (admin only).";
}
public function defineParamTypes() {
return array(
'phids' => 'required list<phid>',
);
}
public function defineReturnType() {
return 'void';
}
public function defineErrorTypes() {
return array(
'ERR-PERMISSIONS' => 'Only admins can call this method.',
'ERR-BAD-PHID' => 'Non existent user PHID.',
);
}
protected function execute(ConduitAPIRequest $request) {
$actor = $request->getUser();
if (!$actor->getIsAdmin()) {
throw new ConduitException('ERR-PERMISSIONS');
}
$phids = $request->getValue('phids');
$users = id(new PhabricatorUser())->loadAllWhere(
'phid IN (%Ls)',
$phids);
if (count($phids) != count($users)) {
throw new ConduitException('ERR-BAD-PHID');
}
foreach ($users as $user) {
id(new PhabricatorUserEditor())
->setActor($actor)
->disableUser($user, true);
}
}
}