add checking duplicates in InitialData

parent 428a47db
module.exports = function(session){
"use strict";
var
csvLoader = require('@unitybase/base').dataLoader,
conn = session.connection;
console.info('\t\tFill enumeration for RequestList model');
csvLoader.loadSimpleCSVData(conn, __dirname + '/ubm_enum-req.csv', 'ubm_enum', 'eGroup;code;name;sortOrder'.split(';'), [0, 1, 2, 3]);
const path = require('path')
const fs = require('fs')
const {dataLoader, csv, argv} = require('@unitybase/base')
let conn = session.connection;
let fn = path.join(__dirname, '/ubm_enum-req.csv')
let fContent = fs.readFileSync(fn)
if (!fContent) { throw new Error(`File ${fn} is empty or not exist`) }
fContent = fContent.trim()
let csvData = csv.parse(fContent)
let notExisted = csvData.filter(
(row) => !conn.lookup('ubm_enum', 'code',
conn.Repository('ubm_enum').where('code', '=', row[1]).ubql().whereList
)
)
console.info('\t\tFill enumeration for RequestList model');
dataLoader.loadArrayData(conn, notExisted, 'ubm_enum', 'eGroup;code;name;sortOrder'.split(';'), [0, 1, 2, 3]);
};
\ No newline at end of file
module.exports = function(session){
"use strict";
var
csvLoader = require('@unitybase/base').dataLoader,
conn = session.connection;
console.info('\t\tFill Departments field (req_depart)');
csvLoader.loadSimpleCSVData(conn, __dirname + '/req_depart.csv', 'req_depart', 'name;postAddr;phoneNum'.split(';'), [0,1,2], 1);
const path = require('path')
const fs = require('fs')
const {dataLoader, csv, argv} = require('@unitybase/base')
let conn = session.connection;
let fn = path.join(__dirname, '/req_depart.csv')
let fContent = fs.readFileSync(fn)
if (!fContent) { throw new Error(`File ${fn} is empty or not exist`) }
fContent = fContent.trim()
let csvData = csv.parse(fContent)
let notExisted = csvData.filter(
(row) => !conn.lookup('req_depart', 'ID',
conn.Repository('req_depart').where('name', '=', row[0]).ubql().whereList
)
)
console.info('\t\tFill Departments field (req_depart)');
dataLoader.loadArrayData(conn, notExisted, 'req_depart', 'name;postAddr;phoneNum'.split(';'), [0,1,2], 1);
};
\ No newline at end of file
......@@ -43,6 +43,11 @@ console.info('\t\tcreate new `HealthDepartment` role');
});
}
var checkUserInRole = conn.lookup('uba_userrole', 'ID',
conn.Repository('uba_userrole').where('userID', '=', userID).where('roleID', '=', usersRoleID).ubRequest().whereList
);
if(!checkUserInRole)
{
console.info('\t\tadd hd_user to Health department role');
conn.insert({
entity: 'uba_userrole',
......@@ -51,10 +56,15 @@ console.info('\t\tadd hd_user to Health department role');
roleID: usersRoleID
}
});
}
desktopID = conn.lookup('ubm_desktop', 'ID', {expression: 'code', condition: 'equal', values: {code: 'CityReq_desktop'}});
if(desktopID){
var checkRoleInDesktop = conn.lookup('ubm_desktop_adm', 'ID',
conn.Repository('ubm_desktop_adm').where('instanceID', '=', desktopID).where('admSubjID', '=', usersRoleID).ubRequest().whereList
);
if(!checkRoleInDesktop){
console.info('\t\tprovide rights for `CityReq_desktop` to HealthDepartment role');
conn.insert({
entity: 'ubm_desktop_adm',
......@@ -63,10 +73,15 @@ console.info('\t\tprovide rights for `CityReq_desktop` to HealthDepartment role'
admSubjID: usersRoleID
}
});
}
lastID=conn.lookup('ubm_navshortcut', 'ID',{expression: 'code', condition: 'equal', values: {code: 'req_reqList'}});
if(lastID){
console.info('\t\tprovide rights for `req_reqList` folder to HealthDepartment role');
var checkRoleInShortcut = conn.lookup('ubm_navshortcut_adm', 'ID',
conn.Repository('ubm_navshortcut_adm').where('instanceID', '=', lastID).where('admSubjID', '=', usersRoleID).ubRequest().whereList
);
if(!checkRoleInShortcut){
console.info('\t\tprovide rights for `req_reqList` shortcut to HealthDepartment role');
conn.insert({
entity: 'ubm_navshortcut_adm',
execParams: {
......@@ -75,11 +90,16 @@ console.info('\t\tprovide rights for `req_reqList` folder to HealthDepartment ro
}
});
}
}
}
//entity level security
var checkCodeEls = conn.lookup('uba_els', 'ID',
conn.Repository('uba_els').where('code', '=', 'READ_UPD_REQ_HD').ubRequest().whereList
);
if(!checkCodeEls){
console.info('\t\tprovide rights for `req*` entities to HealthDepartment role');
conn.insert({
entity: 'uba_els',
......@@ -88,11 +108,12 @@ console.info('\t\tprovide rights for `req*` entities to HealthDepartment role');
entityMask: 'req*',
methodMask: '[su]*',
ruleType: 'A',
ruleRole: 'HealthDepartment',
ruleRole: usersRoleID,
description: 'Read and update RequestList model'
}
});
}
//ed_user and Education Department role
userID=conn.lookup('uba_user', 'ID',{expression: 'name', condition: 'equal', values: {code: 'ed_user'}});
......@@ -123,6 +144,11 @@ console.info('\t\tcreate new `EducationDepartment` role');
});
}
var checkUserInRole = conn.lookup('uba_userrole', 'ID',
conn.Repository('uba_userrole').where('userID', '=', userID).where('roleID', '=', usersRoleID).ubRequest().whereList
);
if(!checkUserInRole)
{
console.info('\t\tadd ed_user to Education department role');
conn.insert({
entity: 'uba_userrole',
......@@ -132,10 +158,14 @@ console.info('\t\tadd ed_user to Education department role');
}
});
}
desktopID = conn.lookup('ubm_desktop', 'ID', {expression: 'code', condition: 'equal', values: {code: 'CityReq_desktop'}});
if(desktopID){
console.info('\t\tprovide rights for `CityReq_desktop` to HealthDepartment role');
var checkRoleInDesktop = conn.lookup('ubm_desktop_adm', 'ID',
conn.Repository('ubm_desktop_adm').where('instanceID', '=', desktopID).where('admSubjID', '=', usersRoleID).ubRequest().whereList
);
if(!checkRoleInDesktop){
console.info('\t\tprovide rights for `CityReq_desktop` to EducationDepartment role');
conn.insert({
entity: 'ubm_desktop_adm',
execParams: {
......@@ -143,10 +173,15 @@ console.info('\t\tprovide rights for `CityReq_desktop` to HealthDepartment role'
admSubjID: usersRoleID
}
});
}
lastID=conn.lookup('ubm_navshortcut', 'ID',{expression: 'code', condition: 'equal', values: {code: 'req_reqList'}});
if(lastID){
console.info('\t\tprovide rights for `req_reqList` folder to HealthDepartment role');
var checkRoleInShortcut = conn.lookup('ubm_navshortcut_adm', 'ID',
conn.Repository('ubm_navshortcut_adm').where('instanceID', '=', lastID).where('admSubjID', '=', usersRoleID).ubRequest().whereList
);
if(!checkRoleInShortcut){
console.info('\t\tprovide rights for `req_reqList` shortcut to EducationDepartment role');
conn.insert({
entity: 'ubm_navshortcut_adm',
execParams: {
......@@ -155,11 +190,16 @@ console.info('\t\tprovide rights for `req_reqList` folder to HealthDepartment ro
}
});
}
}
}
//entity level security
var checkCodeEls = conn.lookup('uba_els', 'ID',
conn.Repository('uba_els').where('code', '=', 'READ_UPD_REQ_ED').ubRequest().whereList
);
if(!checkCodeEls){
console.info('\t\tprovide rights for `req*` entities to EducationDepartment role');
conn.insert({
entity: 'uba_els',
......@@ -168,11 +208,11 @@ console.info('\t\tprovide rights for `req*` entities to EducationDepartment role
entityMask: 'req*',
methodMask: '[su]*',
ruleType: 'A',
ruleRole: 'EducationDepartment',
ruleRole: usersRoleID,
description: 'Read and update RequestList model'
}
});
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment