diff --git a/packages/nc-gui-v2/components.d.ts b/packages/nc-gui-v2/components.d.ts index 7fd5ee4556..5b5095a947 100644 --- a/packages/nc-gui-v2/components.d.ts +++ b/packages/nc-gui-v2/components.d.ts @@ -95,6 +95,7 @@ declare module '@vue/runtime-core' { MdiDrag: typeof import('~icons/mdi/drag')['default'] MdiDragVertical: typeof import('~icons/mdi/drag-vertical')['default'] MdiEmail: typeof import('~icons/mdi/email')['default'] + MdiExitToApp: typeof import('~icons/mdi/exit-to-app')['default'] MdiEyeOffOutline: typeof import('~icons/mdi/eye-off-outline')['default'] MdiFlag: typeof import('~icons/mdi/flag')['default'] MdiFolder: typeof import('~icons/mdi/folder')['default'] diff --git a/packages/nc-gui-v2/components/PreviewAs.vue b/packages/nc-gui-v2/components/PreviewAs.vue new file mode 100644 index 0000000000..d151bd948f --- /dev/null +++ b/packages/nc-gui-v2/components/PreviewAs.vue @@ -0,0 +1,93 @@ + + + + + + + + + Preview as : + + + {{ role.title }} + + + + + + Exit + + + + + + + + + + + {{ role.title + }} + + + + + + + diff --git a/packages/nc-gui-v2/composables/useApi/interceptors.ts b/packages/nc-gui-v2/composables/useApi/interceptors.ts index e5a4882947..c8c6fd1fa6 100644 --- a/packages/nc-gui-v2/composables/useApi/interceptors.ts +++ b/packages/nc-gui-v2/composables/useApi/interceptors.ts @@ -13,8 +13,8 @@ export function addAxiosInterceptors(api: Api) { if (state.token.value) config.headers['xc-auth'] = state.token.value - if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles')) { - // config.headers['xc-preview'] = store.state.users.previewAs + if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles') && state.previewAs?.value) { + config.headers['xc-preview'] = state.previewAs.value } if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles')) { diff --git a/packages/nc-gui-v2/composables/useGlobal/state.ts b/packages/nc-gui-v2/composables/useGlobal/state.ts index fdc8c4da9a..c61b3829cf 100644 --- a/packages/nc-gui-v2/composables/useGlobal/state.ts +++ b/packages/nc-gui-v2/composables/useGlobal/state.ts @@ -57,6 +57,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State { isHidden: false, }, filterAutoSave: true, + previewAs: null, } /** saves a reactive state, any change to these values will write/delete to localStorage */ diff --git a/packages/nc-gui-v2/composables/useGlobal/types.ts b/packages/nc-gui-v2/composables/useGlobal/types.ts index 7f9e54f94e..82ab8b8ed5 100644 --- a/packages/nc-gui-v2/composables/useGlobal/types.ts +++ b/packages/nc-gui-v2/composables/useGlobal/types.ts @@ -22,6 +22,7 @@ export interface StoredState { darkMode: boolean feedbackForm: FeedbackForm filterAutoSave: boolean + previewAs: string | null } export type State = ToRefs> & { diff --git a/packages/nc-gui-v2/composables/useUIPermission/index.ts b/packages/nc-gui-v2/composables/useUIPermission/index.ts index 460664e998..62ff91f05e 100644 --- a/packages/nc-gui-v2/composables/useUIPermission/index.ts +++ b/packages/nc-gui-v2/composables/useUIPermission/index.ts @@ -7,7 +7,7 @@ export function useUIPermission() { const { $state } = useNuxtApp() const projectRoles = useState>(USER_PROJECT_ROLES, () => ({})) - const isUIAllowed = (permission: Permission, _skipPreviewAs = false) => { + const isUIAllowed = (permission: Permission, skipPreviewAs = false) => { const user = $state.user let userRoles = user?.value?.roles || {} // if string populate key-value paired object @@ -19,17 +19,16 @@ export function useUIPermission() { } // merge user role and project specific user roles - const roles = { + let roles = { ...userRoles, ...(projectRoles?.value || {}), } - // todo: handle preview as - // if (state.previewAs && !skipPreviewAs) { - // roles = { - // [state.previewAs]: true - // }; - // } + if ($state.previewAs.value && !skipPreviewAs) { + roles = { + [$state.previewAs.value]: true, + } + } return Object.entries(roles).some(([role, hasRole]) => { const rolePermission = rolePermissions[role as keyof typeof rolePermissions] as '*' | Record diff --git a/packages/nc-gui-v2/pages/nc/[projectId]/index.vue b/packages/nc-gui-v2/pages/nc/[projectId]/index.vue index aed18c85ed..a7104621fd 100644 --- a/packages/nc-gui-v2/pages/nc/[projectId]/index.vue +++ b/packages/nc-gui-v2/pages/nc/[projectId]/index.vue @@ -177,7 +177,7 @@ await loadTables() - Foo + @@ -212,6 +212,8 @@ await loadTables() + +