opensupports/server/controllers/user/edit-custom-fields.php
Guillermo Giuliana 6a34c24d7d
update script and change 4.6 to 4.7 (#809)
* update script and change 4.6 to 4.7

* fix 4.7.0 script
2020-06-16 21:26:04 -03:00

56 lines
1.3 KiB
PHP

<?php
use Respect\Validation\Validator as DataValidator;
/**
* @api {post} /user/edit-custom-fields Edit custom field values
* @apiVersion 4.7.0
*
* @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();
}
}