add acl to idx management in Odmdb

This commit is contained in:
2026-10-31 12:34:44 +01:00
parent 151afd73a1
commit 599eef627d
14 changed files with 766 additions and 372 deletions
+70
View File
@@ -544,6 +544,76 @@ Odmdb.accessright = (apxaccessrights, role, properties) => {
}); });
return accessright; return accessright;
}; };
Odmdb.getIndexAccess = (objectPathname, indexName) => {
const normalized = String(indexName || "")
.replace(/\.json$/, "")
.trim();
if (!/^[A-Za-z0-9_-]+$/.test(normalized)) {
return {
status: 404,
ref: "Odmdb",
msg: "indexnotdeclared",
data: { indexname: normalized, objectPathname },
};
}
let getschema;
try {
getschema = Odmdb.Schema(objectPathname, true);
} catch (err) {
return {
status: 500,
ref: "Odmdb",
msg: "schemainvalid",
data: { objectPathname, error: err.message },
};
}
if (getschema.status != 200) return getschema;
const indexes = (getschema.data.schema.apxidx || []).filter(
(idx) => idx.name === normalized
);
if (indexes.length == 0) {
return {
status: 404,
ref: "Odmdb",
msg: "indexnotdeclared",
data: { indexname: normalized, objectPathname },
};
}
if (indexes.length > 1) {
return {
status: 403,
ref: "Odmdb",
msg: "indexambiguous",
data: { indexname: normalized, objectPathname },
};
}
const index = indexes[0];
const acl =
index.apxaccess && Array.isArray(index.apxaccess.R)
? index.apxaccess.R
: [];
return {
status: 200,
ref: "Odmdb",
msg: "indexaccess",
data: {
indexname: normalized,
acl,
},
};
};
Odmdb.indexAllowed = (indexaccess, role) => {
const acl =
indexaccess && Array.isArray(indexaccess.acl) ? indexaccess.acl : [];
if (acl.length == 0) return false;
if (acl.includes("*")) return true;
const profils =
role && Array.isArray(role.xprofils) ? role.xprofils : [];
return profils.some((profil) => acl.includes(profil));
};
/** /**
* CUD a data itm into objectPathname if checkJson is valid * CUD a data itm into objectPathname if checkJson is valid
* and update idx * and update idx
+58 -11
View File
@@ -105,13 +105,14 @@ router.get(
* @api {get} adminapi/odmdb/idx/:tribe/:objectname/:indexname - index Get * @api {get} adminapi/odmdb/idx/:tribe/:objectname/:indexname - index Get
* @apiGroup Odmdb * @apiGroup Odmdb
* @apiName getIndexbyindexname * @apiName getIndexbyindexname
* @apiDescription Get index file for an object * @apiDescription Get index file for an object. Access is controlled by the index apxaccess.R profiles. Authentication is always required.
* *
* @apiParams {string} tribe if common adminapi or tribename * @apiParams {string} tribe if common adminapi or tribename
* @apiParams {string} objectname If in conf.nationObjects then object is into nationchains/ else in tribes/xtribe/objectname/idx/indexname indexname * @apiParams {string} objectname If in conf.nationObjects then object is into nationchains/ else in tribes/xtribe/objectname/idx/indexname indexname
* @apiParams {String} indexname name of index file in /idx/indexnamme.json * @apiParams {String} indexname name of index file in /idx/indexnamme.json
* *
* *
* @apiError {json} profilnotallow the authenticated user profile cannot read this index
* @apiError {json} objectNotfound the file does not exist * @apiError {json} objectNotfound the file does not exist
* @apiErrorExample {json} * @apiErrorExample {json}
* HTTP/1.1 404 Not Found * HTTP/1.1 404 Not Found
@@ -127,25 +128,71 @@ router.get(
checkHeaders, checkHeaders,
isAuthenticated, isAuthenticated,
(req, res) => { (req, res) => {
console.log("passe"); const tribeids = Array.isArray(req.app.locals.tribeids)
const indexpath = `../${req.params.tribe}/objects/${req.params.objectname}/idx/${req.params.indexname}`; ? req.app.locals.tribeids
console.log(indexpath); : [];
if (fs.existsSync(indexpath)) { if (
res.status(200).json({ !["town", "adminapi", ...tribeids].includes(req.params.tribe) ||
!/^[A-Za-z0-9_-]+$/.test(req.params.objectname)
) {
return res.status(404).json({
status: 404,
ref: "Odmdb", ref: "Odmdb",
msg: "indexexist", msg: "pathnamedoesnotexist",
data: { data: {
indexname: req.params.indexname, tribe: req.params.tribe,
content: fs.readJsonSync(indexpath), objectname: req.params.objectname,
}, },
}); });
} else { }
res.status(404).json({ const objectPathname = `../${req.params.tribe}/objects/${req.params.objectname}`;
const indexaccess = Odmdb.getIndexAccess(
objectPathname,
req.params.indexname
);
if (indexaccess.status != 200) {
return res.status(indexaccess.status).json(indexaccess);
}
if (!Odmdb.indexAllowed(indexaccess.data, req.session.header)) {
return res.status(403).json({
status: 403,
ref: "Odmdb",
msg: "profilnotallow",
data: {
indexname: indexaccess.data.indexname,
profils: req.session.header.xprofils,
},
});
}
const indexpath = `../${req.params.tribe}/objects/${req.params.objectname}/idx/${indexaccess.data.indexname}.json`;
if (!fs.existsSync(indexpath)) {
return res.status(404).json({
status: 404,
ref: "Odmdb", ref: "Odmdb",
msg: "pathnamedoesnotexist", msg: "pathnamedoesnotexist",
data: { indexpath }, data: { indexpath },
}); });
} }
let content;
try {
content = fs.readJsonSync(indexpath);
} catch (err) {
return res.status(500).json({
status: 500,
ref: "Odmdb",
msg: "indexinvalid",
data: { indexpath, error: err.message },
});
}
res.status(200).json({
status: 200,
ref: "Odmdb",
msg: "indexexist",
data: {
indexname: indexaccess.data.indexname,
content,
},
});
} }
); );
+30 -5
View File
@@ -149,12 +149,22 @@
{ {
"name": "lst_articleid", "name": "lst_articleid",
"type": "array", "type": "array",
"keyval": "articleid" "keyval": "articleid",
"apxaccess": {
"R": [
"*"
]
}
}, },
{ {
"name": "lst_author", "name": "lst_author",
"type": "array", "type": "array",
"keyval": "author" "keyval": "author",
"apxaccess": {
"R": [
"*"
]
}
}, },
{ {
"name": "articleid", "name": "articleid",
@@ -173,19 +183,34 @@
"manualkeywords", "manualkeywords",
"autokeywords" "autokeywords"
], ],
"filter": "" "filter": "",
"apxaccess": {
"R": [
"*"
]
}
}, },
{ {
"name": "author_articleid", "name": "author_articleid",
"type": "distribution", "type": "distribution",
"keyval": "author", "keyval": "author",
"filter": "" "filter": "",
"apxaccess": {
"R": [
"*"
]
}
}, },
{ {
"name": "manualkeywords_articleid", "name": "manualkeywords_articleid",
"type": "distribution", "type": "distribution",
"keyval": "manualkeywords", "keyval": "manualkeywords",
"filter": "" "filter": "",
"apxaccess": {
"R": [
"*"
]
}
} }
], ],
"apxaccessrights": { "apxaccessrights": {
+48 -8
View File
@@ -20,7 +20,12 @@
"title": "Contract status", "title": "Contract status",
"description": "todo = pending execution, done = successfully executed, error = failed, cancelled = manually stopped", "description": "todo = pending execution, done = successfully executed, error = failed, cancelled = manually stopped",
"type": "string", "type": "string",
"enum": ["todo", "done", "error", "cancelled"] "enum": [
"todo",
"done",
"error",
"cancelled"
]
}, },
"tribe": { "tribe": {
"title": "Tribe", "title": "Tribe",
@@ -131,17 +136,32 @@
{ {
"name": "lst_contractid", "name": "lst_contractid",
"type": "array", "type": "array",
"keyval": "contractid" "keyval": "contractid",
"apxaccess": {
"R": [
"druid"
]
}
}, },
{ {
"name": "lst_owner", "name": "lst_owner",
"type": "array", "type": "array",
"keyval": "owner" "keyval": "owner",
"apxaccess": {
"R": [
"druid"
]
}
}, },
{ {
"name": "lst_tribe", "name": "lst_tribe",
"type": "array", "type": "array",
"keyval": "tribe" "keyval": "tribe",
"apxaccess": {
"R": [
"druid"
]
}
}, },
{ {
"name": "contractid", "name": "contractid",
@@ -169,7 +189,12 @@
"dt_create", "dt_create",
"dt_update" "dt_update"
], ],
"filter": "" "filter": "",
"apxaccess": {
"R": [
"druid"
]
}
}, },
{ {
"name": "status_scheduledDay", "name": "status_scheduledDay",
@@ -187,19 +212,34 @@
"payload", "payload",
"owner" "owner"
], ],
"filter": "status=todo" "filter": "status=todo",
"apxaccess": {
"R": [
"druid"
]
}
}, },
{ {
"name": "tribe_status", "name": "tribe_status",
"type": "distribution", "type": "distribution",
"keyval": "tribe", "keyval": "tribe",
"filter": "status" "filter": "status",
"apxaccess": {
"R": [
"druid"
]
}
}, },
{ {
"name": "status_contractid", "name": "status_contractid",
"type": "distribution", "type": "distribution",
"keyval": "status", "keyval": "status",
"filter": "" "filter": "",
"apxaccess": {
"R": [
"druid"
]
}
} }
], ],
"apxaccessrights": { "apxaccessrights": {
+8 -2
View File
@@ -56,7 +56,8 @@
"mobile", "mobile",
"windows", "windows",
"mac", "mac",
"linux","" "linux",
""
] ]
}, },
"ip": { "ip": {
@@ -109,7 +110,12 @@
"type", "type",
"os" "os"
], ],
"filter": "" "filter": "",
"apxaccess": {
"R": [
"*"
]
}
} }
], ],
"apxaccessrights": { "apxaccessrights": {
+16 -6
View File
@@ -57,13 +57,13 @@
"properties": { "properties": {
"latitude": { "latitude": {
"type": "number", "type": "number",
"minimum": -90.0, "minimum": -90,
"maximum": 90.0 "maximum": 90
}, },
"longitude": { "longitude": {
"type": "number", "type": "number",
"minimum": -180.0, "minimum": -180,
"maximum": 180.0 "maximum": 180
} }
} }
}, },
@@ -85,7 +85,12 @@
{ {
"name": "lst_locationid", "name": "lst_locationid",
"type": "array", "type": "array",
"keyval": "locationid" "keyval": "locationid",
"apxaccess": {
"R": [
"*"
]
}
}, },
{ {
"name": "frenchlocation", "name": "frenchlocation",
@@ -96,7 +101,12 @@
"city", "city",
"label" "label"
], ],
"filter": "" "filter": "",
"apxaccess": {
"R": [
"*"
]
}
} }
], ],
"apxaccessrights": { "apxaccessrights": {
+34 -5
View File
@@ -25,15 +25,44 @@
"format": "uri" "format": "uri"
} }
}, },
"required": ["nationId", "dtcreate","contracts"], "required": [
"nationId",
"dtcreate",
"contracts"
],
"additionalProperties": false, "additionalProperties": false,
"apxid": "nationId", "apxid": "nationId",
"apxuniquekey":["nationId"], "apxuniquekey": [
"nationId"
],
"apxidx": [ "apxidx": [
{ "name":"lst_nationId","type":"array","keyval": "nationId"}, {
{ "name":"nations","type":"view","keyval":"nationId","objkey":[],"filter":""} "name": "lst_nationId",
"type": "array",
"keyval": "nationId",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "nations",
"type": "view",
"keyval": "nationId",
"objkey": [],
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
}
], ],
"apxaccessrights": { "apxaccessrights": {
"pagan":{"C":[],"R":[]} "pagan": {
"C": [],
"R": []
}
} }
} }
+48 -9
View File
@@ -30,23 +30,62 @@
"type": "string" "type": "string"
} }
}, },
"required": ["publickey", "alias"], "required": [
"publickey",
"alias"
],
"apxid": "alias", "apxid": "alias",
"apxuniquekey": ["publickey"], "apxuniquekey": [
"publickey"
],
"apxidx": [ "apxidx": [
{ "name": "lst_alias", "type": "array", "keyval": "alias" }, {
"name": "lst_alias",
"type": "array",
"keyval": "alias",
"apxaccess": {
"R": [
"*"
]
}
},
{ {
"name": "alias", "name": "alias",
"type": "view", "type": "view",
"keyval": "alias", "keyval": "alias",
"objkey": [], "objkey": [
"filter": "" "alias",
"publickey"
],
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
} }
], ],
"apxaccessrights": { "apxaccessrights": {
"owner": { "R": [], "U": [], "D": [] }, "owner": {
"anonymous": { "C": [], "R": ["alias"] }, "R": [],
"pagans": { "R": ["alias", "publickey"] }, "U": [],
"mayor": { "R": [], "D": [] } "D": []
},
"anonymous": {
"C": [],
"R": [
"alias"
]
},
"pagans": {
"R": [
"alias",
"publickey"
]
},
"mayor": {
"R": [],
"D": []
}
} }
} }
+68 -15
View File
@@ -9,13 +9,17 @@
"title": "alias", "title": "alias",
"description": "A unique string identifying a unique public key", "description": "A unique string identifying a unique public key",
"type": "string", "type": "string",
"options": { "$ref": "adminapi/objects/pagans/idx/lst_alias" } "options": {
"$ref": "adminapi/objects/pagans/idx/lst_alias"
}
}, },
"owner": { "owner": {
"title": "Owner of this person", "title": "Owner of this person",
"description": "For accessright purpose this is always equal as alias", "description": "For accessright purpose this is always equal as alias",
"type": "string", "type": "string",
"options": { "$ref": "adminapi/objects/pagans/idx/lst_alias" } "options": {
"$ref": "adminapi/objects/pagans/idx/lst_alias"
}
}, },
"dt_create": { "dt_create": {
"title": "Creation date", "title": "Creation date",
@@ -69,7 +73,10 @@
"imgbase64_imgavatar": { "imgbase64_imgavatar": {
"title": "Temporary img to update or create", "title": "Temporary img to update or create",
"description": "image will be store in /objects/persons/{alias}_imgavatar.webp", "description": "image will be store in /objects/persons/{alias}_imgavatar.webp",
"sizeHW": [80, 80], "sizeHW": [
80,
80
],
"type": "string", "type": "string",
"format": "imgbase64" "format": "imgbase64"
}, },
@@ -85,25 +92,44 @@
"type": "array", "type": "array",
"items": { "items": {
"type": "string", "type": "string",
"options": { "$ref": "smatchit/objects/options/profil" } "options": {
"$ref": "smatchit/objects/options/profil"
}
} }
} }
}, },
"required": ["alias", "profils"], "required": [
"alias",
"profils"
],
"additionalProperties": true, "additionalProperties": true,
"apxref": [], "apxref": [],
"apxid": "alias", "apxid": "alias",
"apxuniquekey": ["alias"], "apxuniquekey": [
"alias"
],
"apxidx": [ "apxidx": [
{ {
"name": "lst_alias", "name": "lst_alias",
"type": "array", "type": "array",
"keyval": "alias" "keyval": "alias",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
}, },
{ {
"name": "lst_profils", "name": "lst_profils",
"type": "array", "type": "array",
"keyval": "profils" "keyval": "profils",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
}, },
{ {
"name": "alias", "name": "alias",
@@ -121,25 +147,49 @@
"imgavatar", "imgavatar",
"profils" "profils"
], ],
"filter": "" "filter": "",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
}, },
{ {
"name": "profils_alias", "name": "profils_alias",
"type": "distribution", "type": "distribution",
"keyval": "profils", "keyval": "profils",
"filter": "" "filter": "",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
}, },
{ {
"name": "emailcom_alias", "name": "emailcom_alias",
"type": "distribution", "type": "distribution",
"keyval": "emailcom", "keyval": "emailcom",
"filter": "" "filter": "",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
}, },
{ {
"name": "hobbies_alias", "name": "hobbies_alias",
"type": "distribution", "type": "distribution",
"keyval": "hobbies", "keyval": "hobbies",
"filter": "" "filter": "",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
} }
], ],
"commentaccessrights": "only a pagans can create a persons by joining the tribe smatchit. An adminrecruiters can Read person and update only profil by adding value recruiters or interviewers, that will create for this alias a recruiters itm or interviewers itm, use /api/smatchit/profilmanagers/join/:profils/:recruiteralias", "commentaccessrights": "only a pagans can create a persons by joining the tribe smatchit. An adminrecruiters can Read person and update only profil by adding value recruiters or interviewers, that will create for this alias a recruiters itm or interviewers itm, use /api/smatchit/profilmanagers/join/:profils/:recruiteralias",
@@ -174,12 +224,15 @@
}, },
"mayors": { "mayors": {
"D": [], "D": [],
"R": ["alias"] "R": [
"alias"
]
}, },
"druids": { "druids": {
"D": [], "D": [],
"R": ["alias"] "R": [
"alias"
]
} }
} }
} }
+39 -9
View File
@@ -28,17 +28,25 @@
"formcontrol": { "formcontrol": {
"title": "A key word to presents this content", "title": "A key word to presents this content",
"type": "string", "type": "string",
"enum":["squarebluebtn","listbtn","form"] "enum": [
"squarebluebtn",
"listbtn",
"form"
]
}, },
"forms": { "forms": {
"title": "Liste of data collection element into the screen", "title": "Liste of data collection element into the screen",
"type": "array", "type": "array",
"items":{"type":"objects"} "items": {
"type": "objects"
}
}, },
"action": { "action": {
"title": "List of possible action on this element", "title": "List of possible action on this element",
"type": "string", "type": "string",
"enum":["onclick"] "enum": [
"onclick"
]
}, },
"function": { "function": {
"title": "Function name to call, if action", "title": "Function name to call, if action",
@@ -53,17 +61,39 @@
"nextlevel": { "nextlevel": {
"title": "List of new screens to show if function is nextlevel $ref:# means it same current schema", "title": "List of new screens to show if function is nextlevel $ref:# means it same current schema",
"type": "array", "type": "array",
"items":{"$ref":"#"} "items": {
"$ref": "#"
}
} }
}, },
"required": ["screenid", "title"], "required": [
"screenid",
"title"
],
"apxid": "screenid", "apxid": "screenid",
"apxuniquekey": ["screenid"], "apxuniquekey": [
"screenid"
],
"apxidx": [ "apxidx": [
{ "name": "lst_screens", "type": "array", "keyval": "screenid" }, {
"name": "lst_screens",
"type": "array",
"keyval": "screenid",
"apxaccess": {
"R": [
"*"
]
}
}
], ],
"apxaccessrights": { "apxaccessrights": {
"owner": { "R": [], "U": [], "D": [] }, "owner": {
"anonymous": { "R": [] }, "R": [],
"U": [],
"D": []
},
"anonymous": {
"R": []
}
} }
} }
+12 -2
View File
@@ -62,14 +62,24 @@
{ {
"name": "lst_townId", "name": "lst_townId",
"type": "array", "type": "array",
"keyval": "townId" "keyval": "townId",
"apxaccess": {
"R": [
"*"
]
}
}, },
{ {
"name": "towns", "name": "towns",
"keyval": "townId", "keyval": "townId",
"type": "view", "type": "view",
"objkey": [], "objkey": [],
"filter": "" "filter": "",
"apxaccess": {
"R": [
"*"
]
}
} }
], ],
"apxaccessrights": { "apxaccessrights": {
+28 -3
View File
@@ -52,14 +52,24 @@
{ {
"name": "lst_tribeId", "name": "lst_tribeId",
"keyval": "tribeId", "keyval": "tribeId",
"type": "array" "type": "array",
"apxaccess": {
"R": [
"*"
]
}
}, },
{ {
"name": "tribes", "name": "tribes",
"keyval": "tribeId", "keyval": "tribeId",
"type": "view", "type": "view",
"objkey": [], "objkey": [],
"filter": "" "filter": "",
"apxaccess": {
"R": [
"*"
]
}
}, },
{ {
"name": "owner_tribeId", "name": "owner_tribeId",
@@ -67,7 +77,12 @@
"keyval": "owner", "keyval": "owner",
"objkey": [ "objkey": [
"tribeId" "tribeId"
],
"apxaccess": {
"R": [
"*"
] ]
}
}, },
{ {
"name": "dns_tribeId", "name": "dns_tribeId",
@@ -75,7 +90,12 @@
"keyval": "dns", "keyval": "dns",
"objkey": [ "objkey": [
"tribeId" "tribeId"
],
"apxaccess": {
"R": [
"*"
] ]
}
}, },
{ {
"name": "tribes_dns", "name": "tribes_dns",
@@ -84,7 +104,12 @@
"objkey": [ "objkey": [
"dns" "dns"
], ],
"filter": "" "filter": "",
"apxaccess": {
"R": [
"*"
]
}
} }
], ],
"apxacceesrights": { "apxacceesrights": {
+6 -1
View File
@@ -52,7 +52,12 @@
{ {
"name": "lst_wconame", "name": "lst_wconame",
"type": "array", "type": "array",
"keyval": "wconame" "keyval": "wconame",
"apxaccess": {
"R": [
"*"
]
}
} }
], ],
"apxaccessrights": { "apxaccessrights": {
+6 -1
View File
@@ -98,7 +98,12 @@
{ {
"name": "lst_website", "name": "lst_website",
"type": "array", "type": "array",
"keyval": "website" "keyval": "website",
"apxaccess": {
"R": [
"*"
]
}
} }
], ],
"apxaccessrights": { "apxaccessrights": {