modif Odmdb for search and wwws to improve localdb

This commit is contained in:
2024-05-06 06:44:58 +02:00
parent ab562c7e9e
commit 009cbcbd2f
3 changed files with 62 additions and 40 deletions

View File

@@ -395,31 +395,39 @@ Odmdb.search = (objectPathname, objsearch, role) => {
const getschema = Odmdb.Schema(objectPathname, true);
if (getschema.status != 200) return getschema;
//console.log(getschema.data);
const apxid = getschema.data.apxid;
const apxid = getschema.data.schema.apxid;
let subsearch = objsearch.apxid
? objsearch.apxid
: fs.readJSONSync(`${objectPathname}/idx/lst_${apxid}.json`);
// ADD HERE OTHER FILTRATION SEARCH depending of question
if (objsearch.question) {
if (objsearch.condition) {
// remove or add in subsearch
}
if (objsearch.fields) {
const resultat = {};
//console.log(getschema.data.schema.apxaccessrights);
//console.log(role);
const accessright = Odmdb.accessright(
getschema.data.schema.apxaccessrights,
role
);
//console.log(accessright);
const ifields={}
if (objsearch.fields == "all") {
//console.log(getschema.data)
objsearch.fields = Object.keys(getschema.data.schema.properties);
}
const ifields = {};
subsearch.forEach((i) => {
const ifields = {};
if (fs.existsSync(`${objectPathname}/itm/${i}.json`)) {
const itm = fs.readJSONSync(`${objectPathname}/itm/${i}.json`);
if (itm.owner && itm.owner == role.xalias) {
role.xprofils.push("owner");
} else {
role.xprofils = role.xprofils.filter((e) => e !== "owner");
}
objsearch.fields.forEach((f) => {
if (accessright.R.includes(f)) {
if (accessright.R.length==0 || accessright.R.includes(f)) {
ifields[f] = itm[f];
} else {
ifields[f] = "unauthorized";
@@ -564,9 +572,12 @@ Odmdb.accessright = (apxaccessrights, role) => {
if (!accessright[act]) {
accessright[act] = apxaccessrights[p][act];
} else {
accessright[act] = [
...new Set([...accessright[act], ...apxaccessrights[p][act]]),
];
if (accessright[act].length != 0) {
//case where [] that mean all accessright on any properties
accessright[act] = [
...new Set([...accessright[act], ...apxaccessrights[p][act]]),
];
}
}
//if (log) console.log(currentmod,act,accessright[act])
});

View File

@@ -145,9 +145,18 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
localstorage.schema[name] = schema.data.schema;
} else {
console.log(schema);
let msg=`Check your ${fileparam} for schema in ${pagename} :`
if (schema.status==406){
if (schema.msg) msg+=schema.msg
if (schema.multimsg) {
schema.multimsg.forEach(err=>{
msg+=`${err.msg} ${JSON.stringify(err.data)})`
})
}
}
localstorage.schema[
name
] = `Check your ${fileparam} for schema in ${pagename} profil`;
] = msg;
}
});
}