opensupports/server/controllers/user/get-user.php

62 lines
1.8 KiB
PHP
Raw Normal View History

2016-11-30 18:13:57 +01:00
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
2017-04-16 07:35:04 +02:00
/**
* @api {post} /user/get-user Get user information
* @apiVersion 4.10.0
2017-04-16 07:35:04 +02:00
*
* @apiName Get user information
2017-04-16 07:35:04 +02:00
*
* @apiGroup User
*
* @apiDescription This path retrieves information about a specific user.
2017-04-16 07:35:04 +02:00
*
* @apiPermission staff1
2017-04-16 07:35:04 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiParam {String} userId The id of the user to find information of.
2017-04-16 07:35:04 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
* @apiUse INVALID_USER
2017-04-16 07:35:04 +02:00
*
* @apiSuccess {Object} data Information about an user
2017-04-22 03:33:17 +02:00
* @apiSuccess {String} data.name Name of the user
* @apiSuccess {String} data.email Email of the user
* @apiSuccess {Number} data.signupDate Date of signup of the user
* @apiSuccess {Boolean} data.verified Indicates if the user is verified
2017-04-16 07:35:04 +02:00
*
*/
2016-11-30 21:30:00 +01:00
class GetUserByIdController extends Controller {
2016-11-30 18:13:57 +01:00
const PATH = '/get-user';
const METHOD = 'POST';
2016-11-30 18:13:57 +01:00
public function validations() {
return [
'permission' => 'staff_1',
2016-11-30 18:13:57 +01:00
'requestData' => [
'userId' => [
'validation' => DataValidator::dataStoreId('user'),
'error' => ERRORS::INVALID_USER
]
]
];
}
public function handler() {
$userId = Controller::request('userId');
$user = User::getDataStore($userId);
$staff = Controller::getLoggedUser();
2018-09-28 00:46:30 +02:00
2016-11-30 18:13:57 +01:00
Response::respondSuccess([
'name' => $user->name,
'email' => $user->email,
'signupDate' => $user->signupDate,
2018-09-28 00:46:30 +02:00
'verified' => !$user->verificationToken,
2019-02-03 20:47:29 +01:00
'disabled' => !!$user->disabled,
'customfields' => $user->xownCustomfieldvalueList->toArray(),
'userList' => $user->supervisedrelation ? $user->supervisedrelation->sharedUserList->toArray() : []
2016-11-30 18:13:57 +01:00
]);
}
2018-09-28 00:46:30 +02:00
}