diff --git a/backend/src/routes/user.js b/backend/src/routes/user.js index 8fd8db66..a9bc6aeb 100644 --- a/backend/src/routes/user.js +++ b/backend/src/routes/user.js @@ -193,4 +193,113 @@ router.get('/get-settings', passport.authenticate('jwt', {session: false}), asyn } }); +// -- Account management (the "Manage accounts" window of the site settings) ---- +// /api/user is mounted before the JWT guard, so every route below authenticates +// inline; and only an administrator gets past isAdmin (services/middleware.js). + +router.get('/list', passport.authenticate('jwt', {session: false}), isAdmin, async (req, res) => { + try { + // No account gets out with its password or an unfinished setup code. + const users = await User.find().select('-password -setupCode').sort({ date: 1 }); + res.json({ status: "ok", users }); + } catch (err) { + console.error(err); + res.json({ status: "error", msg: "errors.internal" }); + } +}); + +// The admin creates the account with the password its user logs in with; the +// setupCode flow above stays as it is, nothing on the frontend completes it. +router.post('/create', passport.authenticate('jwt', {session: false}), isAdmin, async (req, res) => { + try { + const { name, username, email, password } = req.body; + if (!(name && username && email && password)) { + return res.json({ status: "error", msg: "errors.missing-data" }); + } + + const existingUser = await User.findOne({ + $or: [ + { email: email }, + { username: username } + ] + }); + if (existingUser) { + return res.json({ + status: "error", + msg: "register.errors.email-username-exists" + }); + } + + const salt = await bcrypt.genSalt(10); + let user = new User({ + name: name, + username: username, + email: email, + password: await bcrypt.hash(password, salt) + }); + await user.save(); + res.json({ + status: "ok", + user: { + _id: user._id, + name: user.name, + username: user.username, + email: user.email, + admin: user.admin, + date: user.date + } + }); + } catch (err) { + console.error(err); + res.json({ status: "error", msg: "errors.internal" }); + } +}); + +router.post('/set-admin', passport.authenticate('jwt', {session: false}), isAdmin, async (req, res) => { + try { + const { id, admin } = req.body; + if (!id || typeof admin !== 'boolean') { + return res.json({ status: "error", msg: "errors.missing-data" }); + } + + // Switching one's own rights off could leave an instance with nobody who + // can manage accounts at all, so the row for yourself stays closed. + if (String(req.user._id) === String(id)) { + return res.json({ status: "error", msg: "settings.site-administration.accounts.errors.self-admin" }); + } + + const user = await User.findOne({ _id: id }); + if (!user) return res.json({ status: "error", msg: "errors.notfound" }); + + user.admin = admin; + await user.save(); + res.json({ status: "ok", user: { _id: user._id, admin: user.admin } }); + } catch (err) { + console.error(err); + res.json({ status: "error", msg: "errors.internal" }); + } +}); + +// Only the account itself goes; what it created stays as it is. +router.post('/delete', passport.authenticate('jwt', {session: false}), isAdmin, async (req, res) => { + try { + const { id } = req.body; + if (!id) return res.json({ status: "error", msg: "errors.missing-data" }); + + // Same guard as the admin switch: nobody locks themselves out on the way out. + if (String(req.user._id) === String(id)) { + return res.json({ status: "error", msg: "settings.site-administration.accounts.errors.self-delete" }); + } + + const user = await User.findOne({ _id: id }); + if (!user) return res.json({ status: "error", msg: "errors.notfound" }); + + await user.deleteOne(); + res.json({ status: "ok" }); + } catch (err) { + console.error(err); + res.json({ status: "error", msg: "errors.internal" }); + } +}); + module.exports = router; \ No newline at end of file diff --git a/frontend/app/components/partials/ContentSidebar.vue b/frontend/app/components/partials/ContentSidebar.vue index c32591cc..597a53a6 100644 --- a/frontend/app/components/partials/ContentSidebar.vue +++ b/frontend/app/components/partials/ContentSidebar.vue @@ -7,7 +7,7 @@ import { AnchorMap, AnchoredMap, ClearAnchoredMap, SetActivePane } from '~/servi import { emitter } from '~/services/Emitter'; import { BuildColorMenu } from '~/services/EntryColors'; import { BuildItemRows } from '~/services/ItemFolders'; -import Server from '~/services/Server'; +import Server, { getBaseUrl } from '~/services/Server'; import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows'; import { HideContextMenu, ShowContextMenu } from '~/services/ContextMenu'; import { ACTOR_DRAG_TYPE } from '~/services/MapTokens'; @@ -283,6 +283,13 @@ function itemSummary(item) { return `${t(`campaigns.item.categories.${item.category}`)} · ${t(`campaigns.item.rarities.${item.rarity}`)} · ${t('campaigns.item.quantity-short')} ${item.quantity}`; } +// An item's icon in the sidebar: an uploaded filename served from /api/public, or a full URL +// (Foundry sends its own icon as one) — the same rule the item window uses. +function itemImageUrl(image) { + if (!image) return ''; + return /^(https?:|data:|\/\/)/i.test(image) ? image : `${getBaseUrl()}/public/${image}`; +} + function mapSummary(map) { return t('campaigns.map.summary', { size: map.gridSize, scale: map.scale }); } @@ -670,9 +677,11 @@ onBeforeUnmount(() => { @toggle="toggleFolder(row.folder._id)" />
- + + {{ row.item.name }} - {{ t('campaigns.synced') }}
@@ -865,6 +874,15 @@ onBeforeUnmount(() => { } .entity-entry-meta, .entity-entry-description { font-size: 12px; opacity: 0.72; } .entity-entry-description { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; } +/* An item row leads with the item's own icon on the left of its name, standing in for the + "SYNCED" text it used to show (Syndria98/dragonroll#53). */ +.entity-entry-title { display: flex; align-items: center; gap: 9px; min-width: 0; } +.entity-entry-image { + flex: 0 0 30px; width: 30px; height: 30px; box-sizing: border-box; + display: grid; place-items: center; overflow: hidden; + border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-background-soft); +} +.entity-entry-image img { width: 100%; height: 100%; object-fit: contain; } @media (max-width: 900px) { .notes-sidebar { diff --git a/frontend/app/components/windows/AccountManagementWindow.vue b/frontend/app/components/windows/AccountManagementWindow.vue new file mode 100644 index 00000000..48cc2a3c --- /dev/null +++ b/frontend/app/components/windows/AccountManagementWindow.vue @@ -0,0 +1,289 @@ + + + + + + + diff --git a/frontend/app/components/windows/SettingsWindow.vue b/frontend/app/components/windows/SettingsWindow.vue index 235dcef2..ff9d1890 100644 --- a/frontend/app/components/windows/SettingsWindow.vue +++ b/frontend/app/components/windows/SettingsWindow.vue @@ -80,21 +80,15 @@ onMounted(() => { }); function OpenManageAccounts(){ - ClearWindow('settings'); + ClearWindow({ type: 'settings' }); CreateWindow('account_management', { - type: 'account_management', - title: 'settings.site-administration.manage-accounts.title', - id: 'account-management', + // Back returns to the settings tab this button sits on; CreateWindow leaves + // a window that is already open alone. back: () => { - ClearWindow('account-management') - CreateWindow('settings', { - id: 'settings', - type: 'settings', - title: 'settings.title', - back: () => { ClearWindow('settings'); CreateWindow('main_menu'); } - }); + ClearWindow({ type: 'account_management' }); + CreateWindow('settings'); } - }) + }); } const getLocaleName = (locale) => { diff --git a/frontend/app/services/WindowDefinitions.js b/frontend/app/services/WindowDefinitions.js index 60fb27db..115cc3aa 100644 --- a/frontend/app/services/WindowDefinitions.js +++ b/frontend/app/services/WindowDefinitions.js @@ -34,6 +34,12 @@ const defWindows = { }, movable: true }, + account_management: { + title: 'windows.account-management', + component: () => import('~/components/windows/AccountManagementWindow.vue'), + close: () => ClearWindow({type: 'account_management'}), + movable: true + }, create_campaign: { title: "windows.create-campaign", component: () => import('~/components/windows/CreateCampaignWindow.vue'), diff --git a/frontend/i18n/locales/ca/settings.json b/frontend/i18n/locales/ca/settings.json index 715a1f63..0f654888 100644 --- a/frontend/i18n/locales/ca/settings.json +++ b/frontend/i18n/locales/ca/settings.json @@ -8,6 +8,30 @@ "language": "Idioma" }, "site-administration": { - "manage-accounts": "Gestiona els comptes" + "manage-accounts": "Gestiona els comptes", + "accounts": { + "you": "tu", + "admin": "Administrador", + "make-admin": "Fes-lo administrador", + "remove-admin": "Treu-li l'administrador", + "delete": "Elimina", + "new-account": "Nou compte", + "name": "Nom", + "username": "Nom d'usuari", + "email": "Correu electrònic", + "password": "Contrasenya", + "create": "Crea el compte", + "created": "Compte creat", + "updated": "Compte actualitzat", + "deleted": "Compte eliminat", + "errors": { + "name-empty": "Si us plau, introdueix un nom.", + "username-empty": "Si us plau, introdueix un nom d'usuari.", + "email-empty": "Si us plau, introdueix un correu electrònic vàlid.", + "password-empty": "Si us plau, introdueix una contrasenya.", + "self-admin": "No pots canviar els teus propis privilegis d'administrador.", + "self-delete": "No pots eliminar el teu propi compte." + } + } } } \ No newline at end of file diff --git a/frontend/i18n/locales/ca/windows.json b/frontend/i18n/locales/ca/windows.json index 9a28fcd5..bb86f379 100644 --- a/frontend/i18n/locales/ca/windows.json +++ b/frontend/i18n/locales/ca/windows.json @@ -5,6 +5,7 @@ "example": "Finestra d'exemple", "edit-profile": "Editar perfil", "settings": "Configuració", + "account-management": "Gestió dels comptes", "create-campaign": "Crear campanya", "create-map": "Crear mapa", "map-viewer": "Mapa", diff --git a/frontend/i18n/locales/en/settings.json b/frontend/i18n/locales/en/settings.json index 8be61593..0b2b76c5 100644 --- a/frontend/i18n/locales/en/settings.json +++ b/frontend/i18n/locales/en/settings.json @@ -8,6 +8,30 @@ "language": "Language" }, "site-administration": { - "manage-accounts": "Manage accounts" + "manage-accounts": "Manage accounts", + "accounts": { + "you": "you", + "admin": "Administrator", + "make-admin": "Make administrator", + "remove-admin": "Remove administrator", + "delete": "Delete", + "new-account": "New account", + "name": "Name", + "username": "Username", + "email": "Email", + "password": "Password", + "create": "Create account", + "created": "Account created", + "updated": "Account updated", + "deleted": "Account deleted", + "errors": { + "name-empty": "Please enter a name.", + "username-empty": "Please enter a username.", + "email-empty": "Please enter a valid email address.", + "password-empty": "Please enter a password.", + "self-admin": "You cannot change your own administrator rights.", + "self-delete": "You cannot delete your own account." + } + } } } \ No newline at end of file diff --git a/frontend/i18n/locales/en/windows.json b/frontend/i18n/locales/en/windows.json index 93536f61..e063057f 100644 --- a/frontend/i18n/locales/en/windows.json +++ b/frontend/i18n/locales/en/windows.json @@ -5,6 +5,7 @@ "example": "Example Window", "edit-profile": "Edit Profile", "settings": "Settings", + "account-management": "Manage accounts", "create-campaign": "Create Campaign", "create-map": "Create Map", "map-viewer": "Map", diff --git a/frontend/i18n/locales/es/settings.json b/frontend/i18n/locales/es/settings.json index d292a08e..ef02cf6c 100644 --- a/frontend/i18n/locales/es/settings.json +++ b/frontend/i18n/locales/es/settings.json @@ -8,6 +8,30 @@ "language": "Idioma" }, "site-administration": { - "manage-accounts": "Gestionar cuentas" + "manage-accounts": "Gestionar cuentas", + "accounts": { + "you": "tú", + "admin": "Administrador", + "make-admin": "Nombrar administrador", + "remove-admin": "Quitar administrador", + "delete": "Eliminar", + "new-account": "Nueva cuenta", + "name": "Nombre", + "username": "Nombre de usuario", + "email": "Correo electrónico", + "password": "Contraseña", + "create": "Crear cuenta", + "created": "Cuenta creada", + "updated": "Cuenta actualizada", + "deleted": "Cuenta eliminada", + "errors": { + "name-empty": "Por favor, introduce un nombre.", + "username-empty": "Por favor, introduce un nombre de usuario.", + "email-empty": "Por favor, introduce un correo electrónico válido.", + "password-empty": "Por favor, introduce una contraseña.", + "self-admin": "No puedes cambiar tus propios privilegios de administrador.", + "self-delete": "No puedes eliminar tu propia cuenta." + } + } } } \ No newline at end of file diff --git a/frontend/i18n/locales/es/windows.json b/frontend/i18n/locales/es/windows.json index 98f34193..23e5817e 100644 --- a/frontend/i18n/locales/es/windows.json +++ b/frontend/i18n/locales/es/windows.json @@ -5,6 +5,7 @@ "example": "Ventana de ejemplo", "edit-profile": "Editar perfil", "settings": "Configuración", + "account-management": "Gestionar cuentas", "create-campaign": "Crear campanya", "create-map": "Crear mapa", "map-viewer": "Mapa", diff --git a/tests/item-entry-display.test.js b/tests/item-entry-display.test.js new file mode 100644 index 00000000..a9e21ccc --- /dev/null +++ b/tests/item-entry-display.test.js @@ -0,0 +1,69 @@ +// Tests for Syndria98/dragonroll#53: the item row in the campaign sidebar dropped its "SYNCED" +// text badge and now leads with the item's own icon on the left of the entry. +// +// The repository root installs no dependencies, so these read the sidebar component the way +// tests/sidebar-entity-entry.test.js does — the checks are about the markup and style of the row. +// +// Run with `npm test` from the repository root, or `node --test tests/`. + +const { test } = require("node:test"); +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const path = require("node:path"); + +const source = fs.readFileSync( + path.join(__dirname, "..", "frontend", "app", "components", "partials", "ContentSidebar.vue"), + "utf8" +); + +// The block that renders the item rows, from the items section down to its closing template. The +// items section is followed by the maps section (`v-else`), so the first `` that leads +// there ends it; the inner `v-for` close is followed by another close, not by `v-else`. +const itemSection = + /