pgkiln 0.50.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SECURITY.md +2 -0
- package/db/migrations/119_workspace_home.sql +30 -0
- package/db/migrations/120_datasets.sql +87 -0
- package/docs/apex-feature-parity.md +5 -4
- package/docs/guide/01-installation.md +2 -0
- package/docs/guide/03-builder.md +91 -5
- package/docs/guide/04-pages-and-regions.md +25 -1
- package/docs/guide/12-development.md +26 -3
- package/examples/hr/hr_63_datasets.sql +29 -0
- package/package.json +1 -1
- package/public/app.css +6 -0
- package/public/builder.css +34 -0
- package/src/app.ts +5 -1
- package/src/builder/datasets.ts +472 -0
- package/src/builder/home.ts +12 -7
- package/src/builder/instance.ts +2 -0
- package/src/builder/reporter.ts +52 -3
- package/src/builder/routes.ts +3 -3
- package/src/builder/subscriptions.ts +1 -0
- package/src/builder/ui.ts +7 -5
- package/src/builder/workspace-home.ts +283 -0
- package/src/builder/workspaces.ts +7 -4
- package/src/datasets.ts +367 -0
- package/src/i18n/ar.ts +16 -0
- package/src/i18n/cs.ts +16 -0
- package/src/i18n/da.ts +16 -0
- package/src/i18n/de.ts +16 -0
- package/src/i18n/el.ts +16 -0
- package/src/i18n/es.ts +16 -0
- package/src/i18n/fi.ts +16 -0
- package/src/i18n/fr.ts +16 -0
- package/src/i18n/he.ts +16 -0
- package/src/i18n/it.ts +16 -0
- package/src/i18n/ja.ts +16 -0
- package/src/i18n/ko.ts +16 -0
- package/src/i18n/nb.ts +16 -0
- package/src/i18n/pl.ts +16 -0
- package/src/i18n/pt.ts +16 -0
- package/src/i18n/ru.ts +16 -0
- package/src/i18n/sv.ts +16 -0
- package/src/i18n/tr.ts +16 -0
- package/src/i18n/uk.ts +16 -0
- package/src/i18n/zh.ts +16 -0
- package/src/i18n.ts +32 -0
- package/src/instance.ts +1 -0
- package/src/release-check.ts +139 -0
- package/src/reporting-app.ts +101 -0
- package/src/runtime/data-reporter.ts +199 -32
- package/src/session.ts +2 -0
- package/src/subscriptions.ts +2 -1
- package/src/workspace-export.ts +24 -4
package/src/builder/instance.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { html } from '../html.ts';
|
|
|
3
3
|
import { configurationValue, CONFIGURATION, INSTANCE_SETTINGS, instanceSetting, origin, refreshInstanceSettings, saveInstanceSettings } from '../instance.ts';
|
|
4
4
|
import { clientIp, logActivity, type Session } from '../session.ts';
|
|
5
5
|
import { isAdmin } from './locks.ts';
|
|
6
|
+
import { releaseCheckRegion } from './workspace-home.ts';
|
|
6
7
|
import { back, BASE, csrf, developer, flash, region, send, shell, type Req } from './ui.ts';
|
|
7
8
|
|
|
8
9
|
// Workspace utilities → Instance settings (administrators; APEX: instance
|
|
@@ -37,6 +38,7 @@ export async function instanceRoutes(app: FastifyInstance) {
|
|
|
37
38
|
<small class="help">${x.help} In effect: <b>${instanceSetting(x.key)}</b> (${ORIGIN_TEXT[from]}; <code>${x.env}</code>, default ${x.default}).</small></div>`;
|
|
38
39
|
})}</div>
|
|
39
40
|
<div class="buttons"><button class="btn btn-hot">Save</button></div></form>`)}
|
|
41
|
+
${await releaseCheckRegion(s)}
|
|
40
42
|
${region('Configuration', html`<p class="muted u-mt0">Environment variables of this server (chapter 1 of the guide). Secrets show only whether they are set.</p>
|
|
41
43
|
<div class="table-wrap"><table class="report report-reflow"><thead><tr><th>Variable</th><th>Value</th><th>Purpose</th></tr></thead>
|
|
42
44
|
<tbody>${CONFIGURATION.map((c) => {
|
package/src/builder/reporter.ts
CHANGED
|
@@ -65,7 +65,7 @@ const clip = (v: string | undefined, max: number) => (v ?? '').trim().slice(0, m
|
|
|
65
65
|
* except binary ones.
|
|
66
66
|
*/
|
|
67
67
|
export async function mergeReporterSettings(
|
|
68
|
-
config: Config, b: Body, a: { authz: Set<string> },
|
|
68
|
+
config: Config, b: Body, a: { authz: Set<string>; datasets?: Set<string> },
|
|
69
69
|
lookup: { byName: (schema: string, table: string) => Promise<DbObject | null>; byOid: (oid: number) => Promise<DbObject | null> } = { byName: findObject, byOid: objectByOid },
|
|
70
70
|
): Promise<{ config: Config; errors: string[] }> {
|
|
71
71
|
const out: Config = { ...config };
|
|
@@ -80,6 +80,13 @@ export async function mergeReporterSettings(
|
|
|
80
80
|
delete out.share_authz;
|
|
81
81
|
if (b.sharing === 'off') out.sharing = false;
|
|
82
82
|
else if (b.sharing?.startsWith('authz:') && a.authz.has(b.sharing.slice(6).toUpperCase())) out.share_authz = b.sharing.slice(6);
|
|
83
|
+
// (sprint 110) who may edit reports, who may unpublish and delete anyone's, published reports
|
|
84
|
+
for (const k of ['edit_authz', 'admin_authz'] as const) {
|
|
85
|
+
delete out[k];
|
|
86
|
+
if (b[k] && a.authz.has(b[k]!.toUpperCase())) out[k] = b[k];
|
|
87
|
+
}
|
|
88
|
+
delete out.publishing;
|
|
89
|
+
if (b.publishing === 'true') out.publishing = true;
|
|
83
90
|
|
|
84
91
|
const sources: Source[] = [];
|
|
85
92
|
const existing = sourcesOf({ config });
|
|
@@ -87,6 +94,13 @@ export async function mergeReporterSettings(
|
|
|
87
94
|
const s = existing.find((x) => x.id === b[`s${i}_key`]);
|
|
88
95
|
if (!s || sources.some((x) => x.id === s.id)) continue;
|
|
89
96
|
if (b[`s${i}_remove`] === 'true') continue;
|
|
97
|
+
if (s.dataset) {
|
|
98
|
+
// (sprint 110) a dataset: its columns are the dataset's (SQL Workshop → Data Reporter); label and description may differ here
|
|
99
|
+
const label = clip(b[`s${i}_label`], 80);
|
|
100
|
+
const description = clip(b[`s${i}_description`], 300);
|
|
101
|
+
sources.push({ id: s.id, dataset: s.dataset, ...(label ? { label } : {}), ...(description ? { description } : {}) } as Source);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
90
104
|
const obj = await lookup.byName(s.schema, s.table);
|
|
91
105
|
const names = new Set(obj?.columns.map((c) => c.name));
|
|
92
106
|
const columns: SourceColumn[] = [];
|
|
@@ -129,6 +143,17 @@ export async function mergeReporterSettings(
|
|
|
129
143
|
sources.push({ id, label, schema: obj.schema, table: obj.table, columns });
|
|
130
144
|
}
|
|
131
145
|
}
|
|
146
|
+
// (sprint 110) a dataset of the workspace as a new source
|
|
147
|
+
if (b.new_dataset) {
|
|
148
|
+
const name = b.new_dataset.trim().toLowerCase();
|
|
149
|
+
if (!a.datasets?.has(name)) errors.push('Choose one of the workspace\'s datasets.');
|
|
150
|
+
else if (sources.length >= MAX_SOURCES) errors.push(`A region offers at most ${MAX_SOURCES} data sources.`);
|
|
151
|
+
else {
|
|
152
|
+
let id = name.slice(0, 36);
|
|
153
|
+
for (let n = 2; sources.some((s) => s.id === id); n++) id = `${name.slice(0, 36)}_${n}`;
|
|
154
|
+
sources.push({ id, dataset: name } as Source);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
132
157
|
if (sources.length) out.sources = sources;
|
|
133
158
|
else delete out.sources;
|
|
134
159
|
return { config: out, errors };
|
|
@@ -145,8 +170,23 @@ export async function reporterSettingsForm(pageId: number, appId: number, r: { i
|
|
|
145
170
|
const objects = await objectList(app?.db_role ?? null);
|
|
146
171
|
const sources = sourcesOf({ config: cfg });
|
|
147
172
|
const sharing = cfg.sharing === false ? 'off' : typeof cfg.share_authz === 'string' && cfg.share_authz ? `authz:${cfg.share_authz}` : '';
|
|
173
|
+
const datasets = (await owner.query<{ name: string; label: string }>('select name, label from meta.dataset where workspace_id = meta.app_workspace($1) order by name', [appId])).rows;
|
|
148
174
|
const sourceSets = await Promise.all(
|
|
149
175
|
sources.map(async (src, i) => {
|
|
176
|
+
if (src.dataset) {
|
|
177
|
+
const d = datasets.find((x) => x.name === src.dataset);
|
|
178
|
+
return html`<fieldset class="prop-group"><legend>${src.label || d?.label || src.id} <span class="muted">(dataset ${src.dataset})</span></legend>
|
|
179
|
+
<input type="hidden" name="s${i}_key" value="${src.id}">
|
|
180
|
+
${!d ? html`<div class="alert alert-error" role="alert">The workspace has no dataset ${src.dataset} (any more).</div>` : ''}
|
|
181
|
+
<div class="form-grid">
|
|
182
|
+
<div class="field"><label class="label" for="${id(`s${i}_id`)}">Static id</label><input id="${id(`s${i}_id`)}" value="${src.id}" readonly></div>
|
|
183
|
+
<div class="field"><label class="label" for="${id(`s${i}_label`)}">Label</label><input id="${id(`s${i}_label`)}" name="s${i}_label" maxlength="80" value="${src.label ?? ''}" placeholder="${d?.label ?? ''}"></div>
|
|
184
|
+
<div class="field" data-wide><label class="label" for="${id(`s${i}_description`)}">Description (shown to users)</label><input id="${id(`s${i}_description`)}" name="s${i}_description" maxlength="300" value="${src.description ?? ''}" placeholder="the dataset's"></div>
|
|
185
|
+
</div>
|
|
186
|
+
<p class="muted">Its tables, columns, labels, masks and row filter are the dataset's: <a href="${BASE}/reporter">App Builder → Data Reporter</a>.</p>
|
|
187
|
+
<div class="field"><label class="check"><input type="checkbox" name="s${i}_remove" value="true"> Remove this data source (users' reports on it stop working)</label></div>
|
|
188
|
+
</fieldset>`;
|
|
189
|
+
}
|
|
150
190
|
const obj = await findObject(src.schema, src.table);
|
|
151
191
|
const offered = new Map(src.columns.map((c) => [c.name, c]));
|
|
152
192
|
const all = [...(obj?.columns ?? []).map((c) => ({ name: c.name, type: c.type, missing: false })),
|
|
@@ -184,6 +224,12 @@ export async function reporterSettingsForm(pageId: number, appId: number, r: { i
|
|
|
184
224
|
<select id="${id('sharing')}" name="sharing">${opt('', 'Every signed-in user', sharing)}${opt('off', 'Nobody (private reports only)', sharing)}${schemes.map((n) => opt(`authz:${n}`, `Authorization: ${n}`, sharing))}</select></div>
|
|
185
225
|
<div class="field"><label class="label" for="${id('page_size')}">Rows per page</label>
|
|
186
226
|
<input id="${id('page_size')}" name="page_size" type="number" min="5" max="200" value="${cfg.page_size ?? ''}" placeholder="25"></div>
|
|
227
|
+
<div class="field"><label class="label" for="${id('edit_authz')}">Who may build and save reports</label>
|
|
228
|
+
<select id="${id('edit_authz')}" name="edit_authz">${opt('', 'Every user', cfg.edit_authz ?? '')}${schemes.map((n) => opt(n, `Authorization: ${n}`, cfg.edit_authz ?? ''))}</select>
|
|
229
|
+
<small class="help">Others only run shared reports.</small></div>
|
|
230
|
+
<div class="field"><label class="label" for="${id('admin_authz')}">Who may unpublish and delete anyone's reports</label>
|
|
231
|
+
<select id="${id('admin_authz')}" name="admin_authz">${opt('', 'Nobody', cfg.admin_authz ?? '')}${schemes.map((n) => opt(n, `Authorization: ${n}`, cfg.admin_authz ?? ''))}</select></div>
|
|
232
|
+
<div class="field"><label class="check"><input type="checkbox" name="publishing" value="true"${cfg.publishing === true ? raw(' checked') : ''}> Shared reports are published: a stable URL, pins</label></div>
|
|
187
233
|
<div class="field" data-wide><label class="label" for="${id('empty')}">Text when there are no rows</label>
|
|
188
234
|
<input id="${id('empty')}" name="empty" maxlength="200" value="${cfg.empty ?? ''}" placeholder="No data found"></div>
|
|
189
235
|
</div></fieldset>
|
|
@@ -194,7 +240,9 @@ export async function reporterSettingsForm(pageId: number, appId: number, r: { i
|
|
|
194
240
|
<div class="field"><label class="label" for="${id('new_id')}">Static id</label><input id="${id('new_id')}" name="new_id" maxlength="40" pattern="[a-z][a-z0-9_]*" placeholder="from the name"></div>
|
|
195
241
|
<div class="field"><label class="label" for="${id('new_label')}">Label</label><input id="${id('new_label')}" name="new_label" maxlength="80"></div>
|
|
196
242
|
</div>
|
|
197
|
-
<small class="help">All columns are offered at first (except binary ones); untick those users should not see. Prefer a view that shows exactly what business users may report on.</small
|
|
243
|
+
<small class="help">All columns are offered at first (except binary ones); untick those users should not see. Prefer a view that shows exactly what business users may report on.</small>
|
|
244
|
+
${datasets.length ? html`<div class="form-grid"><div class="field" data-wide><label class="label" for="${id('new_dataset')}">Or a dataset of the workspace</label>
|
|
245
|
+
<select id="${id('new_dataset')}" name="new_dataset"><option value="">- none -</option>${datasets.map((d) => html`<option value="${d.name}">${d.label} (${d.name})</option>`)}</select></div></div>` : ''}</fieldset>
|
|
198
246
|
<div class="buttons"><button class="btn btn-hot">Save Data Reporter settings</button></div>
|
|
199
247
|
</form>`;
|
|
200
248
|
}
|
|
@@ -210,7 +258,8 @@ export async function reporterBuilderRoutes(app: FastifyInstance) {
|
|
|
210
258
|
: undefined;
|
|
211
259
|
if (!r) return reply.code(404).send('Not found');
|
|
212
260
|
const schemes = (await owner.query<{ name: string }>('select name from meta.authz_scheme where app_id = $1', [r.app_id])).rows;
|
|
213
|
-
const
|
|
261
|
+
const datasets = (await owner.query<{ name: string }>('select name from meta.dataset where workspace_id = meta.app_workspace($1)', [r.app_id])).rows;
|
|
262
|
+
const { config, errors } = await mergeReporterSettings(r.config ?? {}, (req.body ?? {}) as Body, { authz: new Set(schemes.map((x) => x.name.toUpperCase())), datasets: new Set(datasets.map((x) => x.name)) });
|
|
214
263
|
await owner.query('update meta.region set config = $2 where id = $1', [r.id, JSON.stringify(config)]);
|
|
215
264
|
if (errors.length) flash(s, errors.join(' '), 'error');
|
|
216
265
|
else flash(s, 'Settings saved.');
|
package/src/builder/routes.ts
CHANGED
|
@@ -43,11 +43,11 @@ export async function builderRoutes(app: FastifyInstance) {
|
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
/** Where to go after signing in: a builder page only. */
|
|
46
|
-
const safeNext = (v: unknown) => (typeof v === 'string' && /^\/builder(\/[A-Za-z0-9_/-]{0,200})?$/.test(v) ? v : BASE);
|
|
46
|
+
const safeNext = (v: unknown) => (typeof v === 'string' && /^\/builder(\/[A-Za-z0-9_/-]{0,200})?$/.test(v) ? v : `${BASE}/home`);
|
|
47
47
|
|
|
48
48
|
app.get(`${BASE}/login`, async (req: Req, reply) => {
|
|
49
49
|
const s = await getSession(req, reply, null, BASE);
|
|
50
|
-
if (s.username) return reply.redirect(BASE);
|
|
50
|
+
if (s.username) return reply.redirect(`${BASE}/home`);
|
|
51
51
|
const error = takeFlash(s, '__ERROR');
|
|
52
52
|
await saveState(s);
|
|
53
53
|
const r = remembered(req);
|
|
@@ -99,7 +99,7 @@ export async function builderRoutes(app: FastifyInstance) {
|
|
|
99
99
|
const { username = '', password = '' } = req.body ?? {};
|
|
100
100
|
const workspace = String(req.body?.workspace ?? '').trim().slice(0, 60);
|
|
101
101
|
const next = safeNext(req.body?.next);
|
|
102
|
-
const again = next === BASE ? `${BASE}/login` : `${BASE}/login?next=${encodeURIComponent(next)}`;
|
|
102
|
+
const again = next === `${BASE}/home` ? `${BASE}/login` : `${BASE}/login?next=${encodeURIComponent(next)}`;
|
|
103
103
|
const ip = clientIp(req);
|
|
104
104
|
if (req.body?.__csrf !== s.csrf_token) {
|
|
105
105
|
flash(s, 'Your session expired. Please try again.', 'error');
|
|
@@ -23,6 +23,7 @@ const TYPE_HELP: Record<AppType, string> = {
|
|
|
23
23
|
theme: 'Its theme (colours, navigation, Theme Roller styles) and template components are offered to other applications.',
|
|
24
24
|
library: 'Its lists of values, authorization schemes, build options, template components and lists are offered to other applications.',
|
|
25
25
|
boilerplate: 'A starting point: Create application can copy it.',
|
|
26
|
+
reporting: 'Made by App Builder → Data Reporter on datasets of the workspace: its users build, publish and share reports.',
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
const what = (kind: Kind, name: string) => (kind === 'theme' ? 'Theme' : `${KINDS[kind].label} ${name}`);
|
package/src/builder/ui.ts
CHANGED
|
@@ -46,7 +46,7 @@ export async function send(reply: FastifyReply, s: Session, body: string) {
|
|
|
46
46
|
return reply.type('text/html').send(body);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export type Section = 'apps' | 'users' | 'sql' | 'developers' | 'gallery';
|
|
49
|
+
export type Section = 'home' | 'apps' | 'users' | 'sql' | 'developers' | 'gallery' | 'reporter';
|
|
50
50
|
|
|
51
51
|
// ------------------------------------------------------------------ builder head
|
|
52
52
|
// Builder-only stylesheets and scripts, loaded on every builder page after
|
|
@@ -105,21 +105,23 @@ export function shell(s: Session, title: string, crumbs: [string, string?][], ma
|
|
|
105
105
|
const rail = (key: Section | 'search' | 'help', href: string, ic: string, label: string, extra: Raw | '' = '') =>
|
|
106
106
|
html`<li><a href="${href}" class="rail-link" title="${label}"${section === key ? raw(' aria-current="page"') : ''}${extra}>${bicon(ic)}<span class="rail-label">${label}</span></a></li>`;
|
|
107
107
|
const back = [...crumbs].reverse().find(([, href], i) => i > 0 && href);
|
|
108
|
-
// (sprint 74) the default-password warning: on the App Builder home and the Developers page only, until
|
|
108
|
+
// (sprint 74) the default-password warning: on the Workspace home (sprint 109), the App Builder home and the Developers page only, until
|
|
109
109
|
// dismissed (for this sign-in); a dot on the avatar stays until the password is changed
|
|
110
110
|
const weak = !!s.state.__WEAK;
|
|
111
|
-
const weakBanner = weak && !s.state.__WEAK_HIDDEN && crumbs.length === 1 && (crumbs[0][0] === 'App Builder' || crumbs[0][0] === 'Developers');
|
|
111
|
+
const weakBanner = weak && !s.state.__WEAK_HIDDEN && crumbs.length === 1 && (crumbs[0][0] === 'Home' || crumbs[0][0] === 'App Builder' || crumbs[0][0] === 'Developers');
|
|
112
112
|
const themeButton = (t: BuilderTheme, ic: string, label: string) =>
|
|
113
113
|
html`<button name="theme" value="${t}" aria-pressed="${theme === t ? 'true' : 'false'}">${bicon(ic)}<span>${label}</span></button>`;
|
|
114
114
|
return documentShell(
|
|
115
115
|
`${title} · Builder`,
|
|
116
116
|
html`<a class="skip-link" href="#main">Skip to content</a>
|
|
117
117
|
<nav class="ide-rail" aria-label="Builder">
|
|
118
|
-
<a class="rail-logo" href="${BASE}" title="pgkiln Builder">${brandMark()}<span class="sr-only">pgkiln Builder home</span></a>
|
|
118
|
+
<a class="rail-logo" href="${BASE}/home" title="pgkiln Builder">${brandMark()}<span class="sr-only">pgkiln Builder home</span></a>
|
|
119
119
|
<ul class="rail-list">
|
|
120
|
-
${rail('
|
|
120
|
+
${rail('home', `${BASE}/home`, 'home', 'Home')}
|
|
121
|
+
${rail('apps', `${BASE}/apps`, 'builder', 'App Builder')}
|
|
121
122
|
${s.workspace?.sql_workshop === false ? '' : rail('sql', `${BASE}/sql`, 'database', 'SQL Workshop')}
|
|
122
123
|
${rail('gallery', `${BASE}/gallery`, 'package', 'App Gallery')}
|
|
124
|
+
${rail('reporter', `${BASE}/reporter`, 'pie-chart', 'Data Reporter')}
|
|
123
125
|
${appId ? rail('search', `${BASE}/apps/${appId}/search`, 'search', 'Search this application') : ''}
|
|
124
126
|
</ul>
|
|
125
127
|
<ul class="rail-list rail-bottom">
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import { owner } from '../db.ts';
|
|
3
|
+
import { html, raw } from '../html.ts';
|
|
4
|
+
import { icon } from '../icons.ts';
|
|
5
|
+
import { cachedRelease, newerVersion, refreshRelease, releaseCheckEnabled, setReleaseCheck, VERSION } from '../release-check.ts';
|
|
6
|
+
import { clientIp, logActivity, type Session } from '../session.ts';
|
|
7
|
+
import { ago } from './home.ts';
|
|
8
|
+
import { isAdmin } from './locks.ts';
|
|
9
|
+
import { back, BASE, csrf, developer, flash, region, send, shell, type Req } from './ui.ts';
|
|
10
|
+
import { currentWorkspace, inWorkspaceSql, workspaceAdmin } from './workspaces.ts';
|
|
11
|
+
|
|
12
|
+
// (sprint 109, WS-1) The Workspace home (APEX: the workspace home page), the page the builder opens after
|
|
13
|
+
// signing in: cards for the tools (App Builder, SQL Workshop, App Gallery), the workspace message (edited in place
|
|
14
|
+
// by its administrators), Top applications and Top users by page views over a reporting timeframe each developer
|
|
15
|
+
// chooses (meta.developer.home_timeframe, migration 119), a Summary of counts that link to their tool, a System
|
|
16
|
+
// message (the running version; "pgkiln X is available" when an administrator turned the release check on:
|
|
17
|
+
// src/release-check.ts) and a side column with Learn more and Resources. Everything is of the current workspace.
|
|
18
|
+
|
|
19
|
+
export const HOME = `${BASE}/home`;
|
|
20
|
+
|
|
21
|
+
export type Timeframe = 'hour' | 'day' | 'week';
|
|
22
|
+
export const TIMEFRAMES: Record<Timeframe, { label: string; interval: string }> = {
|
|
23
|
+
hour: { label: '1 hour', interval: '1 hour' },
|
|
24
|
+
day: { label: '1 day', interval: '1 day' },
|
|
25
|
+
week: { label: '1 week', interval: '7 days' },
|
|
26
|
+
};
|
|
27
|
+
const isTimeframe = (v: unknown): v is Timeframe => typeof v === 'string' && Object.hasOwn(TIMEFRAMES, v);
|
|
28
|
+
const TOP = 5;
|
|
29
|
+
|
|
30
|
+
async function timeframeOf(s: Session): Promise<Timeframe> {
|
|
31
|
+
const r = await owner.one<{ tf: string | null }>('select home_timeframe as tf from meta.developer where username = $1', [s.username]);
|
|
32
|
+
return isTimeframe(r?.tf) ? r.tf : 'day';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The workspace's numbers: top applications and users over the timeframe, and the summary counts. */
|
|
36
|
+
export async function homeData(ws: number, tf: Timeframe) {
|
|
37
|
+
const interval = TIMEFRAMES[tf].interval;
|
|
38
|
+
const [apps, users, devs, counts] = await Promise.all([
|
|
39
|
+
owner.query<{ id: number; name: string; views: number; users: number }>(
|
|
40
|
+
`select * from (
|
|
41
|
+
select a.id, a.name,
|
|
42
|
+
(select count(*) from meta.activity_log l where l.app_id = a.id and l.event = 'page_view' and l.at > now() - $2::interval)::int as views,
|
|
43
|
+
(select count(distinct l.username) from meta.activity_log l where l.app_id = a.id and l.event = 'page_view' and l.at > now() - $2::interval)::int as users
|
|
44
|
+
from meta.app a where ${inWorkspaceSql('a', 1)}) x
|
|
45
|
+
where views > 0 order by views desc, lower(name) limit ${TOP}`,
|
|
46
|
+
[ws, interval],
|
|
47
|
+
),
|
|
48
|
+
owner.query<{ username: string; views: number; apps: number }>(
|
|
49
|
+
`select l.username, count(*)::int as views, count(distinct l.app_id)::int as apps
|
|
50
|
+
from meta.app a join meta.activity_log l on l.app_id = a.id
|
|
51
|
+
where ${inWorkspaceSql('a', 1)} and l.event = 'page_view' and l.at > now() - $2::interval and l.username is not null
|
|
52
|
+
group by l.username order by views desc, lower(l.username) limit ${TOP}`,
|
|
53
|
+
[ws, interval],
|
|
54
|
+
),
|
|
55
|
+
// the workspace's developers (its members and the installation's administrators) as users of its applications
|
|
56
|
+
owner.query<{ username: string; views: number; apps: number }>(
|
|
57
|
+
`select l.username, count(*)::int as views, count(distinct l.app_id)::int as apps
|
|
58
|
+
from meta.app a join meta.activity_log l on l.app_id = a.id
|
|
59
|
+
where ${inWorkspaceSql('a', 1)} and l.event = 'page_view' and l.at > now() - $2::interval
|
|
60
|
+
and lower(l.username) in (select lower(m.username) from meta.workspace_member m where m.workspace_id = $1
|
|
61
|
+
union select lower(d.username) from meta.developer d where d.is_admin)
|
|
62
|
+
group by l.username order by views desc, lower(l.username) limit ${TOP}`,
|
|
63
|
+
[ws, interval],
|
|
64
|
+
),
|
|
65
|
+
owner.one<{ apps: number; tables: number; developers: number; reporting: number }>(
|
|
66
|
+
`select (select count(*) from meta.app a where ${inWorkspaceSql('a', 1)})::int as apps,
|
|
67
|
+
-- the tables of the schemas this workspace's database roles may use (as Workspace utilization counts them)
|
|
68
|
+
(select count(*) from pg_class c join pg_namespace n on n.oid = c.relnamespace
|
|
69
|
+
where c.relkind in ('r', 'p') and not c.relispartition and n.nspname !~ '^pg_' and n.nspname not in ('information_schema', 'meta')
|
|
70
|
+
and exists (select 1 from (select db_role as r from meta.app where meta.app_workspace(id) = $1 and db_role is not null
|
|
71
|
+
union select role_name from meta.workspace_role where workspace_id = $1) x
|
|
72
|
+
join pg_roles rl on rl.rolname = x.r
|
|
73
|
+
where has_schema_privilege(rl.oid, n.oid, 'USAGE')))::int as tables,
|
|
74
|
+
(select count(*) from meta.workspace_member m where m.workspace_id = $1)::int as developers,
|
|
75
|
+
-- reporting applications: apps of type 'reporting' (Data Reporter → Create reporting application)
|
|
76
|
+
meta.reporting_app_count($1) as reporting`,
|
|
77
|
+
[ws],
|
|
78
|
+
),
|
|
79
|
+
]);
|
|
80
|
+
return { apps: apps.rows, users: users.rows, developers: devs.rows, counts: counts! };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The System message: the running version, and a newer release when the check is on. */
|
|
84
|
+
async function systemMessage(s: Session, admin: boolean) {
|
|
85
|
+
const check = await releaseCheckEnabled();
|
|
86
|
+
// never wait for GitHub: show what is cached, refresh in the background
|
|
87
|
+
if (check.on) void refreshRelease();
|
|
88
|
+
const c = check.on ? cachedRelease() : null;
|
|
89
|
+
const r = c?.release;
|
|
90
|
+
const newer = r && newerVersion(r.version, VERSION) ? r : null;
|
|
91
|
+
const body = newer
|
|
92
|
+
? html`<div class="alert alert-info wh-release" role="status">${icon('bell')}<div>
|
|
93
|
+
<strong>pgkiln ${newer.version} is available</strong>
|
|
94
|
+
<p>${newer.name}${newer.publishedAt ? html` <span class="muted">(${ago(newer.publishedAt)})</span>` : ''}. This server runs pgkiln ${VERSION}.</p>
|
|
95
|
+
<p><a href="${newer.url}" target="_blank" rel="noopener noreferrer">Release notes ${icon('external')}</a> ·
|
|
96
|
+
<a href="https://github.com/pgkiln/pgkiln/blob/main/docs/guide/01-installation.md#upgrading" target="_blank" rel="noopener">How to upgrade</a></p>
|
|
97
|
+
<p class="small muted">To upgrade: back up the database, install the new version (<code>npm install -g pgkiln@${newer.version}</code>, or the
|
|
98
|
+
Docker image <code>pgkiln/pgkiln:${newer.version}</code>), run <code>pgkiln migrate</code> and restart the server.</p></div></div>`
|
|
99
|
+
: html`<p class="u-mt0">This server runs <strong>pgkiln ${VERSION}</strong>.${check.on && r && !newer ? ' It is the latest release.' : ''}</p>`;
|
|
100
|
+
const status = !check.on
|
|
101
|
+
? 'The check for new versions is off.'
|
|
102
|
+
: c?.error
|
|
103
|
+
? `The last check failed (${c.error})${c.release ? '; the result above is older' : ''}.`
|
|
104
|
+
: c ? `Checked ${ago(new Date(c.at))}.` : 'Checking for a new version…';
|
|
105
|
+
const admins = admin
|
|
106
|
+
? html`<form method="post" action="${HOME}/release-check" class="wh-release-form">${csrf(s)}
|
|
107
|
+
<p class="small muted u-mt0">${status} ${check.on ? '' : html`When on, the server asks GitHub (<code>api.github.com</code>) once a day for the latest release; nothing about this installation is sent.`}
|
|
108
|
+
${check.from === 'environment' ? html`(<code>PGKILN_RELEASE_CHECK</code>)` : ''}</p>
|
|
109
|
+
<div class="buttons">${check.on
|
|
110
|
+
? html`<button class="btn btn-sm" name="check" value="now">${icon('refresh')} Check now</button><button class="btn btn-sm" name="check" value="off">Turn off</button>`
|
|
111
|
+
: html`<button class="btn btn-sm" name="check" value="on">Check for new versions</button>`}</div></form>`
|
|
112
|
+
: '';
|
|
113
|
+
return region('System message', html`${body}${admins}`, '', 'system-message');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** (Instance settings page) the release check: on, off, or as the environment says. */
|
|
117
|
+
export async function releaseCheckRegion(s: Session) {
|
|
118
|
+
const check = await releaseCheckEnabled();
|
|
119
|
+
const value = check.from === 'builder' ? (check.on ? 'on' : 'off') : 'default';
|
|
120
|
+
const opt = (v: string, label: string) => html`<option value="${v}"${v === value ? raw(' selected') : ''}>${label}</option>`;
|
|
121
|
+
return region('New versions', html`<form method="post" action="${HOME}/release-check">${csrf(s)}<input type="hidden" name="from" value="instance">
|
|
122
|
+
<div class="field"><label class="label" for="f_release_check">Check for new pgkiln releases</label>
|
|
123
|
+
<select id="f_release_check" name="check">${opt('default', `As the environment says (${process.env.PGKILN_RELEASE_CHECK ? 'PGKILN_RELEASE_CHECK' : 'off'})`)}${opt('on', 'On')}${opt('off', 'Off')}</select>
|
|
124
|
+
<small class="help">On: the server asks GitHub (<code>api.github.com</code>) once a day for the latest release and the Workspace home
|
|
125
|
+
announces a newer one with its release notes. Nothing about this installation is sent. In effect: <b>${check.on ? 'on' : 'off'}</b>.
|
|
126
|
+
Turn it off when the server may not reach the internet.</small></div>
|
|
127
|
+
<div class="buttons"><button class="btn">Save</button></div></form>`, '', 'release-check');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The workspace message, with a pencil (a <details> form, no script needed) for its administrators. */
|
|
131
|
+
function workspaceMessage(s: Session, canEdit: boolean) {
|
|
132
|
+
const w = s.workspace;
|
|
133
|
+
if (!w) return '';
|
|
134
|
+
if (!w.message && !canEdit) return '';
|
|
135
|
+
return html`<section class="region region-standard wh-message" id="workspace-message" aria-labelledby="wh-message-title">
|
|
136
|
+
<header class="region-header"><h2 id="wh-message-title">Workspace message</h2></header>
|
|
137
|
+
<div class="region-body">
|
|
138
|
+
${w.message ? html`<p class="wh-message-text">${w.message}</p>` : html`<p class="muted u-mt0">No message for the developers of ${w.name}.</p>`}
|
|
139
|
+
${canEdit ? html`<details class="wh-edit"><summary class="btn btn-sm" title="Edit the workspace message">${icon('edit')}<span>Edit message</span></summary>
|
|
140
|
+
<form method="post" action="${HOME}/message">${csrf(s)}<input type="hidden" name="workspace" value="${w.id}">
|
|
141
|
+
<div class="field"><label class="label" for="f_message">Workspace message</label>
|
|
142
|
+
<textarea id="f_message" name="message" rows="3" maxlength="2000">${w.message ?? ''}</textarea>
|
|
143
|
+
<small class="help">Shown to the developers of ${w.name} here and on the App Builder home. Plain text, up to 2000 characters; empty removes it.</small></div>
|
|
144
|
+
<div class="buttons"><button class="btn btn-hot">Save message</button></div></form></details>` : ''}
|
|
145
|
+
</div></section>`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const REPO = 'https://github.com/pgkiln/pgkiln';
|
|
149
|
+
const GUIDE = `${REPO}/blob/main`;
|
|
150
|
+
/** The Data Reporter tool (sprint 110, WS-2): its card and link only when the route exists. */
|
|
151
|
+
export const REPORTER = `${BASE}/reporter`;
|
|
152
|
+
|
|
153
|
+
export async function workspaceHomeRoutes(app: FastifyInstance) {
|
|
154
|
+
app.get(HOME, async (req: Req, reply) => {
|
|
155
|
+
const s = await developer(req, reply);
|
|
156
|
+
if (!s) return;
|
|
157
|
+
const ws = currentWorkspace(s);
|
|
158
|
+
const [tf, admin, canEdit] = await Promise.all([timeframeOf(s), isAdmin(s.username), s.workspace ? workspaceAdmin(s.username, s.workspace.id) : false]);
|
|
159
|
+
const data = await homeData(ws, tf);
|
|
160
|
+
const sql = s.workspace?.sql_workshop !== false;
|
|
161
|
+
const reporter = app.hasRoute({ method: 'GET', url: REPORTER });
|
|
162
|
+
const card = (href: string, ic: string, title: string, text: string) =>
|
|
163
|
+
html`<a class="ab-tile" href="${href}"><span class="ab-tile-icon">${icon(ic)}</span><strong>${title}</strong><span>${text}</span></a>`;
|
|
164
|
+
const stat = (n: number, one: string, many: string, href: string | null) => {
|
|
165
|
+
const inner = html`<b>${n}</b><span>${n === 1 ? one : many}</span>`;
|
|
166
|
+
return href ? html`<a class="stat" href="${href}">${inner}</a>` : html`<div class="stat">${inner}</div>`;
|
|
167
|
+
};
|
|
168
|
+
const tfLabel = TIMEFRAMES[tf].label;
|
|
169
|
+
const timeframe = html`<form method="post" action="${HOME}/timeframe" class="segmented wh-timeframe" role="group" aria-labelledby="wh-tf-label">${csrf(s)}
|
|
170
|
+
<span class="sr-only" id="wh-tf-label">Reporting timeframe</span>
|
|
171
|
+
${(Object.keys(TIMEFRAMES) as Timeframe[]).map((k) => html`<button name="timeframe" value="${k}" aria-pressed="${k === tf ? 'true' : 'false'}">${TIMEFRAMES[k].label}</button>`)}</form>`;
|
|
172
|
+
const none = html`<p class="muted u-mt0">No page views in the last ${tfLabel}.</p>`;
|
|
173
|
+
const people = (rows: { username: string; views: number; apps: number }[], caption: string, who: string) => rows.length
|
|
174
|
+
? html`<div class="table-wrap"><table class="report"><caption class="sr-only">${caption}, last ${tfLabel}</caption>
|
|
175
|
+
<thead><tr><th scope="col">${who}</th><th scope="col" class="num">Page views</th><th scope="col" class="num">Applications</th></tr></thead>
|
|
176
|
+
<tbody>${rows.map((u) => html`<tr><td class="cell-break">${u.username}</td><td class="num">${u.views}</td><td class="num">${u.apps}</td></tr>`)}</tbody></table></div>`
|
|
177
|
+
: none;
|
|
178
|
+
const topApps = data.apps.length
|
|
179
|
+
? html`<div class="table-wrap"><table class="report"><caption class="sr-only">Top applications, last ${tfLabel}</caption>
|
|
180
|
+
<thead><tr><th scope="col">Application</th><th scope="col" class="num">Page views</th><th scope="col" class="num">Users</th></tr></thead>
|
|
181
|
+
<tbody>${data.apps.map((a) => html`<tr><td class="cell-break"><a href="${BASE}/apps/${a.id}">${a.name}</a></td><td class="num">${a.views}</td><td class="num">${a.users}</td></tr>`)}</tbody></table></div>`
|
|
182
|
+
: none;
|
|
183
|
+
const ext = (href: string, label: string) => html`<li><a href="${href}" target="_blank" rel="noopener">${label}${icon('chevron')}</a></li>`;
|
|
184
|
+
const main = html`<div class="ab-home wh-home">
|
|
185
|
+
<div class="ab-main">
|
|
186
|
+
<h1 class="wh-title">${s.workspace ? html`Workspace ${s.workspace.name}` : 'Workspace home'}</h1>
|
|
187
|
+
<nav class="ab-tiles ab-tiles-wrap wh-tools" aria-label="Tools">
|
|
188
|
+
${card(`${BASE}/apps`, 'grid', 'App Builder', 'Create, edit and run the applications of this workspace.')}
|
|
189
|
+
${sql ? card(`${BASE}/sql`, 'database', 'SQL Workshop', 'Run SQL, browse database objects, load data and build REST services.') : ''}
|
|
190
|
+
${reporter ? card(REPORTER, 'pie-chart', 'Data Reporter', 'Datasets and reports for business users, without building pages.') : ''}
|
|
191
|
+
${card(`${BASE}/gallery`, 'package', 'App Gallery', 'Sample and starter applications to install.')}
|
|
192
|
+
</nav>
|
|
193
|
+
${workspaceMessage(s, canEdit)}
|
|
194
|
+
<section class="wh-summary" aria-labelledby="wh-summary-title">
|
|
195
|
+
<h2 id="wh-summary-title">Summary</h2>
|
|
196
|
+
<div class="stat-grid wh-stats">
|
|
197
|
+
${stat(data.counts.apps, 'application', 'applications', `${BASE}/apps`)}
|
|
198
|
+
${stat(data.counts.tables, 'table', 'tables', sql ? `${BASE}/sql/objects` : null)}
|
|
199
|
+
${stat(data.counts.developers, 'developer', 'developers', `${BASE}/developers`)}
|
|
200
|
+
${stat(data.counts.reporting, 'reporting application', 'reporting applications', reporter ? REPORTER : null)}
|
|
201
|
+
</div>
|
|
202
|
+
</section>
|
|
203
|
+
<div class="wh-top-head"><h2>Activity</h2>${timeframe}</div>
|
|
204
|
+
<div class="wh-top">
|
|
205
|
+
${region(`Top applications (${tfLabel})`, topApps)}
|
|
206
|
+
${region(`Top users (${tfLabel})`, people(data.users, 'Top users', 'User'))}
|
|
207
|
+
${region(`Top developers (${tfLabel})`, people(data.developers, 'Top developers', 'Developer'))}
|
|
208
|
+
</div>
|
|
209
|
+
${await systemMessage(s, admin)}
|
|
210
|
+
</div>
|
|
211
|
+
<aside class="ab-side" aria-label="About and learn more">
|
|
212
|
+
<section><h2>About</h2><p>The workspace home: its tools, how its applications are used and what is new. ${s.workspace ? html`You work in ${s.workspace.name}.` : ''}</p></section>
|
|
213
|
+
<section><h2>Learn more</h2><ul class="ab-links ab-tasks">
|
|
214
|
+
${ext(`${GUIDE}/docs/README.md`, 'The pgkiln guide')}
|
|
215
|
+
${ext(`${GUIDE}/docs/guide/10-tutorial.md`, 'Tutorial')}
|
|
216
|
+
${ext(`${GUIDE}/docs/guide/11-from-apex.md`, 'Coming from APEX')}
|
|
217
|
+
${ext(`${GUIDE}/CHANGELOG.md`, "What's new (changelog)")}
|
|
218
|
+
${ext(`${REPO}/discussions`, 'Discussions')}
|
|
219
|
+
</ul></section>
|
|
220
|
+
<section><h2>Resources</h2><ul class="ab-links ab-tasks">
|
|
221
|
+
${ext(`${GUIDE}/docs/guide/20-ai-agents.md`, 'AI coding agents (MCP)')}
|
|
222
|
+
${ext(`${REPO}/issues`, 'Report a problem')}
|
|
223
|
+
</ul></section>
|
|
224
|
+
</aside>
|
|
225
|
+
</div>`;
|
|
226
|
+
return send(reply, s, shell(s, 'Workspace home', [['Home']], main, 'home'));
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// the reporting timeframe, remembered per developer
|
|
230
|
+
app.post(`${HOME}/timeframe`, async (req: Req, reply) => {
|
|
231
|
+
const s = await developer(req, reply);
|
|
232
|
+
if (!s) return;
|
|
233
|
+
const tf = req.body?.timeframe;
|
|
234
|
+
if (!isTimeframe(tf)) return reply.code(400).send('Unknown timeframe');
|
|
235
|
+
await owner.query('update meta.developer set home_timeframe = $2 where username = $1', [s.username, tf]);
|
|
236
|
+
return back(reply, s, HOME);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// the workspace message, by the workspace's administrators (and the installation's)
|
|
240
|
+
app.post(`${HOME}/message`, async (req: Req, reply) => {
|
|
241
|
+
const s = await developer(req, reply);
|
|
242
|
+
if (!s) return;
|
|
243
|
+
const id = String(req.body?.workspace ?? '');
|
|
244
|
+
if (!/^\d{1,9}$/.test(id)) return reply.code(400).send('Unknown workspace');
|
|
245
|
+
if (!(await workspaceAdmin(s.username, id))) return reply.code(403).send('Only the workspace\'s administrators change its message.');
|
|
246
|
+
const message = String(req.body?.message ?? '').replace(/\r\n/g, '\n').trim();
|
|
247
|
+
if (message.length > 2000) {
|
|
248
|
+
flash(s, 'The message is at most 2000 characters.', 'error');
|
|
249
|
+
return back(reply, s, HOME);
|
|
250
|
+
}
|
|
251
|
+
const r = await owner.query('update meta.workspace set message = $2 where id = $1', [id, message || null]);
|
|
252
|
+
if (!r.rowCount) return reply.code(404).send('Not found');
|
|
253
|
+
await logActivity({ appId: null, username: s.username, event: 'workspace', ip: clientIp(req), detail: `workspace ${id}: message` });
|
|
254
|
+
flash(s, message ? 'Workspace message saved.' : 'Workspace message removed.');
|
|
255
|
+
return back(reply, s, `${HOME}#workspace-message`);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// the release check (administrators): on, off, or check now
|
|
259
|
+
app.post(`${HOME}/release-check`, async (req: Req, reply) => {
|
|
260
|
+
const s = await developer(req, reply);
|
|
261
|
+
if (!s) return;
|
|
262
|
+
if (!(await isAdmin(s.username))) return reply.code(403).send('Only administrators change the release check.');
|
|
263
|
+
const v = req.body?.check;
|
|
264
|
+
// from the Instance settings page (back there) or the Workspace home
|
|
265
|
+
const to = req.body?.from === 'instance' ? `${BASE}/instance#release-check` : `${HOME}#system-message`;
|
|
266
|
+
if (v === 'on' || v === 'off' || v === 'default') {
|
|
267
|
+
await setReleaseCheck(v === 'default' ? '' : v);
|
|
268
|
+
await logActivity({ appId: null, username: s.username, event: 'instance_settings', ip: clientIp(req), detail: `release check ${v}` });
|
|
269
|
+
const now = await releaseCheckEnabled();
|
|
270
|
+
if (now.on) await refreshRelease(true);
|
|
271
|
+
flash(s, now.on ? 'The server checks for new versions once a day.' : 'The check for new versions is off.');
|
|
272
|
+
} else if (v === 'now') {
|
|
273
|
+
if (!(await releaseCheckEnabled()).on) {
|
|
274
|
+
flash(s, 'The check for new versions is off.', 'error');
|
|
275
|
+
return back(reply, s, to);
|
|
276
|
+
}
|
|
277
|
+
await refreshRelease(true);
|
|
278
|
+
const c = cachedRelease();
|
|
279
|
+
flash(s, c?.error ? `The check failed (${c.error}).` : 'Checked for a new version.', c?.error ? 'error' : 'ok');
|
|
280
|
+
} else return reply.code(400).send('Unknown action');
|
|
281
|
+
return back(reply, s, to);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
@@ -29,7 +29,7 @@ export const DEFAULT_WORKSPACE = 1;
|
|
|
29
29
|
export async function loadWorkspaces(s: Session) {
|
|
30
30
|
const rows = (
|
|
31
31
|
await owner.query<WorkspaceRef & { instance_admin?: boolean }>(
|
|
32
|
-
`select w.id, w.name, w.message, w.banner_label, w.banner_color, w.isolated, w.sql_workshop, w.rest_services,
|
|
32
|
+
`select w.id, w.name, w.message, w.banner_label, w.banner_color, w.isolated, w.sql_workshop, w.rest_services, w.builder_home,
|
|
33
33
|
coalesce((select json_agg(json_build_object('label', l.label, 'url', l.url, 'description', l.description) order by l.position, lower(l.label))
|
|
34
34
|
from meta.workspace_link l where l.workspace_id = w.id), '[]') as links,
|
|
35
35
|
exists (select 1 from meta.developer d where d.username = $1 and d.is_admin)
|
|
@@ -211,12 +211,13 @@ function serviceRegion(s: Session, w: { id: number; message: string | null; bann
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
/** (093) Workspace preferences: the SQL Workshop and the applications' REST modules on or off. */
|
|
214
|
-
function preferencesRegion(s: Session, w: { id: number; sql_workshop: boolean; rest_services: boolean }) {
|
|
214
|
+
function preferencesRegion(s: Session, w: { id: number; sql_workshop: boolean; rest_services: boolean; builder_home: string | null }) {
|
|
215
215
|
const check = (name: string, on: boolean, label: string, help: string) =>
|
|
216
216
|
html`<div class="field"><label class="check"><input type="checkbox" name="${name}" value="true"${on ? raw(' checked') : ''}> ${label}</label><small class="help">${help}</small></div>`;
|
|
217
217
|
return region('Workspace preferences', html`<form method="post" action="${BASE}/workspaces/${w.id}/preferences">${csrf(s)}
|
|
218
218
|
${check('sql_workshop', w.sql_workshop, 'Enable the SQL Workshop', 'Off: the SQL Worksheet, the Object Browser, SQL scripts, data loading and unloading, Quick SQL, the query builder, DDL, Compare and AI are refused while this workspace is current, for every developer.')}
|
|
219
219
|
${check('rest_services', w.rest_services, 'Enable RESTful services', 'Off: the REST modules of this workspace\'s applications answer 404 (Not found) at /a/<alias>/rest/…; they can still be edited.')}
|
|
220
|
+
${select('builder_home', 'Builder links open', w.builder_home === 'home' ? 'home' : 'apps', [['apps', 'App Builder'], ['home', 'Workspace home']], 'Where a link to /builder (a bookmark from before the Workspace home) leads in this workspace. Signing in always opens the Workspace home; the App Builder is at /builder/apps.')}
|
|
220
221
|
<div class="buttons"><button class="btn">Save preferences</button></div></form>`, '', 'preferences');
|
|
221
222
|
}
|
|
222
223
|
|
|
@@ -540,9 +541,11 @@ export async function workspaceRoutes(app: FastifyInstance) {
|
|
|
540
541
|
if (!s || !(await workspaceAdminOnly(s, reply, req.params.id))) return;
|
|
541
542
|
const sql = req.body?.sql_workshop === 'true';
|
|
542
543
|
const rest = req.body?.rest_services === 'true';
|
|
543
|
-
|
|
544
|
+
// (119) what /builder opens: the App Builder (null) or the Workspace home
|
|
545
|
+
const home = req.body?.builder_home === 'home' ? 'home' : null;
|
|
546
|
+
const r = await owner.query('update meta.workspace set sql_workshop = $2, rest_services = $3, builder_home = $4 where id = $1', [req.params.id, sql, rest, home]);
|
|
544
547
|
if (!r.rowCount) return reply.code(404).send('Not found');
|
|
545
|
-
await logActivity({ appId: null, username: s.username, event: 'workspace', ip: clientIp(req), detail: `workspace ${req.params.id}: SQL Workshop ${sql ? 'on' : 'off'}, RESTful services ${rest ? 'on' : 'off'}` });
|
|
548
|
+
await logActivity({ appId: null, username: s.username, event: 'workspace', ip: clientIp(req), detail: `workspace ${req.params.id}: SQL Workshop ${sql ? 'on' : 'off'}, RESTful services ${rest ? 'on' : 'off'}, /builder opens ${home ?? 'apps'}` });
|
|
546
549
|
flash(s, 'Preferences saved.');
|
|
547
550
|
return back(reply, s, `${BASE}/workspaces/${req.params.id}`);
|
|
548
551
|
});
|