create-navette 1.0.0-beta.2 → 1.0.0-beta.4
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/lib/templates.js +15 -14
- package/package.json +1 -1
package/lib/templates.js
CHANGED
|
@@ -214,12 +214,10 @@ ${timestamps}
|
|
|
214
214
|
`;
|
|
215
215
|
// ------------------------------------------------------------------ admin panel
|
|
216
216
|
files['src/panels/admin.ts'] = `// The admin panel (/admin): only users with the \`admin\` role can sign in.
|
|
217
|
-
import { AccountWidget, discoverPages, discoverResources, discoverWidgets, fileMailer,
|
|
217
|
+
import { AccountWidget, discoverPages, discoverResources, discoverWidgets, fileMailer, ${sqlite ? 'knexNotificationStore, ' : ''}Panel } from '@navette-js/panels';
|
|
218
218
|
import { Color } from '@navette-js/support';
|
|
219
219
|
import { db } from '../database.ts';
|
|
220
|
-
|
|
221
|
-
const users = knexAuthProvider((table) => db(table));
|
|
222
|
-
const isAdmin = async (id: string | number) => (await db('users').where('id', id).first())?.role === 'admin';
|
|
220
|
+
import { users } from '../users.ts';
|
|
223
221
|
|
|
224
222
|
export default Panel.make()
|
|
225
223
|
.id('admin')
|
|
@@ -237,14 +235,16 @@ ${sqlite ? ' .databaseNotifications(knexNotificationStore((table: string) =>
|
|
|
237
235
|
.resources(await discoverResources(new URL('../admin/resources/', import.meta.url)))
|
|
238
236
|
.pages(await discoverPages(new URL('../admin/pages/', import.meta.url)))
|
|
239
237
|
.widgets([AccountWidget, ...(await discoverWidgets(new URL('../admin/widgets/', import.meta.url)))])
|
|
240
|
-
.auth(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
238
|
+
.auth(users)
|
|
239
|
+
// Only users with the \`admin\` role may sign in here; others are refused at login and get a 403 page.
|
|
240
|
+
.canAccess(async (user) => (await db('users').where('id', user.id).first())?.role === 'admin');
|
|
241
|
+
`;
|
|
242
|
+
files['src/users.ts'] = `// Users of every panel. Panels share one session (signing into one signs into the others), so they share this provider;
|
|
243
|
+
// each panel's \`canAccess()\` decides who may enter it.
|
|
244
|
+
import { knexAuthProvider } from '@navette-js/panels';
|
|
245
|
+
import { db } from './database.ts';
|
|
246
|
+
|
|
247
|
+
export const users = knexAuthProvider((table) => db(table));
|
|
248
248
|
`;
|
|
249
249
|
files['src/admin/pages/Dashboard.ts'] = `import { Dashboard as BaseDashboard } from '@navette-js/panels';
|
|
250
250
|
|
|
@@ -383,8 +383,9 @@ export class TaskStats extends StatsOverviewWidget {
|
|
|
383
383
|
// ------------------------------------------------------------------ user panel
|
|
384
384
|
if (o.userPanel) {
|
|
385
385
|
files['src/panels/app.ts'] = `// The user panel (/app): anyone can sign up${teams ? ', then create or join teams' : ''}.
|
|
386
|
-
import { AccountWidget, discoverPages, discoverResources, discoverWidgets, fileMailer,
|
|
386
|
+
import { AccountWidget, discoverPages, discoverResources, discoverWidgets, fileMailer, ${teams ? 'knexTenantProvider, ' : ''}Panel } from '@navette-js/panels';
|
|
387
387
|
import { db } from '../database.ts';
|
|
388
|
+
import { users } from '../users.ts';
|
|
388
389
|
${teams ? "import { EditTeamProfile, RegisterTeam } from '../app/tenancy.ts';\n" : ''}
|
|
389
390
|
export default Panel.make()
|
|
390
391
|
.id('app')
|
|
@@ -405,7 +406,7 @@ ${teams ? ` // Every page lives under /app/<team>; records with a \`team_id\`
|
|
|
405
406
|
` : ''} .resources(await discoverResources(new URL('../app/resources/', import.meta.url)))
|
|
406
407
|
.pages(await discoverPages(new URL('../app/pages/', import.meta.url)))
|
|
407
408
|
.widgets([AccountWidget, ...(await discoverWidgets(new URL('../app/widgets/', import.meta.url)))])
|
|
408
|
-
.auth(
|
|
409
|
+
.auth(users);
|
|
409
410
|
`;
|
|
410
411
|
files['src/app/pages/Dashboard.ts'] = `import { Dashboard as BaseDashboard } from '@navette-js/panels';
|
|
411
412
|
|