|
|
@@ -1,3 +1,4 @@
|
|
|
+import { Permissions } from 'src/app/interfaces/permissions.interface';
|
|
|
import { EncService } from './../../../services/enc/enc.service';
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
import { DeleteAlertComponent } from './delete-alert/delete-alert.component';
|
|
|
@@ -5,13 +6,16 @@ import { NewPasswordComponent } from './new-password/new-password.component';
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
import { UsersResponse, UserResponse } from './../../../interfaces/users.interface';
|
|
|
import { UsersProfilesService } from './../../../services/users-profiles.service';
|
|
|
-import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
|
|
+import { Component, OnInit, ViewChild } from '@angular/core';
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
import { Location } from '@angular/common';
|
|
|
+import { SocketService } from 'src/app/services/socket.service';
|
|
|
+import { UserConsultResponse } from 'src/app/interfaces/user.interface';
|
|
|
+import { ProfileInterface } from 'src/app/interfaces/profile.interface';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-users-admin',
|
|
|
@@ -39,14 +43,18 @@ export class UsersAdminComponent implements OnInit {
|
|
|
@ViewChild(MatPaginator) paginator?: MatPaginator;
|
|
|
@ViewChild(MatSort) sort?: MatSort;
|
|
|
|
|
|
+ usersConsultEnabled: boolean;
|
|
|
+ regEditUserEnabled: boolean;
|
|
|
+ blockUnblockEnabled: boolean;
|
|
|
+ changePasswordEnabled: boolean;
|
|
|
+
|
|
|
constructor(
|
|
|
- private usersProfilesService: UsersProfilesService,
|
|
|
+ private _usersProfilesService: UsersProfilesService,
|
|
|
private _snackBar: MatSnackBar,
|
|
|
- private router: Router,
|
|
|
- private dialog: MatDialog,
|
|
|
+ private _router: Router,
|
|
|
+ private _dialog: MatDialog,
|
|
|
private _encService: EncService,
|
|
|
- private _location: Location,
|
|
|
- private _activeRoute: ActivatedRoute,
|
|
|
+ private _socketService: SocketService,
|
|
|
) {
|
|
|
this.users = [];
|
|
|
this.isLoading = true;
|
|
|
@@ -60,10 +68,53 @@ export class UsersAdminComponent implements OnInit {
|
|
|
|
|
|
this.usersFinded = [];
|
|
|
this.btnSmall = window.innerWidth <= 1405;
|
|
|
+ this.usersConsultEnabled = true;
|
|
|
+ this.regEditUserEnabled = true;
|
|
|
+ this.blockUnblockEnabled = true;
|
|
|
+ this.changePasswordEnabled = true;
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
this.getData();
|
|
|
+ this._socketService.refreshPermissions().subscribe(async (profUpdEnc) => {
|
|
|
+ let shortID = await lastValueFrom(this._encService.shortEncrypt(localStorage.getItem('idusuario')!));
|
|
|
+ let usrInfo: UserConsultResponse = await lastValueFrom(this._usersProfilesService.getUser(shortID.response.encrypted, shortID.response.encrypted, 1));
|
|
|
+ let currentProfile = await this._encService.desencriptar(localStorage.getItem('perfil')!);
|
|
|
+
|
|
|
+ if(parseInt(currentProfile) != usrInfo.response.PERFIL){
|
|
|
+ this._router.navigate(['/sam/home']);
|
|
|
+ }
|
|
|
+
|
|
|
+ let profileUpdated = await this._encService.desencriptar(`${profUpdEnc}`);
|
|
|
+ if(profileUpdated == currentProfile){
|
|
|
+ try{
|
|
|
+ let shortProf = await lastValueFrom(this._encService.shortEncrypt(localStorage.getItem('perfil')!));
|
|
|
+ let profInfo: ProfileInterface = await lastValueFrom(this._usersProfilesService.getProfile(
|
|
|
+ shortProf.response.encrypted,
|
|
|
+ shortID.response.encrypted,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ let modPerm = profInfo.response.PERMISOS.permissions.filter(item => item.id == 'S002V01M02USPE')[0];
|
|
|
+ let subPerm = modPerm.children.filter(item => item.id == 'S002V01S01GEUS')[0];
|
|
|
+ let funPerm = subPerm.children.filter(item => item.id == 'S002V01F01ADUS')[0];
|
|
|
+
|
|
|
+ this.usersConsultEnabled = funPerm.children.filter(item => item.id == 'S002V01P01COUS')[0].access > 0;
|
|
|
+ this.regEditUserEnabled = funPerm.children.filter(item => item.id == 'S002V01P02RAUS')[0].access > 0;
|
|
|
+
|
|
|
+ this.blockUnblockEnabled = subPerm.children.filter(item => item.id == 'S002V01F02BDAC')[0].access > 0;
|
|
|
+ this.changePasswordEnabled = subPerm.children.filter(item => item.id == 'S002V01F03RECO')[0].access > 0;
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.openSnackBar('Ocurrió un error al actualizar su perfil');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.openSnackBar('Ocurrió un error al actualizar su perfil');
|
|
|
+ }else{
|
|
|
+ this.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
async getData(){
|
|
|
@@ -76,14 +127,13 @@ export class UsersAdminComponent implements OnInit {
|
|
|
let idEnc = localStorage.getItem('idusuario');
|
|
|
let idShort = await lastValueFrom(this._encService.shortEncrypt(idEnc!));
|
|
|
|
|
|
- let data: UsersResponse = await lastValueFrom(this.usersProfilesService.getUsers(idShort.response.encrypted, 1));
|
|
|
+ let data: UsersResponse = await lastValueFrom(this._usersProfilesService.getUsers(idShort.response.encrypted, 1));
|
|
|
let idDec = await this._encService.desencriptar(idEnc!);
|
|
|
+
|
|
|
+ this.hasError = data.error;
|
|
|
+ this.errorStr = data.msg;
|
|
|
|
|
|
- if(data.error){
|
|
|
- this.isLoading = false;
|
|
|
- this.hasError = true;
|
|
|
- this.errorStr = data.msg;
|
|
|
- }else{
|
|
|
+ if(!this.hasError){
|
|
|
data.response.forEach((item: UserResponse) => {
|
|
|
let usr: UserResponse = {
|
|
|
IDUSUARIO: item.IDUSUARIO,
|
|
|
@@ -102,8 +152,22 @@ export class UsersAdminComponent implements OnInit {
|
|
|
this.dataSource.paginator = this.paginator!;
|
|
|
this.dataSource.sort = this.sort!;
|
|
|
|
|
|
- this.isLoading = false;
|
|
|
+ let permissionsEnc = localStorage.getItem('permisos');
|
|
|
+ let permissionsDec = await this._encService.desencriptar(permissionsEnc!);
|
|
|
+ let permissionsArr: Permissions = JSON.parse(permissionsDec);
|
|
|
+
|
|
|
+ let modPerm = permissionsArr.permissions.filter(item => item.id == 'S002V01M02USPE')[0];
|
|
|
+ let subPerm = modPerm.children.filter(item => item.id == 'S002V01S01GEUS')[0];
|
|
|
+ let funPerm = subPerm.children.filter(item => item.id == 'S002V01F01ADUS')[0];
|
|
|
+
|
|
|
+ this.usersConsultEnabled = funPerm.children.filter(item => item.id == 'S002V01P01COUS')[0].access > 0;
|
|
|
+ this.regEditUserEnabled = funPerm.children.filter(item => item.id == 'S002V01P02RAUS')[0].access > 0;
|
|
|
+
|
|
|
+ this.blockUnblockEnabled = subPerm.children.filter(item => item.id == 'S002V01F02BDAC')[0].access > 0;
|
|
|
+ this.changePasswordEnabled = subPerm.children.filter(item => item.id == 'S002V01F03RECO')[0].access > 0;
|
|
|
}
|
|
|
+
|
|
|
+ this.isLoading = false;
|
|
|
}catch(error:any){
|
|
|
this.isLoading = false;
|
|
|
this.hasError = true;
|
|
|
@@ -112,7 +176,7 @@ export class UsersAdminComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
openDialog(usr: string){
|
|
|
- const dialogRef = this.dialog.open(NewPasswordComponent, {
|
|
|
+ const dialogRef = this._dialog.open(NewPasswordComponent, {
|
|
|
data: {
|
|
|
id: usr
|
|
|
}
|
|
|
@@ -153,7 +217,7 @@ export class UsersAdminComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
openAlert(usr: string){
|
|
|
- const dialogRef = this.dialog.open(DeleteAlertComponent, {
|
|
|
+ const dialogRef = this._dialog.open(DeleteAlertComponent, {
|
|
|
data: {
|
|
|
id: usr
|
|
|
}
|
|
|
@@ -166,7 +230,7 @@ export class UsersAdminComponent implements OnInit {
|
|
|
let idEnc = await this._encService.encriptar(usr);
|
|
|
let idUser = localStorage.getItem('idusuario');
|
|
|
|
|
|
- await lastValueFrom(this.usersProfilesService.deleteUser({
|
|
|
+ await lastValueFrom(this._usersProfilesService.deleteUser({
|
|
|
id: idEnc,
|
|
|
id_user: idUser,
|
|
|
linea: 1
|
|
|
@@ -197,7 +261,7 @@ export class UsersAdminComponent implements OnInit {
|
|
|
let newStatus = lastStatus == 'Activo' ? 'Inactivo' : 'Activo';
|
|
|
|
|
|
try{
|
|
|
- await lastValueFrom(this.usersProfilesService.blockUser({
|
|
|
+ await lastValueFrom(this._usersProfilesService.blockUser({
|
|
|
id: idUser,
|
|
|
estatus: newStatus,
|
|
|
id_user: idEnc,
|
|
|
@@ -225,7 +289,7 @@ export class UsersAdminComponent implements OnInit {
|
|
|
let paramsStr = JSON.stringify(params);
|
|
|
let paramsEnc = await this._encService.encriptar(paramsStr);
|
|
|
|
|
|
- this.router.navigate(['sam/USPE/GEUS/ADUS/crear'], {
|
|
|
+ this._router.navigate(['sam/USPE/GEUS/ADUS/crear'], {
|
|
|
queryParams: {
|
|
|
info: paramsEnc,
|
|
|
}
|