Merge branch 'master' into view-calculation-filtering

This commit is contained in:
Sam Rose 2024-10-10 12:03:38 +01:00 committed by GitHub
commit 84ebd6905b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 66 additions and 21 deletions

View File

@ -272,6 +272,7 @@ export const flags = new FlagSet({
SQS: Flag.boolean(env.isDev()), SQS: Flag.boolean(env.isDev()),
[FeatureFlag.AI_CUSTOM_CONFIGS]: Flag.boolean(env.isDev()), [FeatureFlag.AI_CUSTOM_CONFIGS]: Flag.boolean(env.isDev()),
[FeatureFlag.ENRICHED_RELATIONSHIPS]: Flag.boolean(env.isDev()), [FeatureFlag.ENRICHED_RELATIONSHIPS]: Flag.boolean(env.isDev()),
[FeatureFlag.TABLES_DEFAULT_ADMIN]: Flag.boolean(env.isDev()),
}) })
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T type UnwrapPromise<T> = T extends Promise<infer U> ? U : T

View File

@ -133,9 +133,7 @@ export async function buildSqlFieldList(
let fields: string[] = [] let fields: string[] = []
if (sdk.views.isView(source)) { if (sdk.views.isView(source)) {
fields = Object.keys(helpers.views.basicFields(source)).filter( fields = Object.keys(helpers.views.basicFields(source))
key => source.schema?.[key]?.visible !== false
)
} else { } else {
fields = extractRealFields(source) fields = extractRealFields(source)
} }

View File

@ -800,6 +800,34 @@ describe.each([
) )
} }
}) })
isInternal &&
it("shouldn't trigger a complex type check on a group by field if field is invisible", async () => {
const table = await config.api.table.save(
saveTableRequest({
schema: {
field: {
name: "field",
type: FieldType.JSON,
},
},
})
)
await config.api.viewV2.create(
{
tableId: table._id!,
name: generator.guid(),
type: ViewV2Type.CALCULATION,
schema: {
field: { visible: false },
},
},
{
status: 201,
}
)
})
}) })
describe("update", () => { describe("update", () => {

View File

@ -68,9 +68,7 @@ async function buildInternalFieldList(
const { relationships, allowedFields } = opts || {} const { relationships, allowedFields } = opts || {}
let schemaFields: string[] = [] let schemaFields: string[] = []
if (sdk.views.isView(source)) { if (sdk.views.isView(source)) {
schemaFields = Object.keys(helpers.views.basicFields(source)).filter( schemaFields = Object.keys(helpers.views.basicFields(source))
key => source.schema?.[key]?.visible !== false
)
} else { } else {
schemaFields = Object.keys(source.schema).filter( schemaFields = Object.keys(source.schema).filter(
key => source.schema[key].visible !== false key => source.schema[key].visible !== false

View File

@ -1,10 +1,10 @@
import { Row, Table } from "@budibase/types" import { FeatureFlag, Row, Table } from "@budibase/types"
import * as external from "./external" import * as external from "./external"
import * as internal from "./internal" import * as internal from "./internal"
import { isExternal } from "./utils" import { isExternal } from "./utils"
import { setPermissions } from "../permissions" import { setPermissions } from "../permissions"
import { roles } from "@budibase/backend-core" import { features, roles } from "@budibase/backend-core"
export async function create( export async function create(
table: Omit<Table, "_id" | "_rev">, table: Omit<Table, "_id" | "_rev">,
@ -18,10 +18,16 @@ export async function create(
createdTable = await internal.create(table, rows, userId) createdTable = await internal.create(table, rows, userId)
} }
const setExplicitPermission = await features.flags.isEnabled(
FeatureFlag.TABLES_DEFAULT_ADMIN
)
if (setExplicitPermission) {
await setPermissions(createdTable._id!, { await setPermissions(createdTable._id!, {
writeRole: roles.BUILTIN_ROLE_IDS.ADMIN, writeRole: roles.BUILTIN_ROLE_IDS.ADMIN,
readRole: roles.BUILTIN_ROLE_IDS.ADMIN, readRole: roles.BUILTIN_ROLE_IDS.ADMIN,
}) })
}
return createdTable return createdTable
} }

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)
const setExplicitPermission = await features.flags.isEnabled(
FeatureFlag.TABLES_DEFAULT_ADMIN
)
if (setExplicitPermission) {
// Set permissions to be the same as the table // Set permissions to be the same as the table
const tablePerms = await sdk.permissions.getResourcePerms(tableId) const tablePerms = await sdk.permissions.getResourcePerms(tableId)
await sdk.permissions.setPermissions(view.id, { await sdk.permissions.setPermissions(view.id, {
writeRole: tablePerms[PermissionLevel.WRITE].role, writeRole: tablePerms[PermissionLevel.WRITE].role,
readRole: tablePerms[PermissionLevel.READ].role, readRole: tablePerms[PermissionLevel.READ].role,
}) })
}
return view return view
} }

View File

@ -33,6 +33,13 @@ export function calculationFields(view: UnsavedViewV2) {
return pickBy(view.schema || {}, isCalculationField) return pickBy(view.schema || {}, isCalculationField)
} }
export function basicFields(view: UnsavedViewV2) { export function isVisible(field: ViewFieldMetadata) {
return pickBy(view.schema || {}, field => !isCalculationField(field)) return field.visible !== false
}
export function basicFields(view: UnsavedViewV2, opts?: { visible?: boolean }) {
const { visible = true } = opts || {}
return pickBy(view.schema || {}, field => {
return !isCalculationField(field) && (!visible || isVisible(field))
})
} }

View File

@ -3,6 +3,7 @@ export enum FeatureFlag {
PER_CREATOR_PER_USER_PRICE_ALERT = "PER_CREATOR_PER_USER_PRICE_ALERT", PER_CREATOR_PER_USER_PRICE_ALERT = "PER_CREATOR_PER_USER_PRICE_ALERT",
AI_CUSTOM_CONFIGS = "AI_CUSTOM_CONFIGS", AI_CUSTOM_CONFIGS = "AI_CUSTOM_CONFIGS",
ENRICHED_RELATIONSHIPS = "ENRICHED_RELATIONSHIPS", ENRICHED_RELATIONSHIPS = "ENRICHED_RELATIONSHIPS",
TABLES_DEFAULT_ADMIN = "TABLES_DEFAULT_ADMIN",
} }
export interface TenantFeatureFlags { export interface TenantFeatureFlags {