. */ namespace SP\Modules\Web\Controllers\AuthToken; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Common\Attributes\Action; use SP\Domain\Common\Dtos\ActionResponse; use SP\Domain\Common\Enums\ResponseType; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\SPException; use function SP\__u; /** * Class DeleteController * * @package SP\Modules\Web\Controllers */ final class DeleteController extends AuthTokenSaveBase { /** * Delete action * * @param int|null $id * * @return ActionResponse * @throws SPException */ #[Action(ResponseType::JSON)] public function deleteAction(?int $id = null): ActionResponse { if (!$this->acl->checkUserAccess(AclActionsInterface::AUTHTOKEN_DELETE)) { return ActionResponse::error(__u('You don\'t have permission to do this operation')); } if ($id === null) { $ids = $this->getItemsIdFromRequest($this->request); $this->authTokenService->deleteByIdBatch($ids); $this->deleteCustomFieldsForItem(AclActionsInterface::AUTHTOKEN, $ids, $this->customFieldService); $this->eventDispatcher->notify( 'delete.authToken.selection', new Event($this, EventMessage::build(__u('Authorizations deleted'))) ); return ActionResponse::ok(__u('Authorizations deleted')); } $this->authTokenService->delete($id); $this->deleteCustomFieldsForItem(AclActionsInterface::AUTHTOKEN, $id, $this->customFieldService); $this->eventDispatcher->notify( 'delete.authToken', new Event( $this, EventMessage::build(__u('Authorization deleted'))->addDetail(__u('Authorization'), $id) ) ); return ActionResponse::ok(__u('Authorization deleted')); } }