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

fix: prevent commentor/viewer from enabling hidden columns #8268

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
34 changes: 28 additions & 6 deletions packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ const {
toggleFieldVisibility,
} = useViewColumnsOrThrow()

const shouldShowField = (show: boolean) =>
!((baseRoles?.value[ProjectRoles.COMMENTER] || baseRoles?.value[ProjectRoles.VIEWER]) && !show)
const isViewerOrCommentor = computed(() => baseRoles?.value[ProjectRoles.COMMENTER] || baseRoles?.value[ProjectRoles.VIEWER])

const shouldShowField = (show: boolean) => !isViewerOrCommentor.value || show

const { eventBus } = useSmartsheetStoreOrThrow()

Expand Down Expand Up @@ -224,7 +225,7 @@ const coverImageColumnId = computed({
},
})

const onShowAll = () => {
const onShowAll = (hiddenFields: Array<string> = []) => {
addUndo({
undo: {
fn: async () => {
Expand All @@ -240,7 +241,7 @@ const onShowAll = () => {
},
scope: defineViewScope({ view: activeView.value }),
})
showAll()
showAll(hiddenFields)
}

const onHideAll = () => {
Expand All @@ -262,13 +263,31 @@ const onHideAll = () => {
hideAll()
}

const hiddenFields = ref<string[]>([])

onMounted(() => {
if (isViewerOrCommentor.value) {
hiddenFields.value = filteredFieldList.value.filter((field) => !field.show).map((field) => field.id)
}
})

const showAllColumns = computed({
get: () => {
if (isViewerOrCommentor.value) {
if (filteredFieldList.value?.every((field) => !field.show)) return false
return filteredFieldList.value?.every((field) => {
if (hiddenFields.value.includes(field.id)) {
// Skip fields with IDs listed in hiddenFields
return true
}
return field?.show
})
}
return filteredFieldList.value?.every((field) => field.show)
},
set: async (val) => {
if (val) {
await onShowAll()
await onShowAll(hiddenFields.value)
} else {
await onHideAll()
}
Expand Down Expand Up @@ -348,7 +367,10 @@ useMenuCloseOnEsc(open)
{{ $t('objects.fields') }}
</template>
</span>
<span v-if="numberOfHiddenFields" class="bg-brand-50 text-brand-500 py-1 px-2 text-md rounded-md">
<span
v-if="numberOfHiddenFields && !isViewerOrCommentor"
class="bg-brand-50 text-brand-500 py-1 px-2 text-md rounded-md"
>
{{ numberOfHiddenFields }}
</span>
</div>
Expand Down
17 changes: 12 additions & 5 deletions packages/nc-gui/composables/useViewColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,19 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
}
}

const showAll = async (ignoreIds?: any) => {
const showAll = async (ignoreIds: Array<string> = []) => {
console.log(ignoreIds)
sreehari2003 marked this conversation as resolved.
Show resolved Hide resolved
if (isLocalMode.value) {
fields.value = fields.value?.map((field: Field) => ({
...field,
show: true,
}))
fields.value = fields.value?.map((field: Field) => {
if (ignoreIds.includes(field.id)) {
return field
} else {
return {
...field,
show: true,
}
}
})
sreehari2003 marked this conversation as resolved.
Show resolved Hide resolved
reloadData?.()
return
}
Expand Down
1 change: 1 addition & 0 deletions packages/nc-gui/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface ProjectMetaInfo {
}

interface Field {
id: string
order: number
show: number | boolean
bold: boolean | number
Expand Down