From b58e31c5c2d1bb0a99ad87a6375d3d67f6777bd6 Mon Sep 17 00:00:00 2001 From: philc Date: Thu, 5 Sep 2024 09:55:58 +0200 Subject: [PATCH] fix get itm accessright --- models/Odmdb.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/models/Odmdb.js b/models/Odmdb.js index 506e27b..4753bf2 100644 --- a/models/Odmdb.js +++ b/models/Odmdb.js @@ -438,7 +438,10 @@ Odmdb.search = (objectPathname, objsearch, role) => { role.xprofils = role.xprofils.filter((e) => e !== "owner"); } objsearch.fields.forEach((f) => { - if (accessright.R && (accessright.R.length == 0 || accessright.R.includes(f))) { + if ( + accessright.R && + (accessright.R.length == 0 || accessright.R.includes(f)) + ) { ifields[f] = itm[f]; } else { //ifields[f] = "unauthorized"; @@ -494,9 +497,15 @@ Odmdb.r = (objectPathname, apxid, role) => { }; } const data = {}; - accessright.R.forEach((p) => { + const allowedkey = + accessright.R.length == 0 + ? Object.keys(getschema.data.schema.properties) + : accessright.R; + + allowedkey.forEach((p) => { data[p] = itm[p]; }); + return { status: 200, ref: "Odmdb", msg: "profilallow", data }; }; @@ -663,7 +672,10 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => { //Manage base64 case image to convert ans store in webp if (k.includes("imgbase64_") && itmtostore[k] != "") { fs.ensureDirSync(`${objectPathname}/img/`); - const imgb64 = itmtostore[k].replace(/^data:image\/(png|png|gif|bmp|jpg|jpeg);base64,/,"");//.replace(/\+/g," "); + const imgb64 = itmtostore[k].replace( + /^data:image\/(png|png|gif|bmp|jpg|jpeg);base64,/, + "" + ); //.replace(/\+/g," "); const extension = itmtostore[k].split(";base64,")[0].split("/")[1]; const newk = k.split("_").slice(1).join("_"); const filenameimg = `/img/${ @@ -682,7 +694,9 @@ Odmdb.cud = (objectPathname, crud, itm, role, runindex = true) => { //const buf = Buffer.from(itmtostore[k], 'base64'); //const imgwebp = await webp.bufferToWebp(buf); //@TODO use sharp to resize img with attribut sizeHW in propertie - fs.writeFileSync(`${objectPathname}/${filenameimg}`, imgb64,{encoding:"base64"}); + fs.writeFileSync(`${objectPathname}/${filenameimg}`, imgb64, { + encoding: "base64", + }); itmtostore[k] = ""; } } @@ -807,7 +821,7 @@ Odmdb.runidx = (objectPathname, schema) => { ventil[n].keyvaltype == "string" ? [itm[ventil[n].keyval]] : itm[ventil[n].keyval]; - //console.log(ventil[n].keyval, itm[ventil[n].keyval], itm) + //console.log(ventil[n].keyval, itm[ventil[n].keyval], itm) // itm[ventil[n].keyval] is an array listval.forEach((val) => { if (!ventil[n].data[val]) ventil[n].data[val] = [];