Set default permissions to view

This commit is contained in:
Adria Navarro 2024-10-09 14:36:37 +02:00
parent d01462221f
commit c84cda40b3
2 changed files with 16 additions and 8 deletions

View File

@ -227,23 +227,23 @@ describe("/permission", () => {
viewId = view.id viewId = view.id
}) })
it("default permissions inherits the table default value", async () => { it("default permissions inherits and persists the table default value", async () => {
const { permissions } = await config.api.permission.get(viewId) const { permissions } = await config.api.permission.get(viewId)
expect(permissions).toEqual({ expect(permissions).toEqual({
read: { read: {
permissionType: "INHERITED", permissionType: "EXPLICIT",
role: DEFAULT_TABLE_ROLE_ID, role: DEFAULT_TABLE_ROLE_ID,
inheritablePermission: DEFAULT_TABLE_ROLE_ID, inheritablePermission: DEFAULT_TABLE_ROLE_ID,
}, },
write: { write: {
permissionType: "INHERITED", permissionType: "EXPLICIT",
role: DEFAULT_TABLE_ROLE_ID, role: DEFAULT_TABLE_ROLE_ID,
inheritablePermission: DEFAULT_TABLE_ROLE_ID, inheritablePermission: DEFAULT_TABLE_ROLE_ID,
}, },
}) })
}) })
it("default permissions inherits explicit table permissions", async () => { it("does not update view permissions once persisted, even if table permissions change", async () => {
await config.api.permission.add({ await config.api.permission.add({
roleId: STD_ROLE_ID, roleId: STD_ROLE_ID,
resourceId: tableId, resourceId: tableId,
@ -253,12 +253,12 @@ describe("/permission", () => {
const { permissions } = await config.api.permission.get(viewId) const { permissions } = await config.api.permission.get(viewId)
expect(permissions).toEqual({ expect(permissions).toEqual({
read: { read: {
permissionType: "INHERITED", permissionType: "EXPLICIT",
role: STD_ROLE_ID, role: DEFAULT_TABLE_ROLE_ID,
inheritablePermission: STD_ROLE_ID, inheritablePermission: STD_ROLE_ID,
}, },
write: { write: {
permissionType: "INHERITED", permissionType: "EXPLICIT",
role: DEFAULT_TABLE_ROLE_ID, role: DEFAULT_TABLE_ROLE_ID,
inheritablePermission: DEFAULT_TABLE_ROLE_ID, inheritablePermission: DEFAULT_TABLE_ROLE_ID,
}, },
@ -275,7 +275,7 @@ describe("/permission", () => {
const { permissions } = await config.api.permission.get(viewId) const { permissions } = await config.api.permission.get(viewId)
expect(permissions).toEqual({ expect(permissions).toEqual({
read: { read: {
permissionType: "INHERITED", permissionType: "EXPLICIT",
role: DEFAULT_TABLE_ROLE_ID, role: DEFAULT_TABLE_ROLE_ID,
inheritablePermission: DEFAULT_TABLE_ROLE_ID, inheritablePermission: DEFAULT_TABLE_ROLE_ID,
}, },

View File

@ -3,6 +3,7 @@ import {
canGroupBy, canGroupBy,
FieldType, FieldType,
isNumeric, isNumeric,
PermissionLevel,
RelationSchemaField, RelationSchemaField,
RenameColumn, RenameColumn,
Table, Table,
@ -243,6 +244,13 @@ export async function create(
const view = await pickApi(tableId).create(tableId, viewRequest) const view = await pickApi(tableId).create(tableId, viewRequest)
// Set permissions to be the same as the table
const tablePerms = await sdk.permissions.getResourcePerms(tableId)
await sdk.permissions.setPermissions(view.id, {
writeRole: tablePerms[PermissionLevel.WRITE].role,
readRole: tablePerms[PermissionLevel.READ].role,
})
return view return view
} }