pgkiln 0.49.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 +3 -0
- package/db/migrations/119_workspace_home.sql +30 -0
- package/db/migrations/120_datasets.sql +87 -0
- package/docs/apex-feature-parity.md +7 -6
- package/docs/guide/01-installation.md +5 -0
- package/docs/guide/03-builder.md +140 -11
- package/docs/guide/04-pages-and-regions.md +25 -1
- package/docs/guide/12-development.md +47 -11
- package/examples/hr/hr_63_datasets.sql +29 -0
- package/package.json +1 -1
- package/public/app.css +6 -0
- package/public/builder.css +95 -3
- package/public/code-editor.css +32 -79
- package/public/code-editor.js +58 -3
- package/public/data-modeler.css +17 -14
- package/public/worksheet.css +14 -7
- package/public/worksheet.js +119 -3
- package/src/app.ts +5 -1
- package/src/builder/changelog.ts +1 -1
- package/src/builder/data-modeler.ts +1 -1
- package/src/builder/datasets.ts +472 -0
- package/src/builder/db-users.ts +2 -2
- package/src/builder/home.ts +12 -7
- package/src/builder/instance.ts +2 -0
- package/src/builder/object-browser.ts +4 -4
- package/src/builder/querybuilder.ts +1 -1
- package/src/builder/quicksql.ts +1 -1
- package/src/builder/reporter.ts +52 -3
- package/src/builder/routes.ts +3 -3
- package/src/builder/scheduling.ts +2 -2
- package/src/builder/scripts.ts +1 -1
- package/src/builder/sql-charts.ts +1 -1
- package/src/builder/sql-monitor.ts +1 -1
- package/src/builder/subscriptions.ts +1 -0
- package/src/builder/table-editor.ts +2 -2
- package/src/builder/ui.ts +7 -5
- package/src/builder/worksheet.ts +171 -23
- 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 +7 -0
- package/src/sqlworksheet.ts +9 -6
- package/src/subscriptions.ts +2 -1
- package/src/worksheet-txn.ts +270 -0
- package/src/workspace-export.ts +24 -4
|
@@ -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
|
});
|