Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make view readonly columns available for free #14592

Merged
merged 8 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ export const useAppBuilders = () => {
return useFeature(Feature.APP_BUILDERS)
}

export const useViewReadonlyColumns = () => {
return useFeature(Feature.VIEW_READONLY_COLUMNS)
}

// QUOTAS

export const setAutomationLogsQuota = (value: number) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { viewsV2 } from "stores/builder"
import { admin, licensing } from "stores/portal"
import { admin } from "stores/portal"
import { Grid } from "@budibase/frontend-core"
import { API } from "api"
import GridCreateEditRowModal from "components/backend/DataTable/modals/grid/GridCreateEditRowModal.svelte"
Expand Down Expand Up @@ -30,7 +30,6 @@
showAvatars={false}
on:updatedatasource={handleGridViewUpdate}
isCloud={$admin.cloud}
allowViewReadonlyColumns={$licensing.isViewReadonlyColumnsEnabled}
canSetRelationshipSchemas={isEnabled(FeatureFlag.ENRICHED_RELATIONSHIPS)}
>
<svelte:fragment slot="filter">
Expand Down
5 changes: 0 additions & 5 deletions packages/builder/src/stores/portal/licensing.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ export const createLicensingStore = () => {
Constants.Features.VIEW_PERMISSIONS
)

const isViewReadonlyColumnsEnabled = license.features.includes(
Constants.Features.VIEW_READONLY_COLUMNS
)

const budibaseAIEnabled = license.features.includes(
Constants.Features.BUDIBASE_AI
)
Expand Down Expand Up @@ -173,7 +169,6 @@ export const createLicensingStore = () => {
triggerAutomationRunEnabled,
isViewPermissionsEnabled,
perAppBuildersEnabled,
isViewReadonlyColumnsEnabled,
}
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import ColumnsSettingContent from "./ColumnsSettingContent.svelte"
import { FieldPermissions } from "../../../constants"

export let allowViewReadonlyColumns = false

const { columns, datasource } = getContext("grid")

let open = false
let anchor

$: anyRestricted = $columns.filter(col => !col.visible || col.readonly).length
$: text = anyRestricted ? `Columns (${anyRestricted} restricted)` : "Columns"

$: text = anyRestricted ? `Columns: (${anyRestricted} restricted)` : "Columns"
$: permissions =
$datasource.type === "viewV2"
? [
Expand All @@ -22,9 +19,6 @@
FieldPermissions.HIDDEN,
]
: [FieldPermissions.WRITABLE, FieldPermissions.HIDDEN]
$: disabledPermissions = allowViewReadonlyColumns
? []
: [FieldPermissions.READONLY]
</script>

<div bind:this={anchor}>
Expand All @@ -41,9 +35,5 @@
</div>

<Popover bind:open {anchor} align="left">
<ColumnsSettingContent
columns={$columns}
{permissions}
{disabledPermissions}
/>
<ColumnsSettingContent columns={$columns} {permissions} />
</Popover>
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
export let buttons = null
export let darkMode
export let isCloud = null
export let allowViewReadonlyColumns = false
export let rowConditions = null

// Unique identifier for DOM nodes inside this instance
Expand Down Expand Up @@ -115,7 +114,6 @@
buttons,
darkMode,
isCloud,
allowViewReadonlyColumns,
rowConditions,
})

Expand Down Expand Up @@ -157,7 +155,7 @@
<div class="controls-left">
<slot name="filter" />
<SortButton />
<ColumnsSettingButton {allowViewReadonlyColumns} />
<ColumnsSettingButton />
<SizeButton />
<slot name="controls" />
</div>
Expand Down
84 changes: 2 additions & 82 deletions packages/server/src/api/routes/tests/viewV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,6 @@ describe.each([
})

