Use flag for views

This commit is contained in:
Adria Navarro 2024-10-10 10:35:39 +02:00
parent a646b86131
commit cda7782c6d
1 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,7 @@
import { import {
CalculationType, CalculationType,
canGroupBy, canGroupBy,
FeatureFlag,
FieldType, FieldType,
isNumeric, isNumeric,
PermissionLevel, PermissionLevel,
@ -13,7 +14,7 @@ import {
ViewV2ColumnEnriched, ViewV2ColumnEnriched,
ViewV2Enriched, ViewV2Enriched,
} from "@budibase/types" } from "@budibase/types"
import { context, docIds, HTTPError } from "@budibase/backend-core" import { context, docIds, features, HTTPError } from "@budibase/backend-core"
import { import {
helpers, helpers,
PROTECTED_EXTERNAL_COLUMNS, PROTECTED_EXTERNAL_COLUMNS,
@ -244,12 +245,17 @@ 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 setExplicitPermission = await features.flags.isEnabled(
const tablePerms = await sdk.permissions.getResourcePerms(tableId) FeatureFlag.TABLES_DEFAULT_ADMIN
await sdk.permissions.setPermissions(view.id, { )
writeRole: tablePerms[PermissionLevel.WRITE].role, if (setExplicitPermission) {
readRole: tablePerms[PermissionLevel.READ].role, // 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
} }