. */ namespace SP\Modules\Web\Controllers\AuthToken; use Exception; use JsonException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ValidationException; use SP\Domain\Http\Dtos\JsonMessage; /** * Class SaveEditController * * @package SP\Modules\Web\Controllers */ final class SaveEditController extends AuthTokenSaveBase { /** * Saves edit action * * @param int $id * * @return bool * @throws JsonException */ public function saveEditAction(int $id): bool { try { if (!$this->acl->checkUserAccess(AclActionsInterface::AUTHTOKEN_EDIT)) { return $this->returnJsonResponse( JsonMessage::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } $this->form->validateFor(AclActionsInterface::AUTHTOKEN_EDIT, $id); if ($this->form->isRefresh()) { $this->authTokenService->refreshAndUpdate($this->form->getItemData()); $this->eventDispatcher->notify( 'refresh.authToken', new Event( $this, EventMessage::factory() ->addDescription(__u('Authorization updated')) ->addDetail(__u('Authorization'), $id) ) ); } else { $this->authTokenService->update($this->form->getItemData()); $this->eventDispatcher->notify( 'edit.authToken', new Event( $this, EventMessage::factory() ->addDescription(__u('Authorization updated')) ->addDetail(__u('Authorization'), $id) ) ); } $this->updateCustomFieldsForItem( AclActionsInterface::AUTHTOKEN, $id, $this->request, $this->customFieldService ); return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Authorization updated')); } catch (ValidationException $e) { return $this->returnJsonResponse(JsonMessage::JSON_ERROR, $e->getMessage()); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }