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;
};
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
* and update idx
+58 -11
View File
@@ -105,13 +105,14 @@ router.get(
* @api {get} adminapi/odmdb/idx/:tribe/:objectname/:indexname - index Get
* @apiGroup Odmdb
* @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} 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
*
*
* @apiError {json} profilnotallow the authenticated user profile cannot read this index
* @apiError {json} objectNotfound the file does not exist
* @apiErrorExample {json}
* HTTP/1.1 404 Not Found
@@ -127,25 +128,71 @@ router.get(
checkHeaders,
isAuthenticated,
(req, res) => {
console.log("passe");
const indexpath = `../${req.params.tribe}/objects/${req.params.objectname}/idx/${req.params.indexname}`;
console.log(indexpath);
if (fs.existsSync(indexpath)) {
res.status(200).json({
const tribeids = Array.isArray(req.app.locals.tribeids)
? req.app.locals.tribeids
: [];
if (
!["town", "adminapi", ...tribeids].includes(req.params.tribe) ||
!/^[A-Za-z0-9_-]+$/.test(req.params.objectname)
) {
return res.status(404).json({
status: 404,
ref: "Odmdb",
msg: "indexexist",
msg: "pathnamedoesnotexist",
data: {
indexname: req.params.indexname,
content: fs.readJsonSync(indexpath),
tribe: req.params.tribe,
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",
msg: "pathnamedoesnotexist",
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",
"type": "array",
"keyval": "articleid"
"keyval": "articleid",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "lst_author",
"type": "array",
"keyval": "author"
"keyval": "author",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "articleid",
@@ -173,19 +183,34 @@
"manualkeywords",
"autokeywords"
],
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "author_articleid",
"type": "distribution",
"keyval": "author",
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "manualkeywords_articleid",
"type": "distribution",
"keyval": "manualkeywords",
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {
+48 -8
View File
@@ -20,7 +20,12 @@
"title": "Contract status",
"description": "todo = pending execution, done = successfully executed, error = failed, cancelled = manually stopped",
"type": "string",
"enum": ["todo", "done", "error", "cancelled"]
"enum": [
"todo",
"done",
"error",
"cancelled"
]
},
"tribe": {
"title": "Tribe",
@@ -131,17 +136,32 @@
{
"name": "lst_contractid",
"type": "array",
"keyval": "contractid"
"keyval": "contractid",
"apxaccess": {
"R": [
"druid"
]
}
},
{
"name": "lst_owner",
"type": "array",
"keyval": "owner"
"keyval": "owner",
"apxaccess": {
"R": [
"druid"
]
}
},
{
"name": "lst_tribe",
"type": "array",
"keyval": "tribe"
"keyval": "tribe",
"apxaccess": {
"R": [
"druid"
]
}
},
{
"name": "contractid",
@@ -169,7 +189,12 @@
"dt_create",
"dt_update"
],
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"druid"
]
}
},
{
"name": "status_scheduledDay",
@@ -187,19 +212,34 @@
"payload",
"owner"
],
"filter": "status=todo"
"filter": "status=todo",
"apxaccess": {
"R": [
"druid"
]
}
},
{
"name": "tribe_status",
"type": "distribution",
"keyval": "tribe",
"filter": "status"
"filter": "status",
"apxaccess": {
"R": [
"druid"
]
}
},
{
"name": "status_contractid",
"type": "distribution",
"keyval": "status",
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"druid"
]
}
}
],
"apxaccessrights": {
+12 -6
View File
@@ -56,7 +56,8 @@
"mobile",
"windows",
"mac",
"linux",""
"linux",
""
]
},
"ip": {
@@ -109,14 +110,19 @@
"type",
"os"
],
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {
"anonymous":{
"C":[],
"U":[],
"D":[]
"anonymous": {
"C": [],
"U": [],
"D": []
},
"mayor": {
"R": []
+20 -10
View File
@@ -14,10 +14,10 @@
"title": "Type of result found, housenumber is a physical adresse, street position at street, locality: lieud it, municipality",
"type": "string"
},
"nicknameplace":{
"title":"Lacation name for common people",
"description":"This nicknameplace is the common people naming of the place, like 'Sephora Champs elysee' or 'place de la ferme' or 'les bois brulés'",
"type":"string"
"nicknameplace": {
"title": "Lacation name for common people",
"description": "This nicknameplace is the common people naming of the place, like 'Sephora Champs elysee' or 'place de la ferme' or 'les bois brulés'",
"type": "string"
},
"housenumber": {
"title": "number with ince bis ter A B",
@@ -57,13 +57,13 @@
"properties": {
"latitude": {
"type": "number",
"minimum": -90.0,
"maximum": 90.0
"minimum": -90,
"maximum": 90
},
"longitude": {
"type": "number",
"minimum": -180.0,
"maximum": 180.0
"minimum": -180,
"maximum": 180
}
}
},
@@ -85,7 +85,12 @@
{
"name": "lst_locationid",
"type": "array",
"keyval": "locationid"
"keyval": "locationid",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "frenchlocation",
@@ -96,7 +101,12 @@
"city",
"label"
],
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {
+51 -22
View File
@@ -1,39 +1,68 @@
{
"$schema":"http://json-schema.org/schema#",
"$id":"adminapi/schema/nations",
"$schema": "http://json-schema.org/schema#",
"$id": "adminapi/schema/nations",
"title": "Nation definition",
"description": "A nation from apxtri world",
"$comment":"see ./lg/nations_lg.json for description in your languange lg",
"$comment": "see ./lg/nations_lg.json for description in your languange lg",
"type": "object",
"properties": {
"nationId": {
"title":"Unique nation name",
"description":"A unique string that define a nation a-z and 0-9 onlyin a social world",
"title": "Unique nation name",
"description": "A unique string that define a nation a-z and 0-9 onlyin a social world",
"type": "string",
"pattern":"^[a-z0-9]*$"
"pattern": "^[a-z0-9]*$"
},
"dtcreate": {
"title":"Creation date",
"description":"Nation date of creation",
"title": "Creation date",
"description": "Nation date of creation",
"type": "string",
"format":"date-time"
"format": "date-time"
},
"contracts":{
"title":"Social contract of the nation",
"description":"A uri of the signed js contract that rules this nation",
"contracts": {
"title": "Social contract of the nation",
"description": "A uri of the signed js contract that rules this nation",
"type": "string",
"format":"uri"
"format": "uri"
}
},
"required": ["nationId", "dtcreate","contracts"],
"additionalProperties":false,
"apxid":"nationId",
"apxuniquekey":["nationId"],
"apxidx": [
{ "name":"lst_nationId","type":"array","keyval": "nationId"},
{ "name":"nations","type":"view","keyval":"nationId","objkey":[],"filter":""}
"required": [
"nationId",
"dtcreate",
"contracts"
],
"apxaccessrights":{
"pagan":{"C":[],"R":[]}
"additionalProperties": false,
"apxid": "nationId",
"apxuniquekey": [
"nationId"
],
"apxidx": [
{
"name": "lst_nationId",
"type": "array",
"keyval": "nationId",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "nations",
"type": "view",
"keyval": "nationId",
"objkey": [],
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {
"pagan": {
"C": [],
"R": []
}
}
}
+48 -9
View File
@@ -30,23 +30,62 @@
"type": "string"
}
},
"required": ["publickey", "alias"],
"required": [
"publickey",
"alias"
],
"apxid": "alias",
"apxuniquekey": ["publickey"],
"apxuniquekey": [
"publickey"
],
"apxidx": [
{ "name": "lst_alias", "type": "array", "keyval": "alias" },
{
"name": "lst_alias",
"type": "array",
"keyval": "alias",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "alias",
"type": "view",
"keyval": "alias",
"objkey": [],
"filter": ""
"objkey": [
"alias",
"publickey"
],
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {
"owner": { "R": [], "U": [], "D": [] },
"anonymous": { "C": [], "R": ["alias"] },
"pagans": { "R": ["alias", "publickey"] },
"mayor": { "R": [], "D": [] }
"owner": {
"R": [],
"U": [],
"D": []
},
"anonymous": {
"C": [],
"R": [
"alias"
]
},
"pagans": {
"R": [
"alias",
"publickey"
]
},
"mayor": {
"R": [],
"D": []
}
}
}
+69 -16
View File
@@ -9,13 +9,17 @@
"title": "alias",
"description": "A unique string identifying a unique public key",
"type": "string",
"options": { "$ref": "adminapi/objects/pagans/idx/lst_alias" }
"options": {
"$ref": "adminapi/objects/pagans/idx/lst_alias"
}
},
"owner": {
"title": "Owner of this person",
"description": "For accessright purpose this is always equal as alias",
"type": "string",
"options": { "$ref": "adminapi/objects/pagans/idx/lst_alias" }
"options": {
"$ref": "adminapi/objects/pagans/idx/lst_alias"
}
},
"dt_create": {
"title": "Creation date",
@@ -69,7 +73,10 @@
"imgbase64_imgavatar": {
"title": "Temporary img to update or create",
"description": "image will be store in /objects/persons/{alias}_imgavatar.webp",
"sizeHW": [80, 80],
"sizeHW": [
80,
80
],
"type": "string",
"format": "imgbase64"
},
@@ -85,25 +92,44 @@
"type": "array",
"items": {
"type": "string",
"options": { "$ref": "smatchit/objects/options/profil" }
"options": {
"$ref": "smatchit/objects/options/profil"
}
}
}
},
"required": ["alias", "profils"],
"required": [
"alias",
"profils"
],
"additionalProperties": true,
"apxref": [],
"apxid": "alias",
"apxuniquekey": ["alias"],
"apxuniquekey": [
"alias"
],
"apxidx": [
{
"name": "lst_alias",
"type": "array",
"keyval": "alias"
"keyval": "alias",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
},
{
"name": "lst_profils",
"type": "array",
"keyval": "profils"
"keyval": "profils",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
},
{
"name": "alias",
@@ -121,25 +147,49 @@
"imgavatar",
"profils"
],
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
},
{
"name": "profils_alias",
"type": "distribution",
"keyval": "profils",
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
},
{
"name": "emailcom_alias",
"type": "distribution",
"keyval": "emailcom",
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"mayors",
"druids"
]
}
},
{
"name": "hobbies_alias",
"type": "distribution",
"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",
@@ -174,12 +224,15 @@
},
"mayors": {
"D": [],
"R": ["alias"]
"R": [
"alias"
]
},
"druids": {
"D": [],
"R": ["alias"]
"R": [
"alias"
]
}
}
}
}
+56 -26
View File
@@ -5,9 +5,9 @@
"description": "Each propertie value is a mustache template string where a data must be provide to display screen with value",
"type": "object",
"properties": {
"screenid":{
"title":"Screen identification used in html tag id",
"type":"string"
"screenid": {
"title": "Screen identification used in html tag id",
"type": "string"
},
"title": {
"title": "A title in a screen",
@@ -28,42 +28,72 @@
"formcontrol": {
"title": "A key word to presents this content",
"type": "string",
"enum":["squarebluebtn","listbtn","form"]
"enum": [
"squarebluebtn",
"listbtn",
"form"
]
},
"forms":{
"title":"Liste of data collection element into the screen",
"type":"array",
"items":{"type":"objects"}
"forms": {
"title": "Liste of data collection element into the screen",
"type": "array",
"items": {
"type": "objects"
}
},
"action": {
"title": "List of possible action on this element",
"type": "string",
"enum":["onclick"]
"enum": [
"onclick"
]
},
"function":{
"title":"Function name to call, if action",
"comment":"other function than nextlevel",
"type":"string"
"function": {
"title": "Function name to call, if action",
"comment": "other function than nextlevel",
"type": "string"
},
"params":{
"title":" an object containning parameter to send to function",
"comment":"can be empty {}",
"type":"objects"
"params": {
"title": " an object containning parameter to send to function",
"comment": "can be empty {}",
"type": "objects"
},
"nextlevel":{
"title":"List of new screens to show if function is nextlevel $ref:# means it same current schema",
"type":"array",
"items":{"$ref":"#"}
"nextlevel": {
"title": "List of new screens to show if function is nextlevel $ref:# means it same current schema",
"type": "array",
"items": {
"$ref": "#"
}
}
},
"required": ["screenid", "title"],
"required": [
"screenid",
"title"
],
"apxid": "screenid",
"apxuniquekey": ["screenid"],
"apxuniquekey": [
"screenid"
],
"apxidx": [
{ "name": "lst_screens", "type": "array", "keyval": "screenid" },
{
"name": "lst_screens",
"type": "array",
"keyval": "screenid",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {
"owner": { "R": [], "U": [], "D": [] },
"anonymous": { "R": [] },
"owner": {
"R": [],
"U": [],
"D": []
},
"anonymous": {
"R": []
}
}
}
+13 -3
View File
@@ -61,15 +61,25 @@
"apxidx": [
{
"name": "lst_townId",
"type":"array",
"keyval": "townId"
"type": "array",
"keyval": "townId",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "towns",
"keyval": "townId",
"type": "view",
"objkey": [],
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {
+28 -3
View File
@@ -52,14 +52,24 @@
{
"name": "lst_tribeId",
"keyval": "tribeId",
"type": "array"
"type": "array",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "tribes",
"keyval": "tribeId",
"type": "view",
"objkey": [],
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "owner_tribeId",
@@ -67,7 +77,12 @@
"keyval": "owner",
"objkey": [
"tribeId"
],
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "dns_tribeId",
@@ -75,7 +90,12 @@
"keyval": "dns",
"objkey": [
"tribeId"
],
"apxaccess": {
"R": [
"*"
]
}
},
{
"name": "tribes_dns",
@@ -84,7 +104,12 @@
"objkey": [
"dns"
],
"filter": ""
"filter": "",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxacceesrights": {
+43 -38
View File
@@ -18,54 +18,59 @@
"description": "Code signature of alias publickey",
"type": "string"
},
"thumbnail":{
"title":"Thumbnail of the component",
"type":"string"
"thumbnail": {
"title": "Thumbnail of the component",
"type": "string"
},
"title":{
"title":"Short description of the wco",
"type":"string"
"title": {
"title": "Short description of the wco",
"type": "string"
},
"description":{
"title":"Long description in html of the component",
"type":"string"
"description": {
"title": "Long description in html of the component",
"type": "string"
},
"tpl":{
"description":"list of mustache template to manage components each file must ended by _xx.mustache where xx is the language of the template, so you can add translation easily",
"type":"array"
"tpl": {
"description": "list of mustache template to manage components each file must ended by _xx.mustache where xx is the language of the template, so you can add translation easily",
"type": "array"
},
"tpldata":{
"description":"Example of tpldata that you have to add in your local to customize the wco ended by _xx.json where xx is the language of the template",
"type":"array"
"tpldata": {
"description": "Example of tpldata that you have to add in your local to customize the wco ended by _xx.json where xx is the language of the template",
"type": "array"
}
},
"required": [
"wconame",
"owner",
"title"
],
"apxid": "wconame",
"apxuniquekey": [
"wconame"
],
"apxidx": [
{
},
"required": [
"wconame",
"owner",
"title"
],
"apxid": "wconame",
"apxuniquekey": [
"wconame"
],
"apxidx": [
{
"name": "lst_wconame",
"type": "array",
"keyval": "wconame"
}
],
"apxaccessrights": {
"owner": {
"keyval": "wconame",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {
"owner": {
"D": [],
"R": [],
"U": []
},
"mayor": {
},
"mayor": {
"C": []
},
"person": {
},
"person": {
"R": []
}
}
}
}
}
+6 -1
View File
@@ -98,7 +98,12 @@
{
"name": "lst_website",
"type": "array",
"keyval": "website"
"keyval": "website",
"apxaccess": {
"R": [
"*"
]
}
}
],
"apxaccessrights": {