From 122e194b16c44d34f3b7a134b35a0a86ded63bb3 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Sun, 5 May 2024 21:52:42 +0200 Subject: [PATCH] Completada visualizacion y traduccion de roles y permisos --- .../Controllers/Configuracion/Calendario.php | 25 --- ci4/app/Controllers/Configuracion/Group.php | 100 ++++------- .../{UserGroupEntity.php => GroupEntity.php} | 3 +- ci4/app/Entities/Usuarios/PermisosEntity.php | 20 +++ ci4/app/Language/es/Group.php | 56 ------ ci4/app/Language/es/RolesPermisos.php | 65 +++++++ ci4/app/Models/Usuarios/GroupModel.php | 6 +- ci4/app/Models/Usuarios/GroupsUsersModel.php | 16 -- ci4/app/Models/Usuarios/PermisosModel.php | 92 ++++++++++ .../vuexy/form/group/viewUserGroupForm.php | 119 +++++++------ .../vuexy/form/group/viewUserGroupList.php | 6 +- .../backend/vuexy/form/notification/form.php | 166 ------------------ .../backend/vuexy/form/notification/index.php | 149 ---------------- getMethod( | 0 14 files changed, 283 insertions(+), 540 deletions(-) delete mode 100755 ci4/app/Controllers/Configuracion/Calendario.php rename ci4/app/Entities/Usuarios/{UserGroupEntity.php => GroupEntity.php} (78%) mode change 100755 => 100644 create mode 100644 ci4/app/Entities/Usuarios/PermisosEntity.php delete mode 100755 ci4/app/Language/es/Group.php create mode 100644 ci4/app/Language/es/RolesPermisos.php delete mode 100644 ci4/app/Models/Usuarios/GroupsUsersModel.php create mode 100644 ci4/app/Models/Usuarios/PermisosModel.php delete mode 100755 ci4/app/Views/themes/backend/vuexy/form/notification/form.php delete mode 100755 ci4/app/Views/themes/backend/vuexy/form/notification/index.php delete mode 100644 getMethod( diff --git a/ci4/app/Controllers/Configuracion/Calendario.php b/ci4/app/Controllers/Configuracion/Calendario.php deleted file mode 100755 index 82fa2c9f..00000000 --- a/ci4/app/Controllers/Configuracion/Calendario.php +++ /dev/null @@ -1,25 +0,0 @@ -viewData['pageTitle'] = lang('Group.moduleTitle'); self::$viewPath = getenv('theme.path') . 'form/group/'; + // Breadcrumbs + $this->viewData['breadcrumb'] = [ + ['title' => "Home", 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_permission_group"), 'route' => site_url("configuracion/group"), 'active' => true] + ]; + parent::initController($request, $response, $logger); } @@ -47,46 +53,35 @@ class Group extends \App\Controllers\GoBaseController if ($this->request->getPost()) : - $nullIfEmpty = true; // !(phpversion() >= '8.1'); - $postData = $this->request->getPost(); + $temp_data['id'] = $groupEntity->id; + $temp_data['name'] = $postData['name']; + $temp_data['description'] = $postData['description']; - $name = $postData['name']; - unset($postData['name']); + // Clear not rules fields + unset($postData['safekat_token']); unset($postData['id']); + unset($postData['name']); + unset($postData['description']); unset($postData['save']); + unset($postData['selectAll']); - $controller = null; - $rules_access = null; - + $rules_access = []; foreach ($postData as $key => $value) { $exp = explode('_', $key); - $controller[] = $exp[0]; - } - - if ($controller != null) { - foreach (array_unique($controller) as $item) { - $rules_access[$item] = []; - - foreach ($postData as $key => $value) { - $exp = explode('_', $key); - if ($exp[0] == $item) { - array_push($rules_access[$item], str_replace($exp[0] . '_', '', $key)); - } - } + if (!isset($rules_access[$exp[0]])) { + $rules_access[$exp[0]] = []; } + array_push($rules_access[$exp[0]], str_replace($exp[0] . '_', '', $key)); } - $temp_data['rules'] = json_encode($rules_access ?? '{}'); - $temp_data['name'] = $name; - $sanitizedData = $this->sanitized($temp_data, $nullIfEmpty); + $sanitizedData = $this->sanitized($temp_data, true); $noException = true; - if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : - + if ($successfulResult = $this->canValidate()) : if ($this->canValidate()) : try { @@ -123,9 +118,8 @@ class Group extends \App\Controllers\GoBaseController endif; // ($requestMethod === 'post') $this->viewData['group'] = isset($sanitizedData) ? new GroupModel($sanitizedData) : new GroupModel(); + $this->viewData['permisos'] = (new PermisosModel())->find(); $this->viewData['formAction'] = route_to('createGroup'); - $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Group.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix'); - return $this->displayForm(__METHOD__); } @@ -135,7 +129,6 @@ class Group extends \App\Controllers\GoBaseController { helper('general'); - $session = session(); if ($requestedId == null) : return $this->redirect2listView(); @@ -148,49 +141,37 @@ class Group extends \App\Controllers\GoBaseController return $this->redirect2listView('errorMessage', $message); endif; - - if ($this->request->getPost()) : - $nullIfEmpty = true; // !(phpversion() >= '8.1'); - $postData = $this->request->getPost(); - $id_group = $groupEntity->id; - $name = $postData['name']; + $temp_data['id'] = $groupEntity->id; + $temp_data['name'] = $postData['name']; + $temp_data['description'] = $postData['description']; + + // Clear not rules fields + unset($postData['safekat_token']); unset($postData['id']); unset($postData['name']); + unset($postData['description']); + unset($postData['save']); + unset($postData['selectAll']); - $controller = null; - $rules_access = null; - + $rules_access = []; foreach ($postData as $key => $value) { $exp = explode('_', $key); - $controller[] = $exp[0]; - } - - if ($controller != null) { - foreach (array_unique($controller) as $item) { - $rules_access[$item] = []; - - foreach ($postData as $key => $value) { - $exp = explode('_', $key); - if ($exp[0] == $item) { - array_push($rules_access[$item], str_replace($exp[0] . '_', '', $key)); - } - } + if (!isset($rules_access[$exp[0]])) { + $rules_access[$exp[0]] = []; } + array_push($rules_access[$exp[0]], str_replace($exp[0] . '_', '', $key)); } - $temp_data['id'] = $id_group; $temp_data['rules'] = json_encode($rules_access ?? '{}'); - $temp_data['name'] = $name; - $sanitizedData = $this->sanitized($temp_data, $nullIfEmpty); + $sanitizedData = $this->sanitized($temp_data, true); $noException = true; - if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : - + if ($successfulResult = $this->canValidate()) : if ($this->canValidate()) : try { @@ -209,13 +190,11 @@ class Group extends \App\Controllers\GoBaseController $thenRedirect = false; endif; + if ($noException && $successfulResult) : $id = $groupEntity->id ?? $id; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; - if ($session->get('group') == $this->request->getPost('token')) { - $session->set('rules', $temp_data['rules']); - } if ($thenRedirect) : if (!empty($this->indexRoute)) : return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message); @@ -230,9 +209,8 @@ class Group extends \App\Controllers\GoBaseController endif; // ($requestMethod === 'post') $this->viewData['group'] = $groupEntity; + $this->viewData['permisos'] = (new PermisosModel())->find(); $this->viewData['formAction'] = route_to('updateGroup', $id); - $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Group.userGroup') . ' ' . lang('Basic.global.edit3'); - return $this->displayForm(__METHOD__, $id); } // end function edit(...) diff --git a/ci4/app/Entities/Usuarios/UserGroupEntity.php b/ci4/app/Entities/Usuarios/GroupEntity.php old mode 100755 new mode 100644 similarity index 78% rename from ci4/app/Entities/Usuarios/UserGroupEntity.php rename to ci4/app/Entities/Usuarios/GroupEntity.php index 7227916a..d429cf15 --- a/ci4/app/Entities/Usuarios/UserGroupEntity.php +++ b/ci4/app/Entities/Usuarios/GroupEntity.php @@ -3,10 +3,11 @@ namespace App\Entities\Usuarios; use CodeIgniter\Entity; -class UserGroupEntity extends \CodeIgniter\Entity\Entity +class GroupEntity extends \CodeIgniter\Entity\Entity { protected $attributes = [ "id" => null, + "keyword" => null, "name" => null, "description" => null, "rules" => null, diff --git a/ci4/app/Entities/Usuarios/PermisosEntity.php b/ci4/app/Entities/Usuarios/PermisosEntity.php new file mode 100644 index 00000000..339cdd56 --- /dev/null +++ b/ci4/app/Entities/Usuarios/PermisosEntity.php @@ -0,0 +1,20 @@ + null, + "keyword" => null, + "name" => null, + "description" => null, + "rules" => null, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "rules" => "json", + ]; +} diff --git a/ci4/app/Language/es/Group.php b/ci4/app/Language/es/Group.php deleted file mode 100755 index 8f1a9e18..00000000 --- a/ci4/app/Language/es/Group.php +++ /dev/null @@ -1,56 +0,0 @@ - 'Creado en', - 'dashboard' => 'Panel', - 'group_grid_dashboard' => 'Panel', - 'idGroup' => 'ID Rol', - 'moduleTitle' => 'Roles y Permisos', - 'rules' => 'Reglas', - 'title' => 'Nombre', - 'group_grid_title' => 'Nombre', - 'token' => 'Token', - 'updatedAt' => 'Actualizado en', - 'groups' => 'Roles y Permisos', - 'Group' => 'Rol y Permisos', - 'userGroup' => 'Rol y Permisos', - 'group' => 'Rol y Permisos', - 'grouplist' => 'Lista Roles y Permisos', - 'Groups' => 'Roles y Permisos', - 'validation' => [ - 'id_group' => [ - 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', - - ], - - 'dashboard' => [ - 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', - 'required' => 'El campo {field} es obligatorio.', - - ], - - 'rules' => [ - 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', - 'required' => 'El campo {field} es obligatorio.', - - ], - - 'title' => [ - 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', - 'required' => 'El campo {field} es obligatorio.', - - ], - - 'token' => [ - 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', - 'required' => 'El campo {field} es obligatorio.', - - ], - - - ], - - -]; \ No newline at end of file diff --git a/ci4/app/Language/es/RolesPermisos.php b/ci4/app/Language/es/RolesPermisos.php new file mode 100644 index 00000000..7f0a9d4b --- /dev/null +++ b/ci4/app/Language/es/RolesPermisos.php @@ -0,0 +1,65 @@ + 'Roles y Permisos', + 'name' => 'Nombre del Grupo', + 'rules' => 'Reglas', + 'createdAt' => 'Creado en', + 'updatedAt' => 'Actualizado en', + + 'addRol' => 'Añadir rol si no existe', + 'totalUsers' => ' usuarios en total', + 'editRol' => 'Editar Rol', + 'rolName' => 'Nombre del Rol', + 'rolDescription' => 'Descripción del Rol', + 'rolPermissions' => 'Permisos del Rol', + 'selectAll' => 'Seleccionar todos', + + 'adminRol' => 'Rol de Administrador', + 'adminRolTooltip' => 'Permitir acceso completo al sistema', + + // System permissions + 'createPermission' => 'Crear', + 'editPermission' => 'Editar', + 'deletePermission' => 'Eliminar', + + // System sections + 'clientesSection' => 'Clientes', + 'plantillaTarifaSection' => 'Plantilla de tarifas', + 'presupuestoSection' => 'Presupuestos', + 'tarifaPreimpresionSection' => 'Tarifas de preimpresión', + 'tarifaManipuladoSection' => 'Tarifas de manipulado', + 'tarifaAcabadoSection' => 'Tarifas de acabado', + 'tarifaEncuadernacionSection' => 'Tarifas de encuadernación', + 'tarifaEnvioSection' => 'Tarifas de envio', + 'proveedoresSection' => 'Proveedores', + 'ajustesSection' => 'Ajustes', + 'actividadSection' => 'Accesos', + + + + 'validation' => [ + 'id' => [ + 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', + ], + 'keyword' => [ + 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', + 'required' => 'El campo {field} es obligatorio.', + ], + 'name' => [ + 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', + 'required' => 'El campo {field} es obligatorio.', + ], + 'description' => [ + 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', + 'required' => 'El campo {field} es obligatorio.', + ], + 'rules' => [ + 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', + 'required' => 'El campo {field} es obligatorio.', + + ], + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Models/Usuarios/GroupModel.php b/ci4/app/Models/Usuarios/GroupModel.php index fea14738..24080a49 100644 --- a/ci4/app/Models/Usuarios/GroupModel.php +++ b/ci4/app/Models/Usuarios/GroupModel.php @@ -30,15 +30,15 @@ class GroupModel extends \App\Models\BaseModel 7 => "t1.updated_at", ]; - protected $allowedFields = ["id", "name", "description", "rules"]; - protected $returnType = "App\Entities\Usuarios\UserGroupEntity"; + protected $allowedFields = ["id", "keyword", "name", "description", "rules"]; + protected $returnType = "App\Entities\Usuarios\GroupEntity"; public static $labelField = "name"; protected $validationRules = [ "description" => [ "label" => "UserGroups.description", - "rules" => "required|max_length[150]", + "rules" => "max_length[150]", ], "name" => [ "label" => "UserGroups.name", diff --git a/ci4/app/Models/Usuarios/GroupsUsersModel.php b/ci4/app/Models/Usuarios/GroupsUsersModel.php deleted file mode 100644 index 8b40e4d6..00000000 --- a/ci4/app/Models/Usuarios/GroupsUsersModel.php +++ /dev/null @@ -1,16 +0,0 @@ -select('token_user')->where('token_group', $token_group)->countAllResults(); - return $result; - } -} \ No newline at end of file diff --git a/ci4/app/Models/Usuarios/PermisosModel.php b/ci4/app/Models/Usuarios/PermisosModel.php new file mode 100644 index 00000000..bfb72f37 --- /dev/null +++ b/ci4/app/Models/Usuarios/PermisosModel.php @@ -0,0 +1,92 @@ + "t1.id", + 2 => "t1.keyword", + 3 => "t1.name", + 4 => "t1.description", + 5 => "t1.rules", + 6 => "t1.created_at", + 7 => "t1.updated_at", + ]; + + protected $allowedFields = ["id", "keyword", "name", "description", "rules"]; + protected $returnType = "App\Entities\Usuarios\PermisosEntity"; + + public static $labelField = "name"; + + protected $validationRules = [ + "description" => [ + "label" => "UserGroups.description", + "rules" => "max_length[150]", + ], + "name" => [ + "label" => "UserGroups.name", + "rules" => "required|max_length[50]", + ], + + ]; + + protected $validationMessages = [ + "description" => [ + "max_length" => "UserGroups.validation.description.max_length", + "required" => "UserGroups.validation.description.required", + ], + "name" => [ + "max_length" => "UserGroups.validation.name.max_length", + "required" => "UserGroups.validation.name.required", + ], + + ]; + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource(string $search = "") + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.keyword AS keyword, t1.name AS name, t1.description AS description, t1.rules AS rules, + t1.token AS token, t1.created_at AS created_at, t1.updated_at AS updated_at" + ); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orLike("t1.keyword", $search) + ->orLike("t1.name", $search) + ->orLike("t1.description", $search) + ->orLike("t1.rules", $search) + ->orLike("t1.created_at", $search) + ->orLike("t1.updated_at", $search) + ->groupEnd(); + } + +} diff --git a/ci4/app/Views/themes/backend/vuexy/form/group/viewUserGroupForm.php b/ci4/app/Views/themes/backend/vuexy/form/group/viewUserGroupForm.php index f05e66a6..d136000b 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/group/viewUserGroupForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/group/viewUserGroupForm.php @@ -6,7 +6,7 @@
-

+

@@ -14,79 +14,81 @@
-
+
-
-
-
- - +
+ +
+
-
Role Permissions
+
- + - - - + + + + + rules as $key => $rules): ?> - - - - - + + + - - +
- Recurso + + + " + data-bs-original-title=""> + + +
+ + +
-
- - -
-
+ name ?> +
-
- rules, $item['name'], $subitem) ? 'checked' : '' ?> - > - -
-
+    + +
+ rules, $key, $rule) ? 'checked' : '' ?> + > + +
+
@@ -109,15 +111,12 @@ section('additionalInlineJs') ?> -$('#select_all').on('click', function () { - $(':checkbox').each(function() { - this.checked = true; - }); -}); -$('#remove_all').on('click', function () { - $(':checkbox').each(function() { - this.checked = false; +$('input[name="selectAll"]').click(function() { + var checkedStatus = this.checked; + $('input[type="checkbox"]').each(function() { + this.checked = checkedStatus; }); }); + endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/form/group/viewUserGroupList.php b/ci4/app/Views/themes/backend/vuexy/form/group/viewUserGroupList.php index f26aceb9..29dab37d 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/group/viewUserGroupList.php +++ b/ci4/app/Views/themes/backend/vuexy/form/group/viewUserGroupList.php @@ -5,7 +5,7 @@
-

+

@@ -31,7 +31,7 @@ > -

Añadir rol si no existe

+

@@ -43,7 +43,7 @@
-
getUsersWithRol($item->keyword); ?> usuarios en total
+
getUsersWithRol($item->keyword); ?>
diff --git a/ci4/app/Views/themes/backend/vuexy/form/notification/form.php b/ci4/app/Views/themes/backend/vuexy/form/notification/form.php deleted file mode 100755 index 5dd0ecc9..00000000 --- a/ci4/app/Views/themes/backend/vuexy/form/notification/form.php +++ /dev/null @@ -1,166 +0,0 @@ - -" rel="stylesheet"> - -
-
-
-
-
-

- -
-
-
- -
-
-
-
-
-
-
-
-

-
-
- - - -
-
-
-
- - " method="post"> - -
-
-
-
- - - -
-
-
-
- - -
-
-
-
- - -
-
-
-
-
- -
-
-
- -
- > - -
-
-
-
-
-
- - - - -
- -
-
-
-
-
-
- - - - - - - - - - - - - \ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/form/notification/index.php b/ci4/app/Views/themes/backend/vuexy/form/notification/index.php deleted file mode 100755 index 1afde407..00000000 --- a/ci4/app/Views/themes/backend/vuexy/form/notification/index.php +++ /dev/null @@ -1,149 +0,0 @@ - -
-
-
-
-
-

- -
-
-
- -
-
- -
-
-
-
-
-

-
-
- - - -
-
-
- - - -
- - - - - - - - - - - - -
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - diff --git a/getMethod( b/getMethod( deleted file mode 100644 index e69de29b..00000000