diff --git a/pandora_console/api/v1/config/routes.php b/pandora_console/api/v1/config/routes.php index bd525ca076..69759fd906 100644 --- a/pandora_console/api/v1/config/routes.php +++ b/pandora_console/api/v1/config/routes.php @@ -4,4 +4,5 @@ use Slim\App; return function (App $app) { (include __DIR__.'/../../../include/lib/Modules/Users/routes.php')($app); + (include __DIR__.'/../../../include/lib/Modules/Profiles/routes.php')($app); }; diff --git a/pandora_console/api/v1/public/swagger.json b/pandora_console/api/v1/public/swagger.json index bd9607e8be..2594af80a0 100644 --- a/pandora_console/api/v1/public/swagger.json +++ b/pandora_console/api/v1/public/swagger.json @@ -22,6 +22,218 @@ } ], "paths": { + "/profile": { + "post": { + "tags": ["Profiles"], + "summary": "Creates a new profiles", + "operationId": "09c50bd77afb2856ee6625af0ee9c716", + "requestBody": { + "$ref": "#/components/requestBodies/requestBodyProfile" + }, + "responses": { + "200": { + "$ref": "#/components/responses/ResponseProfile" + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } + }, + "/profile/{idProfile}": { + "get": { + "tags": ["Profiles"], + "summary": "Show profile", + "operationId": "e66704aa8cb757e23de04ce65c7bf028", + "parameters": [ + { + "$ref": "#/components/parameters/parameterIdProfile" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/ResponseProfile" + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + }, + "put": { + "tags": ["Profiles"], + "summary": "Updates an profile", + "operationId": "723fc236ab3b6069b7dcca9e317c953f", + "parameters": [ + { + "$ref": "#/components/parameters/parameterIdProfile" + } + ], + "requestBody": { + "$ref": "#/components/requestBodies/requestBodyProfile" + }, + "responses": { + "200": { + "$ref": "#/components/responses/ResponseProfile" + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + }, + "delete": { + "tags": ["Profiles"], + "summary": "Deletes an profile object.", + "operationId": "ca8ec2d296930aac798229f83e93bff8", + "parameters": [ + { + "$ref": "#/components/parameters/parameterIdProfile" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/successfullyDeleted" + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } + }, + "/profile/list": { + "post": { + "tags": ["Profiles"], + "summary": "List profiles", + "operationId": "875c11ea1ec723d55e2f582ed198db7a", + "parameters": [ + { + "$ref": "#/components/parameters/parameterPage" + }, + { + "$ref": "#/components/parameters/parameterSizePage" + }, + { + "$ref": "#/components/parameters/parameterSortField" + }, + { + "$ref": "#/components/parameters/parameterSortDirection" + } + ], + "requestBody": { + "$ref": "#/components/requestBodies/requestBodyProfileFilter" + }, + "responses": { + "200": { + "description": "List Incidence object", + "content": { + "application/json": { + "schema": { + "properties": { + "paginationData": { + "$ref": "#/components/schemas/paginationData" + }, + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Profile" + } + } + }, + "type": "object" + } + } + } + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalServerError" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } + }, "/user": { "post": { "tags": ["Users"], @@ -57,11 +269,11 @@ ] } }, - "/user/{id}": { + "/user/{idUser}": { "get": { "tags": ["Users"], "summary": "show users", - "operationId": "8ebeb7e21b56d63f15d9b6341311a43d", + "operationId": "aca8667503b4f47013622baeea8ecee3", "parameters": [ { "$ref": "#/components/parameters/parameterIdUser" @@ -96,7 +308,7 @@ "put": { "tags": ["Users"], "summary": "Updates an user", - "operationId": "0d9890b106c7c16338fc9f5ff38a9401", + "operationId": "0a1f3fa99cb711d2ed1f47897d0e05f7", "parameters": [ { "$ref": "#/components/parameters/parameterIdUser" @@ -134,7 +346,7 @@ "delete": { "tags": ["Users"], "summary": "Deletes an user object.", - "operationId": "37abf8ed09f93f7739259528c626cc67", + "operationId": "ac81c40c168ebda19372ceb213a4d422", "parameters": [ { "$ref": "#/components/parameters/parameterIdUser" @@ -234,17 +446,17 @@ ] } }, - "/user/{id}/profile/{idProfile}": { + "/user/{idUser}/profile/{idProfile}": { "get": { "tags": ["Users"], "summary": "show data field user profile", - "operationId": "fd19fade240728e3d8e152c6d76e63f7", + "operationId": "6aacb61062bd1ec04b91907273e2dd8f", "parameters": [ { "$ref": "#/components/parameters/parameterIdUser" }, { - "$ref": "#/components/parameters/parameterProfileId" + "$ref": "#/components/parameters/parameterIdProfile" } ], "responses": { @@ -276,13 +488,13 @@ "post": { "tags": ["Users"], "summary": "Create user profile", - "operationId": "c30c48c85aed2f7e3e6c98f7785bd9ca", + "operationId": "9fe3300b6a0e031989b085cdba8def4d", "parameters": [ { "$ref": "#/components/parameters/parameterIdUser" }, { - "$ref": "#/components/parameters/parameterProfileId" + "$ref": "#/components/parameters/parameterIdProfile" } ], "requestBody": { @@ -317,13 +529,13 @@ "delete": { "tags": ["Users"], "summary": "Deletes user profile.", - "operationId": "63a42b4afbd435bee10bd41bbbb95ccc", + "operationId": "4fc44af32440fc1b9feff41f92c63972", "parameters": [ { "$ref": "#/components/parameters/parameterIdUser" }, { - "$ref": "#/components/parameters/parameterProfileId" + "$ref": "#/components/parameters/parameterIdProfile" } ], "responses": { @@ -353,11 +565,11 @@ ] } }, - "/user/{id}/profiles": { + "/user/{idUser}/profiles": { "post": { "tags": ["Users"], "summary": "List user profiles", - "operationId": "1b8d60018091acae41f25a754b028de0", + "operationId": "3952d52c24c4fd099e9c0d15c7104068", "parameters": [ { "$ref": "#/components/parameters/parameterIdUser" @@ -426,6 +638,184 @@ }, "components": { "schemas": { + "Profile": { + "properties": { + "idProfile": { + "description": "Id Incidence Type", + "type": "integer", + "readOnly": true, + "nullable": false + }, + "name": { + "description": "Name of the profile", + "type": "string", + "default": null, + "nullable": false + }, + "isAgentView": { + "description": "Agent Read", + "type": "boolean", + "default": false, + "nullable": true + }, + "isAgentEdit": { + "description": "Agent Write", + "type": "boolean", + "default": false, + "nullable": true + }, + "isAlertEdit": { + "description": "Alert write", + "type": "boolean", + "default": false, + "nullable": true + }, + "isUserManagement": { + "description": "User Management", + "type": "boolean", + "default": false, + "nullable": true + }, + "isDbManagement": { + "description": "Database Management", + "type": "boolean", + "default": false, + "nullable": true + }, + "isAlertManagement": { + "description": "Alert Management", + "type": "boolean", + "default": false, + "nullable": true + }, + "isPandoraManagement": { + "description": "Pandora Management", + "type": "boolean", + "default": false, + "nullable": true + }, + "isReportView": { + "description": "Report view", + "type": "boolean", + "default": false, + "nullable": true + }, + "isReportEdit": { + "description": "Report Edit", + "type": "boolean", + "default": false, + "nullable": true + }, + "isReportManagement": { + "description": "Report Management", + "type": "boolean", + "default": false, + "nullable": true + }, + "isEventView": { + "description": "Event Read", + "type": "boolean", + "default": false, + "nullable": true + }, + "isEventEdit": { + "description": "Event write", + "type": "boolean", + "default": false, + "nullable": true + }, + "isEventManagement": { + "description": "Event Management", + "type": "boolean", + "default": false, + "nullable": true + }, + "isAgentDisable": { + "description": "Agent Disable", + "type": "boolean", + "default": false, + "nullable": true + }, + "isMapView": { + "description": "Map Read", + "type": "boolean", + "default": false, + "nullable": true + }, + "isMapEdit": { + "description": "Map Write", + "type": "boolean", + "default": false, + "nullable": true + }, + "isMapManagement": { + "description": "Map Management", + "type": "boolean", + "default": false, + "nullable": true + }, + "isVconsoleView": { + "description": "Visual console Read", + "type": "boolean", + "default": false, + "nullable": true + }, + "isVconsoleEdit": { + "description": "Visual console Write", + "type": "boolean", + "default": false, + "nullable": true + }, + "isVconsoleManagement": { + "description": "Visual console Management", + "type": "boolean", + "default": false, + "nullable": true + }, + "isNetworkConfigView": { + "description": "Network config read", + "type": "boolean", + "default": false, + "nullable": true + }, + "isNetworkConfigEdit": { + "description": "Network config Write", + "type": "boolean", + "default": false, + "nullable": true + }, + "isNetworkConfigManagement": { + "description": "Network config Management", + "type": "boolean", + "default": false, + "nullable": true + } + }, + "type": "object" + }, + "ProfileFilter": { + "type": "object", + "allOf": [ + { + "$ref": "#/components/schemas/Profile" + }, + { + "properties": { + "idProfile": { + "default": null, + "readOnly": false + }, + "freeSearch": { + "description": "Find word in name field.", + "type": "string", + "default": null, + "nullable": true + } + }, + "type": "object" + } + ] + }, "paginationData": { "description": "Info pagination data", "properties": { @@ -886,12 +1276,40 @@ "type": "integer", "nullable": false }, + "isNoHierarchy": { + "description": "No hierarchy", + "type": "boolean", + "default": false, + "nullable": true + }, "assignedBy": { "description": "Create user profile by", "type": "string", "default": null, "readOnly": true, "nullable": false + }, + "idPolicy": { + "description": "Id Policy", + "type": "integer", + "nullable": false + }, + "tags": { + "description": "Tags to which a user belongs", + "type": "array", + "items": { + "properties": { + "idTags": { + "description": "Tags id", + "type": "integer", + "default": null, + "nullable": true + } + }, + "type": "object" + }, + "default": null, + "nullable": true } }, "type": "object" @@ -915,6 +1333,16 @@ } }, "responses": { + "ResponseProfile": { + "description": "Profile object", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Profile" + } + } + } + }, "BadRequest": { "description": "Bad request", "content": { @@ -1038,6 +1466,16 @@ } }, "parameters": { + "parameterIdProfile": { + "name": "idProfile", + "in": "path", + "description": "Profile id", + "required": true, + "schema": { + "type": "integer", + "default": 1 + } + }, "parameterPage": { "name": "page", "in": "query", @@ -1080,7 +1518,7 @@ } }, "parameterIdUser": { - "name": "id", + "name": "idUser", "in": "path", "description": "User id", "required": true, @@ -1089,10 +1527,10 @@ "default": "admin" } }, - "parameterProfileId": { - "name": "idProfile", + "parameterIdUserProfile": { + "name": "idUserProfile", "in": "path", - "description": "Profile id", + "description": "User profile id", "required": true, "schema": { "type": "integer", @@ -1101,6 +1539,26 @@ } }, "requestBodies": { + "requestBodyProfile": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Profile" + } + } + } + }, + "requestBodyProfileFilter": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProfileFilter" + } + } + } + }, "requestBodyUser": { "required": true, "content": { @@ -1156,12 +1614,20 @@ { "name": "Users", "description": "API Endpoints of users" + }, + { + "name": "Profiles", + "description": "API Endpoints of profiles" } ], "x-tagGroups": [ { "name": "Users", "tags": ["Users"] + }, + { + "name": "Profiles", + "tags": ["Profiles"] } ] } diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/CreateProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/CreateProfileAction.php new file mode 100644 index 0000000000..c0538da7fc --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Actions/CreateProfileAction.php @@ -0,0 +1,19 @@ +createProfileService->__invoke($profile); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/DeleteProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/DeleteProfileAction.php new file mode 100644 index 0000000000..719850a4ed --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Actions/DeleteProfileAction.php @@ -0,0 +1,19 @@ +deleteProfileService->__invoke($profile); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/GetProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/GetProfileAction.php new file mode 100644 index 0000000000..9af07f3686 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Actions/GetProfileAction.php @@ -0,0 +1,19 @@ +getProfileService->__invoke($idProfile); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/ListProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/ListProfileAction.php new file mode 100644 index 0000000000..cdaaa203a4 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Actions/ListProfileAction.php @@ -0,0 +1,28 @@ +getPage(), + $profileFilter->getSizePage(), + $this->countProfileService->__invoke($profileFilter), + $this->listProfileService->__invoke($profileFilter) + ))->toArray(); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Actions/UpdateProfileAction.php b/pandora_console/include/lib/Modules/Profiles/Actions/UpdateProfileAction.php new file mode 100644 index 0000000000..0e564d080e --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Actions/UpdateProfileAction.php @@ -0,0 +1,19 @@ +updateProfileService->__invoke($profile, $oldProfile); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php new file mode 100644 index 0000000000..3ee9289668 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php @@ -0,0 +1,47 @@ +fromRequest($request, Profile::class); + + $this->acl->validate(0, 'UM', ' tried to manage profile'); + + $result = $this->createProfileAction->__invoke($profile); + + return $this->getResponse($response, $result); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php new file mode 100644 index 0000000000..9961ac9b2d --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php @@ -0,0 +1,47 @@ +getParam($request, 'idProfile'); + $profile = $this->getProfileAction->__invoke($idProfile); + + $this->acl->validate(0, 'UM', ' tried to manage profile'); + + $result = $this->deleteProfileAction->__invoke($profile); + return $this->getResponse($response, $result); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/GetProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/GetProfileController.php new file mode 100644 index 0000000000..6db003271d --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/GetProfileController.php @@ -0,0 +1,44 @@ +getParam($request, 'idProfile'); + + $this->acl->validate(0, 'UM', ' tried to manage profile'); + + $result = $this->getProfileAction->__invoke($idProfile); + return $this->getResponse($response, $result); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/ListProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/ListProfileController.php new file mode 100644 index 0000000000..0e870b4c51 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/ListProfileController.php @@ -0,0 +1,74 @@ +fromRequest($request, ProfileFilter::class); + + $this->acl->validate(0, 'UM', ' tried to manage profile'); + + $result = $this->listProfileAction->__invoke($profileFilter); + return $this->getResponse($response, $result); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php new file mode 100644 index 0000000000..f92d5be8c6 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php @@ -0,0 +1,52 @@ +getParam($request, 'idProfile'); + $profile = $this->getProfileAction->__invoke($idProfile); + + $oldProfile = clone $profile; + $params = $this->extractParams($request); + $profile->fromArray($params); + + $this->acl->validate(0, 'UM', ' tried to manage profile'); + + $result = $this->updateProfileAction->__invoke($profile, $oldProfile); + return $this->getResponse($response, $result); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Entities/Profile.php b/pandora_console/include/lib/Modules/Profiles/Entities/Profile.php new file mode 100644 index 0000000000..465346cb7f --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Entities/Profile.php @@ -0,0 +1,581 @@ + 1]; + } + + public function jsonSerialize(): mixed + { + return [ + 'idProfile' => $this->getIdProfile(), + 'name' => $this->getName(), + 'isAgentView' => $this->getIsAgentView(), + 'isAgentEdit' => $this->getIsAgentEdit(), + 'isAlertEdit' => $this->getIsAlertEdit(), + 'isUserManagement' => $this->getIsUserManagement(), + 'isDbManagement' => $this->getIsDbManagement(), + 'isAlertManagement' => $this->getIsAlertManagement(), + 'isPandoraManagement' => $this->getIsPandoraManagement(), + 'isReportView' => $this->getIsReportView(), + 'isReportEdit' => $this->getIsReportEdit(), + 'isReportManagement' => $this->getIsReportManagement(), + 'isEventView' => $this->getIsEventView(), + 'isEventEdit' => $this->getIsEventEdit(), + 'isEventManagement' => $this->getIsEventManagement(), + 'isAgentDisable' => $this->getIsAgentDisable(), + 'isMapView' => $this->getIsMapView(), + 'isMapEdit' => $this->getIsMapEdit(), + 'isMapManagement' => $this->getIsMapManagement(), + 'isVconsoleView' => $this->getIsVconsoleView(), + 'isVconsoleEdit' => $this->getIsVconsoleEdit(), + 'isVconsoleManagement' => $this->getIsVconsoleManagement(), + 'isNetworkConfigView' => $this->getIsNetworkConfigView(), + 'isNetworkConfigEdit' => $this->getIsNetworkConfigEdit(), + 'isNetworkConfigManagement' => $this->getIsNetworkConfigManagement(), + ]; + } + + public function getValidations(): array + { + return [ + 'idProfile' => [ + Validator::INTEGER, + Validator::GREATERTHAN, + ], + 'name' => Validator::STRING, + 'isAgentView' => Validator::BOOLEAN, + 'isAgentEdit' => Validator::BOOLEAN, + 'isAlertEdit' => Validator::BOOLEAN, + 'isUserManagement' => Validator::BOOLEAN, + 'isDbManagement' => Validator::BOOLEAN, + 'isAlertManagement' => Validator::BOOLEAN, + 'isPandoraManagement' => Validator::BOOLEAN, + 'isReportView' => Validator::BOOLEAN, + 'isReportEdit' => Validator::BOOLEAN, + 'isReportManagement' => Validator::BOOLEAN, + 'isEventView' => Validator::BOOLEAN, + 'isEventEdit' => Validator::BOOLEAN, + 'isEventManagement' => Validator::BOOLEAN, + 'isAgentDisable' => Validator::BOOLEAN, + 'isMapView' => Validator::BOOLEAN, + 'isMapEdit' => Validator::BOOLEAN, + 'isMapManagement' => Validator::BOOLEAN, + 'isVconsoleView' => Validator::BOOLEAN, + 'isVconsoleEdit' => Validator::BOOLEAN, + 'isVconsoleManagement' => Validator::BOOLEAN, + 'isNetworkConfigView' => Validator::BOOLEAN, + 'isNetworkConfigEdit' => Validator::BOOLEAN, + 'isNetworkConfigManagement' => Validator::BOOLEAN, + ]; + } + + public function validateFields(array $filters): array + { + return (new Validator())->validate($filters); + } + + public function getIdProfile(): ?int + { + return $this->idProfile; + } + public function setIdProfile(?int $idProfile): self + { + $this->idProfile = $idProfile; + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + public function setName(?string $name): self + { + $this->name = $name; + return $this; + } + + public function getIsAgentView(): ?bool + { + return $this->isAgentView; + } + public function setIsAgentView(?bool $isAgentView): self + { + $this->isAgentView = $isAgentView; + return $this; + } + + public function getIsAgentEdit(): ?bool + { + return $this->isAgentEdit; + } + public function setIsAgentEdit(?bool $isAgentEdit): self + { + $this->isAgentEdit = $isAgentEdit; + return $this; + } + + public function getIsAlertEdit(): ?bool + { + return $this->isAlertEdit; + } + public function setIsAlertEdit(?bool $isAlertEdit): self + { + $this->isAlertEdit = $isAlertEdit; + return $this; + } + + public function getIsUserManagement(): ?bool + { + return $this->isUserManagement; + } + public function setIsUserManagement(?bool $isUserManagement): self + { + $this->isUserManagement = $isUserManagement; + return $this; + } + + public function getIsDbManagement(): ?bool + { + return $this->isDbManagement; + } + public function setIsDbManagement(?bool $isDbManagement): self + { + $this->isDbManagement = $isDbManagement; + return $this; + } + + public function getIsAlertManagement(): ?bool + { + return $this->isAlertManagement; + } + public function setIsAlertManagement(?bool $isAlertManagement): self + { + $this->isAlertManagement = $isAlertManagement; + return $this; + } + + public function getIsPandoraManagement(): ?bool + { + return $this->isPandoraManagement; + } + public function setIsPandoraManagement(?bool $isPandoraManagement): self + { + $this->isPandoraManagement = $isPandoraManagement; + return $this; + } + + public function getIsReportView(): ?bool + { + return $this->isReportView; + } + public function setIsReportView(?bool $isReportView): self + { + $this->isReportView = $isReportView; + return $this; + } + + public function getIsReportEdit(): ?bool + { + return $this->isReportEdit; + } + public function setIsReportEdit(?bool $isReportEdit): self + { + $this->isReportEdit = $isReportEdit; + return $this; + } + + public function getIsReportManagement(): ?bool + { + return $this->isReportManagement; + } + public function setIsReportManagement(?bool $isReportManagement): self + { + $this->isReportManagement = $isReportManagement; + return $this; + } + + public function getIsEventView(): ?bool + { + return $this->isEventView; + } + public function setIsEventView(?bool $isEventView): self + { + $this->isEventView = $isEventView; + return $this; + } + + public function getIsEventEdit(): ?bool + { + return $this->isEventEdit; + } + public function setIsEventEdit(?bool $isEventEdit): self + { + $this->isEventEdit = $isEventEdit; + return $this; + } + + public function getIsEventManagement(): ?bool + { + return $this->isEventManagement; + } + public function setIsEventManagement(?bool $isEventManagement): self + { + $this->isEventManagement = $isEventManagement; + return $this; + } + + public function getIsAgentDisable(): ?bool + { + return $this->isAgentDisable; + } + public function setIsAgentDisable(?bool $isAgentDisable): self + { + $this->isAgentDisable = $isAgentDisable; + return $this; + } + + public function getIsMapView(): ?bool + { + return $this->isMapView; + } + public function setIsMapView(?bool $isMapView): self + { + $this->isMapView = $isMapView; + return $this; + } + + public function getIsMapEdit(): ?bool + { + return $this->isMapEdit; + } + public function setIsMapEdit(?bool $isMapEdit): self + { + $this->isMapEdit = $isMapEdit; + return $this; + } + + public function getIsMapManagement(): ?bool + { + return $this->isMapManagement; + } + public function setIsMapManagement(?bool $isMapManagement): self + { + $this->isMapManagement = $isMapManagement; + return $this; + } + + public function getIsVconsoleView(): ?bool + { + return $this->isVconsoleView; + } + public function setIsVconsoleView(?bool $isVconsoleView): self + { + $this->isVconsoleView = $isVconsoleView; + return $this; + } + + public function getIsVconsoleEdit(): ?bool + { + return $this->isVconsoleEdit; + } + public function setIsVconsoleEdit(?bool $isVconsoleEdit): self + { + $this->isVconsoleEdit = $isVconsoleEdit; + return $this; + } + + public function getIsVconsoleManagement(): ?bool + { + return $this->isVconsoleManagement; + } + public function setIsVconsoleManagement(?bool $isVconsoleManagement): self + { + $this->isVconsoleManagement = $isVconsoleManagement; + return $this; + } + + public function getIsNetworkConfigView(): ?bool + { + return $this->isNetworkConfigView; + } + public function setIsNetworkConfigView(?bool $isNetworkConfigView): self + { + $this->isNetworkConfigView = $isNetworkConfigView; + return $this; + } + + public function getIsNetworkConfigEdit(): ?bool + { + return $this->isNetworkConfigEdit; + } + public function setIsNetworkConfigEdit(?bool $isNetworkConfigEdit): self + { + $this->isNetworkConfigEdit = $isNetworkConfigEdit; + return $this; + } + + public function getIsNetworkConfigManagement(): ?bool + { + return $this->isNetworkConfigManagement; + } + public function setIsNetworkConfigManagement(?bool $isNetworkConfigManagement): self + { + $this->isNetworkConfigManagement = $isNetworkConfigManagement; + return $this; + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Entities/ProfileDataMapper.php b/pandora_console/include/lib/Modules/Profiles/Entities/ProfileDataMapper.php new file mode 100644 index 0000000000..46f3214143 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Entities/ProfileDataMapper.php @@ -0,0 +1,116 @@ +builder->build(new Profile(), [ + 'idProfile' => $data[self::ID_PROFILE], + 'name' => $this->repository->safeOutput($data[self::NAME]), + 'isAgentView' => $data[self::IS_AGENT_VIEW], + 'isAgentEdit' => $data[self::IS_AGENT_EDIT], + 'isAlertEdit' => $data[self::IS_ALERT_EDIT], + 'isUserManagement' => $data[self::IS_USER_MANAGEMENT], + 'isDbManagement' => $data[self::IS_DB_MANAGEMENT], + 'isAlertManagement' => $data[self::IS_ALERT_MANAGEMENT], + 'isPandoraManagement' => $data[self::IS_PANDORA_MANAGEMENT], + 'isReportView' => $data[self::IS_REPORT_VIEW], + 'isReportEdit' => $data[self::IS_REPORT_EDIT], + 'isReportManagement' => $data[self::IS_REPORT_MANAGEMENT], + 'isEventView' => $data[self::IS_EVENT_VIEW], + 'isEventEdit' => $data[self::IS_EVENT_EDIT], + 'isEventManagement' => $data[self::IS_EVENT_MANAGEMENT], + 'isAgentDisable' => $data[self::IS_AGENT_DISABLE], + 'isMapView' => $data[self::IS_MAP_VIEW], + 'isMapEdit' => $data[self::IS_MAP_EDIT], + 'isMapManagement' => $data[self::IS_MAP_MANAGEMENT], + 'isVconsoleView' => $data[self::IS_VCONSOLE_VIEW], + 'isVconsoleEdit' => $data[self::IS_VCONSOLE_EDIT], + 'isVconsoleManagement' => $data[self::IS_VCONSOLE_MANAGEMENT], + 'isNetworkConfigView' => $data[self::IS_NETWORK_CONFIG_VIEW], + 'isNetworkConfigEdit' => $data[self::IS_NETWORK_CONFIG_EDIT], + 'isNetworkConfigManagement' => $data[self::IS_NETWORK_CONFIG_MANAGEMENT], + ]); + } + + public function toDatabase(MappeableInterface $data): array + { + /** @var Profile $data */ + return [ + self::ID_PROFILE => $data->getIdProfile(), + self::NAME => $this->repository->safeInput($data->getName()), + self::IS_AGENT_VIEW => $data->getIsAgentView(), + self::IS_AGENT_EDIT => $data->getIsAgentEdit(), + self::IS_ALERT_EDIT => $data->getIsAlertEdit(), + self::IS_USER_MANAGEMENT => $data->getIsUserManagement(), + self::IS_DB_MANAGEMENT => $data->getIsDbManagement(), + self::IS_ALERT_MANAGEMENT => $data->getIsAlertManagement(), + self::IS_PANDORA_MANAGEMENT => $data->getIsPandoraManagement(), + self::IS_REPORT_VIEW => $data->getIsReportView(), + self::IS_REPORT_EDIT => $data->getIsReportEdit(), + self::IS_REPORT_MANAGEMENT => $data->getIsReportManagement(), + self::IS_EVENT_VIEW => $data->getIsEventView(), + self::IS_EVENT_EDIT => $data->getIsEventEdit(), + self::IS_EVENT_MANAGEMENT => $data->getIsEventManagement(), + self::IS_AGENT_DISABLE => $data->getIsAgentDisable(), + self::IS_MAP_VIEW => $data->getIsMapView(), + self::IS_MAP_EDIT => $data->getIsMapEdit(), + self::IS_MAP_MANAGEMENT => $data->getIsMapManagement(), + self::IS_VCONSOLE_VIEW => $data->getIsVconsoleView(), + self::IS_VCONSOLE_EDIT => $data->getIsVconsoleEdit(), + self::IS_VCONSOLE_MANAGEMENT => $data->getIsVconsoleManagement(), + self::IS_NETWORK_CONFIG_VIEW => $data->getIsNetworkConfigView(), + self::IS_NETWORK_CONFIG_EDIT => $data->getIsNetworkConfigEdit(), + self::IS_NETWORK_CONFIG_MANAGEMENT => $data->getIsNetworkConfigManagement(), + ]; + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Entities/ProfileFilter.php b/pandora_console/include/lib/Modules/Profiles/Entities/ProfileFilter.php new file mode 100644 index 0000000000..bc0e87652f --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Entities/ProfileFilter.php @@ -0,0 +1,118 @@ +setDefaultFieldOrder(ProfileDataMapper::NAME); + $this->setDefaultDirectionOrder($this::ASC); + $this->setEntityFilter(new Profile()); + } + + public function fieldsTranslate(): array + { + return [ + 'idProfile' => ProfileDataMapper::ID_PROFILE, + 'name' => ProfileDataMapper::NAME, + ]; + } + + public function fieldsReadOnly(): array + { + return []; + } + + public function jsonSerialize(): mixed + { + return [ + 'freeSearch' => $this->getFreeSearch(), + ]; + } + + public function getValidations(): array + { + $validations = []; + if($this->getEntityFilter() !== null) { + $validations = $this->getEntityFilter()->getValidations(); + } + $validations['freeSearch'] = Validator::STRING; + return $validations; + } + + public function validateFields(array $filters): array + { + return (new Validator())->validate($filters); + } + + /** + * Get the value of freeSearch. + * + * @return ?string + */ + public function getFreeSearch(): ?string + { + return $this->freeSearch; + } + + /** + * Set the value of freeSearch. + * + * @param ?string $freeSearch + * + */ + public function setFreeSearch(?string $freeSearch): self + { + $this->freeSearch = $freeSearch; + return $this; + } + + /** + * Get the value of fieldsFreeSearch. + * + * @return ?array + */ + public function getFieldsFreeSearch(): ?array + { + return [ProfileDataMapper::NAME]; + } + +} diff --git a/pandora_console/include/lib/Modules/Profiles/Repositories/ProfileRepository.php b/pandora_console/include/lib/Modules/Profiles/Repositories/ProfileRepository.php new file mode 100644 index 0000000000..ca556cf912 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Repositories/ProfileRepository.php @@ -0,0 +1,65 @@ +repository->__list( + $profileFilter, + $this->profileDataMapper + ); + } + + public function count(ProfileFilter $profileFilter): int + { + return $this->repository->__count( + $profileFilter, + $this->profileDataMapper + ); + } + + public function getOne(ProfileFilter $profileFilter): Profile + { + return $this->repository->__getOne( + $profileFilter, + $this->profileDataMapper + ); + } + + public function create(Profile $profile): Profile + { + $id = $this->repository->__create($profile, $this->profileDataMapper); + return $profile->setIdProfile($id); + } + + public function update(Profile $profile): Profile + { + return $this->repository->__update( + $profile, + $this->profileDataMapper, + $profile->getIdProfile() + ); + } + + public function delete(int $id): void + { + $this->repository->__delete($id, $this->profileDataMapper); + } + +} diff --git a/pandora_console/include/lib/Modules/Profiles/Services/CountProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/CountProfileService.php new file mode 100644 index 0000000000..3fb03cd721 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Services/CountProfileService.php @@ -0,0 +1,19 @@ +profileRepository->count($profileFilter); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Services/CreateProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/CreateProfileService.php new file mode 100644 index 0000000000..c64ac5e77c --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Services/CreateProfileService.php @@ -0,0 +1,33 @@ +profileValidation->__invoke($profile); + + $profile = $this->profileRepository->create($profile); + + $this->audit->write( + AUDIT_LOG_USER_MANAGEMENT, + 'Create profile '.$profile->getName(), + json_encode($profile->toArray()) + ); + + return $profile; + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Services/DeleteProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/DeleteProfileService.php new file mode 100644 index 0000000000..f2e391ee20 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Services/DeleteProfileService.php @@ -0,0 +1,29 @@ +getIdProfile(); + $nameProfile = $profile->getName(); + $this->profileRepository->delete($idProfile); + + $this->audit->write( + AUDIT_LOG_USER_MANAGEMENT, + 'Deleted profile '.$nameProfile + ); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Services/ExistNameProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/ExistNameProfileService.php new file mode 100644 index 0000000000..1620a804be --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Services/ExistNameProfileService.php @@ -0,0 +1,31 @@ +getEntityFilter(); + $entityFilter->setName($name); + + try { + $this->profileRepository->getOne($profileFilter); + return true; + } catch (NotFoundException) { + return false; + } + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Services/GetProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/GetProfileService.php new file mode 100644 index 0000000000..330a248f45 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Services/GetProfileService.php @@ -0,0 +1,25 @@ +getEntityFilter(); + $entityFilter->setIdProfile($idProfile); + + return $this->profileRepository->getOne($profileFilter); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Services/ListProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/ListProfileService.php new file mode 100644 index 0000000000..24f684f5b6 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Services/ListProfileService.php @@ -0,0 +1,19 @@ +profileRepository->list($profileFilter); + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Services/UpdateProfileService.php b/pandora_console/include/lib/Modules/Profiles/Services/UpdateProfileService.php new file mode 100644 index 0000000000..b4c66e6952 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Services/UpdateProfileService.php @@ -0,0 +1,33 @@ +profileValidation->__invoke($profile, $oldProfile); + + $profile = $this->profileRepository->update($profile); + + $this->audit->write( + AUDIT_LOG_USER_MANAGEMENT, + 'Update profile '.$profile->getName(), + json_encode($profile->toArray()) + ); + + return $profile; + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/Validations/ProfileValidation.php b/pandora_console/include/lib/Modules/Profiles/Validations/ProfileValidation.php new file mode 100644 index 0000000000..e284e3d82f --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/Validations/ProfileValidation.php @@ -0,0 +1,122 @@ +getName()) { + throw new BadRequestException(__('Name is missing')); + } + + if($oldProfile === null || $oldProfile->getName() !== $profile->getName()) { + if($this->existNameProfileService->__invoke($profile->getName()) === true) { + throw new BadRequestException( + __('Name %s is already exists', $profile->getName()) + ); + } + } + + if($profile->getIsAgentView() === null) { + $profile->setIsAgentView(false); + } + + if($profile->getIsAgentEdit() === null) { + $profile->setIsAgentEdit(false); + } + + if($profile->getIsAlertEdit() === null) { + $profile->setIsAlertEdit(false); + } + + if($profile->getIsUserManagement() === null) { + $profile->setIsUserManagement(false); + } + + if($profile->getIsDbManagement() === null) { + $profile->setIsDbManagement(false); + } + + if($profile->getIsAlertManagement() === null) { + $profile->setIsAlertManagement(false); + } + + if($profile->getIsPandoraManagement() === null) { + $profile->setIsPandoraManagement(false); + } + + if($profile->getIsReportView() === null) { + $profile->setIsReportView(false); + } + + if($profile->getIsReportEdit() === null) { + $profile->setIsReportEdit(false); + } + + if($profile->getIsReportManagement() === null) { + $profile->setIsReportManagement(false); + } + + if($profile->getIsEventView() === null) { + $profile->setIsEventView(false); + } + + if($profile->getIsEventEdit() === null) { + $profile->setIsEventEdit(false); + } + + if($profile->getIsEventManagement() === null) { + $profile->setIsEventManagement(false); + } + + if($profile->getIsAgentDisable() === null) { + $profile->setIsAgentDisable(false); + } + + if($profile->getIsMapView() === null) { + $profile->setIsMapView(false); + } + + if($profile->getIsMapEdit() === null) { + $profile->setIsMapEdit(false); + } + + if($profile->getIsMapManagement() === null) { + $profile->setIsMapManagement(false); + } + + if($profile->getIsVconsoleView() === null) { + $profile->setIsVconsoleView(false); + } + + if($profile->getIsVconsoleEdit() === null) { + $profile->setIsVconsoleEdit(false); + } + + if($profile->getIsVconsoleManagement() === null) { + $profile->setIsVconsoleManagement(false); + } + + if($profile->getIsNetworkConfigView() === null) { + $profile->setIsNetworkConfigView(false); + } + + if($profile->getIsNetworkConfigEdit() === null) { + $profile->setIsNetworkConfigEdit(false); + } + + if($profile->getIsNetworkConfigManagement() === null) { + $profile->setIsNetworkConfigManagement(false); + } + } +} diff --git a/pandora_console/include/lib/Modules/Profiles/routes.php b/pandora_console/include/lib/Modules/Profiles/routes.php new file mode 100644 index 0000000000..09d72647a9 --- /dev/null +++ b/pandora_console/include/lib/Modules/Profiles/routes.php @@ -0,0 +1,16 @@ +map(['GET', 'POST'], '/profile/list', ListProfileController::class); + $app->get('/profile/{idProfile}', GetProfileController::class); + $app->post('/profile', CreateProfileController::class); + $app->put('/profile/{idProfile}', UpdateProfileController::class); + $app->delete('/profile/{idProfile}', DeleteProfileController::class); +}; diff --git a/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php b/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php index 5144563346..ce31f1ad85 100644 --- a/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php +++ b/pandora_console/include/lib/Modules/Shared/Core/DataMapperAbstract.php @@ -82,7 +82,9 @@ abstract class DataMapperAbstract public function getStringNameClass(): string { $strname = [ - 'PandoraFMS\\Modules\\Users\\Entities\\User' => 'User', + 'PandoraFMS\\Modules\\Users\\Entities\\User' => 'User', + 'PandoraFMS\\Modules\\Users\\Entities\\Profile' => 'Profile', + 'PandoraFMS\\Modules\\Users\\UserProfiles\\Entities\\UserProfile' => 'UserProfile', ]; $result = ($strname[$this->getClassName()] ?? ''); diff --git a/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php b/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php index 980bef53cb..ec18565a37 100644 --- a/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php +++ b/pandora_console/include/lib/Modules/Shared/Documentation/OpenApi.php @@ -39,6 +39,10 @@ use OpenApi\Annotations as OA; * name="Users", * description="API Endpoints of users" * ), + * @OA\Tag( + * name="Profiles", + * description="API Endpoints of profiles" + * ), * @OA\OpenApi( * x={ * "tagGroups"= { @@ -46,6 +50,10 @@ use OpenApi\Annotations as OA; * "name"="Users", * "tags"={"Users"} * }, + * { + * "name"="Profiles", + * "tags"={"Profiles"} + * }, * } * } * ), diff --git a/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php index 4b075bd25b..ffb5ff9410 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php @@ -23,7 +23,7 @@ final class DeleteUserController extends Controller * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Users"}, - * path="/user/{id}", + * path="/user/{idUser}", * summary="Deletes an user object.", * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), * @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"), @@ -36,7 +36,7 @@ final class DeleteUserController extends Controller */ public function __invoke(Request $request, Response $response): Response { - $idUser = $this->getParam($request, 'id'); + $idUser = $this->getParam($request, 'idUser'); $user = $this->getUserAction->__invoke($idUser); $this->acl->validate(0, 'UM', ' tried to manage user'); diff --git a/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php index f29d264403..a4d255f167 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php @@ -20,7 +20,7 @@ final class GetUserController extends Controller /** * @OA\Get( * security={{ "bearerAuth": {}}}, - * path="/user/{id}", + * path="/user/{idUser}", * tags={"Users"}, * summary="show users", * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), @@ -34,7 +34,7 @@ final class GetUserController extends Controller */ public function __invoke(Request $request, Response $response): Response { - $idUser = $this->getParam($request, 'id'); + $idUser = $this->getParam($request, 'idUser'); $result = $this->getUserAction->__invoke($idUser); 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 d787180198..92857f9f01 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php @@ -13,7 +13,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; /** * @OA\Put( * security={{ "bearerAuth": {}}}, - * path="/user/{id}", + * path="/user/{idUser}", * tags={"Users"}, * summary="Updates an user", * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), @@ -37,7 +37,7 @@ final class UpdateUserController extends Controller public function __invoke(Request $request, Response $response): Response { - $idUser = $this->getParam($request, 'id'); + $idUser = $this->getParam($request, 'idUser'); $user = $this->getUserAction->__invoke($idUser); $oldUser = clone $user; diff --git a/pandora_console/include/lib/Modules/Users/Entities/User.php b/pandora_console/include/lib/Modules/Users/Entities/User.php index ae9afbda4a..6e1fe22893 100644 --- a/pandora_console/include/lib/Modules/Users/Entities/User.php +++ b/pandora_console/include/lib/Modules/Users/Entities/User.php @@ -454,7 +454,7 @@ use PandoraFMS\Modules\Users\Validators\UserValidator; * * @OA\Parameter( * parameter="parameterIdUser", - * name="id", + * name="idUser", * in="path", * description="User id", * required=true, diff --git a/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php b/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php index b7a7eaa806..2ed1582337 100644 --- a/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php +++ b/pandora_console/include/lib/Modules/Users/Entities/UserDataMapper.php @@ -66,7 +66,6 @@ final class UserDataMapper extends DataMapperAbstract public const AUTH_TOKEN_SECRET = 'auth_token_secret'; public const SESSION_MAX_TIME_EXPIRE = 'session_max_time_expire'; - public function __construct( private Repository $repository, private Builder $builder, @@ -77,13 +76,11 @@ final class UserDataMapper extends DataMapperAbstract ); } - public function getClassName(): string { return User::class; } - public function fromDatabase(array $data): User { return $this->builder->build( @@ -128,7 +125,7 @@ final class UserDataMapper extends DataMapperAbstract 'defaultEventFilter' => $data[self::DEFAULT_EVENT_FILTER], 'metaconsoleDefaultEventFilter' => $data[self::METACONSOLE_DEFAULT_EVENT_FILTER], 'showTipsStartup' => $data[self::SHOW_TIPS_STARTUP], - 'autorefreshWhiteList' => ($data[self::AUTOREFRESH_WHITE_LIST] !== null) ? json_decode($this->repository->safeOutput($data[self::AUTOREFRESH_WHITE_LIST])) : null, + 'autorefreshWhiteList' => (empty($data[self::AUTOREFRESH_WHITE_LIST]) === false) ? json_decode($this->repository->safeOutput($data[self::AUTOREFRESH_WHITE_LIST])) : null, 'timeAutorefresh' => $data[self::TIME_AUTOREFRESH], 'defaultCustomView' => $data[self::DEFAULT_CUSTOM_VIEW], 'ehorusUserLevelUser' => $this->repository->safeOutput($data[self::EHORUS_USER_LEVEL_USER]), @@ -190,7 +187,7 @@ final class UserDataMapper extends DataMapperAbstract self::DEFAULT_EVENT_FILTER => $data->getDefaultEventFilter(), self::METACONSOLE_DEFAULT_EVENT_FILTER => $data->getMetaconsoleDefaultEventFilter(), self::SHOW_TIPS_STARTUP => $data->getShowTipsStartup(), - self::AUTOREFRESH_WHITE_LIST => ($data->getAutorefreshWhiteList() !== null) ? $this->repository->safeInput(json_encode($data->getAutorefreshWhiteList())) : null, + self::AUTOREFRESH_WHITE_LIST => (empty($data->getAutorefreshWhiteList()) === false) ? $this->repository->safeInput(json_encode($data->getAutorefreshWhiteList())) : null, self::TIME_AUTOREFRESH => $data->getTimeAutorefresh(), self::DEFAULT_CUSTOM_VIEW => $data->getDefaultCustomView(), self::EHORUS_USER_LEVEL_USER => $this->repository->safeInput($data->getEhorusUserLevelUser()), @@ -205,6 +202,4 @@ final class UserDataMapper extends DataMapperAbstract self::SESSION_MAX_TIME_EXPIRE => $data->getSessionMaxTimeExpire(), ]; } - - } diff --git a/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php b/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php index a495b61ab1..7872a1a27f 100644 --- a/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php +++ b/pandora_console/include/lib/Modules/Users/Enums/UserAutoRefreshPagesEnum.php @@ -22,5 +22,4 @@ enum UserAutoRefreshPagesEnum: string 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 6080247bc9..9207a2b387 100644 --- a/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php +++ b/pandora_console/include/lib/Modules/Users/Enums/UserHomeScreenEnum.php @@ -17,5 +17,4 @@ enum UserHomeScreenEnum: string case EXTERNAL_LINK = 'external_link'; case OTHER = 'other'; case DASHBOARD = 'dashboard'; - } diff --git a/pandora_console/include/lib/Modules/Users/Services/CheckOldPasswordUserService.php b/pandora_console/include/lib/Modules/Users/Services/CheckOldPasswordUserService.php index 969642d247..7fdf3ae305 100644 --- a/pandora_console/include/lib/Modules/Users/Services/CheckOldPasswordUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/CheckOldPasswordUserService.php @@ -20,9 +20,7 @@ final class CheckOldPasswordUserService public function __invoke(User $user): void { $userFilter = new UserFilter(); - /** - @var User $entityFilter - */ + /** @var User $entityFilter */ $entityFilter = $userFilter->getEntityFilter(); $entityFilter->setIdUser($user->getIdUser()); $entityFilter->setPassword($user->getOldPassword()); diff --git a/pandora_console/include/lib/Modules/Users/Services/GetUserService.php b/pandora_console/include/lib/Modules/Users/Services/GetUserService.php index 0725760615..cea233c8fa 100644 --- a/pandora_console/include/lib/Modules/Users/Services/GetUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/GetUserService.php @@ -17,9 +17,7 @@ final class GetUserService { $userFilter = new UserFilter(); - /** - @var User $entityFilter - */ + /** @var User $entityFilter */ $entityFilter = $userFilter->getEntityFilter(); $entityFilter->setIdUser($idUser); diff --git a/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php b/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php index 274830786c..ffdb1367d1 100644 --- a/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php +++ b/pandora_console/include/lib/Modules/Users/Services/ValidatePasswordUserService.php @@ -23,8 +23,7 @@ final class ValidatePasswordUserService ); } - // Si es una actualizacion, revisas el o los antiguos paswords, - // que no se pueda repetir. + // Si es una actualizacion, revisas el o los antiguos paswords, que no se pueda repetir. if ($oldUser !== null) { $newPass = password_hash($user->getPassword(), PASSWORD_BCRYPT); if ((bool) $this->config->get('enable_pass_history') === true) { diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/CreateUserProfileAction.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/CreateUserProfileAction.php index fcc4d6b375..60fe948892 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/CreateUserProfileAction.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/CreateUserProfileAction.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\CreateUserProfileService; final class CreateUserProfileAction { - - public function __construct( private CreateUserProfileService $createUserProfileService ) { } - public function __invoke(UserProfile $userProfile): UserProfile { return $this->createUserProfileService->__invoke($userProfile); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/DeleteUserProfileAction.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/DeleteUserProfileAction.php index de6f9b0993..e106ed9479 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/DeleteUserProfileAction.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/DeleteUserProfileAction.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\DeleteUserProfileService; final class DeleteUserProfileAction { - - public function __construct( private DeleteUserProfileService $deleteService ) { } - public function __invoke(UserProfile $userProfile): void { $this->deleteService->__invoke($userProfile); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/GetUserProfileAction.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/GetUserProfileAction.php index 699924a69a..e32623a4f2 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/GetUserProfileAction.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/GetUserProfileAction.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\GetUserProfileService; final class GetUserProfileAction { - - public function __construct( private GetUserProfileService $getUserProfileService ) { } - public function __invoke(string $idUser, int $idProfile): UserProfile { return $this->getUserProfileService->__invoke($idUser, $idProfile); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/ListUserProfileAction.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/ListUserProfileAction.php index c4ed7ce073..abaf2d7caf 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/ListUserProfileAction.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Actions/ListUserProfileAction.php @@ -2,22 +2,19 @@ namespace PandoraFMS\Modules\Users\UserProfiles\Actions; +use PandoraFMS\Modules\Shared\Entities\PaginationData; use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfileFilter; use PandoraFMS\Modules\Users\UserProfiles\Services\CountUserProfileService; use PandoraFMS\Modules\Users\UserProfiles\Services\ListUserProfileService; -use PandoraFMS\Modules\Shared\Entities\PaginationData; final class ListUserProfileAction { - - public function __construct( private ListUserProfileService $listUserProfileService, private CountUserProfileService $countUserProfileService ) { } - public function __invoke(UserProfileFilter $userProfileFilter): array { return (new PaginationData( @@ -27,6 +24,4 @@ final class ListUserProfileAction $this->listUserProfileService->__invoke($userProfileFilter) ))->toArray(); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php index 7592117f0f..1a702e9ede 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php @@ -2,19 +2,18 @@ namespace PandoraFMS\Modules\Users\UserProfiles\Controllers; -use PandoraFMS\Modules\Users\UserProfiles\Actions\CreateUserProfileAction; -use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfile; use PandoraFMS\Modules\Profiles\Actions\GetProfileAction; use PandoraFMS\Modules\Shared\Controllers\Controller; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use PandoraFMS\Modules\Users\Actions\GetUserAction; +use PandoraFMS\Modules\Users\UserProfiles\Actions\CreateUserProfileAction; +use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfile; + use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; final class CreateUserProfileController extends Controller { - - public function __construct( private CreateUserProfileAction $createUserProfileAction, private ValidateAclSystem $acl, @@ -23,33 +22,32 @@ final class CreateUserProfileController extends Controller ) { } - /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Users"}, - * path="/user/{id}/profile/{idProfile}", + * path="/user/{idUser}/profile/{idProfile}", * summary="Create user profile", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Parameter(ref="#/components/parameters/parameterProfileId"), - * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserProfile"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUserProfile"), - * @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\Parameter(ref="#/components/parameters/parameterIdProfile"), + * @OA\RequestBody(ref="#/components/requestBodies/requestBodyUserProfile"), + * @OA\Response(response=200, ref="#/components/responses/ResponseUserProfile"), + * @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 { - $idUser = $this->getParam($request, 'id'); - $user = $this->getUserAction->__invoke($idUser); + $idUser = $this->getParam($request, 'idUser'); + $this->getUserAction->__invoke($idUser); $this->acl->validate(0, 'UM', ' tried to manage user'); $idProfile = $this->getParam($request, 'idProfile'); - $profile = $this->getProfileAction->__invoke($idProfile); + $this->getProfileAction->__invoke($idProfile); // @var UserProfile $userProfile. $userProfile = $this->fromRequest($request, UserProfile::class); @@ -59,6 +57,4 @@ final class CreateUserProfileController extends Controller $result = $this->createUserProfileAction->__invoke($userProfile); return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php index beed13278d..359b86918e 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php @@ -8,13 +8,12 @@ use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use PandoraFMS\Modules\Users\Actions\GetUserAction; use PandoraFMS\Modules\Users\UserProfiles\Actions\DeleteUserProfileAction; use PandoraFMS\Modules\Users\UserProfiles\Actions\GetUserProfileAction; + use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; final class DeleteUserProfileController extends Controller { - - public function __construct( private DeleteUserProfileAction $deleteUserProfileAction, private ValidateAclSystem $acl, @@ -24,26 +23,25 @@ final class DeleteUserProfileController extends Controller ) { } - /** * @OA\Delete( * security={{ "bearerAuth": {}}}, * tags={"Users"}, - * path="/user/{id}/profile/{idProfile}", + * path="/user/{idUser}/profile/{idProfile}", * summary="Deletes user profile.", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Parameter(ref="#/components/parameters/parameterProfileId"), - * @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\Parameter(ref="#/components/parameters/parameterIdProfile"), + * @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 { - $idUser = $this->getParam($request, 'id'); + $idUser = $this->getParam($request, 'idUser'); $user = $this->getUserAction->__invoke($idUser); $idProfile = $this->getParam($request, 'idProfile'); @@ -53,6 +51,4 @@ final class DeleteUserProfileController extends Controller $result = $this->deleteUserProfileAction->__invoke($userProfile); return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/GetUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/GetUserProfileController.php index 46d2530f71..ef9197c3c1 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/GetUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/GetUserProfileController.php @@ -13,8 +13,6 @@ use Psr\Http\Message\ServerRequestInterface as Request; final class GetUserProfileController extends Controller { - - public function __construct( private GetUserProfileAction $getUserProfileAction, private GetUserAction $getUserAction, @@ -23,26 +21,25 @@ final class GetUserProfileController extends Controller ) { } - /** * @OA\Get( * security={{ "bearerAuth": {}}}, - * path="/user/{id}/profile/{idProfile}", + * path="/user/{idUser}/profile/{idProfile}", * tags={"Users"}, * summary="show data field user profile", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @OA\Parameter(ref="#/components/parameters/parameterProfileId"), - * @OA\Response(response=200, ref="#/components/responses/ResponseUserProfile"), - * @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\Parameter(ref="#/components/parameters/parameterIdProfile"), + * @OA\Response(response=200, ref="#/components/responses/ResponseUserProfile"), + * @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 { - $idUser = $this->getParam($request, 'id'); + $idUser = $this->getParam($request, 'idUser'); $user = $this->getUserAction->__invoke($idUser); $idProfile = $this->getParam($request, 'idProfile'); @@ -51,6 +48,4 @@ final class GetUserProfileController extends Controller $result = $this->getUserProfileAction->__invoke($idUser, $idProfile); return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/ListUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/ListUserProfileController.php index 83678156f4..9ec36ba741 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/ListUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/ListUserProfileController.php @@ -7,13 +7,12 @@ use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use PandoraFMS\Modules\Users\Actions\GetUserAction; use PandoraFMS\Modules\Users\UserProfiles\Actions\ListUserProfileAction; use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfileFilter; + use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; final class ListUserProfileController extends Controller { - - public function __construct( private ListUserProfileAction $listUserProfileAction, private GetUserAction $getUserAction, @@ -21,55 +20,54 @@ final class ListUserProfileController extends Controller ) { } - /** * @OA\Post( * security={{ "bearerAuth": {}}}, * tags={"Users"}, - * path="/user/{id}/profiles", + * path="/user/{idUser}/profiles", * summary="List user profiles", - * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), - * @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/requestBodyUserProfile"), - * @OA\Response( - * response="200", - * description="List data profiles user object", - * content={ - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * @OA\Property( - * property="paginationData", - * type="object", - * ref="#/components/schemas/paginationData", - * description="Page object", + * @OA\Parameter(ref="#/components/parameters/parameterIdUser"), + * @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/requestBodyUserProfile"), + * @OA\Response( + * response="200", + * description="List data profiles user 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/UserProfile", + * description="Array of profiles" + * ) + * ), * ), - * @OA\Property( - * property="data", - * type="array", - * @OA\Items( - * ref="#/components/schemas/UserProfile", - * description="Array of profiles" - * ) - * ), - * ), - * ) - * } - * ), - * @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 { - $idUser = $this->getParam($request, 'id'); - $user = $this->getUserAction->__invoke($idUser); + $idUser = $this->getParam($request, 'idUser'); + $this->getUserAction->__invoke($idUser); // @var UserProfileFilter $userProfileFilter. $userProfileFilter = $this->fromRequest($request, UserProfileFilter::class); @@ -78,6 +76,4 @@ final class ListUserProfileController extends Controller $result = $this->listUserProfileAction->__invoke($userProfileFilter); return $this->getResponse($response, $result); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfile.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfile.php index 8bf8463378..a370f8c5f3 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfile.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfile.php @@ -37,13 +37,42 @@ use PandoraFMS\Modules\Shared\Validators\Validator; * description="Id Group" * ), * @OA\Property( + * property="isNoHierarchy", + * type="boolean", + * nullable=true, + * default=false, + * description="No hierarchy" + * ), + * @OA\Property( * property="assignedBy", * type="string", * nullable=false, * default=null, * readOnly=true, * description="Create user profile by" - * ) + * ), + * @OA\Property( + * property="idPolicy", + * type="integer", + * nullable=false, + * description="Id Policy" + * ), + * @OA\Property( + * property="tags", + * type="array", + * nullable=true, + * default=null, + * description="Tags to which a user belongs", + * @OA\Items( + * @OA\Property( + * property="idTags", + * type="integer", + * nullable=true, + * default=null, + * description="Tags id", + * ) + * ) + * ), * ) * * @OA\Response( @@ -62,10 +91,10 @@ use PandoraFMS\Modules\Shared\Validators\Validator; * ) * * @OA\Parameter( - * parameter="parameterProfileId", - * name="idProfile", + * parameter="parameterIdUserProfile", + * name="idUserProfile", * in="path", - * description="Profile id", + * description="User profile id", * required=true, * @OA\Schema( * type="integer", @@ -84,29 +113,24 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class UserProfile extends Entity { - private ?int $idUserProfile = null; - private ?string $idUser = null; - private ?int $idProfile = null; - private ?int $idGroup = null; - + private ?bool $isNoHierarchy = null; private ?string $assignedBy = null; - + private ?int $idPolicy = null; + private ?array $tags = null; public function __construct() { } - public function fieldsReadOnly(): array { return ['idUserProfile' => 1]; } - public function jsonSerialize(): mixed { return [ @@ -114,11 +138,13 @@ final class UserProfile extends Entity 'idUser' => $this->getIdUser(), 'idProfile' => $this->getIdProfile(), 'idGroup' => $this->getIdGroup(), + 'isNoHierarchy' => $this->getIsNoHierarchy(), 'assignedBy' => $this->getAssignedBy(), + 'idPolicy' => $this->getIdPolicy(), + 'tags' => $this->getTags(), ]; } - public function getValidations(): array { return [ @@ -126,42 +152,34 @@ final class UserProfile extends Entity Validator::INTEGER, Validator::GREATEREQUALTHAN, ], - 'idUser' => Validator::STRING, - 'idProfile' => [ + 'idUser' => Validator::STRING, + 'idProfile' => [ Validator::INTEGER, Validator::GREATEREQUALTHAN, ], - 'idGroup' => [ + 'idGroup' => [ Validator::INTEGER, Validator::GREATEREQUALTHAN, ], + 'isNoHierarchy' => Validator::BOOLEAN, 'assignedBy' => Validator::STRING, + 'idPolicy' => [ + Validator::INTEGER, + Validator::GREATEREQUALTHAN, + ], + 'tags' => Validator::ARRAY, ]; } - public function validateFields(array $filters): array { return (new Validator())->validate($filters); } - - /** - * Get the value of idUserProfile. - * - * @return ?int - */ public function getIdUserProfile(): ?int { return $this->idUserProfile; } - - - /** - * Set the value of idUserProfile. - * - * @param integer $idUserProfile - */ public function setIdUserProfile(?int $idUserProfile): self { $this->idUserProfile = $idUserProfile; @@ -169,23 +187,10 @@ final class UserProfile extends Entity return $this; } - - /** - * Get the value of idUser. - * - * @return ?string - */ public function getIdUser(): ?string { return $this->idUser; } - - - /** - * Set the value of idUser. - * - * @param string $idUser - */ public function setIdUser(?string $idUser): self { $this->idUser = $idUser; @@ -193,23 +198,10 @@ final class UserProfile extends Entity return $this; } - - /** - * Get the value of idProfile. - * - * @return ?int - */ public function getIdProfile(): ?int { return $this->idProfile; } - - - /** - * Set the value of idProfile. - * - * @param integer $idProfile - */ public function setIdProfile(?int $idProfile): self { $this->idProfile = $idProfile; @@ -217,23 +209,10 @@ final class UserProfile extends Entity return $this; } - - /** - * Get the value of idGroup. - * - * @return ?int - */ public function getIdGroup(): ?int { return $this->idGroup; } - - - /** - * Set the value of idGroup. - * - * @param integer $idGroup - */ public function setIdGroup(?int $idGroup): self { $this->idGroup = $idGroup; @@ -241,23 +220,10 @@ final class UserProfile extends Entity return $this; } - - /** - * Get the value of assignedBy. - * - * @return ?string - */ public function getAssignedBy(): ?string { return $this->assignedBy; } - - - /** - * Set the value of assignedBy. - * - * @param string $assignedBy - */ public function setAssignedBy(?string $assignedBy): self { $this->assignedBy = $assignedBy; @@ -265,5 +231,38 @@ final class UserProfile extends Entity return $this; } + public function getIsNoHierarchy(): ?bool + { + return $this->isNoHierarchy; + } + public function setIsNoHierarchy(?bool $isNoHierarchy): self + { + $this->isNoHierarchy = $isNoHierarchy; + return $this; + } + public function getIdPolicy(): ?int + { + return $this->idPolicy; + } + public function setIdPolicy(?int $idPolicy): self + { + $this->idPolicy = $idPolicy; + return $this; + } + + public function getTags(): ?array + { + return $this->tags; + } + public function setTags(array|string|null $tags): self + { + if (is_string($tags) === true) { + $tags = json_decode($tags); + } + + $this->tags = $tags; + + return $this; + } } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileDataMapper.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileDataMapper.php index 585526ad7b..e36293550c 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileDataMapper.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileDataMapper.php @@ -14,8 +14,10 @@ final class UserProfileDataMapper extends DataMapperAbstract public const ID_USER = 'id_usuario'; public const ID_PROFILE = 'id_perfil'; public const ID_GROUP = 'id_grupo'; + public const IS_NO_HIERARCHY = 'no_hierarchy'; public const ASSIGNED_BY = 'assigned_by'; - + public const ID_POLICY = 'id_policy'; + public const TAGS = 'tags'; public function __construct( private Repository $repository, @@ -27,13 +29,11 @@ final class UserProfileDataMapper extends DataMapperAbstract ); } - public function getClassName(): string { return UserProfile::class; } - public function fromDatabase(array $data): UserProfile { return $this->builder->build( @@ -43,25 +43,26 @@ final class UserProfileDataMapper extends DataMapperAbstract 'idUser' => $data[self::ID_USER], 'idProfile' => $data[self::ID_PROFILE], 'idGroup' => $data[self::ID_GROUP], + 'isNoHierarchy' => $data[self::IS_NO_HIERARCHY], 'assignedBy' => $data[self::ASSIGNED_BY], + 'idPolicy' => $data[self::ID_POLICY], + 'tags' => (empty($data[self::TAGS]) === false) ? explode(',', $data[self::TAGS]) : null, ] ); } - public function toDatabase(MappeableInterface $data): array { - /* - @var UserProfile $data - */ + /** @var UserProfile $data */ return [ self::ID_USER_PROFILE => $data->getIdUserProfile(), self::ID_USER => $data->getIdUser(), self::ID_PROFILE => $data->getIdProfile(), self::ID_GROUP => $data->getIdGroup(), + self::IS_NO_HIERARCHY => $data->getIsNoHierarchy(), self::ASSIGNED_BY => $data->getAssignedBy(), + self::ID_POLICY => $data->getIdPolicy(), + self::TAGS => (empty($data->getTags()) === false) ? implode(',', $data->getTags()) : null, ]; } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileFilter.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileFilter.php index 70a168c2e8..487071a183 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileFilter.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Entities/UserProfileFilter.php @@ -32,8 +32,6 @@ use PandoraFMS\Modules\Shared\Validators\Validator; */ final class UserProfileFilter extends FilterAbstract { - - public function __construct() { $this->setDefaultFieldOrder(UserProfileDataMapper::ID_USER_PROFILE); @@ -41,7 +39,6 @@ final class UserProfileFilter extends FilterAbstract $this->setEntityFilter(new UserProfile()); } - public function fieldsTranslate(): array { return [ @@ -49,19 +46,16 @@ final class UserProfileFilter extends FilterAbstract ]; } - public function fieldsReadOnly(): array { return []; } - public function jsonSerialize(): mixed { return []; } - public function getValidations(): array { $validations = []; @@ -72,11 +66,8 @@ final class UserProfileFilter extends FilterAbstract return $validations; } - public function validateFields(array $filters): array { return (new Validator())->validate($filters); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Repositories/UserProfileRepository.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Repositories/UserProfileRepository.php index 12569c6bb8..907abb0390 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Repositories/UserProfileRepository.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Repositories/UserProfileRepository.php @@ -2,26 +2,21 @@ namespace PandoraFMS\Modules\Users\UserProfiles\Repositories; +use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; +use PandoraFMS\Modules\Shared\Repositories\Repository; use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfile; use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfileDataMapper; use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfileFilter; -use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; -use PandoraFMS\Modules\Shared\Repositories\Repository; class UserProfileRepository { - - public function __construct( private Repository $repository, private UserProfileDataMapper $userProfileDataMapper ) { } - - /** - * @return UserProfile[], - */ + /** @return UserProfile[] */ public function list(UserProfileFilter $userProfileFilter): array { return $this->repository->__list( @@ -30,7 +25,6 @@ class UserProfileRepository ); } - public function count(UserProfileFilter $userProfileFilter): int { return $this->repository->__count( @@ -39,7 +33,6 @@ class UserProfileRepository ); } - public function getOne(UserProfileFilter $userProfileFilter): UserProfile { return $this->repository->__getOne( @@ -48,7 +41,6 @@ class UserProfileRepository ); } - public function create(UserProfile $userProfile): UserProfile { try { @@ -59,7 +51,6 @@ class UserProfileRepository } } - public function update(UserProfile $userProfile): UserProfile { return $this->repository->__update( @@ -69,11 +60,8 @@ class UserProfileRepository ); } - - public function delete(int $id, ?string $key=null): void + public function delete(int $id, ?string $key = null): void { $this->repository->__delete($id, $this->userProfileDataMapper, $key); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CountUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CountUserProfileService.php index 77526e0e9a..8786e01ed9 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CountUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CountUserProfileService.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class CountUserProfileService { - - public function __construct( private UserProfileRepository $userProfileRepository, ) { } - public function __invoke(UserProfileFilter $userProfileFilter): int { return $this->userProfileRepository->count($userProfileFilter); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CreateUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CreateUserProfileService.php index 39ff99621d..564174b523 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CreateUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/CreateUserProfileService.php @@ -2,16 +2,13 @@ namespace PandoraFMS\Modules\Users\UserProfiles\Services; +use PandoraFMS\Modules\Shared\Services\Audit; use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfile; use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; use PandoraFMS\Modules\Users\UserProfiles\Validations\UserProfileValidation; -use PandoraFMS\Modules\IncidenceTypes\Fields\Entities\IncidenceTypeField; -use PandoraFMS\Modules\Shared\Services\Audit; final class CreateUserProfileService { - - public function __construct( private UserProfileRepository $userProfileRepository, private UserProfileValidation $userProfileValidation, @@ -19,7 +16,6 @@ final class CreateUserProfileService ) { } - public function __invoke(UserProfile $userProfile): UserProfile { $this->userProfileValidation->__invoke($userProfile); @@ -33,6 +29,4 @@ final class CreateUserProfileService return $userProfile; } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/DeleteUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/DeleteUserProfileService.php index cd5b75889e..29e5b9f899 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/DeleteUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/DeleteUserProfileService.php @@ -2,16 +2,13 @@ namespace PandoraFMS\Modules\Users\UserProfiles\Services; +use PandoraFMS\Modules\Shared\Services\Audit; +use PandoraFMS\Modules\Shared\Services\Config; use PandoraFMS\Modules\Users\UserProfiles\Entities\UserProfile; use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; -use PandoraFMS\Modules\Shared\Services\Audit; -use PandoraFMS\Modules\Shared\Services\Config; - final class DeleteUserProfileService { - - public function __construct( private Config $config, private Audit $audit, @@ -19,7 +16,6 @@ final class DeleteUserProfileService ) { } - public function __invoke(UserProfile $userProfile): void { $id = $userProfile->getIdUserProfile(); @@ -31,6 +27,4 @@ final class DeleteUserProfileService ' Deleted field incidence type #'.$id ); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ExistUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ExistUserProfileService.php index 4f7124668f..175b540540 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ExistUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ExistUserProfileService.php @@ -9,20 +9,15 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class ExistUserProfileService { - - public function __construct( private UserProfileRepository $userProfileRepository, ) { } - public function __invoke(UserProfile $userProfile): bool { $groupFilter = new UserProfileFilter(); - /* - @var UserProfile $entityFilter - */ + /** @var UserProfile $entityFilter */ $entityFilter = $groupFilter->getEntityFilter(); $entityFilter->setIdUser($userProfile->getIdUser()); $entityFilter->setIdProfile($userProfile->getIdProfile()); @@ -35,6 +30,4 @@ final class ExistUserProfileService return false; } } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/GetUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/GetUserProfileService.php index e28f5ffbbb..ff43755db8 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/GetUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/GetUserProfileService.php @@ -8,26 +8,19 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class GetUserProfileService { - - public function __construct( private UserProfileRepository $userProfileRepository, ) { } - public function __invoke(string $idUser, int $idProfile): UserProfile { $userProfileFilter = new UserProfileFilter(); - /* - @var UserProfile $entityFilter - */ + /** @var UserProfile $entityFilter */ $entityFilter = $userProfileFilter->getEntityFilter(); $entityFilter->setIdUser($idUser); $entityFilter->setIdProfile($idProfile); return $this->userProfileRepository->getOne($userProfileFilter); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ListUserProfileService.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ListUserProfileService.php index dfa928f074..ae57f96df5 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ListUserProfileService.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Services/ListUserProfileService.php @@ -7,18 +7,13 @@ use PandoraFMS\Modules\Users\UserProfiles\Repositories\UserProfileRepository; final class ListUserProfileService { - - public function __construct( private UserProfileRepository $userProfileRepository, ) { } - public function __invoke(UserProfileFilter $userProfileFilter): array { return $this->userProfileRepository->list($userProfileFilter); } - - } diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Validations/UserProfileValidation.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Validations/UserProfileValidation.php index 7952d2bf64..cc104d34a0 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Validations/UserProfileValidation.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Validations/UserProfileValidation.php @@ -2,7 +2,7 @@ namespace PandoraFMS\Modules\Users\UserProfiles\Validations; -use PandoraFMS\Modules\Groups\Services\GetGroupService; +//use PandoraFMS\Modules\Groups\Services\GetGroupService; use PandoraFMS\Modules\Profiles\Services\GetProfileService; use PandoraFMS\Modules\Shared\Exceptions\BadRequestException; use PandoraFMS\Modules\Shared\Services\Config; @@ -13,10 +13,8 @@ use PandoraFMS\Modules\Users\UserProfiles\Services\ExistUserProfileService; final class UserProfileValidation { - - public function __construct( - private GetGroupService $getGroupService, + //private GetGroupService $getGroupService, private GetUserService $getUserService, private GetProfileService $getProfileService, private ExistUserProfileService $existUserProfileService, @@ -25,7 +23,6 @@ final class UserProfileValidation ) { } - public function __invoke(UserProfile $userProfile): void { if (!$userProfile->getIdUser()) { @@ -36,7 +33,7 @@ final class UserProfileValidation throw new BadRequestException(__('Id profile is missing')); } - if (!$userProfile->getIdGroup()) { + if ($userProfile->getIdGroup() === null || $userProfile->getIdGroup() === '') { throw new BadRequestException(__('Id group is missing')); } @@ -46,16 +43,10 @@ final class UserProfileValidation if (empty($userProfile->getIdProfile()) === false) { $this->validateProfile($userProfile->getIdProfile()); - $this->acl->validateUserProfile($userProfile->getIdProfile()); } if (empty($userProfile->getIdGroup()) === false) { $this->validateGroup($userProfile->getIdGroup()); - $this->acl->validateUserGroups( - $userProfile->getIdGroup(), - 'UM', - ' tried to manage groups' - ); } if ($this->existUserProfileService->__invoke($userProfile) === true) { @@ -63,25 +54,54 @@ final class UserProfileValidation } $userProfile->setAssignedBy($this->config->get('id_user')); - } + if ($userProfile->getIsNoHierarchy() === null) { + $userProfile->setIsNoHierarchy(false); + } + + if ($userProfile->getIdPolicy() === null) { + $userProfile->setIdPolicy(0); + } + + if (empty($userProfile->getIdPolicy()) === false) { + $this->validatePolicy($userProfile->getIdPolicy()); + } + + if (empty($userProfile->getTags()) === false) { + $this->validateTags($userProfile->getTags()); + } + } private function validateUser(string $idUser): void { $this->getUserService->__invoke($idUser); } - private function validateProfile(int $idProfile): void { $this->getProfileService->__invoke($idProfile); } - private function validateGroup(int $idGroup): void { - $this->getGroupService->__invoke($idGroup); + //$this->getGroupService->__invoke($idGroup); } + protected function validatePolicy(int $idPolicy): void + { + // TODO: create new service for this. + if (! (bool) \policies_get_policy($idPolicy)) { + throw new BadRequestException(__('Invalid id policy')); + } + } + protected function validateTags(array $tags): void + { + // TODO: create new service for this. + foreach ($tags as $tag) { + if (! (bool) \tags_get_name($tag)) { + throw new BadRequestException(__('Invalid id tag:, %', $tag)); + } + } + } } diff --git a/pandora_console/include/lib/Modules/Users/routes.php b/pandora_console/include/lib/Modules/Users/routes.php index ed7b77975d..c2d3dcaae3 100644 --- a/pandora_console/include/lib/Modules/Users/routes.php +++ b/pandora_console/include/lib/Modules/Users/routes.php @@ -13,13 +13,13 @@ use Slim\App; return function (App $app) { $app->map(['GET', 'POST'], '/user/list', ListUserController::class); - $app->get('/user/{id}', GetUserController::class); + $app->get('/user/{idUser}', GetUserController::class); $app->post('/user', CreateUserController::class); - $app->put('/user/{id}', UpdateUserController::class); - $app->delete('/user/{id}', DeleteUserController::class); + $app->put('/user/{idUser}', UpdateUserController::class); + $app->delete('/user/{idUser}', DeleteUserController::class); - $app->map(['GET', 'POST'], '/user/{id}/profiles', ListUserProfileController::class); - $app->get('/user/{id}/profile/{idProfile}', GetUserProfileController::class); - $app->post('/user/{id}/profile/{idProfile}', CreateUserProfileController::class); - $app->delete('/user/{id}/profile/{idProfile}', DeleteUserProfileController::class); + $app->map(['GET', 'POST'], '/user/{idUser}/profiles', ListUserProfileController::class); + $app->get('/user/{idUser}/profile/{idProfile}', GetUserProfileController::class); + $app->post('/user/{idUser}/profile/{idProfile}', CreateUserProfileController::class); + $app->delete('/user/{idUser}/profile/{idProfile}', DeleteUserProfileController::class); };