opensupports/server/controllers/user/edit-custom-fields.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2019-02-03 20:47:29 +01:00
<?php
use Respect\Validation\Validator as DataValidator;
/**
* @api {post} /user/edit-custom-fields Edit custom field values
2019-10-08 01:21:43 +02:00
* @apiVersion 4.5.0
2019-02-03 20:47:29 +01:00
*
* @apiName Edit custom field values
*
* @apiGroup User
*
* @apiDescription This path is for editing the custom fields of a user.
*
* @apiPermission user
*
* @apiParam {String} userId Id of the user if it is not the one logged. Optional.
* @apiParam {String} customfield_ Custom field values for this user.
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_CUSTOM_FIELD_OPTION
*
* @apiSuccess {Object} data Empty object
*
*/
class EditCustomFieldsController extends Controller {
const PATH = '/edit-custom-fields';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'user',
'requestData' => []
];
}
public function handler() {
$userId = Controller::request('userId') * 1;
$user = Controller::getLoggedUser();
if($userId && Controller::isStaffLogged(2)) {
$user = User::getDataStore($userId);
if($user->isNull())
throw new RequestException(ERRORS::INVALID_USER);
}
$user->setProperties([
'xownCustomfieldvalueList' => $this->getCustomFieldValues()
]);
$user->store();
Response::respondSuccess();
}
}