mod
This commit is contained in:
@@ -94,6 +94,7 @@ Checkjson.schema.properties.format = {
|
||||
"idn-email": / /,
|
||||
uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,
|
||||
uri: / /,
|
||||
url: /^(?:(?:https?|ftp):\/\/)(?:\w+(?::\w+)?@)?(?:(?:[a-z0-9-\.]+\.[a-z]{2,})(?:[-a-z0-9+\._\%\!\\[\]\(\)\,\*\?\&\=\:]*){1,})|(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?))(?:[:\/#][^#]*)?$/,
|
||||
"uri-reference": / /,
|
||||
iri: / /,
|
||||
hostname: / /,
|
||||
|
@@ -32,21 +32,23 @@ Notifications.get = (alias, tribeId) => {
|
||||
*/
|
||||
Notifications.statmaillist=(tribe)=>{
|
||||
const statinfo={}
|
||||
let csv="email/phone;name;srckey\n"
|
||||
const src=`../../${tribe}/objects/maillinglists/*.json`
|
||||
console.log(path.resolve(src))
|
||||
glob.sync(src).forEach(f=>{
|
||||
const name=path.basename(f,".json");
|
||||
const mlst=fs.readJSONSync(f)
|
||||
Object.keys(mlst).forEach(c=>{
|
||||
csv+=`"${c}";"${name}";"${mlst[c].srckeys.join('-')}"\n`
|
||||
mlst[c].srckeys.forEach(s=>{
|
||||
if (!statinfo[s]) statinfo[s]={}
|
||||
if (!statinfo[s][name]) statinfo[s][name]=0
|
||||
statinfo[s][name]++
|
||||
})
|
||||
//console.log(c) recupere les contact tel ou email
|
||||
})
|
||||
})
|
||||
|
||||
// fichier csv stocker en local en attendant d'avoir un back pour stocker la reponse dans data.csv
|
||||
fs.outputFileSync(`../../${tribe}/mailinglst.csv`,csv,"utf-8");
|
||||
return {status:200,ref:"Notifications",msg:"statistics",data:statinfo}
|
||||
}
|
||||
|
||||
|
228
models/Odmdb.js
228
models/Odmdb.js
@@ -156,114 +156,163 @@ Odmdb.updateObject = (objectPathname, meta) => {};
|
||||
* @lg language you want to get schema
|
||||
* @return {status:200,data:{conf:"schemaconf",schema:"schemacontent"} }
|
||||
*/
|
||||
Odmdb.Schema = (objectPathname, validschema, lg="en") => {
|
||||
|
||||
const replacelg = (data)=>{
|
||||
Odmdb.Schema = (objectPathname, validschema, lg = "en") => {
|
||||
const replacelg = (data) => {
|
||||
// data.en version schema de base, data.fr version schema traduite
|
||||
Object.keys(data.lg).forEach(k=>{
|
||||
console.log(k)
|
||||
if (data.lg[k].title) data.en[k].title = data.lg[k].title
|
||||
if (data.lg[k].description) data.en[k].description = data.lg[k].description
|
||||
if (data.lg.properties){
|
||||
console.log('properties')
|
||||
console.log(data.en.properties)
|
||||
console.log(data.lg.properties)
|
||||
const res = replacelg({en:data.en.properties,lg:data.lg.properties})
|
||||
data.lg.properties=res.lg
|
||||
data.en.properties=res.en
|
||||
}
|
||||
})
|
||||
return data
|
||||
}
|
||||
const getschemalg = (schemaPath,lg) => {
|
||||
Object.keys(data.lg).forEach((k) => {
|
||||
console.log(k);
|
||||
if (data.lg[k].title) data.en[k].title = data.lg[k].title;
|
||||
if (data.lg[k].description)
|
||||
data.en[k].description = data.lg[k].description;
|
||||
if (data.lg.properties) {
|
||||
console.log("properties");
|
||||
console.log(data.en.properties);
|
||||
console.log(data.lg.properties);
|
||||
const res = replacelg({
|
||||
en: data.en.properties,
|
||||
lg: data.lg.properties,
|
||||
});
|
||||
data.lg.properties = res.lg;
|
||||
data.en.properties = res.en;
|
||||
}
|
||||
});
|
||||
return data;
|
||||
};
|
||||
const getschemalg = (schemaPath, lg) => {
|
||||
if (schemaPath.slice(-5) != ".json") schemaPath += ".json";
|
||||
if (schemaPath.substring(0, 4) == "http") {
|
||||
// lance requete http pour recuperer le schema avec un await axios
|
||||
} else {
|
||||
schemaPath = `../../${schemaPath}`;
|
||||
if (log) console.log(currentmod,"resolve path schemaPath:",path.resolve(schemaPath))
|
||||
if (log)
|
||||
console.log(
|
||||
currentmod,
|
||||
"resolve path schemaPath:",
|
||||
path.resolve(schemaPath)
|
||||
);
|
||||
if (!fs.existsSync(schemaPath)) {
|
||||
return {};
|
||||
} else {
|
||||
let schemalg = fs.readJsonSync(schemaPath);
|
||||
if (lg!="en"){
|
||||
let lgtrans={}
|
||||
try{
|
||||
lgtrans=fs.readJsonSync(schemaPath.replace('/schema/','/schema/lg/').replace('.json',`_${lg}.json`));
|
||||
const res= replacelg({en:schemalg,lg:lgtrans})
|
||||
//console.log(res.en.title,res.lg.title)
|
||||
schemalg=res.en
|
||||
}catch(err){
|
||||
if (lg != "en") {
|
||||
let lgtrans = {};
|
||||
try {
|
||||
lgtrans = fs.readJsonSync(
|
||||
schemaPath
|
||||
.replace("/schema/", "/schema/lg/")
|
||||
.replace(".json", `_${lg}.json`)
|
||||
);
|
||||
const res = replacelg({ en: schemalg, lg: lgtrans });
|
||||
//console.log(res.en.title,res.lg.title)
|
||||
schemalg = res.en;
|
||||
} catch (err) {
|
||||
// console.log('Err',err)
|
||||
// no translation file deliver en by default
|
||||
}
|
||||
}
|
||||
return schemalg
|
||||
return schemalg;
|
||||
}
|
||||
}
|
||||
};
|
||||
if (log) console.log(currentmod,`${objectPathname}/conf.json`);
|
||||
const res = {
|
||||
status: 200,
|
||||
ref: "Odmdb",
|
||||
msg: "getschema",
|
||||
data: {},
|
||||
};
|
||||
const convoptionstoenum=(propertie,lg)=>{
|
||||
if (!propertie.options) return propertie;
|
||||
if (!(propertie.options["$ref"])){
|
||||
propertie.msg="missingref"
|
||||
return propertie
|
||||
}
|
||||
let optionsfile;
|
||||
let optionstype;
|
||||
if (propertie.options["$ref"].includes("/options/")) {
|
||||
optionstype = "options";
|
||||
optionsfile = path.resolve(
|
||||
`../../${propertie.options["$ref"]}_${lg}.json`
|
||||
);
|
||||
}
|
||||
if (propertie.options["$ref"].includes("/idx/")) {
|
||||
optionstype = "idx";
|
||||
optionsfile = path.resolve(
|
||||
`../../${propertie.options["$ref"]}.json`
|
||||
);
|
||||
}
|
||||
if (log) console.log(currentmod, "Lien vers options:", optionsfile);
|
||||
if (!fs.existsSync(optionsfile)) {
|
||||
propertie.msg = "missingref";
|
||||
return propertie;
|
||||
} else {
|
||||
delete propertie.options
|
||||
if (optionstype == "options") {
|
||||
propertie.enum =
|
||||
fs.readJSONSync(optionsfile).lst_idx;
|
||||
}
|
||||
if (optionstype == "idx") {
|
||||
propertie.enum = fs.readJSONSync(optionsfile);
|
||||
}
|
||||
}
|
||||
return propertie
|
||||
}
|
||||
|
||||
if (log) console.log(currentmod, `${objectPathname}/conf.json`);
|
||||
const res = {
|
||||
status: 200,
|
||||
ref: "Odmdb",
|
||||
msg: "getschema",
|
||||
data: {},
|
||||
};
|
||||
|
||||
if (fs.existsSync(`${objectPathname}/conf.json`)) {
|
||||
res.data.conf=fs.readJsonSync(`${objectPathname}/conf.json`);
|
||||
res.data.schema = getschemalg(res.data.conf.schema,lg)
|
||||
}else{
|
||||
res.data.conf={}
|
||||
res.data.conf = fs.readJsonSync(`${objectPathname}/conf.json`);
|
||||
res.data.schema = getschemalg(res.data.conf.schema, lg);
|
||||
} else {
|
||||
res.data.conf = {};
|
||||
}
|
||||
if (!res.data.schema || Object.keys(res.data.schema).length == 0 ) {
|
||||
if (!res.data.schema || Object.keys(res.data.schema).length == 0) {
|
||||
return {
|
||||
status: 404,
|
||||
ref: "Odmdb",
|
||||
msg: "schemanotfound",
|
||||
data: { objectPathname:path.resolve(objectPathname), schema: {} },
|
||||
data: { objectPathname: path.resolve(objectPathname), schema: {} },
|
||||
};
|
||||
}
|
||||
|
||||
//@todo only 1 level $ref if multi level need to rewrite with recursive call
|
||||
// get $ref from $def
|
||||
if (res.data.schema["$defs"]){
|
||||
Object.keys(res.data.schema["$defs"]).forEach(ss=>{
|
||||
Object.keys(res.data.schema["$defs"][ss].properties).forEach(pp=>{
|
||||
res.data.schema["$defs"][ss].properties[pp]=convoptionstoenum(res.data.schema["$defs"][ss].properties[pp],lg)
|
||||
})
|
||||
})
|
||||
}
|
||||
Object.keys(res.data.schema.properties).forEach((p) => {
|
||||
//looking for type:object with $ref to load and replace by ref content (ref must be adminapi/ or tribeid/)
|
||||
if (
|
||||
res.data.schema.properties[p].type == "object" &&
|
||||
res.data.schema.properties[p]["$ref"]
|
||||
) {
|
||||
const subschema = path.resolve(`../../${res.data.schema.properties[p]["$ref"]}.json`);
|
||||
if (Object.keys(res.data.schema).length == 0) {
|
||||
let subschema
|
||||
const localdef=res.data.schema.properties[p]["$ref"].includes("#/")
|
||||
if (
|
||||
localdef &&
|
||||
!(res.data.schema["$defs"] && res.data.schema["$defs"][propertie["$ref"]])
|
||||
) {
|
||||
res.status = 404;
|
||||
res.msg = "missingref";
|
||||
res.data.missingref = res.data.schema.properties[p]["$ref"];
|
||||
res.msg = "missinglocalref";
|
||||
res.data.missingref = propertie;
|
||||
return res;
|
||||
} else {
|
||||
subschema.description += ` from external schema: ${res.data.schema.properties[p]["$ref"]}`;
|
||||
res.data.schema.properties[p] = subschema;
|
||||
}
|
||||
}
|
||||
//`../../${req.session.header.xtribe}/objects/persons`
|
||||
//looking for options:{"$ref":"../objects/options/xxx.json"}
|
||||
//to add enum:[] = content of options available in
|
||||
if (
|
||||
res.data.schema.properties[p].options &&
|
||||
res.data.schema.properties[p].options["$ref"]
|
||||
) {
|
||||
const optionsfile = path.resolve(`../../${res.data.schema.properties[p].options["$ref"]}_${lg}.json`)
|
||||
if (log) console.log(currentmod,"Lien vers options:", optionsfile)
|
||||
if (!fs.existsSync(optionsfile)){
|
||||
res.status = 404;
|
||||
res.msg = "missingref";
|
||||
res.data.missingref = res.data.schema.properties[p].options["$ref"];
|
||||
return res;
|
||||
if (localdef) {
|
||||
res.data.schema.properties[p]=res.data.schema["$defs"][res.data.schema.properties[p]["$ref"]]
|
||||
}else{
|
||||
if (!res.data.schema.apxref) {res.data.schema.apxref=[]}
|
||||
if (!res.data.schema.apxref.includes(res.data.schema.properties[p].options["$ref"]))
|
||||
res.data.schema.apxref.push(res.data.schema.properties[p].options["$ref"])
|
||||
res.data.schema.properties[p].enum=fs.readJSONSync(optionsfile).lst_idx
|
||||
subschema = Odmdb.Schema(path.resolve(res.data.schema.properties[p]["$ref"]), validschema, lg)
|
||||
if(subschema.status==200){
|
||||
res.data.schema.properties[p]=subschema.data.schema;
|
||||
}else{
|
||||
subschema.data.originschemaproperty=p
|
||||
return subschema
|
||||
}
|
||||
}
|
||||
}
|
||||
if (res.data.schema.properties[p].options){
|
||||
//remplace options par enum:[]
|
||||
res.data.schema.properties[p]=convoptionstoenum(res.data.schema.properties[p],lg)
|
||||
}
|
||||
});
|
||||
|
||||
if (!res.data.schema.apxid) {
|
||||
@@ -471,7 +520,7 @@ Odmdb.accessright = (apxaccessrights, role) => {
|
||||
|
||||
Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
||||
const getschema = Odmdb.Schema(objectPathname, true);
|
||||
|
||||
|
||||
if (getschema.status != 200) return getschema;
|
||||
|
||||
if (!itm[getschema.data.schema.apxid]) {
|
||||
@@ -487,7 +536,7 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
||||
const existid = fs.existsSync(
|
||||
`${objectPathname}/itm/${itm[getschema.data.schema.apxid]}.json`
|
||||
);
|
||||
if (log) console.log(currentmod,"Pass schema itm existid = ", existid)
|
||||
if (log) console.log(currentmod, "Pass schema itm existid = ", existid);
|
||||
/*const pathindex = `${objectPathname}/idx/lst_${getschema.data.schema.apxid}.json`;
|
||||
if (!fs.existsSync(pathindex)) {
|
||||
fs.outputJSONSync(pathindex, []);
|
||||
@@ -545,7 +594,7 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
||||
(crud == "D" && !accessright.D) ||
|
||||
(crud == "U" && !accessright.U)
|
||||
) {
|
||||
if (log) console.log(currentmod,"Forbidden accessright:", accessright);
|
||||
if (log) console.log(currentmod, "Forbidden accessright:", accessright);
|
||||
return {
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
@@ -581,14 +630,18 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
||||
false
|
||||
);
|
||||
if (chkdata.status != 200) {
|
||||
if (log) console.log(currentmod,"Unconsistency data", chkdata);
|
||||
if (log) console.log(currentmod, "Unconsistency data", chkdata);
|
||||
return chkdata;
|
||||
}
|
||||
if (log) console.log(currentmod,"Data compliance with schema");
|
||||
if (log) console.log(currentmod, "Data compliance with schema");
|
||||
if (!getschema.data.schema.apxuniquekey)
|
||||
getschema.data.schema.apxuniquekey = [];
|
||||
if (log) console.log(currentmod,`${objectPathname}/itm/${chkdata.data.apxid}.json`);
|
||||
if (log) console.log(currentmod,chkdata.data.itm);
|
||||
if (log)
|
||||
console.log(
|
||||
currentmod,
|
||||
`${objectPathname}/itm/${chkdata.data.apxid}.json`
|
||||
);
|
||||
if (log) console.log(currentmod, chkdata.data.itm);
|
||||
fs.outputJSONSync(
|
||||
`${objectPathname}/itm/${chkdata.data.apxid}.json`,
|
||||
chkdata.data.itm
|
||||
@@ -596,7 +649,7 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
||||
}
|
||||
//if (log) console.log(currentmod,"getschema", getschema);
|
||||
//rebuild index if requested
|
||||
if (log) console.log(currentmod,"runidx", runindex);
|
||||
if (log) console.log(currentmod, "runidx", runindex);
|
||||
if (runindex) Odmdb.runidx(objectPathname, getschema.data.schema);
|
||||
getschema.data.conf.lastupdatedata = dayjs().toISOString();
|
||||
fs.outputJSONSync(`${objectPathname}/conf.json`, getschema.data.conf);
|
||||
@@ -619,7 +672,7 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => {
|
||||
*
|
||||
*/
|
||||
Odmdb.runidx = (objectPathname, schema) => {
|
||||
if (log) console.log(currentmod,`idx for ${objectPathname}`);
|
||||
if (log) console.log(currentmod, `idx for ${objectPathname}`);
|
||||
if (!schema || !schema.apxid) {
|
||||
const getschema = Odmdb.Schema(objectPathname, true);
|
||||
if (getschema.status != 200) return getschema;
|
||||
@@ -701,8 +754,8 @@ Odmdb.runidx = (objectPathname, schema) => {
|
||||
itm[ventil[n].keyval.split(".")[0]]
|
||||
) {
|
||||
let itmval = JSON.parse(JSON.stringify(itm));
|
||||
if (log) console.log(currentmod,ventil[n].keyval);
|
||||
if (log) console.log(currentmod,itmval);
|
||||
if (log) console.log(currentmod, ventil[n].keyval);
|
||||
if (log) console.log(currentmod, itmval);
|
||||
ventil[n].keyval
|
||||
.split(".")
|
||||
.forEach((i) => (itmval = itmval[i] ? itmval[i] : null));
|
||||
@@ -752,15 +805,16 @@ Odmdb.ASUPidxfromitm = (
|
||||
idxs = [],
|
||||
schema
|
||||
) => {
|
||||
if (log) console.log(currentmod,`idxfromitem for ${objectPathname} action:${crud}`);
|
||||
if (log)
|
||||
console.log(currentmod, `idxfromitem for ${objectPathname} action:${crud}`);
|
||||
if (!schema || !schema.apxid) {
|
||||
const getschema = Odmdb.Schema(objectPathname, true);
|
||||
if (getschema.status != 200) return getschema;
|
||||
schema = getschema.data.schema;
|
||||
}
|
||||
if (log) console.log(currentmod,schema.apxuniquekey);
|
||||
if (log) console.log(currentmod, schema.apxuniquekey);
|
||||
const itms = crud == "I" ? glob.sync(`${objectPathname}/itm/*.json`) : [itm];
|
||||
if (log) console.log(currentmod,itms);
|
||||
if (log) console.log(currentmod, itms);
|
||||
if (crud == "I") {
|
||||
//reinit all idx
|
||||
idxs.forEach((idx) => {
|
||||
@@ -787,8 +841,8 @@ Odmdb.ASUPidxfromitm = (
|
||||
idxtoreindex.push(idx); //@todo
|
||||
}
|
||||
}
|
||||
if (log) console.log(currentmod,idx.keyval);
|
||||
if (log) console.log(currentmod,itm[idx.keyval]);
|
||||
if (log) console.log(currentmod, idx.keyval);
|
||||
if (log) console.log(currentmod, itm[idx.keyval]);
|
||||
|
||||
if (
|
||||
["C", "U", "I"].includes(crud) &&
|
||||
|
@@ -32,16 +32,6 @@ At each reboot run a process to analyse /apxtri/routes and api/models whre only
|
||||
4 to delete a user sudo userdel smatchit (this keep folder smatchit to remove folder smatchit => sudo userdel --remove smacthit)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/tribes/tribeid
|
||||
Manage a tribeid space
|
||||
* create
|
||||
|
Reference in New Issue
Block a user