From 9f2df6af2a858abddb9a3c98fae2e18fab587dc8 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 8 May 2024 14:59:50 +0200 Subject: [PATCH] Add wildcard support to management.js. --- static/change-password.js | 2 +- static/management.js | 50 +++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/static/change-password.js b/static/change-password.js index ed713f0..419d0c1 100644 --- a/static/change-password.js +++ b/static/change-password.js @@ -44,7 +44,7 @@ document.getElementById('passwordform').onsubmit = async function(e) { } try { - await setPassword(group, user, new1, old); + await setPassword(group, user, false, new1, old); document.getElementById('old').value = ''; document.getElementById('new1').value = ''; document.getElementById('new2').value = ''; diff --git a/static/management.js b/static/management.js index 2c3b006..c059e23 100644 --- a/static/management.js +++ b/static/management.js @@ -216,17 +216,33 @@ async function listUsers(group) { return await listObjects(`/galene-api/v0/.groups/${group}/.users/`); } +/** + * userURL returns the URL for a user entry + * + * @param {string} group + * @param {string} user + * @param {boolean} wildcard + */ +function userURL(group, user, wildcard) { + if(wildcard) + return `/galene-api/v0/.groups/${group}/.wildcard-user`; + else if(user === "") + return `/galene-api/v0/.groups/${group}/.empty-user`; + else + return `/galene-api/v0/.groups/${group}/.users/${user}` +} + /** * getUser returns a given user entry. * * @param {string} group * @param {string} user + * @param {boolean} wildcard * @param {string} [etag] * @returns {Promise} */ -async function getUser(group, user, etag) { - return await getObject(`/galene-api/v0/.groups/${group}/.users/${user}`, - etag); +async function getUser(group, user, wildcard, etag) { + return await getObject(userURL(group, user, wildcard), etag); } /** @@ -235,11 +251,11 @@ async function getUser(group, user, etag) { * * @param {string} group * @param {string} user + * @param {boolean} wildcard * @param {Object} values */ -async function createUser(group, user, values) { - return await createObject(`/galene-api/v0/.groups/${group}/.users/${user}`, - values); +async function createUser(group, user, wildcard, values) { + return await createObject(userURL(group, user, wildcard), values); } /** @@ -247,12 +263,11 @@ async function createUser(group, user, values) { * * @param {string} group * @param {string} user + * @param {boolean} wildcard * @param {string} [etag] */ -async function deleteUser(group, user, etag) { - return await deleteObject( - `/galene-api/v0/.groups/${group}/.users/${user}/`, etag, - ); +async function deleteUser(group, user, wildcard, etag) { + return await deleteObject(userURL(group, user, wildcard), etag); } /** @@ -261,11 +276,11 @@ async function deleteUser(group, user, etag) { * @param {string} group * @param {string} user * @param {Object} values + * @param {boolean} wildcard * @param {string} [etag] */ -async function updateUser(group, user, values, etag) { - return await updateObject(`/galene-api/v0/.groups/${group}/.users/${user}`, - values, etag); +async function updateUser(group, user, wildcard, values, etag) { + return await updateObject(userURL(group, user, wildcard), values, etag); } /** @@ -275,10 +290,11 @@ async function updateUser(group, user, values, etag) { * * @param {string} group * @param {string} user + * @param {boolean} wildcard * @param {string} password * @param {string} [oldpassword] */ -async function setPassword(group, user, password, oldpassword) { +async function setPassword(group, user, wildcard, password, oldpassword) { let options = { method: 'POST', headers: { @@ -292,15 +308,13 @@ async function setPassword(group, user, password, oldpassword) { `Basic ${btoa(user + ':' + oldpassword)}` } - let r = await fetch( - `/galene-api/v0/.groups/${group}/.users/${user}/.password`, - options); + let r = await fetch(userURL(group, user, wildcard) + '/.password', options); if(!r.ok) throw httpError(r); } /** - * listUsers lists the tokens for a given group. + * listTokens lists the tokens for a given group. * * @param {string} group * @returns {Promise>}