fix delUser naming,

update config template,
implement getAllUsers/getAllGroups in USER_BACKEND_MANAGER
This commit is contained in:
Arthur Lu 2024-07-10 22:38:14 +00:00
parent 8f7ea51787
commit 79ec20ad74
2 changed files with 42 additions and 11 deletions

View File

@ -34,9 +34,18 @@
"pve": "pve" "pve": "pve"
}, },
"users": { "users": {
"pve": [ "realm": {
"pve": [
"localdb"
],
"ldap": [
"localdb",
"paasldap"
]
},
"any": [
"localdb", "localdb",
"pve" "paasldap"
] ]
} }
}, },

View File

@ -98,7 +98,7 @@ class USER_BACKEND extends BACKEND {
* @param {Object} params authentication params, usually req.cookies * @param {Object} params authentication params, usually req.cookies
* @returns {{ok: boolean, status: number, message: string}} error object or null * @returns {{ok: boolean, status: number, message: string}} error object or null
*/ */
deluser (user, params = null) {} delUser (user, params = null) {}
/** /**
* Add group to backend * Add group to backend
@ -188,14 +188,14 @@ class USER_BACKEND_MANAGER extends USER_BACKEND {
} }
getBackendsByUser (user) { getBackendsByUser (user) {
return this.#config[user.realm]; return this.#config.realm[user.realm];
} }
addUser (user, attributes, params = null) {} addUser (user, attributes, params = null) {}
async getUser (user, params = null) { async getUser (user, params = null) {
let userData = {}; let userData = {};
for (const backend of this.#config[user.realm]) { for (const backend of this.#config.realm[user.realm]) {
const backendData = await global.backends[backend].getUser(user, params); const backendData = await global.backends[backend].getUser(user, params);
if (backendData) { if (backendData) {
userData = { ...backendData, ...userData }; userData = { ...backendData, ...userData };
@ -204,7 +204,18 @@ class USER_BACKEND_MANAGER extends USER_BACKEND {
return userData; return userData;
} }
async getAllUsers (params = null) {} async getAllUsers (params = null) {
const userData = {};
for (const backend of this.#config.any) {
const backendData = await global.backends[backend].getAllUsers(params);
if (backendData) {
for (const user of Object.keys(backendData)) {
userData[user] = { ...backendData[user], ...userData[user] };
}
}
}
return userData;
}
async setUser (user, attributes, params = null) { async setUser (user, attributes, params = null) {
const results = { const results = {
@ -212,9 +223,9 @@ class USER_BACKEND_MANAGER extends USER_BACKEND {
status: 200, status: 200,
message: "" message: ""
}; };
for (const backend of this.#config[user.realm]) { for (const backend of this.#config.realm[user.realm]) {
const r = await global.backends[backend].setUser(user, attributes, params); const result = await global.backends[backend].setUser(user, attributes, params);
if (!r) { if (!result) {
results.ok = false; results.ok = false;
results.status = 500; results.status = 500;
return results; return results;
@ -223,13 +234,24 @@ class USER_BACKEND_MANAGER extends USER_BACKEND {
return results; return results;
} }
deluser (user, params = null) {} delUser (user, params = null) {}
addGroup (group, attributes, params = null) {} addGroup (group, attributes, params = null) {}
getGroup (group, params = null) {} getGroup (group, params = null) {}
getAllGroups (params = null) {} async getAllGroups (params = null) {
const groupData = {};
for (const backend of this.#config.any) {
const backendData = await global.backends[backend].getAllGroups(params);
if (backendData) {
for (const group of Object.keys(backendData)) {
groupData[group] = { ...backendData[group], ...groupData[group] };
}
}
}
return groupData;
}
setGroup (group, attributes, params = null) {} setGroup (group, attributes, params = null) {}