aaa538c7f9
tos.md was baked into the repo and read once at startup, so changing the terms required a code change and deploy. It's now a Redis-backed singleton (models/tos.js), editable from a new "Terms of Service" card on the admin Dashboard, with the bundled tos.md used only as a one-time seed for new deployments. - routes/tos.js: GET (any authenticated user) / PUT (app_sso_admin only) via /api/tos. Saving can optionally reset every user's tos_accepted flag so they're asked to re-accept -- off by default, since a wording fix shouldn't re-prompt everyone. - routes/index.js: /tos and /onboarding now render the live content instead of a module-level constant computed once at process start.
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const Table = require('.');
|
|
|
|
// Terms-of-Service text, editable by an admin at runtime (see routes/tos.js
|
|
// + the Dashboard's "Terms of Service" card) instead of being baked into the
|
|
// repo. A singleton row -- always keyed 'current' -- rather than a UUID like
|
|
// the other Redis models here, since there's only ever one live ToS.
|
|
class Tos extends Table {
|
|
static _key = 'name';
|
|
static _keyMap = {
|
|
name: {default: 'current', type: 'string'},
|
|
content: {isRequired: true, type: 'string'},
|
|
updated_by: {isRequired: true, type: 'string'},
|
|
updated_on: {default: () => Date.now()},
|
|
};
|
|
|
|
// Fetch the live row, seeding it from the bundled tos.md template the
|
|
// first time this is ever called on a deployment (so upgrading an
|
|
// existing install doesn't start with a blank ToS).
|
|
static async getCurrent() {
|
|
try {
|
|
return await this.get('current');
|
|
} catch (error) {
|
|
const content = fs.readFileSync(path.join(__dirname, '../../tos.md'), 'utf8');
|
|
return this.create({name: 'current', content, updated_by: 'system'});
|
|
}
|
|
}
|
|
}
|
|
Tos.register();
|
|
|
|
module.exports = {Tos};
|