Show operator name groups in widget

This commit is contained in:
rajchales-monito
2026-07-24 10:44:12 +02:00
parent e1d63db62f
commit 69fa9075ab
3 changed files with 22 additions and 6 deletions
+9 -4
View File
@@ -229,19 +229,24 @@ function configuredUsers() {
for (let i = 1; i < 50; i += 1) {
const username = process.env[`USER_${i}`];
const password = process.env[`PASS_${i}`];
const displayName = process.env[`NAME_${i}`] || username;
if (!username && !password) break;
if (username && password) users.push({ username, password });
if (username && password) users.push({ username, password, displayName });
}
return users;
}
function adminProfile(username) {
return configuredUsers().find((user) => user.username === username) || { username, displayName: username };
}
async function adminLogin(req, res) {
const body = await readJson(req);
const match = configuredUsers().find((u) => u.username === body.username && u.password === body.password);
if (!match) return json(res, 401, { error: "bad_credentials" });
const token = signSession(match.username);
res.setHeader("Set-Cookie", `${COOKIE_NAME}=${token}; HttpOnly; SameSite=Lax; Path=/; Max-Age=${60 * 60 * 24 * 14}`);
return json(res, 200, { ok: true, user: { username: match.username } });
return json(res, 200, { ok: true, user: { username: match.username, displayName: match.displayName } });
}
function adminLogout(res) {
@@ -253,7 +258,7 @@ function requireAdmin(req, res, next) {
const token = parseCookies(req.headers.cookie || "")[COOKIE_NAME];
const username = token && verifySession(token);
if (!username) return json(res, 401, { error: "unauthorized" });
req.adminUser = { username };
req.adminUser = adminProfile(username);
return next();
}
@@ -423,7 +428,7 @@ async function createAdminMessage(req, res, url) {
if (!attachmentsAreAllowed(body.attachments || [])) return json(res, 400, { error: "only_images_allowed" });
const conversation = findConversation(publicIdFrom(url));
if (!conversation) return json(res, 404, { error: "conversation_not_found" });
const messageId = insertMessage(conversation.id, "admin", req.adminUser.username, String(body.message || "").trim());
const messageId = insertMessage(conversation.id, "admin", req.adminUser.displayName || req.adminUser.username, String(body.message || "").trim());
saveAttachments(conversation.id, messageId, body.attachments || []);
bumpConversation(conversation.id, conversation.status === "new" ? "open" : conversation.status);
markConversationSeen(conversation.id);