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

75 lines
2.2 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
2018-11-29 17:35:14 +01:00
* @apiVersion 4.3.2
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
* @apiUse USER_SYSTEM_DISABLED
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 {[Ticket](#api-Data_Structures-ObjectTicket)[]} data.tickets Array of tickets 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() {
if(!Controller::isUserSystemEnabled()) {
2018-11-20 23:41:00 +01:00
throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
}
2018-09-28 00:46:30 +02:00
2016-11-30 18:13:57 +01:00
$userId = Controller::request('userId');
$user = User::getDataStore($userId);
$staff = Controller::getLoggedUser();
2018-09-28 00:46:30 +02:00
$tickets = new DataStoreList();
2018-09-28 00:46:30 +02:00
foreach($user->sharedTicketList as $ticket) {
if($staff->sharedDepartmentList->includesId($ticket->department->id)) {
$tickets->add($ticket);
}
}
2016-11-30 18:13:57 +01:00
Response::respondSuccess([
'name' => $user->name,
'email' => $user->email,
'signupDate' => $user->signupDate,
'tickets' => $tickets->toArray(),
2018-09-28 00:46:30 +02:00
'verified' => !$user->verificationToken,
'disabled' => !!$user->disabled
2016-11-30 18:13:57 +01:00
]);
}
2018-09-28 00:46:30 +02:00
}