From 17edd73f35f19d28407628d1aa31de4a1f7819cf Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 17 Jan 2024 00:15:41 +0100 Subject: [PATCH] new api 2.0 --- .../lib/Modules/Shared/Builders/Builder.php | 4 - .../Modules/Shared/Controllers/Controller.php | 16 +- .../Shared/Core/DataMapperAbstract.php | 58 +- .../Modules/Shared/Core/FilterAbstract.php | 115 +-- .../Shared/Core/SerializableAbstract.php | 13 +- .../Modules/Shared/Documentation/OpenApi.php | 80 +- .../Shared/Entities/PaginationData.php | 85 +- .../Modules/Shared/Enums/HttpCodesEnum.php | 148 ++- .../Modules/Shared/Enums/LanguagesEnum.php | 16 +- .../Shared/Exceptions/BadRequestException.php | 4 - .../Exceptions/ForbiddenACLException.php | 4 - .../Exceptions/ForbiddenActionException.php | 4 - .../Exceptions/InvalidClassException.php | 4 - .../Exceptions/InvalidFilterException.php | 4 - .../Shared/Exceptions/NotFoundException.php | 4 - .../Middlewares/UserTokenMiddleware.php | 5 - .../Shared/Repositories/Repository.php | 47 +- .../Shared/Repositories/RepositoryMySQL.php | 39 +- .../lib/Modules/Shared/Services/Audit.php | 9 +- .../lib/Modules/Shared/Services/Config.php | 8 +- .../Modules/Shared/Services/FileService.php | 18 +- .../lib/Modules/Shared/Services/Timestamp.php | 10 +- .../Shared/Services/ValidateAclSystem.php | 11 +- .../lib/Modules/Shared/Traits/EnumTrait.php | 6 +- .../Shared/Traits/GroupByFilterTrait.php | 15 - .../Shared/Traits/OrderFilterTrait.php | 28 - .../Shared/Traits/PaginationFilterTrait.php | 28 - .../lib/Modules/Shared/Utils/ArrayTools.php | 5 - .../Modules/Shared/Validators/Validator.php | 17 +- .../Users/Actions/CreateUserAction.php | 5 - .../Users/Actions/DeleteUserAction.php | 5 - .../Modules/Users/Actions/GetUserAction.php | 5 - .../Modules/Users/Actions/ListUserAction.php | 8 +- .../Users/Actions/UpdateUserAction.php | 5 - .../Controllers/CreateUserController.php | 23 +- .../Controllers/DeleteUserController.php | 23 +- .../Users/Controllers/GetUserController.php | 21 +- .../Users/Controllers/ListUserController.php | 77 +- .../Controllers/UpdateUserController.php | 22 +- .../lib/Modules/Users/Entities/User.php | 924 +----------------- .../Modules/Users/Entities/UserDataMapper.php | 7 +- .../lib/Modules/Users/Entities/UserFilter.php | 19 +- .../Users/Enums/UserAutoRefreshPagesEnum.php | 30 +- .../Users/Enums/UserHomeScreenEnum.php | 20 +- .../Users/Enums/UserMetaconsoleAccessEnum.php | 6 +- .../Users/Repositories/UserRepository.php | 9 - .../Repositories/UserRepositoryMySQL.php | 17 +- .../Services/CheckOldPasswordUserService.php | 9 +- .../Users/Services/CountUserService.php | 5 - .../Users/Services/CreateUserService.php | 7 +- .../Users/Services/DeleteUserService.php | 11 +- .../Modules/Users/Services/GetUserService.php | 8 +- .../Users/Services/ListUserService.php | 5 - .../Users/Services/UpdateUserService.php | 5 - .../Services/ValidatePasswordUserService.php | 7 - .../Users/Validations/UserValidation.php | 21 +- .../Users/Validators/UserValidator.php | 6 - 57 files changed, 322 insertions(+), 1793 deletions(-) diff --git a/pandora_console/include/lib/Modules/Shared/Builders/Builder.php b/pandora_console/include/lib/Modules/Shared/Builders/Builder.php index 0cd68976f2..09c43fb0a2 100644 --- a/pandora_console/include/lib/Modules/Shared/Builders/Builder.php +++ b/pandora_console/include/lib/Modules/Shared/Builders/Builder.php @@ -7,8 +7,6 @@ use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; class Builder { - - public function build(Entity $entity, array $data): Entity { foreach ($data as $field => $value) { @@ -21,6 +19,4 @@ class Builder return $entity; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Controllers/Controller.php b/pandora_console/include/lib/Modules/Shared/Controllers/Controller.php index cdbb8d50e1..8be849b606 100644 --- a/pandora_console/include/lib/Modules/Shared/Controllers/Controller.php +++ b/pandora_console/include/lib/Modules/Shared/Controllers/Controller.php @@ -2,27 +2,26 @@ namespace PandoraFMS\Modules\Shared\Controllers; +use Nyholm\Psr7\Stream; + use PandoraFMS\Modules\Shared\Core\SerializableAbstract; use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; use PandoraFMS\Modules\Shared\Exceptions\ForbiddenActionException; use PandoraFMS\Modules\Shared\Exceptions\InvalidClassException; -use Nyholm\Psr7\Stream; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\UploadedFileInterface; + use Slim\Routing\RouteContext; abstract class Controller { - - public function __construct() { } - public function getParam(Request $request, string $param): mixed { $routeContext = RouteContext::fromRequest($request); @@ -36,7 +35,6 @@ abstract class Controller return $value; } - public function getFile(Request $request, string $file): UploadedFileInterface { $files = $request->getUploadedFiles(); @@ -51,7 +49,6 @@ abstract class Controller return $files[$file]; } - public function extractParams(Request $request): array { $queryParams = ($request->getQueryParams() ?? []); @@ -70,7 +67,6 @@ abstract class Controller return $params; } - public function fromRequest(Request $request, string $className): mixed { $params = $this->extractParams($request); @@ -88,11 +84,10 @@ abstract class Controller return $class->fromArray($params); } - public function getResponse( Response $response, mixed $result, - ?string $contentType='application/json' + ?string $contentType = 'application/json' ): Response { if ($contentType === 'application/json') { $result = json_encode($result); @@ -102,7 +97,6 @@ abstract class Controller return $response->withHeader('Content-Type', $contentType); } - public function getResponseAttachment(Response $response, string $path, string $fileName) { try { @@ -118,6 +112,4 @@ abstract class Controller return $response->withBody($file_stream)->withHeader('Content-Disposition', 'attachment; filename='.$fileName)->withHeader('Content-Type', mime_content_type($path)); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php b/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php index da03c3b484..5144563346 100644 --- a/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php +++ b/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php @@ -4,62 +4,38 @@ namespace PandoraFMS\Modules\Shared\Core; abstract class DataMapperAbstract { - private null|string $tableRelated = null; - private null|string $keyRelated = null; - private null|string $searchFieldRelated = null; - private mixed $searchFieldValueRelated = null; - public function __construct( private string $tableName, private string $primaryKey ) { } - abstract public function getClassName(): string; - abstract public function fromDatabase(array $data): MappeableInterface; - abstract public function toDatabase(MappeableInterface $data): array; - - /** - * Get the value of tableName. - */ public function getTableName(): string { return $this->tableName; } - - /** - * Get the value of primaryKey. - */ public function getPrimaryKey(): string { return $this->primaryKey; } - - /** - * Get the value of tableRelated. - */ public function getTableRelated(): null|string { return $this->tableRelated; } - - /** - * Set the value of tableRelated. - */ public function setTableRelated(null|string $tableRelated): self { $this->tableRelated = $tableRelated; @@ -67,19 +43,11 @@ abstract class DataMapperAbstract return $this; } - - /** - * Get the value of keyRelated. - */ public function getKeyRelated(): null|string { return $this->keyRelated; } - - /** - * Set the value of keyRelated. - */ public function setKeyRelated(null|string $keyRelated): self { $this->keyRelated = $keyRelated; @@ -87,19 +55,11 @@ abstract class DataMapperAbstract return $this; } - - /** - * Get the value of searchFieldRelated. - */ public function getSearchFieldRelated(): null|string { return $this->searchFieldRelated; } - - /** - * Set the value of searchFieldRelated. - */ public function setSearchFieldRelated(null|string $searchFieldRelated): self { $this->searchFieldRelated = $searchFieldRelated; @@ -107,19 +67,11 @@ abstract class DataMapperAbstract return $this; } - - /** - * Get the value of searchFieldValueRelated. - */ public function getSearchFieldValueRelated(): mixed { return $this->searchFieldValueRelated; } - - /** - * Set the value of searchFieldValueRelated. - */ public function setSearchFieldValueRelated(mixed $searchFieldValueRelated): self { $this->searchFieldValueRelated = $searchFieldValueRelated; @@ -127,22 +79,14 @@ abstract class DataMapperAbstract return $this; } - public function getStringNameClass(): string { $strname = [ - 'PandoraFMS\\Modules\\Users\\Entities\\User' => 'User', - 'PandoraFMS\\Modules\\Shared\\Workunits\\Entities\\Workunit' => 'Workunit', - 'PandoraFMS\\Modules\\Shared\\Attachments\\Entities\\Attachment' => 'Attachment', - 'PandoraFMS\\Modules\\Users\\UserProfiles\\Entities\\UserProfile' => 'Profile', - 'PandoraFMS\\Modules\\Profiles\\Entities\\Profile' => 'Profile', - 'PandoraFMS\\Modules\\Groups\\Entities\\Group' => 'Group', + 'PandoraFMS\\Modules\\Users\\Entities\\User' => 'User', ]; $result = ($strname[$this->getClassName()] ?? ''); return $result; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Core/FilterAbstract.php b/pandora_console/include/lib/Modules/Shared/Core/FilterAbstract.php index 96a3bcd8e9..de8170e835 100644 --- a/pandora_console/include/lib/Modules/Shared/Core/FilterAbstract.php +++ b/pandora_console/include/lib/Modules/Shared/Core/FilterAbstract.php @@ -19,82 +19,43 @@ abstract class FilterAbstract extends SerializableAbstract public const DESC = 'descending'; private ?int $limit = null; - private ?int $offset = null; - private ?string $defaultFieldOrder = null; - private ?string $defaultDirectionOrder = null; - private ?array $fields = null; - private ?Entity $entityFilter = null; - public function __construct() { } - - // abstract public function getWhereClause(): string; abstract public function fieldsTranslate(): array; - - /** - * Get the value of fieldsFreeSearch. - * - * @return ?array - */ public function getFieldsFreeSearch(): ?array { return []; } - - /** - * Get the value of multipleSearch. - * - * @return ?array - */ public function getMultipleSearch(): ?array { return []; } - - /** - * Get the value of multipleSearchString. - * - * @return ?array - */ public function getMultipleSearchString(): ?array { return []; } - - /** - * Get the value of fieldsFreeSearch. - * - * @return ?string - */ public function getFieldAclGroupMysql(): ?string { return ''; } - - /** - * Get the value of fieldsFreeSearch. - * - * @return ?string - */ public function getModeAclGroupMysql(): ?string { return null; } - public function fromArray(array $params): static { $fails = $this->validate($params); @@ -111,7 +72,7 @@ abstract class FilterAbstract extends SerializableAbstract if (method_exists($this, 'set'.ucfirst($field)) === true) { $this->{'set'.ucfirst($field)}($value ?? null); - } else if ($this->getEntityFilter() !== null && method_exists($this->getEntityFilter(), 'set'.ucfirst($field)) === true) { + } elseif ($this->getEntityFilter() !== null && method_exists($this->getEntityFilter(), 'set'.ucfirst($field)) === true) { $this->getEntityFilter()->{'set'.ucfirst($field)}($value ?? null); } } @@ -119,23 +80,11 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } - - /** - * Get the value of limit. - * - * @return ?int - */ public function getLimit(): ?int { return $this->limit; } - - /** - * Set the value of limit. - * - * @param integer $limit - */ public function setLimit(?int $limit): self { $this->limit = $limit; @@ -143,23 +92,11 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } - - /** - * Get the value of offset. - * - * @return ?int - */ public function getOffset(): ?int { return $this->offset; } - - /** - * Set the value of offset. - * - * @param integer $offset - */ public function setOffset(?int $offset): self { $this->offset = $offset; @@ -167,23 +104,11 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } - - /** - * Get the value of defaultFieldOrder. - * - * @return ?string - */ public function getDefaultFieldOrder(): ?string { return $this->defaultFieldOrder; } - - /** - * Set the value of defaultFieldOrder. - * - * @param string $defaultFieldOrder - */ public function setDefaultFieldOrder(?string $defaultFieldOrder): self { $this->defaultFieldOrder = $defaultFieldOrder; @@ -191,23 +116,11 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } - - /** - * Get the value of defaultDirectionOrder. - * - * @return ?string - */ public function getDefaultDirectionOrder(): ?string { return $this->defaultDirectionOrder; } - - /** - * Set the value of defaultDirectionOrder. - * - * @param string $defaultDirectionOrder - */ public function setDefaultDirectionOrder(?string $defaultDirectionOrder): self { $this->defaultDirectionOrder = $defaultDirectionOrder; @@ -215,23 +128,11 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } - - /** - * Get the value of entityFilter. - * - * @return ?Entity - */ public function getEntityFilter(): ?Entity { return $this->entityFilter; } - - /** - * Set the value of entityFilter. - * - * @param Entity $entityFilter - */ public function setEntityFilter(?Entity $entityFilter): self { $this->entityFilter = $entityFilter; @@ -239,29 +140,15 @@ abstract class FilterAbstract extends SerializableAbstract return $this; } - - /** - * Get the value of fields. - * - * @return ?array - */ public function getFields(): ?array { return $this->fields; } - - /** - * Set the value of fields. - * - * @param array $fields - */ public function setFields(?array $fields): self { $this->fields = $fields; return $this; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Core/SerializableAbstract.php b/pandora_console/include/lib/Modules/Shared/Core/SerializableAbstract.php index 7b1203d45c..21777880fa 100644 --- a/pandora_console/include/lib/Modules/Shared/Core/SerializableAbstract.php +++ b/pandora_console/include/lib/Modules/Shared/Core/SerializableAbstract.php @@ -2,37 +2,29 @@ namespace PandoraFMS\Modules\Shared\Core; +use JsonSerializable; use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; use PandoraFMS\Modules\Shared\Exceptions\InvalidFilterException; -use JsonSerializable; abstract class SerializableAbstract implements JsonSerializable { - - public function __construct() { } - abstract public function fieldsReadOnly(): array; - abstract public function jsonSerialize(): mixed; - abstract public function getValidations(): array; - abstract public function validateFields(array $filters): array; - public function toArray() { return $this->jsonSerialize(); } - public function validate(array $params): array { $filters = []; @@ -48,7 +40,6 @@ abstract class SerializableAbstract implements JsonSerializable return $this->validateFields($filters); } - public function fromArray(array $params): static { $fails = $this->validate($params); @@ -72,6 +63,4 @@ abstract class SerializableAbstract implements JsonSerializable return $this; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php b/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php index e9b08908f6..980bef53cb 100644 --- a/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php +++ b/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php @@ -6,19 +6,19 @@ use OpenApi\Annotations as OA; /** * @OA\Info( - * title="Nueva API de Pandora FMS", - * description="Nueva Api de pandora FMS", - * termsOfService="https://example.com/terms/", - * @OA\Contact( - * name="Nombre del contacto", - * url="https://www.example.com/support", - * email="contacto@example.com" - * ), - * @OA\License( - * name="Apache 2.0", - * url="https://www.apache.org/licenses/LICENSE-2.0.html" - * ), - * version="0.0.1" + * title="Nueva API de Pandora FMS", + * description="Nueva Api de pandora FMS", + * termsOfService="https://example.com/terms/", + * @OA\Contact( + * name="Nombre del contacto", + * url="https://www.example.com/support", + * email="contacto@example.com" + * ), + * @OA\License( + * name="Apache 2.0", + * url="https://www.apache.org/licenses/LICENSE-2.0.html" + * ), + * version="0.0.1" * ), * @OA\Schemes( * format="http" @@ -56,7 +56,7 @@ use OpenApi\Annotations as OA; * in="query", * description="page", * required=false, - * @OA\Schema( + * @OA\Schema( * type="integer", * default=0 * ), @@ -68,7 +68,7 @@ use OpenApi\Annotations as OA; * in="query", * description="Size page", * required=false, - * @OA\Schema( + * @OA\Schema( * type="integer", * default=0 * ), @@ -80,7 +80,7 @@ use OpenApi\Annotations as OA; * in="query", * description="sort field", * required=false, - * @OA\Schema( + * @OA\Schema( * type="string", * default="" * ), @@ -92,7 +92,7 @@ use OpenApi\Annotations as OA; * in="query", * description="sort direction", * required=false, - * @OA\Schema( + * @OA\Schema( * type="string", * enum={ * "ascending", @@ -106,12 +106,12 @@ use OpenApi\Annotations as OA; * response="BadRequest", * description="Bad request", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( + * @OA\Schema( * type="object", * description="Error", - * @OA\Property( + * @OA\Property( * property="error", * type="string", * default="Message error" @@ -125,12 +125,12 @@ use OpenApi\Annotations as OA; * response="Unauthorized", * description="Unauthorized", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( + * @OA\Schema( * type="object", * description="Error", - * @OA\Property( + * @OA\Property( * property="error", * type="string", * default="Message error" @@ -144,12 +144,12 @@ use OpenApi\Annotations as OA; * response="Forbidden", * description="Forbidden", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( + * @OA\Schema( * type="object", * description="Error", - * @OA\Property( + * @OA\Property( * property="error", * type="string", * default="Message error" @@ -163,12 +163,12 @@ use OpenApi\Annotations as OA; * response="NotFound", * description="Not found", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( + * @OA\Schema( * type="object", * description="Error", - * @OA\Property( + * @OA\Property( * property="error", * type="string", * default="Message error" @@ -182,12 +182,12 @@ use OpenApi\Annotations as OA; * response="InternalServerError", * description="Internal server error", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( + * @OA\Schema( * type="object", * description="Error", - * @OA\Property( + * @OA\Property( * property="error", * type="string", * default="Message error" @@ -201,10 +201,10 @@ use OpenApi\Annotations as OA; * response="successfullyDeleted", * description="Successfully deleted", * content={ - * @OA\MediaType( + * @OA\MediaType( * mediaType="application/json", - * @OA\Schema( - * @OA\Property( + * @OA\Schema( + * @OA\Property( * property="result", * type="string", * default="Successfully deleted" @@ -218,35 +218,35 @@ use OpenApi\Annotations as OA; * schema="paginationData", * type="object", * description="Info pagination data", - * @OA\Property( + * @OA\Property( * property="totalPages", * type="integer", * nullable=true, * description="Number of pages", * readOnly=true * ), - * @OA\Property( + * @OA\Property( * property="sizePage", * type="integer", * nullable=true, * description="Items per page", * readOnly=true * ), - * @OA\Property( + * @OA\Property( * property="totalRegisters", * type="integer", * nullable=true, * description="Number of items", * readOnly=true * ), - * @OA\Property( + * @OA\Property( * property="totalRegistersPage", * type="integer", * nullable=true, * description="Number of items this page", * readOnly=true * ), - * @OA\Property( + * @OA\Property( * property="currentPage", * type="integer", * nullable=true, diff --git a/pandora_console/include/lib/Modules/Shared/Entities/PaginationData.php b/pandora_console/include/lib/Modules/Shared/Entities/PaginationData.php index eae2708a2f..d55aee91cc 100644 --- a/pandora_console/include/lib/Modules/Shared/Entities/PaginationData.php +++ b/pandora_console/include/lib/Modules/Shared/Entities/PaginationData.php @@ -6,20 +6,13 @@ use JsonSerializable; class PaginationData implements JsonSerializable { - private ?int $totalPages = null; - private ?int $sizePage = null; - private ?int $currentPage = null; - private ?int $totalRegisters = null; - private ?int $totalRegistersPage = null; - private ?array $data = null; - public function __construct( $currentPage, $sizePage, @@ -36,13 +29,11 @@ class PaginationData implements JsonSerializable $this->setData($data); } - public function toArray() { return $this->jsonSerialize(); } - public function jsonSerialize(): mixed { return [ @@ -53,27 +44,15 @@ class PaginationData implements JsonSerializable 'totalRegisters' => $this->getTotalRegisters(), 'totalRegistersPage' => $this->getTotalRegistersPage(), ], - 'data' => $this->getData(), + 'data' => $this->getData(), ]; } - - /** - * Get the value of totalPages. - * - * @return ?int - */ public function getTotalPages(): ?int { return $this->totalPages; } - - /** - * Set the value of totalPages. - * - * @param integer $totalPages - */ public function setTotalPages(?int $totalPages): self { $this->totalPages = $totalPages; @@ -81,23 +60,11 @@ class PaginationData implements JsonSerializable return $this; } - - /** - * Get the value of sizePage. - * - * @return ?int - */ public function getSizePage(): ?int { return $this->sizePage; } - - /** - * Set the value of sizePage. - * - * @param integer $sizePage - */ public function setSizePage(?int $sizePage): self { $this->sizePage = $sizePage; @@ -105,23 +72,11 @@ class PaginationData implements JsonSerializable return $this; } - - /** - * Get the value of currentPage. - * - * @return ?int - */ public function getCurrentPage(): ?int { return $this->currentPage; } - - /** - * Set the value of currentPage. - * - * @param integer $currentPage - */ public function setCurrentPage(?int $currentPage): self { $this->currentPage = $currentPage; @@ -129,23 +84,11 @@ class PaginationData implements JsonSerializable return $this; } - - /** - * Get the value of totalRegisters. - * - * @return ?int - */ public function getTotalRegisters(): ?int { return $this->totalRegisters; } - - /** - * Set the value of totalRegisters. - * - * @param integer $totalRegisters - */ public function setTotalRegisters(?int $totalRegisters): self { $this->totalRegisters = $totalRegisters; @@ -153,23 +96,11 @@ class PaginationData implements JsonSerializable return $this; } - - /** - * Get the value of totalRegistersPage. - * - * @return ?int - */ public function getTotalRegistersPage(): ?int { return $this->totalRegistersPage; } - - /** - * Set the value of totalRegistersPage. - * - * @param integer $totalRegistersPage - */ public function setTotalRegistersPage(?int $totalRegistersPage): self { $this->totalRegistersPage = $totalRegistersPage; @@ -177,29 +108,15 @@ class PaginationData implements JsonSerializable return $this; } - - /** - * Get the value of data. - * - * @return ?array - */ public function getData(): ?array { return $this->data; } - - /** - * Set the value of data. - * - * @param array $data - */ public function setData(?array $data): self { $this->data = $data; return $this; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Enums/HttpCodesEnum.php b/pandora_console/include/lib/Modules/Shared/Enums/HttpCodesEnum.php index ac7dc58231..acd2ec8a45 100644 --- a/pandora_console/include/lib/Modules/Shared/Enums/HttpCodesEnum.php +++ b/pandora_console/include/lib/Modules/Shared/Enums/HttpCodesEnum.php @@ -4,89 +4,67 @@ namespace PandoraFMS\Modules\Shared\Enums; enum HttpCodesEnum: int { -public const CONTINUE = 100; -public const SWITCHING_PROTOCOLS = 101; -public const PROCESSING = 102; -// RFC2518 -public const EARLY_HINTS = 103; -// RFC8297 -public const OK = 200; -public const CREATED = 201; -public const ACCEPTED = 202; -public const NON_AUTHORITATIVE_INFORMATION = 203; -public const NO_CONTENT = 204; -public const RESET_CONTENT = 205; -public const PARTIAL_CONTENT = 206; -public const MULTI_STATUS = 207; -// RFC4918 -public const ALREADY_REPORTED = 208; -// RFC5842 -public const IM_USED = 226; -// RFC3229 -public const MULTIPLE_CHOICES = 300; -public const MOVED_PERMANENTLY = 301; -public const FOUND = 302; -public const SEE_OTHER = 303; -public const NOT_MODIFIED = 304; -public const USE_PROXY = 305; -public const RESERVED = 306; -public const TEMPORARY_REDIRECT = 307; -public const PERMANENTLY_REDIRECT = 308; -// RFC7238 -public const BAD_REQUEST = 400; -public const UNAUTHORIZED = 401; -public const PAYMENT_REQUIRED = 402; -public const FORBIDDEN = 403; -public const NOT_FOUND = 404; -public const METHOD_NOT_ALLOWED = 405; -public const NOT_ACCEPTABLE = 406; -public const PROXY_AUTHENTICATION_REQUIRED = 407; -public const REQUEST_TIMEOUT = 408; -public const CONFLICT = 409; -public const GONE = 410; -public const LENGTH_REQUIRED = 411; -public const PRECONDITION_FAILED = 412; -public const REQUEST_ENTITY_TOO_LARGE = 413; -public const REQUEST_URI_TOO_LONG = 414; -public const UNSUPPORTED_MEDIA_TYPE = 415; -public const REQUESTED_RANGE_NOT_SATISFIABLE = 416; -public const EXPECTATION_FAILED = 417; -public const I_AM_A_TEAPOT = 418; -// RFC2324 -public const MISDIRECTED_REQUEST = 421; -// RFC7540 -public const UNPROCESSABLE_ENTITY = 422; -// RFC4918 -public const LOCKED = 423; -// RFC4918 -public const FAILED_DEPENDENCY = 424; -// RFC4918 -public const TOO_EARLY = 425; -// RFC-ietf-httpbis-replay-04 -public const UPGRADE_REQUIRED = 426; -// RFC2817 -public const PRECONDITION_REQUIRED = 428; -// RFC6585 -public const TOO_MANY_REQUESTS = 429; -// RFC6585 -public const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; -// RFC6585 -public const UNAVAILABLE_FOR_LEGAL_REASONS = 451; -// RFC7725 -public const INTERNAL_SERVER_ERROR = 500; -public const NOT_IMPLEMENTED = 501; -public const BAD_GATEWAY = 502; -public const SERVICE_UNAVAILABLE = 503; -public const GATEWAY_TIMEOUT = 504; -public const VERSION_NOT_SUPPORTED = 505; -public const VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; -// RFC2295 -public const INSUFFICIENT_STORAGE = 507; -// RFC4918 -public const LOOP_DETECTED = 508; -// RFC5842 -public const NOT_EXTENDED = 510; -// RFC2774 -public const NETWORK_AUTHENTICATION_REQUIRED = 511; -// RFC6585 + public const CONTINUE = 100; + public const SWITCHING_PROTOCOLS = 101; + public const PROCESSING = 102; // RFC2518 + public const EARLY_HINTS = 103; // RFC8297 + public const OK = 200; + public const CREATED = 201; + public const ACCEPTED = 202; + public const NON_AUTHORITATIVE_INFORMATION = 203; + public const NO_CONTENT = 204; + public const RESET_CONTENT = 205; + public const PARTIAL_CONTENT = 206; + public const MULTI_STATUS = 207; // RFC4918 + public const ALREADY_REPORTED = 208; // RFC5842 + public const IM_USED = 226; // RFC3229 + public const MULTIPLE_CHOICES = 300; + public const MOVED_PERMANENTLY = 301; + public const FOUND = 302; + public const SEE_OTHER = 303; + public const NOT_MODIFIED = 304; + public const USE_PROXY = 305; + public const RESERVED = 306; + public const TEMPORARY_REDIRECT = 307; + public const PERMANENTLY_REDIRECT = 308; // RFC7238 + public const BAD_REQUEST = 400; + public const UNAUTHORIZED = 401; + public const PAYMENT_REQUIRED = 402; + public const FORBIDDEN = 403; + public const NOT_FOUND = 404; + public const METHOD_NOT_ALLOWED = 405; + public const NOT_ACCEPTABLE = 406; + public const PROXY_AUTHENTICATION_REQUIRED = 407; + public const REQUEST_TIMEOUT = 408; + public const CONFLICT = 409; + public const GONE = 410; + public const LENGTH_REQUIRED = 411; + public const PRECONDITION_FAILED = 412; + public const REQUEST_ENTITY_TOO_LARGE = 413; + public const REQUEST_URI_TOO_LONG = 414; + public const UNSUPPORTED_MEDIA_TYPE = 415; + public const REQUESTED_RANGE_NOT_SATISFIABLE = 416; + public const EXPECTATION_FAILED = 417; + public const I_AM_A_TEAPOT = 418; // RFC2324 + public const MISDIRECTED_REQUEST = 421; // RFC7540 + public const UNPROCESSABLE_ENTITY = 422; // RFC4918 + public const LOCKED = 423; // RFC4918 + public const FAILED_DEPENDENCY = 424; // RFC4918 + public const TOO_EARLY = 425; // RFC-ietf-httpbis-replay-04 + public const UPGRADE_REQUIRED = 426; // RFC2817 + public const PRECONDITION_REQUIRED = 428; // RFC6585 + public const TOO_MANY_REQUESTS = 429; // RFC6585 + public const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 + public const UNAVAILABLE_FOR_LEGAL_REASONS = 451; // RFC7725 + public const INTERNAL_SERVER_ERROR = 500; + public const NOT_IMPLEMENTED = 501; + public const BAD_GATEWAY = 502; + public const SERVICE_UNAVAILABLE = 503; + public const GATEWAY_TIMEOUT = 504; + public const VERSION_NOT_SUPPORTED = 505; + public const VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; // RFC2295 + public const INSUFFICIENT_STORAGE = 507; // RFC4918 + public const LOOP_DETECTED = 508; // RFC5842 + public const NOT_EXTENDED = 510; // RFC2774 + public const NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 } diff --git a/pandora_console/include/lib/Modules/Shared/Enums/LanguagesEnum.php b/pandora_console/include/lib/Modules/Shared/Enums/LanguagesEnum.php index 5f33df8115..b5919a9fb4 100644 --- a/pandora_console/include/lib/Modules/Shared/Enums/LanguagesEnum.php +++ b/pandora_console/include/lib/Modules/Shared/Enums/LanguagesEnum.php @@ -8,12 +8,12 @@ enum LanguagesEnum: string { use EnumTrait; -case CATALONIAN = 'ca'; -case ENGLISH = 'en_GB'; -case SPANISH = 'es'; -case FRENCH = 'fr'; -case JAPANESE = 'ja'; -case RUSSIAN = 'ru'; -case CHINESE = 'zh_CN'; + case CATALONIAN = 'ca'; + case ENGLISH = 'en_GB'; + case SPANISH = 'es'; + case FRENCH = 'fr'; + case JAPANESE = 'ja'; + case RUSSIAN = 'ru'; + case CHINESE = 'zh_CN'; - } +} diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/BadRequestException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/BadRequestException.php index fe4e2f4692..e9e9e9c4f7 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/BadRequestException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/BadRequestException.php @@ -7,12 +7,8 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class BadRequestException extends Exception { - - public function __construct(string $fails) { parent::__construct($fails, HttpCodesEnum::BAD_REQUEST); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenACLException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenACLException.php index a7f18e0b33..b08d274483 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenACLException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenACLException.php @@ -7,12 +7,8 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class ForbiddenACLException extends Exception { - - public function __construct(string $fails) { parent::__construct($fails, HttpCodesEnum::FORBIDDEN); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenActionException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenActionException.php index f25e4c1ace..b561f6e7a2 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenActionException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/ForbiddenActionException.php @@ -6,12 +6,8 @@ use Exception; class ForbiddenActionException extends Exception { - - public function __construct(string $fails, int $httpCodesEnum) { parent::__construct($fails, $httpCodesEnum); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidClassException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidClassException.php index f7d5683519..8a2f0ecacb 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidClassException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidClassException.php @@ -7,12 +7,8 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class InvalidClassException extends Exception { - - public function __construct(string $fails) { parent::__construct($fails, HttpCodesEnum::NOT_IMPLEMENTED); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidFilterException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidFilterException.php index 4da4ab06c3..6f0e4ce76d 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidFilterException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/InvalidFilterException.php @@ -7,8 +7,6 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class InvalidFilterException extends Exception { - - public function __construct(array $fails) { $str = ''; @@ -18,6 +16,4 @@ class InvalidFilterException extends Exception parent::__construct(__($str), HttpCodesEnum::BAD_REQUEST); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Exceptions/NotFoundException.php b/pandora_console/include/lib/Modules/Shared/Exceptions/NotFoundException.php index 2ac602fa9e..054090cd5f 100644 --- a/pandora_console/include/lib/Modules/Shared/Exceptions/NotFoundException.php +++ b/pandora_console/include/lib/Modules/Shared/Exceptions/NotFoundException.php @@ -7,12 +7,8 @@ use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; class NotFoundException extends Exception { - - public function __construct(string $fails) { parent::__construct($fails, HttpCodesEnum::NOT_FOUND); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Middlewares/UserTokenMiddleware.php b/pandora_console/include/lib/Modules/Shared/Middlewares/UserTokenMiddleware.php index caf0fd22bd..db8fcbd096 100644 --- a/pandora_console/include/lib/Modules/Shared/Middlewares/UserTokenMiddleware.php +++ b/pandora_console/include/lib/Modules/Shared/Middlewares/UserTokenMiddleware.php @@ -11,8 +11,6 @@ use Psr\Http\Message\ServerRequestInterface as Request; class UserTokenMiddleware { - - public function __construct( private readonly ValidateUserTokenService $validateUserTokenService, private readonly GetUserTokenService $getUserTokenService, @@ -21,7 +19,6 @@ class UserTokenMiddleware ) { } - public function check(Request $request): bool { global $config; @@ -66,6 +63,4 @@ class UserTokenMiddleware return $token !== null && $validToken; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Repositories/Repository.php b/pandora_console/include/lib/Modules/Shared/Repositories/Repository.php index 18cfd51606..111bec0484 100644 --- a/pandora_console/include/lib/Modules/Shared/Repositories/Repository.php +++ b/pandora_console/include/lib/Modules/Shared/Repositories/Repository.php @@ -2,89 +2,70 @@ namespace PandoraFMS\Modules\Shared\Repositories; +use InvalidArgumentException; use PandoraFMS\Modules\Shared\Core\DataMapperAbstract; use PandoraFMS\Modules\Shared\Core\FilterAbstract; use PandoraFMS\Modules\Shared\Entities\Entity; use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; -use InvalidArgumentException; abstract class Repository { - - abstract protected function dbGetRow( string $field, string $table, mixed $value ): array; - abstract protected function dbGetValue( string $field, string $table, array $filters, - string $whereJoin='AND' + string $whereJoin = 'AND' ): mixed; - abstract protected function dbGetValueSql( string $sql, - ?bool $cache=false + ?bool $cache = false ): string; - abstract protected function dbGetRowSql( string $sql ): array; - abstract protected function dbGetAllRowsSql( string $sql, - ?bool $cache=false + ?bool $cache = false ): array; - abstract protected function dbInsert(string $table, array $values): mixed; - abstract protected function dbUpdate(string $table, array $values, array $condition): mixed; - abstract protected function dbDelete(string $table, array $where): mixed; - - abstract protected function dbFormatWhereClauseSQL(array $values, $prefix=''): string; - + abstract protected function dbFormatWhereClauseSQL(array $values, $prefix = ''): string; abstract public function buildQueryFilters(FilterAbstract $filter, DataMapperAbstract $mapper): string; - abstract public function buildQueryPagination(FilterAbstract $filter): string; - abstract public function buildQueryOrderBy(FilterAbstract $filter): string; - - abstract public function checkAclGroupMysql(string $field, ?string $mode=''): string; - + abstract public function checkAclGroupMysql(string $field, ?string $mode = ''): string; abstract public function buildQuery( FilterAbstract $filter, DataMapperAbstract $mapper, - bool $count=false + bool $count = false ): string; - abstract public function maxFieldSql(string $field): string; - abstract public function safeInput(?string $value): ?string; - abstract public function safeOutput(?string $value): ?string; - /** * @return object[], */ @@ -113,7 +94,6 @@ abstract class Repository return $result; } - public function __rows(FilterAbstract $filter, DataMapperAbstract $mapper): array { try { @@ -130,7 +110,6 @@ abstract class Repository return $rows; } - public function __count(FilterAbstract $filter, DataMapperAbstract $mapper): int { $sql = $this->buildQuery($filter, $mapper, true); @@ -147,7 +126,6 @@ abstract class Repository return (int) $count; } - public function __getOne(FilterAbstract $filter, DataMapperAbstract $mapper): object { try { @@ -168,7 +146,6 @@ abstract class Repository return $mapper->fromDatabase($result); } - public function __create(Entity $entity, DataMapperAbstract $mapper): int { try { @@ -198,7 +175,6 @@ abstract class Repository return $id; } - public function __update(Entity $entity, DataMapperAbstract $mapper, mixed $id): object { $values = $mapper->toDatabase($entity); @@ -220,12 +196,11 @@ abstract class Repository return $entity; } - public function __delete( mixed $id, DataMapperAbstract $mapper, - ?string $key=null, - ?array $where=null + ?string $key = null, + ?array $where = null ): void { try { if (empty($key) === true) { @@ -258,7 +233,6 @@ abstract class Repository } } - public function __getValue(FilterAbstract $filter, DataMapperAbstract $mapper): mixed { try { @@ -275,11 +249,8 @@ abstract class Repository return $result; } - public function __maxField(string $field): string { return $this->maxFieldSql($field); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Repositories/RepositoryMySQL.php b/pandora_console/include/lib/Modules/Shared/Repositories/RepositoryMySQL.php index 76090797a1..cf39189a96 100644 --- a/pandora_console/include/lib/Modules/Shared/Repositories/RepositoryMySQL.php +++ b/pandora_console/include/lib/Modules/Shared/Repositories/RepositoryMySQL.php @@ -9,8 +9,6 @@ use PandoraFMS\Modules\Shared\Services\Config; class RepositoryMySQL extends Repository { - - protected function dbGetRow( string $field, string $table, @@ -31,20 +29,18 @@ class RepositoryMySQL extends Repository return $result; } - protected function dbGetValue( string $field, string $table, array $filters, - string $whereJoin='AND' + string $whereJoin = 'AND' ): mixed { return \db_get_value_filter($field, $table, $filters, $whereJoin); } - protected function dbGetValueSql( string $sql, - ?bool $cache=false + ?bool $cache = false ): string { ob_start(); $result = \db_get_value_sql($sql, $cache); @@ -61,7 +57,6 @@ class RepositoryMySQL extends Repository return $result; } - protected function dbGetRowSql( string $sql ): array { @@ -80,10 +75,9 @@ class RepositoryMySQL extends Repository return $result; } - protected function dbGetAllRowsSql( string $sql, - ?bool $cache=false + ?bool $cache = false ): array { ob_start(); $result = \db_get_all_rows_sql($sql, $cache); @@ -100,7 +94,6 @@ class RepositoryMySQL extends Repository return $result; } - protected function dbInsert(string $table, array $values): mixed { ob_start(); @@ -117,7 +110,6 @@ class RepositoryMySQL extends Repository return $result; } - protected function dbUpdate(string $table, array $values, array $condition): mixed { ob_start(); @@ -138,7 +130,6 @@ class RepositoryMySQL extends Repository return $result; } - protected function dbDelete(string $table, array $where): mixed { ob_start(); @@ -156,8 +147,7 @@ class RepositoryMySQL extends Repository return $result; } - - protected function dbFormatWhereClauseSQL(array $values, $prefix=''): string + protected function dbFormatWhereClauseSQL(array $values, $prefix = ''): string { ob_start(); $result = \db_format_array_where_clause_sql($values, 'AND', $prefix); @@ -169,7 +159,6 @@ class RepositoryMySQL extends Repository return $result; } - public function buildQueryFilters(FilterAbstract $filter, DataMapperAbstract $mapper): string { $where_clause = '1=1'; @@ -206,7 +195,6 @@ class RepositoryMySQL extends Repository return $where_clause; } - private function freeSearch(array $fields, string $value): string { $clause = ' AND ('; @@ -224,7 +212,6 @@ class RepositoryMySQL extends Repository return $clause; } - private function multipleSearch(FilterAbstract $filter): string { $fields = $filter->fieldsTranslate(); @@ -241,7 +228,6 @@ class RepositoryMySQL extends Repository return $clause; } - private function multipleSearchString(FilterAbstract $filter): string { $fields = $filter->fieldsTranslate(); @@ -258,7 +244,6 @@ class RepositoryMySQL extends Repository return $clause; } - public function buildQueryPagination(FilterAbstract $filter): string { $filter->setLimit($filter->getSizePage()); @@ -276,7 +261,6 @@ class RepositoryMySQL extends Repository return $sqlLimit; } - public function buildQueryOrderBy(FilterAbstract $filter): string { $default = ''; @@ -307,7 +291,6 @@ class RepositoryMySQL extends Repository return $return; } - public function buildQueryGroupBy(FilterAbstract $filter): string { $groupBy = ''; @@ -330,7 +313,6 @@ class RepositoryMySQL extends Repository return $groupBy; } - private function checkDirectionOrderByMsql(?string $direction): string { $directionArray = [ @@ -341,8 +323,7 @@ class RepositoryMySQL extends Repository return (isset($directionArray[$direction]) === true) ? $directionArray[$direction] : 'ASC'; } - - public function checkAclGroupMysql(string $field, ?string $mode=''): string + public function checkAclGroupMysql(string $field, ?string $mode = ''): string { $config = new Config(); $isAdmin = users_is_admin($config->get('id_user')); @@ -351,7 +332,7 @@ class RepositoryMySQL extends Repository } $userGroups = array_keys( - \get_user_groups( + \users_get_groups( $config->get('id_user'), 'IM', true, @@ -390,11 +371,10 @@ class RepositoryMySQL extends Repository return $filter; } - public function buildQuery( FilterAbstract $filter, DataMapperAbstract $mapper, - bool $count=false + bool $count = false ): string { $filters = $this->buildQueryFilters($filter, $mapper); if (empty($mapper->getSearchFieldRelated()) === false) { @@ -462,23 +442,18 @@ class RepositoryMySQL extends Repository return $sql; } - public function maxFieldSql(string $field): string { return 'MAX('.$field.')'; } - public function safeInput(?string $value): ?string { return \io_safe_input($value); } - public function safeOutput(?string $value): ?string { return \io_safe_output($value); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Services/Audit.php b/pandora_console/include/lib/Modules/Shared/Services/Audit.php index 1eee66ec2f..b2ff3c5cec 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/Audit.php +++ b/pandora_console/include/lib/Modules/Shared/Services/Audit.php @@ -4,18 +4,15 @@ namespace PandoraFMS\Modules\Shared\Services; class Audit { - - public function __construct( private Config $config, ) { } - public function write( string $action, - string $message='', - string $extra='' + string $message = '', + string $extra = '' ): void { $idUser ??= $this->config->get('id_user'); $remoteAddr ??= $this->config->get('REMOTE_ADDR'); @@ -27,6 +24,4 @@ class Audit $extra ); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Services/Config.php b/pandora_console/include/lib/Modules/Shared/Services/Config.php index 672fdcbf90..2c4616d344 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/Config.php +++ b/pandora_console/include/lib/Modules/Shared/Services/Config.php @@ -4,16 +4,12 @@ namespace PandoraFMS\Modules\Shared\Services; final class Config { - - - public function get(string $key, mixed $default=null): mixed + public function get(string $key, mixed $default = null): mixed { global $config; - return ($config[$key] ?? $default); } - public function set(string $key, mixed $value): bool { global $config; @@ -25,6 +21,4 @@ final class Config return $res; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Services/FileService.php b/pandora_console/include/lib/Modules/Shared/Services/FileService.php index 6da58f1355..b57a834ee7 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/FileService.php +++ b/pandora_console/include/lib/Modules/Shared/Services/FileService.php @@ -2,26 +2,23 @@ namespace PandoraFMS\Modules\Shared\Services; +use InvalidArgumentException; use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; use PandoraFMS\Modules\Shared\Exceptions\ForbiddenActionException; -use InvalidArgumentException; use Psr\Http\Message\UploadedFileInterface; class FileService { - - public function __construct( private Config $config, ) { } - public function moveUploadedFile( UploadedFileInterface $uploadedFile, - ?string $filename=null, - ?string $subdirectory='' + ?string $filename = null, + ?string $subdirectory = '' ) { $directory = $this->config->get('attachment_directory'); $extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION); @@ -50,7 +47,6 @@ class FileService return $filename; } - public function removeFile(string $filename) { $directory = $this->config->get('attachment_directory'); @@ -62,11 +58,10 @@ class FileService } } - public function validationFile( UploadedFileInterface $file, - string $regexInvalidExtension=null, - int $maxSize=null + string $regexInvalidExtension = null, + int $maxSize = null ): void { if (empty($regexInvalidExtension) === true) { $regexInvalidExtension = '/^(bat|exe|cmd|sh|php|php1|php2|php3|php4|php5|pl|cgi|386|dll|com|torrent|js|app|jar|iso| @@ -89,7 +84,6 @@ class FileService } } - private function calculateSizeBytes(int $maxSize) { $max = ini_get('upload_max_filesize'); @@ -99,6 +93,4 @@ class FileService return ($maxSize * 1000000); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Services/Timestamp.php b/pandora_console/include/lib/Modules/Shared/Services/Timestamp.php index ca766ee016..ad00509763 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/Timestamp.php +++ b/pandora_console/include/lib/Modules/Shared/Services/Timestamp.php @@ -4,17 +4,14 @@ namespace PandoraFMS\Modules\Shared\Services; class Timestamp { - - public function __construct( private Config $config ) { } - public function getMysqlCurrentTimestamp( int $unixtime, - ?string $format='Y-m-d H:i:s', + ?string $format = 'Y-m-d H:i:s', ): string { if ($unixtime == 0) { $unixtime = time(); @@ -27,12 +24,9 @@ class Timestamp return date($format, $unixtime); } - - public function getMysqlSystemUtimestamp() : int + public function getMysqlSystemUtimestamp(): int { $return = \mysql_get_system_time(); return $return; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Services/ValidateAclSystem.php b/pandora_console/include/lib/Modules/Shared/Services/ValidateAclSystem.php index 0ab24d5f93..ad562eb1ed 100644 --- a/pandora_console/include/lib/Modules/Shared/Services/ValidateAclSystem.php +++ b/pandora_console/include/lib/Modules/Shared/Services/ValidateAclSystem.php @@ -7,8 +7,6 @@ use PandoraFMS\Modules\Users\UserProfiles\Actions\GetUserProfileAction; class ValidateAclSystem { - - public function __construct( private Config $config, private Audit $audit, @@ -16,11 +14,10 @@ class ValidateAclSystem ) { } - public function validate( int $idGroup, string|array $permissions, - string $message='', + string $message = '', ): void { // ACL. $idUser ??= $this->config->get('id_user'); @@ -44,11 +41,10 @@ class ValidateAclSystem } } - public function validateUserGroups( int|array|null $idGroup, string $permissions, - string $message='', + string $message = '', ): void { $idUser ??= $this->config->get('id_user'); @@ -73,13 +69,10 @@ class ValidateAclSystem } } - public function validateUserProfile( int $idProfile ): void { $idUser ??= $this->config->get('id_user'); $this->getUserProfileAction->__invoke($idUser, $idProfile); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Traits/EnumTrait.php b/pandora_console/include/lib/Modules/Shared/Traits/EnumTrait.php index 7ec56339df..c4a6c87eb6 100644 --- a/pandora_console/include/lib/Modules/Shared/Traits/EnumTrait.php +++ b/pandora_console/include/lib/Modules/Shared/Traits/EnumTrait.php @@ -4,11 +4,9 @@ namespace PandoraFMS\Modules\Shared\Traits; trait EnumTrait { - - public static function get( mixed $value, - string $type='name' + string $type = 'name' ): mixed { $cases = static::cases(); $index = array_search($value, array_column($cases, $type)); @@ -18,6 +16,4 @@ trait EnumTrait return null; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Traits/GroupByFilterTrait.php b/pandora_console/include/lib/Modules/Shared/Traits/GroupByFilterTrait.php index 80940d650c..90e8f57356 100644 --- a/pandora_console/include/lib/Modules/Shared/Traits/GroupByFilterTrait.php +++ b/pandora_console/include/lib/Modules/Shared/Traits/GroupByFilterTrait.php @@ -4,32 +4,17 @@ namespace PandoraFMS\Modules\Shared\Traits; trait GroupByFilterTrait { - private ?array $groupByFields = null; - - /** - * Get the value of groupByFields. - * - * @return ?array - */ public function getGroupByFields(): ?array { return $this->groupByFields; } - - /** - * Set the value of groupByFields. - * - * @param array $groupByFields - */ public function setGroupByFields(?array $groupByFields): self { $this->groupByFields = $groupByFields; return $this; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Traits/OrderFilterTrait.php b/pandora_console/include/lib/Modules/Shared/Traits/OrderFilterTrait.php index cab89b7109..7a0f040b34 100644 --- a/pandora_console/include/lib/Modules/Shared/Traits/OrderFilterTrait.php +++ b/pandora_console/include/lib/Modules/Shared/Traits/OrderFilterTrait.php @@ -4,28 +4,14 @@ namespace PandoraFMS\Modules\Shared\Traits; trait OrderFilterTrait { - private ?string $sortField = null; - private ?string $sortDirection = null; - - /** - * Get the value of sortField. - * - * @return ?string - */ public function getSortField(): ?string { return $this->sortField; } - - /** - * Set the value of sortField. - * - * @param string $sortField - */ public function setSortField(?string $sortField): self { $this->sortField = $sortField; @@ -33,29 +19,15 @@ trait OrderFilterTrait return $this; } - - /** - * Get the value of sortDirection. - * - * @return ?string - */ public function getSortDirection(): ?string { return $this->sortDirection; } - - /** - * Set the value of sortDirection. - * - * @param string $sortDirection - */ public function setSortDirection(?string $sortDirection): self { $this->sortDirection = $sortDirection; return $this; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Traits/PaginationFilterTrait.php b/pandora_console/include/lib/Modules/Shared/Traits/PaginationFilterTrait.php index 198b627e85..078f31fe8e 100644 --- a/pandora_console/include/lib/Modules/Shared/Traits/PaginationFilterTrait.php +++ b/pandora_console/include/lib/Modules/Shared/Traits/PaginationFilterTrait.php @@ -4,28 +4,14 @@ namespace PandoraFMS\Modules\Shared\Traits; trait PaginationFilterTrait { - private ?int $sizePage = null; - private ?int $page = null; - - /** - * Get the value of sizePage. - * - * @return ?int - */ public function getSizePage(): ?int { return $this->sizePage; } - - /** - * Set the value of sizePage. - * - * @param integer $sizePage - */ public function setSizePage(?int $sizePage): self { $this->sizePage = $sizePage; @@ -33,29 +19,15 @@ trait PaginationFilterTrait return $this; } - - /** - * Get the value of page. - * - * @return ?int - */ public function getPage(): ?int { return $this->page; } - - /** - * Set the value of page. - * - * @param integer $page - */ public function setPage(?int $page): self { $this->page = $page; return $this; } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Utils/ArrayTools.php b/pandora_console/include/lib/Modules/Shared/Utils/ArrayTools.php index 92e4c239a0..347394dcd3 100644 --- a/pandora_console/include/lib/Modules/Shared/Utils/ArrayTools.php +++ b/pandora_console/include/lib/Modules/Shared/Utils/ArrayTools.php @@ -4,8 +4,6 @@ namespace PandoraFMS\Modules\Shared\Utils; final class ArrayTools { - - public function extractFromObjectByAttribute(string $attribute, array $list): array { return array_reduce( @@ -18,7 +16,6 @@ final class ArrayTools ); } - public function indexObjectByAttribute(string $attribute, array $list): array { return array_reduce( @@ -30,6 +27,4 @@ final class ArrayTools [] ); } - - } diff --git a/pandora_console/include/lib/Modules/Shared/Validators/Validator.php b/pandora_console/include/lib/Modules/Shared/Validators/Validator.php index 946db3c4d7..02034b38cc 100644 --- a/pandora_console/include/lib/Modules/Shared/Validators/Validator.php +++ b/pandora_console/include/lib/Modules/Shared/Validators/Validator.php @@ -17,12 +17,10 @@ class Validator public const LANGUAGE = 'Language'; public const MAIL = 'Mail'; - public function __construct() { } - public function validate(array $args): array { $failed = []; @@ -48,7 +46,6 @@ class Validator return $failed; } - private function buildError(string $type, string $field, $value): ?array { if ($this->{'is'.$type}($value) !== true) { @@ -61,56 +58,47 @@ class Validator return null; } - public function isInteger($arg): bool { return is_numeric($arg); } - public function isGreaterThan($arg): bool { return $arg > 0; } - public function isGreaterEqualThan($arg): bool { return $arg >= 0; } - public function isBool($arg): bool { return is_bool($arg); } - public function isString($arg): bool { return is_string($arg) || is_numeric($arg); } - public function isArray($arg): bool { return is_array($arg); } - - public function isDateTime($date, $format='Y-m-d H:i:s') + public function isDateTime($date, $format = 'Y-m-d H:i:s') { $d = \DateTime::createFromFormat($format, $date); return $d && $d->format($format) == $date; } - public function isTimeZone(string $timeZone): string { return array_search($timeZone, timezone_identifiers_list()); } - protected function isLanguage(string $language): bool { $result = LanguagesEnum::get(strtoupper($language)); @@ -118,11 +106,8 @@ class Validator return empty($result) === true ? false : true; } - protected function isMail(string $mail): bool { return filter_var($mail, FILTER_VALIDATE_EMAIL); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Actions/CreateUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/CreateUserAction.php index cb94c67919..8ddae2852d 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/CreateUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/CreateUserAction.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\Services\CreateUserService; final class CreateUserAction { - - public function __construct( private CreateUserService $createUserService ) { } - public function __invoke(User $user): User { return $this->createUserService->__invoke($user); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Actions/DeleteUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/DeleteUserAction.php index f74118083c..988955be02 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/DeleteUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/DeleteUserAction.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\Services\DeleteUserService; final class DeleteUserAction { - - public function __construct( private DeleteUserService $deleteUserService ) { } - public function __invoke(User $user): void { $this->deleteUserService->__invoke($user); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Actions/GetUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/GetUserAction.php index eb96a1941d..33e7f5b9d4 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/GetUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/GetUserAction.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\Services\GetUserService; final class GetUserAction { - - public function __construct( private GetUserService $getUserService ) { } - public function __invoke(string $idUser): User { return $this->getUserService->__invoke($idUser); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Actions/ListUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/ListUserAction.php index 318764724f..ca04e41771 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/ListUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/ListUserAction.php @@ -2,23 +2,19 @@ namespace PandoraFMS\Modules\Users\Actions; +use PandoraFMS\Modules\Shared\Entities\PaginationData; use PandoraFMS\Modules\Users\Entities\UserFilter; use PandoraFMS\Modules\Users\Services\CountUserService; use PandoraFMS\Modules\Users\Services\ListUserService; -use PandoraFMS\Modules\Shared\Entities\PaginationData; - final class ListUserAction { - - public function __construct( private ListUserService $listUserService, private CountUserService $countUserService ) { } - public function __invoke(UserFilter $userFilter): array { return (new PaginationData( @@ -28,6 +24,4 @@ final class ListUserAction $this->listUserService->__invoke($userFilter) ))->toArray(); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Actions/UpdateUserAction.php b/pandora_console/include/lib/Modules/Users/Actions/UpdateUserAction.php index 3a1eb9a896..c9ff136384 100644 --- a/pandora_console/include/lib/Modules/Users/Actions/UpdateUserAction.php +++ b/pandora_console/include/lib/Modules/Users/Actions/UpdateUserAction.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\Services\UpdateUserService; final class UpdateUserAction { - - public function __construct( private UpdateUserService $updateUserService ) { } - public function __invoke(User $user, User $oldUser): User { return $this->updateUserService->__invoke($user, $oldUser); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php index f9355e3932..627d5b5616 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php @@ -2,38 +2,35 @@ namespace PandoraFMS\Modules\Users\Controllers; -use PandoraFMS\Modules\Users\Actions\CreateUserAction; -use PandoraFMS\Modules\Users\Entities\User; use PandoraFMS\Modules\Shared\Controllers\Controller; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; +use PandoraFMS\Modules\Users\Actions\CreateUserAction; +use PandoraFMS\Modules\Users\Entities\User; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; final class CreateUserController extends Controller { - - public function __construct( private CreateUserAction $createUserAction, private ValidateAclSystem $acl, ) { } - /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user", * summary="Creates a new users", - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUser"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUser"), + * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -47,6 +44,4 @@ final class CreateUserController extends Controller return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php index ee6935ccb8..4b075bd25b 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php @@ -2,18 +2,16 @@ namespace PandoraFMS\Modules\Users\Controllers; -use PandoraFMS\Modules\Users\Actions\DeleteUserAction; -use PandoraFMS\Modules\Users\Actions\GetUserAction; use PandoraFMS\Modules\Shared\Controllers\Controller; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; +use PandoraFMS\Modules\Users\Actions\DeleteUserAction; +use PandoraFMS\Modules\Users\Actions\GetUserAction; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteUserController extends Controller { - - public function __construct( private DeleteUserAction $deleteUserAction, private ValidateAclSystem $acl, @@ -21,20 +19,19 @@ final class DeleteUserController extends Controller ) { } - /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user/{id}", * summary="Deletes an user object.", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -47,6 +44,4 @@ final class DeleteUserController extends Controller $result = $this->deleteUserAction->__invoke($user); return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php index de33ee5693..f29d264403 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php @@ -2,37 +2,34 @@ namespace PandoraFMS\Modules\Users\Controllers; -use PandoraFMS\Modules\Users\Actions\GetUserAction; use PandoraFMS\Modules\Shared\Controllers\Controller; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; +use PandoraFMS\Modules\Users\Actions\GetUserAction; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; final class GetUserController extends Controller { - - public function __construct( private GetUserAction $getUserAction, private ValidateAclSystem $acl ) { } - /** * @OA\Get( * security={{ "bearerAuth": {}}}, * path="/user/{id}", * tags={"Users"}, * summary="show users", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -41,6 +38,4 @@ final class GetUserController extends Controller $result = $this->getUserAction->__invoke($idUser); return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/ListUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/ListUserController.php index e103120c5a..8faa04e8cd 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/ListUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/ListUserController.php @@ -2,66 +2,63 @@ namespace PandoraFMS\Modules\Users\Controllers; -use PandoraFMS\Modules\Users\Actions\ListUserAction; -use PandoraFMS\Modules\Users\Entities\UserFilter; use PandoraFMS\Modules\Shared\Controllers\Controller; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; +use PandoraFMS\Modules\Users\Actions\ListUserAction; +use PandoraFMS\Modules\Users\Entities\UserFilter; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; final class ListUserController extends Controller { - - public function __construct( private ListUserAction $listUserAction, private ValidateAclSystem $acl, ) { } - /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Users"}, * path="/user/list", * summary="List user", - * @OA\Parameter(ref="#/components/parameters/parameterPage"), - * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), - * @OA\Parameter(ref="#/components/parameters/parameterSortField"), - * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserFilter"), - * @OA\Response( - * response="200", - * description="List Incidence object", - * content={ - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * @OA\Property( - * property="paginationData", - * type="object", - * ref="#/components/schemas/paginationData", - * description="Page object", - * ), - * @OA\Property( - * property="data", - * type="array", - * @OA\Items( - * ref="#/components/schemas/User", - * description="Array of user objects" - * ) - * ), - * ), - * ) - * } + * @OA\Parameter(ref="#/components/parameters/parameterPage"), + * @OA\Parameter(ref="#/components/parameters/parameterSizePage"), + * @OA\Parameter(ref="#/components/parameters/parameterSortField"), + * @OA\Parameter(ref="#/components/parameters/parameterSortDirection"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserFilter"), + * @OA\Response( + * response="200", + * description="List Incidence object", + * content={ + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * @OA\Property( + * property="paginationData", + * type="object", + * ref="#/components/schemas/paginationData", + * description="Page object", + * ), + * @OA\Property( + * property="data", + * type="array", + * @OA\Items( + * ref="#/components/schemas/User", + * description="Array of user objects" + * ) + * ), + * ), + * ) + * } * ), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ public function __invoke(Request $request, Response $response): Response @@ -73,6 +70,4 @@ final class ListUserController extends Controller return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php index b108a4952a..d787180198 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php @@ -2,11 +2,10 @@ namespace PandoraFMS\Modules\Users\Controllers; +use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use PandoraFMS\Modules\Users\Actions\GetUserAction; use PandoraFMS\Modules\Users\Actions\UpdateUserAction; -use PandoraFMS\Modules\Shared\Controllers\Controller; - -use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; @@ -19,18 +18,16 @@ use Psr\Http\Message\ServerRequestInterface as Request; * summary="Updates an user", * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUser"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), - * @OA\Response(response=400, ref="#/components/responses/BadRequest"), - * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), - * @OA\Response(response=403, ref="#/components/responses/Forbidden"), - * @OA\Response(response=404, ref="#/components/responses/NotFound"), - * @OA\Response(response=500, ref="#/components/responses/InternalServerError") + * @OA\Response(response=200, ref="#/components/responses/ResponseUser"), + * @OA\Response(response=400, ref="#/components/responses/BadRequest"), + * @OA\Response(response=401, ref="#/components/responses/Unauthorized"), + * @OA\Response(response=403, ref="#/components/responses/Forbidden"), + * @OA\Response(response=404, ref="#/components/responses/NotFound"), + * @OA\Response(response=500, ref="#/components/responses/InternalServerError") * ) */ final class UpdateUserController extends Controller { - - public function __construct( private UpdateUserAction $updateUserAction, private ValidateAclSystem $acl, @@ -38,7 +35,6 @@ final class UpdateUserController extends Controller ) { } - public function __invoke(Request $request, Response $response): Response { $idUser = $this->getParam($request, 'id'); @@ -53,6 +49,4 @@ final class UpdateUserController extends Controller $result = $this->updateUserAction->__invoke($user, $oldUser); return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Entities/User.php b/pandora_console/include/lib/Modules/Users/Entities/User.php index 8a2219dc58..ae9afbda4a 100644 --- a/pandora_console/include/lib/Modules/Users/Entities/User.php +++ b/pandora_console/include/lib/Modules/Users/Entities/User.php @@ -8,7 +8,6 @@ use PandoraFMS\Modules\Users\Enums\UserHomeScreenEnum; use PandoraFMS\Modules\Users\Enums\UserMetaconsoleAccessEnum; use PandoraFMS\Modules\Users\Validators\UserValidator; - /** * @OA\Schema( * schema="User", @@ -476,121 +475,65 @@ use PandoraFMS\Modules\Users\Validators\UserValidator; */ final class User extends Entity { - private ?string $idUser = null; - private ?string $fullName = null; - private ?string $firstName = null; - private ?string $lastName = null; - private ?string $middleName = null; - private ?string $password = null; - private ?string $passwordValidate = null; - private ?string $oldPassword = null; - private ?string $comments = null; - private ?int $lastConnect = null; - private ?int $registered = null; - private ?string $email = null; - private ?string $phone = null; - private ?bool $isAdmin = null; - private ?LanguagesEnum $language = null; - private ?string $timezone = null; - private ?int $blockSize = null; - private ?int $idSkin = null; - private ?bool $disabled = null; - private ?int $shortcut = null; - private ?string $shortcutData = null; - private ?UserHomeScreenEnum $section = null; - private ?string $dataSection = null; - private ?UserHomeScreenEnum $metaconsoleSection = null; - private ?string $metaconsoleDataSection = null; - private ?bool $forceChangePass = null; - private ?string $lastPassChange = null; - private ?string $lastFailedLogin = null; - private ?int $failedAttempt = null; - private ?bool $loginBlocked = null; - private ?UserMetaconsoleAccessEnum $metaconsoleAccess = null; - private ?bool $notLogin = null; - private ?bool $localUser = null; - private ?int $metaconsoleAgentsManager = null; - private ?int $metaconsoleAccessNode = null; - private ?bool $strictAcl = null; - private ?int $idFilter = null; - private ?int $sessionTime = null; - private ?int $defaultEventFilter = null; - private ?int $metaconsoleDefaultEventFilter = null; - private ?bool $showTipsStartup = null; - private ?array $autorefreshWhiteList = null; - private ?int $timeAutorefresh = null; - private ?int $defaultCustomView = null; - private ?string $ehorusUserLevelUser = null; - private ?string $ehorusUserLevelPass = null; - private ?bool $ehorusUserLevelEnabled = null; - private ?string $itsmUserLevelUser = null; - private ?string $itsmUserLevelPass = null; - private ?string $apiToken = null; - private ?bool $allowedIpActive = null; - private ?string $allowedIpList = null; - private ?string $authTokenSecret = null; - private ?string $sessionMaxTimeExpire = null; - public function __construct() { } - public function fieldsReadOnly(): array { return [ @@ -603,7 +546,6 @@ final class User extends Entity ]; } - public function jsonSerialize(): mixed { return [ @@ -659,67 +601,66 @@ final class User extends Entity ]; } - public function getValidations(): array { return [ - 'idUser' => UserValidator::STRING, - 'fullName' => UserValidator::STRING, - 'firstName' => UserValidator::STRING, - 'lastName' => UserValidator::STRING, - 'middleName' => UserValidator::STRING, - 'password' => UserValidator::STRING, - 'passwordValidate' => UserValidator::STRING, - 'oldPassword' => UserValidator::STRING, - 'comments' => UserValidator::STRING, - 'lastConnect' => [ + 'idUser' => UserValidator::STRING, + 'fullName' => UserValidator::STRING, + 'firstName' => UserValidator::STRING, + 'lastName' => UserValidator::STRING, + 'middleName' => UserValidator::STRING, + 'password' => UserValidator::STRING, + 'passwordValidate' => UserValidator::STRING, + 'oldPassword' => UserValidator::STRING, + 'comments' => UserValidator::STRING, + 'lastConnect' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'registered' => [ + 'registered' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'email' => UserValidator::MAIL, - 'phone' => UserValidator::STRING, - 'isAdmin' => UserValidator::BOOLEAN, - 'language' => UserValidator::LANGUAGE, - 'timezone' => UserValidator::TIMEZONE, - 'blockSize' => [ + 'email' => UserValidator::MAIL, + 'phone' => UserValidator::STRING, + 'isAdmin' => UserValidator::BOOLEAN, + 'language' => UserValidator::LANGUAGE, + 'timezone' => UserValidator::TIMEZONE, + 'blockSize' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'idSkin' => [ + 'idSkin' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'disabled' => UserValidator::BOOLEAN, - 'shortcut' => UserValidator::INTEGER, - 'shortcutData' => UserValidator::STRING, - 'section' => UserValidator::VALIDSECTION, - 'dataSection' => UserValidator::STRING, - 'metaconsoleSection' => UserValidator::VALIDSECTION, - 'metaconsoleDataSection' => UserValidator::STRING, - 'forceChangePass' => UserValidator::BOOLEAN, - 'lastPassChange' => UserValidator::DATETIME, - 'lastFailedLogin' => UserValidator::DATETIME, - 'failedAttempt' => [ + 'disabled' => UserValidator::BOOLEAN, + 'shortcut' => UserValidator::INTEGER, + 'shortcutData' => UserValidator::STRING, + 'section' => UserValidator::VALIDSECTION, + 'dataSection' => UserValidator::STRING, + 'metaconsoleSection' => UserValidator::VALIDSECTION, + 'metaconsoleDataSection' => UserValidator::STRING, + 'forceChangePass' => UserValidator::BOOLEAN, + 'lastPassChange' => UserValidator::DATETIME, + 'lastFailedLogin' => UserValidator::DATETIME, + 'failedAttempt' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'loginBlocked' => UserValidator::BOOLEAN, - 'metaconsoleAccess' => UserValidator::VALIDMETACONSOLEACCESS, - 'notLogin' => UserValidator::BOOLEAN, - 'localUser' => UserValidator::BOOLEAN, - 'metaconsoleAgentsManager' => UserValidator::INTEGER, - 'metaconsoleAccessNode' => UserValidator::INTEGER, - 'strictAcl' => UserValidator::BOOLEAN, - 'idFilter' => [ + 'loginBlocked' => UserValidator::BOOLEAN, + 'metaconsoleAccess' => UserValidator::VALIDMETACONSOLEACCESS, + 'notLogin' => UserValidator::BOOLEAN, + 'localUser' => UserValidator::BOOLEAN, + 'metaconsoleAgentsManager' => UserValidator::INTEGER, + 'metaconsoleAccessNode' => UserValidator::INTEGER, + 'strictAcl' => UserValidator::BOOLEAN, + 'idFilter' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'sessionTime' => UserValidator::INTEGER, - 'defaultEventFilter' => [ + 'sessionTime' => UserValidator::INTEGER, + 'defaultEventFilter' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], @@ -727,51 +668,36 @@ final class User extends Entity UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'showTipsStartup' => UserValidator::BOOLEAN, - 'autorefreshWhiteList' => UserValidator::ARRAY, - 'timeAutorefresh' => UserValidator::INTEGER, - 'defaultCustomView' => [ + 'showTipsStartup' => UserValidator::BOOLEAN, + 'autorefreshWhiteList' => UserValidator::ARRAY, + 'timeAutorefresh' => UserValidator::INTEGER, + 'defaultCustomView' => [ UserValidator::INTEGER, UserValidator::GREATERTHAN, ], - 'ehorusUserLevelUser' => UserValidator::STRING, - 'ehorusUserLevelPass' => UserValidator::STRING, - 'ehorusUserLevelEnabled' => UserValidator::BOOLEAN, - 'itsmUserLevelUser' => UserValidator::STRING, - 'itsmUserLevelPass' => UserValidator::STRING, - 'apiToken' => UserValidator::STRING, - 'allowedIpActive' => UserValidator::BOOLEAN, - 'allowedIpList' => UserValidator::STRING, - 'authTokenSecret' => UserValidator::STRING, - 'sessionMaxTimeExpire' => UserValidator::INTEGER, + 'ehorusUserLevelUser' => UserValidator::STRING, + 'ehorusUserLevelPass' => UserValidator::STRING, + 'ehorusUserLevelEnabled' => UserValidator::BOOLEAN, + 'itsmUserLevelUser' => UserValidator::STRING, + 'itsmUserLevelPass' => UserValidator::STRING, + 'apiToken' => UserValidator::STRING, + 'allowedIpActive' => UserValidator::BOOLEAN, + 'allowedIpList' => UserValidator::STRING, + 'authTokenSecret' => UserValidator::STRING, + 'sessionMaxTimeExpire' => UserValidator::INTEGER, ]; } - public function validateFields(array $filters): array { return (new UserValidator())->validate($filters); } - - /** - * Get the value of idUser - * - * @return ?string - */ public function getIdUser(): ?string { return $this->idUser; } - - /** - * Set the value of idUser - * - * @param string $idUser - * - * @return self - */ public function setIdUser(?string $idUser): self { $this->idUser = $idUser; @@ -779,25 +705,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of fullName - * - * @return ?string - */ public function getFullName(): ?string { return $this->fullName; } - - /** - * Set the value of fullName - * - * @param string $fullName - * - * @return self - */ public function setFullName(?string $fullName): self { $this->fullName = $fullName; @@ -805,25 +717,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of firstName - * - * @return ?string - */ public function getFirstName(): ?string { return $this->firstName; } - - /** - * Set the value of firstName - * - * @param string $firstName - * - * @return self - */ public function setFirstName(?string $firstName): self { $this->firstName = $firstName; @@ -831,25 +729,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of lastName - * - * @return ?string - */ public function getLastName(): ?string { return $this->lastName; } - - /** - * Set the value of lastName - * - * @param string $lastName - * - * @return self - */ public function setLastName(?string $lastName): self { $this->lastName = $lastName; @@ -857,25 +741,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of middleName - * - * @return ?string - */ public function getMiddleName(): ?string { return $this->middleName; } - - /** - * Set the value of middleName - * - * @param string $middleName - * - * @return self - */ public function setMiddleName(?string $middleName): self { $this->middleName = $middleName; @@ -883,25 +753,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of password - * - * @return ?string - */ public function getPassword(): ?string { return $this->password; } - - /** - * Set the value of password - * - * @param string $password - * - * @return self - */ public function setPassword(?string $password): self { $this->password = $password; @@ -909,25 +765,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of comments - * - * @return ?string - */ public function getComments(): ?string { return $this->comments; } - - /** - * Set the value of comments - * - * @param string $comments - * - * @return self - */ public function setComments(?string $comments): self { $this->comments = $comments; @@ -935,25 +777,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of lastConnect - * - * @return ?int - */ public function getLastConnect(): ?int { return $this->lastConnect; } - - /** - * Set the value of lastConnect - * - * @param integer $lastConnect - * - * @return self - */ public function setLastConnect(?int $lastConnect): self { $this->lastConnect = $lastConnect; @@ -961,25 +789,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of registered - * - * @return ?int - */ public function getRegistered(): ?int { return $this->registered; } - - /** - * Set the value of registered - * - * @param integer $registered - * - * @return self - */ public function setRegistered(?int $registered): self { $this->registered = $registered; @@ -987,25 +801,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of email - * - * @return ?string - */ public function getEmail(): ?string { return $this->email; } - - /** - * Set the value of email - * - * @param string $email - * - * @return self - */ public function setEmail(?string $email): self { $this->email = $email; @@ -1013,25 +813,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of phone - * - * @return ?string - */ public function getPhone(): ?string { return $this->phone; } - - /** - * Set the value of phone - * - * @param string $phone - * - * @return self - */ public function setPhone(?string $phone): self { $this->phone = $phone; @@ -1039,25 +825,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of isAdmin - * - * @return ?bool - */ public function getIsAdmin(): ?bool { return $this->isAdmin; } - - /** - * Set the value of isAdmin - * - * @param boolean $isAdmin - * - * @return self - */ public function setIsAdmin(?bool $isAdmin): self { $this->isAdmin = $isAdmin; @@ -1065,25 +837,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of language - * - * @return ?LanguagesEnum - */ public function getLanguage(): ?LanguagesEnum { return $this->language; } - - /** - * Set the value of language - * - * @param null|string|LanguagesEnum $language - * - * @return self - */ public function setLanguage(null|string|LanguagesEnum $language): self { if (is_string($language) === true) { @@ -1095,25 +853,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of timezone - * - * @return ?string - */ public function getTimezone(): ?string { return $this->timezone; } - - /** - * Set the value of timezone - * - * @param string $timezone - * - * @return self - */ public function setTimezone(?string $timezone): self { $this->timezone = $timezone; @@ -1121,25 +865,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of blockSize - * - * @return ?int - */ public function getBlockSize(): ?int { return $this->blockSize; } - - /** - * Set the value of blockSize - * - * @param integer $blockSize - * - * @return self - */ public function setBlockSize(?int $blockSize): self { $this->blockSize = $blockSize; @@ -1147,25 +877,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of idSkin - * - * @return ?int - */ public function getIdSkin(): ?int { return $this->idSkin; } - - /** - * Set the value of idSkin - * - * @param integer $idSkin - * - * @return self - */ public function setIdSkin(?int $idSkin): self { $this->idSkin = $idSkin; @@ -1173,25 +889,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of disabled - * - * @return ?bool - */ public function getDisabled(): ?bool { return $this->disabled; } - - /** - * Set the value of disabled - * - * @param boolean $disabled - * - * @return self - */ public function setDisabled(?bool $disabled): self { $this->disabled = $disabled; @@ -1199,25 +901,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of shortcut - * - * @return ?int - */ public function getShortcut(): ?int { return $this->shortcut; } - - /** - * Set the value of shortcut - * - * @param integer $shortcut - * - * @return self - */ public function setShortcut(?int $shortcut): self { $this->shortcut = $shortcut; @@ -1225,25 +913,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of shortcutData - * - * @return ?string - */ public function getShortcutData(): ?string { return $this->shortcutData; } - - /** - * Set the value of shortcutData - * - * @param string $shortcutData - * - * @return self - */ public function setShortcutData(?string $shortcutData): self { $this->shortcutData = $shortcutData; @@ -1251,25 +925,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of section - * - * @return ?UserHomeScreenEnum - */ public function getSection(): ?UserHomeScreenEnum { return $this->section; } - - /** - * Set the value of section - * - * @param null|string|UserHomeScreenEnum $section - * - * @return self - */ public function setSection(null|string|UserHomeScreenEnum $section): self { if (is_string($section) === true) { @@ -1281,25 +941,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of dataSection - * - * @return ?string - */ public function getDataSection(): ?string { return $this->dataSection; } - - /** - * Set the value of dataSection - * - * @param string $dataSection - * - * @return self - */ public function setDataSection(?string $dataSection): self { $this->dataSection = $dataSection; @@ -1307,25 +953,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of metaconsoleSection - * - * @return ?UserHomeScreenEnum - */ public function getMetaconsoleSection(): ?UserHomeScreenEnum { return $this->metaconsoleSection; } - - /** - * Set the value of metaconsoleSection - * - * @param null|string|UserHomeScreenEnum $metaconsoleSection - * - * @return self - */ public function setMetaconsoleSection(null|string|UserHomeScreenEnum $metaconsoleSection): self { if (is_string($metaconsoleSection) === true) { @@ -1337,25 +969,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of metaconsoleDataSection - * - * @return ?string - */ public function getMetaconsoleDataSection(): ?string { return $this->metaconsoleDataSection; } - - /** - * Set the value of metaconsoleDataSection - * - * @param string $metaconsoleDataSection - * - * @return self - */ public function setMetaconsoleDataSection(?string $metaconsoleDataSection): self { $this->metaconsoleDataSection = $metaconsoleDataSection; @@ -1363,25 +981,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of forceChangePass - * - * @return ?bool - */ public function getForceChangePass(): ?bool { return $this->forceChangePass; } - - /** - * Set the value of forceChangePass - * - * @param boolean $forceChangePass - * - * @return self - */ public function setForceChangePass(?bool $forceChangePass): self { $this->forceChangePass = $forceChangePass; @@ -1389,25 +993,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of lastPassChange - * - * @return ?string - */ public function getLastPassChange(): ?string { return $this->lastPassChange; } - - /** - * Set the value of lastPassChange - * - * @param string $lastPassChange - * - * @return self - */ public function setLastPassChange(?string $lastPassChange): self { $this->lastPassChange = $lastPassChange; @@ -1415,25 +1005,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of lastFailedLogin - * - * @return ?string - */ public function getLastFailedLogin(): ?string { return $this->lastFailedLogin; } - - /** - * Set the value of lastFailedLogin - * - * @param string $lastFailedLogin - * - * @return self - */ public function setLastFailedLogin(?string $lastFailedLogin): self { $this->lastFailedLogin = $lastFailedLogin; @@ -1441,25 +1017,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of failedAttempt - * - * @return ?int - */ public function getFailedAttempt(): ?int { return $this->failedAttempt; } - - /** - * Set the value of failedAttempt - * - * @param integer $failedAttempt - * - * @return self - */ public function setFailedAttempt(?int $failedAttempt): self { $this->failedAttempt = $failedAttempt; @@ -1467,25 +1029,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of loginBlocked - * - * @return ?bool - */ public function getLoginBlocked(): ?bool { return $this->loginBlocked; } - - /** - * Set the value of loginBlocked - * - * @param boolean $loginBlocked - * - * @return self - */ public function setLoginBlocked(?bool $loginBlocked): self { $this->loginBlocked = $loginBlocked; @@ -1493,25 +1041,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of metaconsoleAccess - * - * @return ?UserMetaconsoleAccessEnum - */ public function getMetaconsoleAccess(): ?UserMetaconsoleAccessEnum { return $this->metaconsoleAccess; } - - /** - * Set the value of metaconsoleAccess - * - * @param null|string|UserMetaconsoleAccessEnum $metaconsoleAccess - * - * @return self - */ public function setMetaconsoleAccess(null|string|UserMetaconsoleAccessEnum $metaconsoleAccess): self { if (is_string($metaconsoleAccess) === true) { @@ -1525,25 +1059,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of notLogin - * - * @return ?bool - */ public function getNotLogin(): ?bool { return $this->notLogin; } - - /** - * Set the value of notLogin - * - * @param boolean $notLogin - * - * @return self - */ public function setNotLogin(?bool $notLogin): self { $this->notLogin = $notLogin; @@ -1551,25 +1071,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of localUser - * - * @return ?bool - */ public function getLocalUser(): ?bool { return $this->localUser; } - - /** - * Set the value of localUser - * - * @param boolean $localUser - * - * @return self - */ public function setLocalUser(?bool $localUser): self { $this->localUser = $localUser; @@ -1577,25 +1083,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of metaconsoleAgentsManager - * - * @return ?int - */ public function getMetaconsoleAgentsManager(): ?int { return $this->metaconsoleAgentsManager; } - - /** - * Set the value of metaconsoleAgentsManager - * - * @param integer $metaconsoleAgentsManager - * - * @return self - */ public function setMetaconsoleAgentsManager(?int $metaconsoleAgentsManager): self { $this->metaconsoleAgentsManager = $metaconsoleAgentsManager; @@ -1603,25 +1095,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of metaconsoleAccessNode - * - * @return ?int - */ public function getMetaconsoleAccessNode(): ?int { return $this->metaconsoleAccessNode; } - - /** - * Set the value of metaconsoleAccessNode - * - * @param integer $metaconsoleAccessNode - * - * @return self - */ public function setMetaconsoleAccessNode(?int $metaconsoleAccessNode): self { $this->metaconsoleAccessNode = $metaconsoleAccessNode; @@ -1629,25 +1107,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of strictAcl - * - * @return ?bool - */ public function getStrictAcl(): ?bool { return $this->strictAcl; } - - /** - * Set the value of strictAcl - * - * @param boolean $strictAcl - * - * @return self - */ public function setStrictAcl(?bool $strictAcl): self { $this->strictAcl = $strictAcl; @@ -1655,25 +1119,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of idFilter - * - * @return ?int - */ public function getIdFilter(): ?int { return $this->idFilter; } - - /** - * Set the value of idFilter - * - * @param integer $idFilter - * - * @return self - */ public function setIdFilter(?int $idFilter): self { $this->idFilter = $idFilter; @@ -1681,25 +1131,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of sessionTime - * - * @return ?int - */ public function getSessionTime(): ?int { return $this->sessionTime; } - - /** - * Set the value of sessionTime - * - * @param integer $sessionTime - * - * @return self - */ public function setSessionTime(?int $sessionTime): self { $this->sessionTime = $sessionTime; @@ -1707,25 +1143,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of defaultEventFilter - * - * @return ?int - */ public function getDefaultEventFilter(): ?int { return $this->defaultEventFilter; } - - /** - * Set the value of defaultEventFilter - * - * @param integer $defaultEventFilter - * - * @return self - */ public function setDefaultEventFilter(?int $defaultEventFilter): self { $this->defaultEventFilter = $defaultEventFilter; @@ -1733,25 +1155,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of metaconsoleDefaultEventFilter - * - * @return ?int - */ public function getMetaconsoleDefaultEventFilter(): ?int { return $this->metaconsoleDefaultEventFilter; } - - /** - * Set the value of metaconsoleDefaultEventFilter - * - * @param integer $metaconsoleDefaultEventFilter - * - * @return self - */ public function setMetaconsoleDefaultEventFilter(?int $metaconsoleDefaultEventFilter): self { $this->metaconsoleDefaultEventFilter = $metaconsoleDefaultEventFilter; @@ -1759,25 +1167,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of showTipsStartup - * - * @return ?bool - */ public function getShowTipsStartup(): ?bool { return $this->showTipsStartup; } - - /** - * Set the value of showTipsStartup - * - * @param boolean $showTipsStartup - * - * @return self - */ public function setShowTipsStartup(?bool $showTipsStartup): self { $this->showTipsStartup = $showTipsStartup; @@ -1785,25 +1179,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of autorefreshWhiteList - * - * @return ?array - */ public function getAutorefreshWhiteList(): ?array { return $this->autorefreshWhiteList; } - - /** - * Set the value of autorefreshWhiteList - * - * @param array|string|null $autorefreshWhiteList - * - * @return self - */ public function setAutorefreshWhiteList(array|string|null $autorefreshWhiteList): self { if (is_string($autorefreshWhiteList) === true) { @@ -1817,25 +1197,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of timeAutorefresh - * - * @return ?int - */ public function getTimeAutorefresh(): ?int { return $this->timeAutorefresh; } - - /** - * Set the value of timeAutorefresh - * - * @param integer $timeAutorefresh - * - * @return self - */ public function setTimeAutorefresh(?int $timeAutorefresh): self { $this->timeAutorefresh = $timeAutorefresh; @@ -1843,25 +1209,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of defaultCustomView - * - * @return ?int - */ public function getDefaultCustomView(): ?int { return $this->defaultCustomView; } - - /** - * Set the value of defaultCustomView - * - * @param integer $defaultCustomView - * - * @return self - */ public function setDefaultCustomView(?int $defaultCustomView): self { $this->defaultCustomView = $defaultCustomView; @@ -1869,25 +1221,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of ehorusUserLevelUser - * - * @return ?string - */ public function getEhorusUserLevelUser(): ?string { return $this->ehorusUserLevelUser; } - - /** - * Set the value of ehorusUserLevelUser - * - * @param string $ehorusUserLevelUser - * - * @return self - */ public function setEhorusUserLevelUser(?string $ehorusUserLevelUser): self { $this->ehorusUserLevelUser = $ehorusUserLevelUser; @@ -1895,25 +1233,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of ehorusUserLevelPass - * - * @return ?string - */ public function getEhorusUserLevelPass(): ?string { return $this->ehorusUserLevelPass; } - - /** - * Set the value of ehorusUserLevelPass - * - * @param string $ehorusUserLevelPass - * - * @return self - */ public function setEhorusUserLevelPass(?string $ehorusUserLevelPass): self { $this->ehorusUserLevelPass = $ehorusUserLevelPass; @@ -1921,25 +1245,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of ehorusUserLevelEnabled - * - * @return ?bool - */ public function getEhorusUserLevelEnabled(): ?bool { return $this->ehorusUserLevelEnabled; } - - /** - * Set the value of ehorusUserLevelEnabled - * - * @param boolean $ehorusUserLevelEnabled - * - * @return self - */ public function setEhorusUserLevelEnabled(?bool $ehorusUserLevelEnabled): self { $this->ehorusUserLevelEnabled = $ehorusUserLevelEnabled; @@ -1947,25 +1257,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of itsmUserLevelUser - * - * @return ?string - */ public function getItsmUserLevelUser(): ?string { return $this->itsmUserLevelUser; } - - /** - * Set the value of itsmUserLevelUser - * - * @param string $itsmUserLevelUser - * - * @return self - */ public function setItsmUserLevelUser(?string $itsmUserLevelUser): self { $this->itsmUserLevelUser = $itsmUserLevelUser; @@ -1973,25 +1269,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of itsmUserLevelPass - * - * @return ?string - */ public function getItsmUserLevelPass(): ?string { return $this->itsmUserLevelPass; } - - /** - * Set the value of itsmUserLevelPass - * - * @param string $itsmUserLevelPass - * - * @return self - */ public function setItsmUserLevelPass(?string $itsmUserLevelPass): self { $this->itsmUserLevelPass = $itsmUserLevelPass; @@ -1999,25 +1281,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of apiToken - * - * @return ?string - */ public function getApiToken(): ?string { return $this->apiToken; } - - /** - * Set the value of apiToken - * - * @param string $apiToken - * - * @return self - */ public function setApiToken(?string $apiToken): self { $this->apiToken = $apiToken; @@ -2025,25 +1293,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of allowedIpActive - * - * @return ?bool - */ public function getAllowedIpActive(): ?bool { return $this->allowedIpActive; } - - /** - * Set the value of allowedIpActive - * - * @param boolean $allowedIpActive - * - * @return self - */ public function setAllowedIpActive(?bool $allowedIpActive): self { $this->allowedIpActive = $allowedIpActive; @@ -2051,25 +1305,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of allowedIpList - * - * @return ?string - */ public function getAllowedIpList(): ?string { return $this->allowedIpList; } - - /** - * Set the value of allowedIpList - * - * @param string $allowedIpList - * - * @return self - */ public function setAllowedIpList(?string $allowedIpList): self { $this->allowedIpList = $allowedIpList; @@ -2077,25 +1317,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of authTokenSecret - * - * @return ?string - */ public function getAuthTokenSecret(): ?string { return $this->authTokenSecret; } - - /** - * Set the value of authTokenSecret - * - * @param string $authTokenSecret - * - * @return self - */ public function setAuthTokenSecret(?string $authTokenSecret): self { $this->authTokenSecret = $authTokenSecret; @@ -2103,25 +1329,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of sessionMaxTimeExpire - * - * @return ?string - */ public function getSessionMaxTimeExpire(): ?string { return $this->sessionMaxTimeExpire; } - - /** - * Set the value of sessionMaxTimeExpire - * - * @param string $sessionMaxTimeExpire - * - * @return self - */ public function setSessionMaxTimeExpire(?string $sessionMaxTimeExpire): self { $this->sessionMaxTimeExpire = $sessionMaxTimeExpire; @@ -2129,25 +1341,11 @@ final class User extends Entity return $this; } - - /** - * Get the value of passwordValidate - * - * @return ?string - */ public function getPasswordValidate(): ?string { return $this->passwordValidate; } - - /** - * Set the value of passwordValidate - * - * @param string $passwordValidate - * - * @return self - */ public function setPasswordValidate(?string $passwordValidate): self { $this->passwordValidate = $passwordValidate; @@ -2155,31 +1353,15 @@ final class User extends Entity return $this; } - - /** - * Get the value of oldPassword - * - * @return ?string - */ public function getOldPassword(): ?string { return $this->oldPassword; } - - /** - * Set the value of oldPassword - * - * @param string $oldPassword - * - * @return self - */ public function setOldPassword(?string $oldPassword): self { $this->oldPassword = $oldPassword; return $this; } - - } diff --git a/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php b/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php index 89474a5161..b7a7eaa806 100644 --- a/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php +++ b/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php @@ -145,12 +145,11 @@ final class UserDataMapper extends DataMapperAbstract ); } - + /** + * @param User $data + */ public function toDatabase(MappeableInterface $data): array { - /* - @var User $data - */ return [ self::ID_USER => $data->getIdUser(), self::FULLNAME => $this->repository->safeInput($data->getFullName()), diff --git a/pandora_console/include/lib/Modules/Users/Entities/UserFilter.php b/pandora_console/include/lib/Modules/Users/Entities/UserFilter.php index 9b118bdeb2..eb3b5ca3b7 100644 --- a/pandora_console/include/lib/Modules/Users/Entities/UserFilter.php +++ b/pandora_console/include/lib/Modules/Users/Entities/UserFilter.php @@ -41,12 +41,9 @@ use PandoraFMS\Modules\Users\Validators\UserValidator; */ final class UserFilter extends FilterAbstract { - private ?string $freeSearch = null; - private ?array $multipleSearchString = null; - public function __construct() { $this->setDefaultFieldOrder(UserDataMapper::ID_USER); @@ -54,7 +51,6 @@ final class UserFilter extends FilterAbstract $this->setEntityFilter(new User()); } - public function fieldsTranslate(): array { return [ @@ -63,13 +59,11 @@ final class UserFilter extends FilterAbstract ]; } - public function fieldsReadOnly(): array { return []; } - public function jsonSerialize(): mixed { return [ @@ -77,7 +71,6 @@ final class UserFilter extends FilterAbstract ]; } - public function getValidations(): array { $validations = []; @@ -89,13 +82,11 @@ final class UserFilter extends FilterAbstract return $validations; } - public function validateFields(array $filters): array { return (new UserValidator())->validate($filters); } - /** * Get the value of freeSearch. * @@ -106,11 +97,10 @@ final class UserFilter extends FilterAbstract return $this->freeSearch; } - /** * Set the value of freeSearch. * - * @param string $freeSearch + * @param ?string $freeSearch */ public function setFreeSearch(?string $freeSearch): self { @@ -118,7 +108,6 @@ final class UserFilter extends FilterAbstract return $this; } - /** * Get the value of fieldsFreeSearch. * @@ -132,7 +121,6 @@ final class UserFilter extends FilterAbstract ]; } - /** * Get the value of multipleSearchString. * @@ -143,17 +131,14 @@ final class UserFilter extends FilterAbstract return $this->multipleSearchString; } - /** * Set the value of multipleSearchString. * - * @param array $multipleSearchString + * @param ?array $multipleSearchString */ public function setMultipleSearchString(?array $multipleSearchString): self { $this->multipleSearchString = $multipleSearchString; return $this; } - - } diff --git a/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php b/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php index 6048e12ef9..a495b61ab1 100644 --- a/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php +++ b/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php @@ -8,19 +8,19 @@ enum UserAutoRefreshPagesEnum: string { use EnumTrait; -case AGENT_DETAIL = 'operation/agentes/estado_agente'; -case ALERT_DETAIL = 'operation/agentes/alerts_status'; -case CLUSTER_VIEW = 'enterprise/operation/cluster/cluster'; -case GIS_MAP = 'operation/gis_maps/render_view'; -case GRAPH_VIEWER = 'operation/reporting/graph_viewer'; -case SNMP_CONSOLE = 'operation/snmpconsole/snmp_view'; -case SAP_VIEW = 'general/sap_view'; -case TACTICAL_VIEW = 'operation/agentes/tactical'; -case GROUP_VIEW = 'operation/agentes/group_view'; -case MONITOR_DETAIL = 'operation/agentes/status_monitor'; -case SERVICES = 'enterprise/operation/services/services'; -case DASHBOARD = 'operation/dashboard/dashboard'; -case VISUAL_CONSOLE = 'operation/visual_console/render_view'; -case EVENTS = 'operation/events/events'; + case AGENT_DETAIL = 'operation/agentes/estado_agente'; + case ALERT_DETAIL = 'operation/agentes/alerts_status'; + case CLUSTER_VIEW = 'enterprise/operation/cluster/cluster'; + case GIS_MAP = 'operation/gis_maps/render_view'; + case GRAPH_VIEWER = 'operation/reporting/graph_viewer'; + case SNMP_CONSOLE = 'operation/snmpconsole/snmp_view'; + case SAP_VIEW = 'general/sap_view'; + case TACTICAL_VIEW = 'operation/agentes/tactical'; + case GROUP_VIEW = 'operation/agentes/group_view'; + case MONITOR_DETAIL = 'operation/agentes/status_monitor'; + case SERVICES = 'enterprise/operation/services/services'; + case DASHBOARD = 'operation/dashboard/dashboard'; + case VISUAL_CONSOLE = 'operation/visual_console/render_view'; + case EVENTS = 'operation/events/events'; - } +} diff --git a/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php b/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php index c9c93dbae8..6080247bc9 100644 --- a/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php +++ b/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php @@ -8,14 +8,14 @@ enum UserHomeScreenEnum: string { use EnumTrait; - case default = 'default'; -case VISUAL_CONSOLE = 'visual_console'; -case EVENT_LIST = 'event_list'; -case GROUP_VIEW = 'group_view'; -case TACTICAL_VIEW = 'tactical_view'; -case ALERT_DETAIL = 'alert_detail'; -case EXTERNAL_LINK = 'external_link'; -case OTHER = 'other'; -case DASHBOARD = 'dashboard'; + case DEFAULT = 'default'; + case VISUAL_CONSOLE = 'visual_console'; + case EVENT_LIST = 'event_list'; + case GROUP_VIEW = 'group_view'; + case TACTICAL_VIEW = 'tactical_view'; + case ALERT_DETAIL = 'alert_detail'; + case EXTERNAL_LINK = 'external_link'; + case OTHER = 'other'; + case DASHBOARD = 'dashboard'; - } +} diff --git a/pandora_console/include/lib/Modules/Users/Enums/UserMetaconsoleAccessEnum.php b/pandora_console/include/lib/Modules/Users/Enums/UserMetaconsoleAccessEnum.php index 26566f9360..c261f9c945 100644 --- a/pandora_console/include/lib/Modules/Users/Enums/UserMetaconsoleAccessEnum.php +++ b/pandora_console/include/lib/Modules/Users/Enums/UserMetaconsoleAccessEnum.php @@ -8,6 +8,6 @@ enum UserMetaconsoleAccessEnum: string { use EnumTrait; -case BASIC = 'basic'; -case ADVANCED = 'advanced'; - } + case BASIC = 'basic'; + case ADVANCED = 'advanced'; +} diff --git a/pandora_console/include/lib/Modules/Users/Repositories/UserRepository.php b/pandora_console/include/lib/Modules/Users/Repositories/UserRepository.php index 01af529535..c4a3b39c60 100644 --- a/pandora_console/include/lib/Modules/Users/Repositories/UserRepository.php +++ b/pandora_console/include/lib/Modules/Users/Repositories/UserRepository.php @@ -7,27 +7,18 @@ use PandoraFMS\Modules\Users\Entities\UserFilter; interface UserRepository { - - /** * @return User[], */ public function list(UserFilter $userFilter): array; - public function count(UserFilter $userFilter): int; - public function getOne(UserFilter $userFilter): User; - public function create(User $user): User; - public function update(User $user): User; - public function delete(string $id): void; - - } diff --git a/pandora_console/include/lib/Modules/Users/Repositories/UserRepositoryMySQL.php b/pandora_console/include/lib/Modules/Users/Repositories/UserRepositoryMySQL.php index f7c08e76b6..9e8993dc45 100644 --- a/pandora_console/include/lib/Modules/Users/Repositories/UserRepositoryMySQL.php +++ b/pandora_console/include/lib/Modules/Users/Repositories/UserRepositoryMySQL.php @@ -2,28 +2,23 @@ namespace PandoraFMS\Modules\Users\Repositories; +use InvalidArgumentException; use PandoraFMS\Modules\Shared\Core\DataMapperAbstract; use PandoraFMS\Modules\Shared\Core\FilterAbstract; use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum; use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; use PandoraFMS\Modules\Shared\Repositories\RepositoryMySQL; -use PandoraFMS\Modules\Shared\Services\Config; use PandoraFMS\Modules\Users\Entities\User; use PandoraFMS\Modules\Users\Entities\UserDataMapper; use PandoraFMS\Modules\Users\Entities\UserFilter; -use PandoraFMS\Modules\Users\Enums\UserLevelEnum; -use InvalidArgumentException; class UserRepositoryMySQL extends RepositoryMySQL implements UserRepository { - - public function __construct( private UserDataMapper $userDataMapper ) { } - /** * @return User[], */ @@ -52,7 +47,6 @@ class UserRepositoryMySQL extends RepositoryMySQL implements UserRepository return $result; } - public function count(UserFilter $userFilter): int { $sql = $this->getUsersQuery($userFilter, $this->userDataMapper, true); @@ -69,7 +63,6 @@ class UserRepositoryMySQL extends RepositoryMySQL implements UserRepository return (int) $count; } - public function getOne(UserFilter $userFilter): User { try { @@ -90,14 +83,12 @@ class UserRepositoryMySQL extends RepositoryMySQL implements UserRepository return $this->userDataMapper->fromDatabase($result); } - public function create(User $user): User { $this->__create($user, $this->userDataMapper); return $user; } - public function update(User $user): User { return $this->__update( @@ -107,17 +98,15 @@ class UserRepositoryMySQL extends RepositoryMySQL implements UserRepository ); } - public function delete(string $id): void { $this->__delete($id, $this->userDataMapper); } - private function getUsersQuery( FilterAbstract $filter, DataMapperAbstract $mapper, - bool $count=false + bool $count = false ): string { $pagination = ''; $orderBy = ''; @@ -159,6 +148,4 @@ class UserRepositoryMySQL extends RepositoryMySQL implements UserRepository return $sql; } - - } diff --git a/pandora_console/include/lib/Modules/Users/Services/CheckOldPasswordUserService.php b/pandora_console/include/lib/Modules/Users/Services/CheckOldPasswordUserService.php index 04cf4e6ed8..969642d247 100644 --- a/pandora_console/include/lib/Modules/Users/Services/CheckOldPasswordUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/CheckOldPasswordUserService.php @@ -20,8 +20,13 @@ final class CheckOldPasswordUserService public function __invoke(User $user): void { $userFilter = new UserFilter(); - $userFilter->setIdUser($user->getIdUser()); - $userFilter->setPassword($user->getOldPassword()); + /** + @var User $entityFilter + */ + $entityFilter = $userFilter->getEntityFilter(); + $entityFilter->setIdUser($user->getIdUser()); + $entityFilter->setPassword($user->getOldPassword()); + try { $this->repository->__getOne( $userFilter, diff --git a/pandora_console/include/lib/Modules/Users/Services/CountUserService.php b/pandora_console/include/lib/Modules/Users/Services/CountUserService.php index b68a376a42..bdb156e663 100644 --- a/pandora_console/include/lib/Modules/Users/Services/CountUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/CountUserService.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\Repositories\UserRepository; final class CountUserService { - - public function __construct( private UserRepository $userRepository, ) { } - public function __invoke(UserFilter $userFilter): int { return $this->userRepository->count($userFilter); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Services/CreateUserService.php b/pandora_console/include/lib/Modules/Users/Services/CreateUserService.php index 612fabf9cb..73b898ba56 100644 --- a/pandora_console/include/lib/Modules/Users/Services/CreateUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/CreateUserService.php @@ -2,15 +2,13 @@ namespace PandoraFMS\Modules\Users\Services; +use PandoraFMS\Modules\Shared\Services\Audit; use PandoraFMS\Modules\Users\Entities\User; use PandoraFMS\Modules\Users\Repositories\UserRepository; use PandoraFMS\Modules\Users\Validations\UserValidation; -use PandoraFMS\Modules\Shared\Services\Audit; final class CreateUserService { - - public function __construct( private Audit $audit, private UserRepository $userRepository, @@ -18,7 +16,6 @@ final class CreateUserService ) { } - public function __invoke(User $user): User { $this->userValidation->__invoke($user); @@ -36,6 +33,4 @@ final class CreateUserService return $user; } - - } diff --git a/pandora_console/include/lib/Modules/Users/Services/DeleteUserService.php b/pandora_console/include/lib/Modules/Users/Services/DeleteUserService.php index c804cc66ca..83f190b680 100644 --- a/pandora_console/include/lib/Modules/Users/Services/DeleteUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/DeleteUserService.php @@ -2,22 +2,19 @@ namespace PandoraFMS\Modules\Users\Services; -use PandoraFMS\Modules\Users\Entities\User; -use PandoraFMS\Modules\Users\Repositories\UserRepository; - use PandoraFMS\Modules\Shared\Services\Audit; +use PandoraFMS\Modules\Users\Entities\User; + +use PandoraFMS\Modules\Users\Repositories\UserRepository; final class DeleteUserService { - - public function __construct( private Audit $audit, private UserRepository $userRepository, ) { } - public function __invoke(User $user): void { $idUser = $user->getIdUser(); @@ -29,6 +26,4 @@ final class DeleteUserService ' Deleted user #'.$idUser ); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Services/GetUserService.php b/pandora_console/include/lib/Modules/Users/Services/GetUserService.php index c8fea38dc8..0725760615 100644 --- a/pandora_console/include/lib/Modules/Users/Services/GetUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/GetUserService.php @@ -5,23 +5,19 @@ namespace PandoraFMS\Modules\Users\Services; use PandoraFMS\Modules\Users\Entities\User; use PandoraFMS\Modules\Users\Entities\UserFilter; use PandoraFMS\Modules\Users\Repositories\UserRepository; -use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfileDataMapper; final class GetUserService { - - public function __construct( private UserRepository $userRepository, ) { } - public function __invoke(string $idUser): User { $userFilter = new UserFilter(); - /* + /** @var User $entityFilter */ $entityFilter = $userFilter->getEntityFilter(); @@ -29,6 +25,4 @@ final class GetUserService return $this->userRepository->getOne($userFilter); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Services/ListUserService.php b/pandora_console/include/lib/Modules/Users/Services/ListUserService.php index 89e02523b5..014a046f28 100644 --- a/pandora_console/include/lib/Modules/Users/Services/ListUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/ListUserService.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\Repositories\UserRepository; final class ListUserService { - - public function __construct( private UserRepository $userRepository, ) { } - public function __invoke(UserFilter $userFilter): array { return $this->userRepository->list($userFilter); } - - } diff --git a/pandora_console/include/lib/Modules/Users/Services/UpdateUserService.php b/pandora_console/include/lib/Modules/Users/Services/UpdateUserService.php index a4878aca8e..b1fcae7c51 100644 --- a/pandora_console/include/lib/Modules/Users/Services/UpdateUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/UpdateUserService.php @@ -9,8 +9,6 @@ use PandoraFMS\Modules\Users\Validations\UserValidation; final class UpdateUserService { - - public function __construct( private Audit $audit, private UserRepository $userRepository, @@ -18,7 +16,6 @@ final class UpdateUserService ) { } - public function __invoke(User $user, User $oldUser): User { $this->userValidation->__invoke($user, $oldUser); @@ -38,6 +35,4 @@ final class UpdateUserService return $user; } - - } diff --git a/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php b/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php index dd4f4a2896..274830786c 100644 --- a/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php @@ -8,14 +8,11 @@ use PandoraFMS\Modules\Users\Entities\User; final class ValidatePasswordUserService { - - public function __construct( private Config $config, ) { } - public function __invoke(User $user, ?User $oldUser): void { // Excluyes palabras. @@ -69,7 +66,6 @@ final class ValidatePasswordUserService } } - private function checkExcludePassword(string $newPassword): bool { if ((bool) $this->config->get('enable_pass_policy') === true @@ -88,7 +84,6 @@ final class ValidatePasswordUserService return false; } - private function getOldPasswords(string $idUser): array { // TODO: create new service for this. @@ -109,6 +104,4 @@ final class ValidatePasswordUserService return $oldPasswords; } - - } diff --git a/pandora_console/include/lib/Modules/Users/Validations/UserValidation.php b/pandora_console/include/lib/Modules/Users/Validations/UserValidation.php index c3da7bd851..3b2cf4d642 100644 --- a/pandora_console/include/lib/Modules/Users/Validations/UserValidation.php +++ b/pandora_console/include/lib/Modules/Users/Validations/UserValidation.php @@ -2,6 +2,7 @@ namespace PandoraFMS\Modules\Users\Validations; +use Models\VisualConsole\Container as VisualConsole; use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; use PandoraFMS\Modules\Shared\Exceptions\ForbiddenACLException; use PandoraFMS\Modules\Shared\Exceptions\NotFoundException; @@ -11,14 +12,10 @@ use PandoraFMS\Modules\Users\Entities\User; use PandoraFMS\Modules\Users\Enums\UserHomeScreenEnum; use PandoraFMS\Modules\Users\Services\CheckOldPasswordUserService; use PandoraFMS\Modules\Users\Services\GetUserService; - -use Models\VisualConsole\Container as VisualConsole; use PandoraFMS\Modules\Users\Services\ValidatePasswordUserService; final class UserValidation { - - public function __construct( private Config $config, private Timestamp $timestamp, @@ -28,8 +25,7 @@ final class UserValidation ) { } - - public function __invoke(User $user, ?User $oldUser=null): void + public function __invoke(User $user, ?User $oldUser = null): void { $isAdmin = $this->isAdmin($this->config->get('id_user')); $this->validateIdUser($user); @@ -260,19 +256,16 @@ final class UserValidation } } - private function getCurrentTimestamp(): string { return $this->timestamp->getMysqlCurrentTimestamp(0); } - private function getCurrentUtimestamp(): int { return $this->timestamp->getMysqlSystemUtimestamp(); } - private function existsUser(string $idUser): void { $exist = true; @@ -287,7 +280,6 @@ final class UserValidation } } - private function validateIdUser(User $user): void { if ($user->getIdUser() === false) { @@ -302,21 +294,18 @@ final class UserValidation } } - private function generateApiToken(): string { // TODO: create new service for this. return \api_token_generate(); } - private function isAdmin(string $idUser): bool { // TODO: create new service for this. return \users_is_admin($idUser); } - protected function validateSkin(int $idSkin): void { // TODO: create new service for this. @@ -325,7 +314,6 @@ final class UserValidation } } - protected function validateEventFilter(int $idFilter): void { // TODO: create new service for this. @@ -334,7 +322,6 @@ final class UserValidation } } - protected function validateCustomView(int $idView): void { // TODO: create new service for this. @@ -343,7 +330,6 @@ final class UserValidation } } - protected function validateDashboard(string $idUser, int $idDashboard): void { // TODO: create new service for this. @@ -352,7 +338,6 @@ final class UserValidation } } - protected function validateVisualConsole(int $visualConsoleId): void { // TODO: create new service for this. @@ -362,6 +347,4 @@ final class UserValidation throw new BadRequestException(__('Invalid visual console id')); } } - - } diff --git a/pandora_console/include/lib/Modules/Users/Validators/UserValidator.php b/pandora_console/include/lib/Modules/Users/Validators/UserValidator.php index c9634ee9e5..1a7e4cbab3 100644 --- a/pandora_console/include/lib/Modules/Users/Validators/UserValidator.php +++ b/pandora_console/include/lib/Modules/Users/Validators/UserValidator.php @@ -11,21 +11,15 @@ class UserValidator extends Validator public const VALIDSECTION = 'ValidSection'; public const VALIDMETACONSOLEACCESS = 'ValidMetaconsoleAccess'; - protected function isValidSection($section): bool { $result = UserHomeScreenEnum::get(strtoupper($section)); - return empty($result) === true ? false : true; } - protected function isValidMetaconsoleAccess($metaconsoleAccess): bool { $result = UserMetaconsoleAccessEnum::get(strtoupper($metaconsoleAccess)); - return empty($result) === true ? false : true; } - - }