describe("readonly fields", () => {
beforeEach(() => {
mocks.licenses.useViewReadonlyColumns()
})

it("readonly fields are persisted", async () => {
const table = await config.api.table.save(
saveTableRequest({
Expand Down Expand Up @@ -436,7 +432,7 @@ describe.each([
})
})

it("readonly fields cannot be used on free license", async () => {
it("readonly fields can be used on free license", async () => {
mocks.licenses.useCloudFree()
const table = await config.api.table.save(
saveTableRequest({
Expand Down Expand Up @@ -466,11 +462,7 @@ describe.each([
}

await config.api.viewV2.create(newView, {
status: 400,
body: {
message: "Readonly fields are not enabled",
status: 400,
},
status: 201,
})
})
})
Expand Down Expand Up @@ -513,7 +505,6 @@ describe.each([
})

it("display fields can be readonly", async () => {
mocks.licenses.useViewReadonlyColumns()
const table = await config.api.table.save(
saveTableRequest({
schema: {
Expand Down Expand Up @@ -588,7 +579,6 @@ describe.each([
})

it("can update all fields", async () => {
mocks.licenses.useViewReadonlyColumns()
const tableId = table._id!

const updatedData: Required<UpdateViewRequest> = {
Expand Down Expand Up @@ -802,71 +792,6 @@ describe.each([
)
})

it("cannot update views with readonly on on free license", async () => {
mocks.licenses.useViewReadonlyColumns()

view = await config.api.viewV2.update({
...view,
schema: {
id: { visible: true },
Price: {
visible: true,
readonly: true,
},
},
})

mocks.licenses.useCloudFree()
await config.api.viewV2.update(view, {
status: 400,
body: {
message: "Readonly fields are not enabled",
},
})
})

it("can remove readonly config after license downgrade", async () => {
mocks.licenses.useViewReadonlyColumns()

view = await config.api.viewV2.update({
...view,
schema: {
id: { visible: true },
Price: {
visible: true,
readonly: true,
},
Category: {
visible: true,
readonly: true,
},
},
})
mocks.licenses.useCloudFree()
const res = await config.api.viewV2.update({
...view,
schema: {
id: { visible: true },
Price: {
visible: true,
readonly: false,
},
},
})
expect(res).toEqual(
expect.objectContaining({
...view,
schema: {
id: { visible: true },
Price: {
visible: true,
readonly: false,
},
},
})
)
})

isInternal &&
it("updating schema will only validate modified field", async () => {
let view = await config.api.viewV2.create({
Expand Down Expand Up @@ -1046,7 +971,6 @@ describe.each([
})

it("should be able to fetch readonly config after downgrades", async () => {
mocks.licenses.useViewReadonlyColumns()
const res = await config.api.viewV2.create({
name: generator.name(),
tableId: table._id!,
Expand Down Expand Up @@ -1112,8 +1036,6 @@ describe.each([
})

it("rejects if field is readonly in any view", async () => {
mocks.licenses.useViewReadonlyColumns()

await config.api.viewV2.create({
name: "view a",
tableId: table._id!,
Expand Down Expand Up @@ -1538,7 +1460,6 @@ describe.each([
})

it("can't persist readonly columns", async () => {
mocks.licenses.useViewReadonlyColumns()
const view = await config.api.viewV2.create({
tableId: table._id!,
name: generator.guid(),
Expand Down Expand Up @@ -1607,7 +1528,6 @@ describe.each([
})

it("can't update readonly columns", async () => {
mocks.licenses.useViewReadonlyColumns()
const view = await config.api.viewV2.create({
tableId: table._id!,
name: generator.guid(),
Expand Down
9 changes: 0 additions & 9 deletions packages/server/src/sdk/app/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import {
Table,
TableSchema,
View,
ViewFieldMetadata,
ViewV2,
ViewV2ColumnEnriched,
ViewV2Enriched,
} from "@budibase/types"
import { HTTPError } from "@budibase/backend-core"
import { features } from "@budibase/pro"
import {
helpers,
PROTECTED_EXTERNAL_COLUMNS,
Expand Down Expand Up @@ -59,13 +57,6 @@ async function guardViewSchema(
}

if (viewSchema[field].readonly) {
if (
!(await features.isViewReadonlyColumnsEnabled()) &&
!(tableSchemaField as ViewFieldMetadata).readonly
) {
throw new HTTPError(`Readonly fields are not enabled`, 400)
}

if (!viewSchema[field].visible) {
throw new HTTPError(
`Field "${field}" must be visible if you want to make it readonly`,
Expand Down
Loading