create-protobase 0.46.3 → 0.46.5
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/dist/templates/erp/config/account.tsx +18 -0
- package/dist/templates/erp/config/index.ts +3 -0
- package/dist/templates/erp/config/notification_settings/data.ts +13 -0
- package/dist/templates/erp/config/notification_settings/ui.ts +13 -0
- package/dist/templates/erp/config/pages.test.ts +1 -1
- package/dist/templates/erp/config/roles.test.ts +17 -1
- package/dist/templates/erp/config/roles.ts +9 -2
- package/dist/templates/erp/db/migrations/021_notification_settings.sql +6 -0
- package/dist/templates/erp/package.json +5 -5
- package/dist/templates/real-estate/package.json +5 -5
- package/dist/templates/scratch/package.json +5 -5
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @jsxImportSource @protobase/layout */
|
|
2
|
+
import { Page, Settings, Tab, Tabs, accountTabs, page } from '@protobase/layout'
|
|
3
|
+
|
|
4
|
+
/** The standard account page with a Notifications tab, where each person picks the emails they get. */
|
|
5
|
+
export const account = page(
|
|
6
|
+
'account',
|
|
7
|
+
<Page title="Account">
|
|
8
|
+
<Tabs>
|
|
9
|
+
{accountTabs.profile}
|
|
10
|
+
{accountTabs.security}
|
|
11
|
+
<Tab name="notifications" label="Notifications">
|
|
12
|
+
<Settings resource="notification_settings" title="Emails" description="What the ERP emails you about." />
|
|
13
|
+
</Tab>
|
|
14
|
+
{accountTabs.devices}
|
|
15
|
+
{accountTabs.apps}
|
|
16
|
+
</Tabs>
|
|
17
|
+
</Page>,
|
|
18
|
+
)
|
|
@@ -36,7 +36,10 @@ export { orderLines } from './order_lines/data'
|
|
|
36
36
|
export { orderLinesView } from './order_lines/ui'
|
|
37
37
|
export { orders } from './orders/data'
|
|
38
38
|
export { ordersView } from './orders/ui'
|
|
39
|
+
export { notificationSettings } from './notification_settings/data'
|
|
40
|
+
export { notificationSettingsView } from './notification_settings/ui'
|
|
39
41
|
export { accountMenu } from './user-menu'
|
|
40
42
|
export { usersPage } from '@protobase/layout'
|
|
43
|
+
export { account } from './account'
|
|
41
44
|
export { warehouseBar } from './bottom-bar'
|
|
42
45
|
export { salesOverview } from './overview/page'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { f, resource } from '@protobase/schema'
|
|
2
|
+
import { erpAccess } from '../roles'
|
|
3
|
+
|
|
4
|
+
/** core.notification_settings: each person's own, shown by the account page's Notifications tab. */
|
|
5
|
+
export const notificationSettings = resource('notification_settings')
|
|
6
|
+
.table('core.notification_settings')
|
|
7
|
+
.fields({
|
|
8
|
+
user_id: f.text(),
|
|
9
|
+
overdue_invoices: f.enum(['each', 'daily', 'never']).default('each'),
|
|
10
|
+
})
|
|
11
|
+
.primaryKey((r) => r.user_id)
|
|
12
|
+
.owner((r) => r.user_id)
|
|
13
|
+
.access(erpAccess('notification_settings'))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { view } from '@protobase/schema'
|
|
2
|
+
import type { notificationSettings } from './data'
|
|
3
|
+
|
|
4
|
+
export const notificationSettingsView = view<typeof notificationSettings>('notification_settings')
|
|
5
|
+
.names({ singular: 'Notification setting', plural: 'Notification settings' })
|
|
6
|
+
// Each person changes their own on the account page.
|
|
7
|
+
.nav({ hidden: true })
|
|
8
|
+
.fields((r) => ({
|
|
9
|
+
overdue_invoices: r.overdue_invoices
|
|
10
|
+
.label('Overdue invoices')
|
|
11
|
+
.help('An email when an invoice passes its due date unpaid.')
|
|
12
|
+
.valueLabels({ each: 'For each invoice', daily: 'Once a day', never: 'Never' }),
|
|
13
|
+
}))
|
|
@@ -8,7 +8,7 @@ describe('ERP pages', () => {
|
|
|
8
8
|
const { resources, views, pages } = configExports(config)
|
|
9
9
|
const models = Object.fromEntries(resources.map((source) => [source.toModel().name, source.toModel()]))
|
|
10
10
|
const actions = (resource: string) => new Set(views.map((view) => view.toModel()).filter((view) => view.resource === resource).flatMap((view) => view.actions.map((action) => action.name)))
|
|
11
|
-
expect(pages.map((entry) => entry.name)).toEqual(['accounts', 'overview'])
|
|
11
|
+
expect(pages.map((entry) => entry.name)).toEqual(['accounts', 'account', 'overview'])
|
|
12
12
|
expect(() => checkPages(pages.map((entry) => entry.toModel()), { models, actions })).not.toThrow()
|
|
13
13
|
})
|
|
14
14
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveAccess } from '@protobase/schema'
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import { empMaster, orders, stockMoves } from './index'
|
|
3
|
+
import { empMaster, notificationSettings, orders, stockMoves } from './index'
|
|
4
4
|
|
|
5
5
|
const as = (role: string) => ({ user: { id: 3, roles: [role] } })
|
|
6
6
|
|
|
@@ -54,3 +54,19 @@ describe('hidden columns', () => {
|
|
|
54
54
|
expect(access.writableFields.create).toContain('unit_cost')
|
|
55
55
|
})
|
|
56
56
|
})
|
|
57
|
+
|
|
58
|
+
describe('ERP roles on notification settings', () => {
|
|
59
|
+
// Owned by the Better Auth id, which is text.
|
|
60
|
+
const person = (role: string) => ({ user: { id: '3', roles: [role] } })
|
|
61
|
+
|
|
62
|
+
// The account page's Settings keeps everyone to their own record, admins too; these are who has settings at all.
|
|
63
|
+
it.each(['admin', 'auditor', 'manager', 'sales', 'accountant', 'warehouse', 'editor'])('%s reads and writes their own', async (role) => {
|
|
64
|
+
const access = await resolveAccess(notificationSettings, person(role))
|
|
65
|
+
expect(access.operations).toMatchObject({ read: true, create: true, update: true })
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('leaves the integration role, which is no person, without any', async () => {
|
|
69
|
+
const access = await resolveAccess(notificationSettings, person('integration'))
|
|
70
|
+
expect(access.operations).toMatchObject({ read: false, create: false, update: false })
|
|
71
|
+
})
|
|
72
|
+
})
|
|
@@ -5,18 +5,22 @@ export type ErpName =
|
|
|
5
5
|
| 'categories' | 'products' | 'countries' | 'currencies' | 'organizations' | 'users'
|
|
6
6
|
| 'companies' | 'company_tags' | 'people' | 'tags' | 'emp_master' | 'locations'
|
|
7
7
|
| 'stock_levels' | 'stock_moves' | 'warehouses' | 'invoice_lines' | 'invoices'
|
|
8
|
-
| 'order_lines' | 'orders'
|
|
8
|
+
| 'order_lines' | 'orders' | 'notification_settings'
|
|
9
9
|
| 'costs'
|
|
10
10
|
|
|
11
|
+
/** Each person's own notification settings, which the account page's Notifications tab shows. */
|
|
12
|
+
const ownNotificationSettings = ['notification_settings.read.own', 'notification_settings.create.own', 'notification_settings.update.own'] as const
|
|
13
|
+
|
|
11
14
|
/**
|
|
12
15
|
* Capabilities are `<resource|area>.<action>[.<scope>]`. `.own` rows are those whose `.owner()`
|
|
13
16
|
* field is the user's id. The `costs` area gates cost columns; salaries are admin-only via `roles.is('admin')`.
|
|
14
17
|
*/
|
|
15
18
|
export const roles = defineRoles<ErpName>({
|
|
16
19
|
admin: ['*'],
|
|
17
|
-
auditor: ['*.read'],
|
|
20
|
+
auditor: ['*.read', ...ownNotificationSettings],
|
|
18
21
|
manager: ['*.read', '*.create', '*.update', 'costs.read'],
|
|
19
22
|
sales: [
|
|
23
|
+
...ownNotificationSettings,
|
|
20
24
|
'orders.read.own', 'orders.create', 'orders.update.own',
|
|
21
25
|
'order_lines.read', 'order_lines.create', 'order_lines.update', 'order_lines.delete',
|
|
22
26
|
'companies.read', 'companies.create', 'companies.update',
|
|
@@ -25,17 +29,20 @@ export const roles = defineRoles<ErpName>({
|
|
|
25
29
|
'products.read', 'categories.read', 'countries.read', 'currencies.read', 'stock_levels.read',
|
|
26
30
|
],
|
|
27
31
|
accountant: [
|
|
32
|
+
...ownNotificationSettings,
|
|
28
33
|
'invoices.*', 'invoice_lines.*',
|
|
29
34
|
'orders.read', 'order_lines.read', 'companies.read',
|
|
30
35
|
'products.read', 'categories.read', 'countries.read', 'currencies.read',
|
|
31
36
|
'costs.read',
|
|
32
37
|
],
|
|
33
38
|
warehouse: [
|
|
39
|
+
...ownNotificationSettings,
|
|
34
40
|
'stock_levels.*', 'stock_moves.*', 'locations.*', 'warehouses.read',
|
|
35
41
|
'orders.read', 'orders.update', 'order_lines.read',
|
|
36
42
|
'products.read', 'categories.read',
|
|
37
43
|
],
|
|
38
44
|
editor: [
|
|
45
|
+
...ownNotificationSettings,
|
|
39
46
|
'products.*', 'categories.*', 'tags.*', 'company_tags.*',
|
|
40
47
|
'countries.read', 'currencies.read',
|
|
41
48
|
],
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Each person's choice of notification emails, one row per person, keyed by their Better Auth id. Someone who never
|
|
2
|
+
-- saved a choice has no row: read the default for them.
|
|
3
|
+
create table core.notification_settings (
|
|
4
|
+
user_id text primary key references auth."user" (id) on delete cascade,
|
|
5
|
+
overdue_invoices text not null default 'each' check (overdue_invoices in ('each', 'daily', 'never'))
|
|
6
|
+
);
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"dev": "protobase dev"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@protobase/cli": ">=0.46.
|
|
20
|
-
"@protobase/layout": ">=0.46.
|
|
21
|
-
"@protobase/schema": ">=0.46.
|
|
22
|
-
"@protobase/server": ">=0.46.
|
|
23
|
-
"@protobase/ui": ">=0.46.
|
|
19
|
+
"@protobase/cli": ">=0.46.5 <1",
|
|
20
|
+
"@protobase/layout": ">=0.46.5 <1",
|
|
21
|
+
"@protobase/schema": ">=0.46.5 <1",
|
|
22
|
+
"@protobase/server": ">=0.46.5 <1",
|
|
23
|
+
"@protobase/ui": ">=0.46.5 <1",
|
|
24
24
|
"better-auth": "^1.7.12",
|
|
25
25
|
"jose": "^6.2.12",
|
|
26
26
|
"kysely": "^0.29.6",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"dev": "protobase dev"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@protobase/cli": ">=0.46.
|
|
20
|
-
"@protobase/layout": ">=0.46.
|
|
21
|
-
"@protobase/schema": ">=0.46.
|
|
22
|
-
"@protobase/server": ">=0.46.
|
|
23
|
-
"@protobase/ui": ">=0.46.
|
|
19
|
+
"@protobase/cli": ">=0.46.5 <1",
|
|
20
|
+
"@protobase/layout": ">=0.46.5 <1",
|
|
21
|
+
"@protobase/schema": ">=0.46.5 <1",
|
|
22
|
+
"@protobase/server": ">=0.46.5 <1",
|
|
23
|
+
"@protobase/ui": ">=0.46.5 <1",
|
|
24
24
|
"better-auth": "^1.7.12",
|
|
25
25
|
"jose": "^6.2.12",
|
|
26
26
|
"kysely": "^0.29.6",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"dev": "protobase dev"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@protobase/cli": ">=0.46.
|
|
17
|
-
"@protobase/layout": ">=0.46.
|
|
18
|
-
"@protobase/schema": ">=0.46.
|
|
19
|
-
"@protobase/server": ">=0.46.
|
|
20
|
-
"@protobase/ui": ">=0.46.
|
|
16
|
+
"@protobase/cli": ">=0.46.5 <1",
|
|
17
|
+
"@protobase/layout": ">=0.46.5 <1",
|
|
18
|
+
"@protobase/schema": ">=0.46.5 <1",
|
|
19
|
+
"@protobase/server": ">=0.46.5 <1",
|
|
20
|
+
"@protobase/ui": ">=0.46.5 <1",
|
|
21
21
|
"better-auth": "^1.7.12",
|
|
22
22
|
"jose": "^6.2.12",
|
|
23
23
|
"kysely": "^0.29.6",
|