diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index 455c78ec..a669d1d3 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -55,6 +55,8 @@ class Users extends \App\Controllers\GoBaseController { $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]); $this->viewData['user_model'] = $this->user_model; + $this->viewData['userList2'] = $this->user_model->getUsersList(); + parent::index(); } @@ -136,6 +138,7 @@ class Users extends \App\Controllers\GoBaseController { endif; // ($requestMethod === 'post') $this->viewData['user'] = isset($sanitizedData) ? new UserEntity($sanitizedData) : new UserEntity(); + $this->viewData['clienteList'] = $this->getClienteListItems(); $this->viewData['formAction'] = route_to('createUser'); $this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll(); $this->viewData['boxTitle'] = lang('Basic.global.addNew') .lang('Users.user').' '.lang('Basic.global.addNewSuffix'); @@ -176,7 +179,22 @@ class Users extends \App\Controllers\GoBaseController { if ($this->canValidate()) : try { - $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + if (in_array('cliente-editor', $currentGroups) || in_array('cliente-administrador', $currentGroups)) { + if(!array_key_exists('cliente_id', $sanitizedData) || is_null($sanitizedData['cliente_id'])) { + $this->viewData['errorMessage'] = lang('Users.errors.cliente_sin_clienteID'); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + $successfulResult = false; + } + else{ + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } + } + else { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } + + } catch (\Exception $e) { $noException = false; $this->dealWithException($e); @@ -221,6 +239,7 @@ class Users extends \App\Controllers\GoBaseController { endif; // ($requestMethod === 'post') $this->viewData['user'] = $user; + $this->viewData['clienteList'] = $this->getClienteListItems($user->cliente_id); $this->viewData['formAction'] = route_to('updateUser', $id); $this->viewData['selectedGroups'] = $this->group_model->getUsersRoles($requestedId); $this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll(); @@ -329,5 +348,19 @@ class Users extends \App\Controllers\GoBaseController { return $registers; } + + protected function getClienteListItems($selId = null) + { + $data = ['' => ""]; + if (!empty($selId)) : + $clienteModel = model('App\Models\Clientes\ClienteModel'); + + $selOption = $clienteModel->where('id', $selId)->findColumn('nombre'); + if (!empty($selOption)) : + $data[$selId] = $selOption[0]; + endif; + endif; + return $data; + } } diff --git a/ci4/app/Entities/Usuarios/UserEntity.php b/ci4/app/Entities/Usuarios/UserEntity.php index 33d26f31..0c1d5383 100755 --- a/ci4/app/Entities/Usuarios/UserEntity.php +++ b/ci4/app/Entities/Usuarios/UserEntity.php @@ -6,36 +6,23 @@ use CodeIgniter\Entity; class UserEntity extends \CodeIgniter\Entity\Entity { protected $attributes = [ - "id_user" => null, + "id" => null, "first_name" => null, "last_name" => null, - "date_birth" => null, - "address" => "", - "city" => "", - "state" => "", - "country" => "", - "zip_code" => "", - "mobile" => null, - "email" => null, - "password" => null, - "last_ip" => null, - "last_access" => null, - "picture" => "/assets/img/default-user.png", - "language" => null, - "tfa" => false, - "tfa_secret" => "", - "tfa_code" => "", - "blocked" => null, - "email_confirmed" => 0, - "token" => null, - "status" => false, + "cliente_id" => null, + "status" => null, + "status_message" => null, + 'active' => null, + "last_active" => null, "created_at" => null, "updated_at" => null, + "deleted_at" => null, + ]; protected $casts = [ - "tfa" => "boolean", - "email_confirmed" => "int", - "status" => "boolean", + "id" => "int", + "cliente_id" => "int", + "active" => "boolean", ]; /** * Returns a full name: "first last" diff --git a/ci4/app/Language/en/Users.php b/ci4/app/Language/en/Users.php index 9260533d..116d67bc 100755 --- a/ci4/app/Language/en/Users.php +++ b/ci4/app/Language/en/Users.php @@ -38,6 +38,23 @@ return [ 'userList' => 'User List', 'users' => 'Users', 'zipCode' => 'Zip Code', + + 'admin' => 'Administrator', + 'cliente-admin' => 'Client administrator', + 'cliente-editor' => 'Client editor', + 'comercial' => 'Commercial', + 'produccion' => 'Production', + 'maquina' => 'Machine', + 'maquetador' => 'Layout designer', + 'director' => 'Director', + 'contabilidad' => 'Accounting', + 'editor' => 'Editor', + 'beta' => 'Beta', + + 'errors' => [ + 'cliente_sin_clienteID' => 'The user must have a client assigned when using any client role.', + ], + 'validation' => [ 'address' => [ 'max_length' => 'The {field} field cannot exceed {param} characters in length.', diff --git a/ci4/app/Language/es/Users.php b/ci4/app/Language/es/Users.php index 4bdd4884..3417f937 100755 --- a/ci4/app/Language/es/Users.php +++ b/ci4/app/Language/es/Users.php @@ -38,6 +38,23 @@ return [ 'userList' => 'Lista de usuarios', 'users' => 'Usuarios', 'zipCode' => 'Código postal', + + 'admin' => 'Administrador', + 'cliente-admin' => 'Cliente administrador', + 'cliente-editor' => 'Cliente editor', + 'comercial' => 'Comercial', + 'produccion' => 'Producción', + 'maquina' => 'Máquina', + 'maquetador' => 'Maquetador', + 'director' => 'Director', + 'contabilidad' => 'Contabilidad', + 'editor' => 'Editor', + 'beta' => 'Beta', + + 'errors' => [ + 'cliente_sin_clienteID' => 'El usuario debe de tener un cliente asignado cuando se usa algún rol de cliente.', + ], + 'validation' => [ 'address' => [ 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', diff --git a/ci4/app/Models/UserModel.php b/ci4/app/Models/UserModel.php index 18ead92b..934604ff 100644 --- a/ci4/app/Models/UserModel.php +++ b/ci4/app/Models/UserModel.php @@ -16,9 +16,17 @@ class UserModel extends ShieldUserModel ...$this->allowedFields, 'first_name', // Añadido 'last_name', // Añadido + 'cliente_id', // Añadido ]; } + protected $useSoftDeletes = true; + protected $useTimestamps = true; + protected $createdField = 'created_at'; + protected $updatedField = 'updated_at'; + protected $deletedField = 'deleted_at'; + + protected $validationRules = [ "username" => [ "label" => "correo duplicado", @@ -42,4 +50,18 @@ class UserModel extends ShieldUserModel return $builder->get()->getResult(); } + + public function getUsersList(){ + $builder = $this->db + ->table("users" . " t1") + ->select( + "t1.id AS id, t1.first_name AS first_name, t1.last_name AS last_name, t1.last_active AS last_active, t2.group AS group" + ); + + $builder->where('t1.deleted_at', null); + $builder->join("auth_groups_users t2", "t1.id = t2.user_id", "left"); + + return $builder->get()->getResult(); + + } } diff --git a/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php b/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php index 976fecde..ba0c3c02 100644 --- a/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/user/_userFormItems.php @@ -73,5 +73,22 @@ +