From 090ae8d6114419919811cea7955aedc5491e0f8f Mon Sep 17 00:00:00 2001 From: ronaldchavezjortilles Date: Thu, 17 Oct 2024 15:23:51 +0200 Subject: [PATCH 1/4] Almacenando el cache de Sinergia CRM --- .../updateModel/updateModel.controller.ts | 74 ++++++++++++------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/eda/eda_api/lib/module/updateModel/updateModel.controller.ts b/eda/eda_api/lib/module/updateModel/updateModel.controller.ts index de037c000..1d3d12a86 100644 --- a/eda/eda_api/lib/module/updateModel/updateModel.controller.ts +++ b/eda/eda_api/lib/module/updateModel/updateModel.controller.ts @@ -128,30 +128,36 @@ export class updateModel { await connection.query(query) .then(async customUserPermissionsValue => { - - let customUserPermissions = customUserPermissionsValue - - try { - crm_to_eda = await userAndGroupsToMongo.crm_to_eda_UsersAndGroups(users_crm, roles) - } catch (e) { - console.log('Error 1',e); - res.status(500).json({'status' : 'ko'}) - } - try { - grantedRolesAt = await updateModel.grantedRolesToModel(grantedRoles, tables, permissions, permissionsColumns, customUserPermissions ) - } catch (e) { - console.log('Error 2',e); - res.status(500).json({'status' : 'ko'}) - } - - console.log('Generando el modelo'); + let customUserPermissions = customUserPermissionsValue; - try { - modelToExport = updateModel.createModel(tables, columns, relations, grantedRolesAt, ennumeration, res); - } catch (e) { - console.log('Error 3',e); - res.status(500).json({'status' : 'ko'}) - } + await connection.query("select * from sda_def_config") + .then(async cacheConfigSDA => { + let cache_config_SDA = cacheConfigSDA; + + try { + crm_to_eda = await userAndGroupsToMongo.crm_to_eda_UsersAndGroups(users_crm, roles) + } catch (e) { + console.log('Error 1',e); + res.status(500).json({'status' : 'ko'}) + } + try { + grantedRolesAt = await updateModel.grantedRolesToModel(grantedRoles, tables, permissions, permissionsColumns, customUserPermissions ) + } catch (e) { + console.log('Error 2',e); + res.status(500).json({'status' : 'ko'}) + } + + console.log('Generando el modelo'); + + try { + modelToExport = updateModel.createModel(tables, columns, relations, grantedRolesAt, ennumeration, res, cache_config_SDA); + } catch (e) { + console.log('Error 3',e); + res.status(500).json({'status' : 'ko'}) + } + + }) + }) connection.end() @@ -370,7 +376,7 @@ export class updateModel { } - static createModel(tables: any, columns: any, relations: any, grantedRoles: any, ennumeration: any, res: any): string[] { + static createModel(tables: any, columns: any, relations: any, grantedRoles: any, ennumeration: any, res: any, cache_configSDA: any): string[] { let visible = false ; @@ -417,8 +423,7 @@ export class updateModel { } - this.extractJsonModelAndPushToMongo(destTables, grantedRoles, res); - + this.extractJsonModelAndPushToMongo(destTables, grantedRoles, res, cache_configSDA); return destTables; @@ -556,7 +561,7 @@ export class updateModel { - static async extractJsonModelAndPushToMongo(tables: any, grantedRoles: any, res: any) { + static async extractJsonModelAndPushToMongo(tables: any, grantedRoles: any, res: any, cache_configSDA: any) { //le damos formato json a nuestras tablas @@ -569,7 +574,20 @@ export class updateModel { main_model.ds.connection.password = EnCrypterService.encrypt(sinergiaDatabase.sinergiaConn.password); main_model.ds.model.tables = tables; //añadimos el parámetro en la columna adecuada main_model.ds.metadata.model_granted_roles = await grantedRoles; - + + // Verificando si desde Sinergia CRM viene enabled la información del cache + let sda_config_cache_enabled_value = cache_configSDA.find( v => v.key === 'sda_config_cache_enabled').value + if(sda_config_cache_enabled_value === "1") { + main_model.ds.metadata.cache_config = { + units: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_units').value, + quantity: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_quantity').value, + hours: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_hours').value, + minutes: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_minutes').value, + enabled: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_enabled').value, + } + } + // Fin de la verificación. + try { const cleanM = new CleanModel; main_model = await cleanM.cleanModel(main_model); From f064e909d621696e14a6722c4933607c8c6727d4 Mon Sep 17 00:00:00 2001 From: ronaldchavezjortilles Date: Thu, 17 Oct 2024 15:30:13 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Verificaci=C3=B3n=20de=20la=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eda/eda_api/lib/module/updateModel/updateModel.controller.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eda/eda_api/lib/module/updateModel/updateModel.controller.ts b/eda/eda_api/lib/module/updateModel/updateModel.controller.ts index 1d3d12a86..b5b4e216c 100644 --- a/eda/eda_api/lib/module/updateModel/updateModel.controller.ts +++ b/eda/eda_api/lib/module/updateModel/updateModel.controller.ts @@ -577,6 +577,7 @@ export class updateModel { // Verificando si desde Sinergia CRM viene enabled la información del cache let sda_config_cache_enabled_value = cache_configSDA.find( v => v.key === 'sda_config_cache_enabled').value + // Se pueden configurar mas variables if(sda_config_cache_enabled_value === "1") { main_model.ds.metadata.cache_config = { units: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_units').value, @@ -585,6 +586,10 @@ export class updateModel { minutes: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_minutes').value, enabled: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_enabled').value, } + } else { + main_model.ds.metadata.cache_config = { + enabled: "0" + } } // Fin de la verificación. From c7fb40600c7bec24162f4dbc4f74296edb76a940 Mon Sep 17 00:00:00 2001 From: ronaldchavezjortilles Date: Fri, 18 Oct 2024 11:14:26 +0200 Subject: [PATCH 3/4] Se cambio el enable de 1 y 0 por true y false --- .../lib/module/updateModel/updateModel.controller.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eda/eda_api/lib/module/updateModel/updateModel.controller.ts b/eda/eda_api/lib/module/updateModel/updateModel.controller.ts index b5b4e216c..ff6f885b6 100644 --- a/eda/eda_api/lib/module/updateModel/updateModel.controller.ts +++ b/eda/eda_api/lib/module/updateModel/updateModel.controller.ts @@ -584,11 +584,15 @@ export class updateModel { quantity: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_quantity').value, hours: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_hours').value, minutes: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_minutes').value, - enabled: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_enabled').value, + enabled: true, } } else { main_model.ds.metadata.cache_config = { - enabled: "0" + units: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_units').value, + quantity: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_quantity').value, + hours: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_hours').value, + minutes: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_minutes').value, + enabled: false, } } // Fin de la verificación. From 45a2e95c0062f8f11ae8814b9e28f9256b1d14a5 Mon Sep 17 00:00:00 2001 From: Juanjo Date: Tue, 3 Dec 2024 11:35:53 +0100 Subject: [PATCH 4/4] =?UTF-8?q?A=C3=B1adido=20control=20de=20seguridad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../updateModel/updateModel.controller.ts | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/eda/eda_api/lib/module/updateModel/updateModel.controller.ts b/eda/eda_api/lib/module/updateModel/updateModel.controller.ts index ff6f885b6..42300b4f7 100644 --- a/eda/eda_api/lib/module/updateModel/updateModel.controller.ts +++ b/eda/eda_api/lib/module/updateModel/updateModel.controller.ts @@ -130,7 +130,7 @@ export class updateModel { .then(async customUserPermissionsValue => { let customUserPermissions = customUserPermissionsValue; - await connection.query("select * from sda_def_config") + await connection.query("select `key`, `value` from sda_def_config") .then(async cacheConfigSDA => { let cache_config_SDA = cacheConfigSDA; @@ -575,27 +575,35 @@ export class updateModel { main_model.ds.model.tables = tables; //añadimos el parámetro en la columna adecuada main_model.ds.metadata.model_granted_roles = await grantedRoles; - // Verificando si desde Sinergia CRM viene enabled la información del cache - let sda_config_cache_enabled_value = cache_configSDA.find( v => v.key === 'sda_config_cache_enabled').value - // Se pueden configurar mas variables - if(sda_config_cache_enabled_value === "1") { - main_model.ds.metadata.cache_config = { - units: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_units').value, - quantity: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_quantity').value, - hours: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_hours').value, - minutes: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_minutes').value, - enabled: true, - } - } else { - main_model.ds.metadata.cache_config = { - units: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_units').value, - quantity: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_quantity').value, - hours: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_hours').value, - minutes: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_minutes').value, - enabled: false, - } + + + try{ + // Verificando si desde Sinergia CRM viene enabled la información del cache + let sda_config_cache_enabled_value = cache_configSDA.find( v => v.key === 'sda_config_cache_enabled').value + // Se pueden configurar mas variables + if(sda_config_cache_enabled_value === "1") { + main_model.ds.metadata.cache_config = { + units: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_units').value, + quantity: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_quantity').value, + hours: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_hours').value, + minutes: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_minutes').value, + enabled: true, + } + } else { + main_model.ds.metadata.cache_config = { + units: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_units').value, + quantity: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_quantity').value, + hours: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_hours').value, + minutes: cache_configSDA.find( (v: any) => v.key === 'sda_config_cache_minutes').value, + enabled: false, + } + } + + }catch( e){ + console.log('\n \n \n IT IS MISSING SOME OF THE CACHE CONFIGURATION. WE DISABLE IT! \n \n \n ') + main_model.ds.metadata.cache_config.enabled = false; } - // Fin de la verificación. + try { const cleanM = new CleanModel;