Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

refactor: reuse isLocked instead of redundant isRestrictedEditor/shouldShowLockedFooter

Pranav C9a7bbc580cde
diff --git a/packages/nc-gui/components/smartsheet/toolbar/Calendar/Range.vue b/packages/nc-gui/components/smartsheet/toolbar/Calendar/Range.vue
index 4393f3e53f..0f3ba10e88 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/Calendar/Range.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/Calendar/Range.vue
@@ -1,13 +1,5 @@
<script lang="ts" setup>
-import {
- type CalendarRangeType,
- FormulaDataTypes,
- PlanFeatureTypes,
- PlanTitles,
- UITypes,
- ViewLockType,
- ViewTypes,
-} from 'nocodb-sdk'
+import { type CalendarRangeType, FormulaDataTypes, PlanFeatureTypes, PlanTitles, UITypes, ViewTypes } from 'nocodb-sdk'
import type { SelectProps } from 'ant-design-vue'
const meta = inject(MetaInj, ref())
@@ -25,7 +17,7 @@ const isToolbarIconMode = inject(
computed(() => false),
)
-const { loadViewColumns, canUpdateViewMeta } = useViewColumnsOrThrow()
+const { loadViewColumns } = useViewColumnsOrThrow()
const viewStore = useViewsStore()
@@ -33,14 +25,6 @@ const { updateViewMeta } = viewStore
const { loadCalendarData, loadSidebarData, fetchActiveDates, viewMetaProperties } = useCalendarViewStoreOrThrow()
-// Check if user can update calendar settings based on role OR personal view ownership
-const isRestrictedEditor = computed(() => isLocked.value && !canUpdateViewMeta.value)
-
-// Show locked footer for locked views OR personal views not owned by current user
-const shouldShowLockedFooter = computed(
- () => isLocked.value || (activeView.value?.lock_type === ViewLockType.Personal && !isUserViewOwner(activeView.value)),
-)
-
const calendarRangeDropdown = ref(false)
const showWeekends = computed({
@@ -213,7 +197,7 @@ const onValueChange = async () => {
size="small"
type="secondary"
data-testid="nc-calendar-range-btn"
- :show-as-disabled="isRestrictedEditor"
+ :show-as-disabled="isLocked"
>
<div class="flex items-center gap-2">
<component :is="iconMap.calendar" class="h-4 w-4" />
@@ -242,7 +226,7 @@ const onValueChange = async () => {
dropdown-class-name="!rounded-lg"
:placeholder="$t('placeholder.notSelected')"
data-testid="nc-calendar-range-from-field-select"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
@change="
() => {
onValueChange()
@@ -290,7 +274,7 @@ const onValueChange = async () => {
data-testid="nc-calendar-range-add-end-date"
type="text"
:shadow="false"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
@click="
click(PlanFeatureTypes.FEATURE_CALENDAR_RANGE, () => {
range.fk_to_column_id = undefined
@@ -377,7 +361,7 @@ const onValueChange = async () => {
</div>
<div>
- <NcSwitch v-model:checked="showWeekends" :disabled="isRestrictedEditor">
+ <NcSwitch v-model:checked="showWeekends" :disabled="isLocked">
<span class="text-nc-content-gray font-semibold">
{{ $t('activity.showSaturdaysAndSundays') }}
</span>
@@ -387,7 +371,7 @@ const onValueChange = async () => {
<!--
<div class="text-[13px] text-nc-content-gray-muted py-2">Records in this view will be based on the specified date field.</div>
-->
- <GeneralLockedViewFooter v-if="shouldShowLockedFooter" class="!-mb-4 -mx-4" @on-open="calendarRangeDropdown = false" />
+ <GeneralLockedViewFooter v-if="isLocked" class="!-mb-4 -mx-4" @on-open="calendarRangeDropdown = false" />
</div>
</template>
</NcDropdown>
diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
index a472af007b..3793a84b2f 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
@@ -225,7 +225,7 @@ watch(
class="nc-filter-menu-btn nc-toolbar-btn !border-0 !h-7 group"
size="small"
type="secondary"
- :show-as-disabled="isRestrictedEditor"
+ :show-as-disabled="isLocked"
:class="{
[filteredOrSortedAppearanceConfig.FILTERED.toolbarBgClass]: combinedFilterLength,
}"
diff --git a/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue
index 1568f90f80..2d2bf26f3d 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue
@@ -1,6 +1,6 @@
<script setup lang="ts">
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
-import { RelationTypes, UITypes, ViewLockType, ViewSettingOverrideOptions, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
+import { RelationTypes, UITypes, ViewSettingOverrideOptions, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
import Draggable from 'vuedraggable'
import { getColumnUidtByID as sortGetColumnUidtByID } from '~/utils/sortUtils'
@@ -15,20 +15,12 @@ const isToolbarIconMode = inject(
computed(() => false),
)
-const { gridViewCols, updateGridViewColumn, metaColumnById, showSystemFields, canUpdateViewMeta } = useViewColumnsOrThrow()
+const { gridViewCols, updateGridViewColumn, metaColumnById, showSystemFields } = useViewColumnsOrThrow()
const { fieldsToGroupBy, groupByLimit } = useViewGroupByOrThrow()
const { $e } = useNuxtApp()
-// Check if user can update group by based on role OR personal view ownership
-const isRestrictedEditor = computed(() => isLocked.value && !canUpdateViewMeta.value)
-
-// Show locked footer for locked views OR personal views not owned by current user
-const shouldShowLockedFooter = computed(
- () => isLocked.value || (view.value?.lock_type === ViewLockType.Personal && !isUserViewOwner(view.value)),
-)
-
interface Group {
fk_column_id?: string
sort: string
@@ -227,7 +219,7 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
class="nc-group-by-menu-btn nc-toolbar-btn !border-0 !h-7"
size="small"
type="secondary"
- :show-as-disabled="isRestrictedEditor"
+ :show-as-disabled="isLocked"
>
<div class="flex items-center gap-1 min-h-5">
<div class="flex items-center gap-2">
@@ -247,14 +239,14 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
<template #overlay>
<div
:class="{
- 'nc-locked-view': isRestrictedEditor,
+ 'nc-locked-view': isLocked,
}"
>
<SmartsheetToolbarCreateGroupBy
v-if="!_groupBy.length"
:is-parent-open="open"
:columns="getFieldsToGroupBy({})"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
@created="addFieldToGroupBy"
/>
<div
@@ -267,7 +259,7 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
:model-value="_groupBy"
item-key="fk_column_id"
ghost-class="bg-nc-bg-gray-extralight"
- :disabled="isRestrictedEditor || !isEeUI"
+ :disabled="isLocked || !isEeUI"
@change="onMove($event)"
>
<template #item="{ element: group }">
@@ -278,7 +270,7 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
size="small"
class="!border-r-transparent !rounded-r-none"
:shadow="false"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
>
<component :is="iconMap.drag" />
</NcButton>
@@ -289,7 +281,7 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
:columns="getFieldsToGroupBy(group)"
:allow-empty="true"
:meta="meta"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
@change="saveGroupBy"
@click.stop
/>
@@ -299,7 +291,7 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
class="flex flex-grow-1 w-full nc-group-sort-dir-select"
:label="$t('labels.operation')"
dropdown-class-name="sort-dir-dropdown nc-dropdown-group-sort-dir"
- :disabled="!group.fk_column_id || isRestrictedEditor"
+ :disabled="!group.fk_column_id || isLocked"
@change="saveGroupBy"
@click.stop
>
@@ -345,7 +337,7 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
size="small"
type="secondary"
:shadow="false"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
@click.stop="removeFieldFromGroupBy(group)"
>
<component :is="iconMap.deleteListItem" />
@@ -361,7 +353,7 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
v-model:visible="showCreateGroupBy"
:trigger="['click']"
overlay-class-name="nc-toolbar-dropdown"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
>
<NcButton
v-e="['c:group-by:add']"
@@ -370,9 +362,9 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
style="width: fit-content"
class="nc-add-group-by-btn"
:class="{
- '!text-nc-content-brand': !isRestrictedEditor,
+ '!text-nc-content-brand': !isLocked,
}"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
@click.stop="showCreateGroupBy = true"
>
<div class="flex gap-1 items-center">
@@ -398,7 +390,7 @@ const getFieldsToGroupBy = (currentGroup: Group) => {
</div>
</div>
<GeneralLockedViewFooter
- v-if="shouldShowLockedFooter"
+ v-if="isLocked"
:class="{
'-mt-2': _groupBy.length,
}"
diff --git a/packages/nc-gui/components/smartsheet/toolbar/MappedBy.vue b/packages/nc-gui/components/smartsheet/toolbar/MappedBy.vue
index 217a758528..236e03bf86 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/MappedBy.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/MappedBy.vue
@@ -13,13 +13,10 @@ const isLocked = inject(IsLockedInj, ref(false))
const IsPublic = inject(IsPublicInj, ref(false))
-const { fields, loadViewColumns, metaColumnById, canUpdateViewMeta } = useViewColumnsOrThrow()
+const { fields, loadViewColumns, metaColumnById } = useViewColumnsOrThrow()
const { loadMapData, loadMapMeta, updateMapMeta, mapMetaData, geoDataFieldColumn } = useMapViewStoreOrThrow()
-// Check if user can update map settings based on role OR personal view ownership
-const isRestrictedEditor = computed(() => isLocked.value && !canUpdateViewMeta.value)
-
const mappedByDropdown = ref(false)
watch(
@@ -66,11 +63,7 @@ const handleChange = () => {
<template>
<a-dropdown v-if="!IsPublic" v-model:visible="mappedByDropdown" :trigger="['click']" class="!xs:hidden">
<div class="nc-map-btn">
- <a-button
- v-e="['c:map:change-grouping-field']"
- class="nc-map-stacked-by-menu-btn nc-toolbar-btn"
- :disabled="isRestrictedEditor"
- >
+ <a-button v-e="['c:map:change-grouping-field']" class="nc-map-stacked-by-menu-btn nc-toolbar-btn" :disabled="isLocked">
<div class="flex items-center gap-1">
<mdi-arrow-down-drop-circle-outline />
<span class="text-capitalize !text-sm font-weight-normal">
diff --git a/packages/nc-gui/components/smartsheet/toolbar/RowHeight.vue b/packages/nc-gui/components/smartsheet/toolbar/RowHeight.vue
index d32c51b3f8..59eb8e026b 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/RowHeight.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/RowHeight.vue
@@ -36,12 +36,10 @@ const { canUpdateViewMeta } = useViewColumnsOrThrow()
const { addUndo, defineViewScope } = useUndoRedo()
-const isRestrictedEditor = computed(() => isLocked.value || !canUpdateViewMeta.value)
-
const open = ref(false)
const updateRowHeight = async (rh: number, undo = false) => {
- if (isRestrictedEditor.value) return
+ if (isLocked.value) return
if (view.value?.id) {
if (rh === (view.value.view as GridType).row_height) return
@@ -95,7 +93,7 @@ useMenuCloseOnEsc(open)
class="nc-height-menu-btn nc-toolbar-btn !border-0 !h-7 !px-1.5 !min-w-7"
size="small"
type="secondary"
- :show-as-disabled="isRestrictedEditor"
+ :show-as-disabled="isLocked"
>
<div class="flex items-center gap-0.5">
<component :is="iconMap.rowHeight" class="!h-3.75 !w-3.75" />
diff --git a/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue
index b59506c2e4..3c6d6ec79d 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue
@@ -166,7 +166,7 @@ watch(
class="nc-sort-menu-btn nc-toolbar-btn !h-7 group"
size="small"
type="secondary"
- :show-as-disabled="isRestrictedEditor"
+ :show-as-disabled="isLocked"
>
<div class="flex items-center gap-1 min-h-5">
<div class="flex items-center gap-2">
diff --git a/packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue b/packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue
index 0597aa282c..58805c78cb 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue
@@ -1,6 +1,6 @@
<script setup lang="ts">
import type { KanbanType } from 'nocodb-sdk'
-import { UITypes, ViewLockType } from 'nocodb-sdk'
+import { UITypes } from 'nocodb-sdk'
import type { SelectProps } from 'ant-design-vue'
provide(IsKanbanInj, ref(true))
@@ -18,7 +18,7 @@ const isToolbarIconMode = inject(
computed(() => false),
)
-const { fields, loadViewColumns, metaColumnById, canUpdateViewMeta } = useViewColumnsOrThrow(activeView, meta)
+const { fields, loadViewColumns, metaColumnById } = useViewColumnsOrThrow(activeView, meta)
const { kanbanMetaData, updateKanbanMeta, groupingField } = useKanbanViewStoreOrThrow()
@@ -26,14 +26,6 @@ const { addUndo, defineViewScope } = useUndoRedo()
const open = ref(false)
-// Check if user can update kanban settings based on role OR personal view ownership
-const isRestrictedEditor = computed(() => isLocked.value && !canUpdateViewMeta.value)
-
-// Show locked footer for locked views OR personal views not owned by current user
-const shouldShowLockedFooter = computed(
- () => isLocked.value || (activeView.value?.lock_type === ViewLockType.Personal && !isUserViewOwner(activeView.value)),
-)
-
useMenuCloseOnEsc(open)
watch(
@@ -145,7 +137,7 @@ const handleChange = () => {
class="nc-kanban-stacked-by-menu-btn nc-toolbar-btn !border-0 !h-7 group"
size="small"
type="secondary"
- :show-as-disabled="isRestrictedEditor"
+ :show-as-disabled="isLocked"
>
<div class="flex items-center gap-2">
<GeneralIcon icon="settings" class="h-4 w-4" />
@@ -156,7 +148,7 @@ const handleChange = () => {
<div
class="flex items-center rounded-md transition-colors duration-0.3s bg-nc-bg-gray-light px-1 min-h-5 max-w-[108px]"
:class="{
- 'group-hover:bg-nc-bg-gray-medium': !isRestrictedEditor,
+ 'group-hover:bg-nc-bg-gray-medium': !isLocked,
}"
>
<span class="!text-[13px] font-medium truncate !leading-5">{{ groupingField }}</span>
@@ -179,7 +171,7 @@ const handleChange = () => {
class="nc-select-shadow w-full nc-kanban-grouping-field-select !rounded-lg"
dropdown-class-name="!rounded-lg"
placeholder="Select a Grouping Field"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
@change="handleChange"
@click.stop
>
@@ -218,7 +210,7 @@ const handleChange = () => {
size="small"
class="nc-switch"
:loading="isLoading === 'hideEmptyStack'"
- :disabled="isRestrictedEditor"
+ :disabled="isLocked"
>
<div class="text-sm text-nc-content-gray">
{{ $t('general.hide') }}
@@ -227,7 +219,7 @@ const handleChange = () => {
</div>
</NcSwitch>
</div>
- <GeneralLockedViewFooter v-if="shouldShowLockedFooter" class="-mb-4 -mx-4" @on-open="open = false" />
+ <GeneralLockedViewFooter v-if="isLocked" class="-mb-4 -mx-4" @on-open="open = false" />
</div>
</template>
</NcDropdown>
diff --git a/packages/nc-gui/lib/acl.ts b/packages/nc-gui/lib/acl.ts
index 2c57897287..f8380d22c3 100644
--- a/packages/nc-gui/lib/acl.ts
+++ b/packages/nc-gui/lib/acl.ts
@@ -122,10 +122,6 @@ const rolePermissions = {
// Extensions
extensionUpdate: true,
-
- // Sort/Filter sync for personal views (middleware handles non-personal view restrictions)
- // sortSync: true,
- // filterSync: true,
},
},
[ProjectRoles.COMMENTER]: {