fix(fe): wrong permission alerts in the move flow
fix(fe): wrong permission alerts in the move flow
This commit is contained in:
@@ -4,10 +4,7 @@
|
||||
<WorkspaceMoveProjectSelectProject
|
||||
v-if="!selectedProject"
|
||||
:workspace-slug="workspaceSlug"
|
||||
:can-move-to-workspace="canMoveToWorkspace"
|
||||
:is-sso-required="isSsoRequired"
|
||||
:is-limit-reached="isLimitReached"
|
||||
:get-disabled-tooltip="getDisabledTooltip"
|
||||
:project-permissions="projectResult?.project.permissions.canMoveToWorkspace"
|
||||
@project-selected="onProjectSelected"
|
||||
/>
|
||||
|
||||
@@ -15,10 +12,9 @@
|
||||
<WorkspaceMoveProjectSelectWorkspace
|
||||
v-if="selectedProject && activeDialog === 'workspace'"
|
||||
:project="selectedProject"
|
||||
:can-move-to-workspace="canMoveToWorkspace"
|
||||
:is-sso-required="isSsoRequired"
|
||||
:is-limit-reached="isLimitReached"
|
||||
:get-disabled-tooltip="getDisabledTooltip"
|
||||
:workspace-permissions="
|
||||
workspaceResult?.workspaceBySlug.permissions.canMoveProjectToWorkspace
|
||||
"
|
||||
@workspace-selected="onWorkspaceSelected"
|
||||
/>
|
||||
|
||||
@@ -56,7 +52,6 @@
|
||||
import { useQuery } from '@vue/apollo-composable'
|
||||
import { graphql } from '~~/lib/common/generated/gql'
|
||||
import type {
|
||||
FullPermissionCheckResultFragment,
|
||||
WorkspaceMoveProjectManager_ProjectFragment,
|
||||
WorkspaceMoveProjectManager_WorkspaceFragment
|
||||
} from '~/lib/common/generated/gql/graphql'
|
||||
@@ -141,43 +136,6 @@ const selectedWorkspace = ref<WorkspaceMoveProjectManager_WorkspaceFragment | nu
|
||||
null
|
||||
)
|
||||
|
||||
// Permission check computeds
|
||||
const isSsoRequired = computed(
|
||||
() => (permission: FullPermissionCheckResultFragment) => {
|
||||
return permission?.code === 'WorkspaceSsoSessionNoAccess'
|
||||
}
|
||||
)
|
||||
|
||||
const isLimitReached = computed(
|
||||
() => (permission: FullPermissionCheckResultFragment) => {
|
||||
return permission?.code === 'WorkspaceLimitsReached'
|
||||
}
|
||||
)
|
||||
|
||||
const canMoveToWorkspace = computed(
|
||||
() => (permission: FullPermissionCheckResultFragment) => {
|
||||
return permission?.authorized && permission?.code === 'OK'
|
||||
}
|
||||
)
|
||||
|
||||
const getDisabledTooltip = computed(
|
||||
() => (permission: FullPermissionCheckResultFragment) => {
|
||||
if (permission?.code === 'WorkspaceLimitsReached') {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (permission?.code === 'WorkspaceSsoSessionNoAccess') {
|
||||
return 'SSO login required to access this workspace'
|
||||
}
|
||||
|
||||
if (!permission?.authorized) {
|
||||
return permission?.message
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
)
|
||||
|
||||
// Dialog states based on what we have
|
||||
const activeDialog = computed(() => {
|
||||
if (!selectedProject.value) return 'project'
|
||||
|
||||
@@ -65,7 +65,16 @@
|
||||
<WorkspacePlanLimitReachedDialog
|
||||
v-model:open="showLimitDialog"
|
||||
subtitle="Upgrade your plan to move project"
|
||||
></WorkspacePlanLimitReachedDialog>
|
||||
>
|
||||
<template v-if="limitReachedWorkspace">
|
||||
<p class="text-body-xs text-foreground-2">
|
||||
The workspace
|
||||
<span class="font-bold">{{ limitReachedWorkspace.name }}</span>
|
||||
is on a {{ formatName(limitReachedWorkspace.plan?.name) }} plan with a limit
|
||||
of 1 project and 5 models. Upgrade the workspace to add more projects.
|
||||
</p>
|
||||
</template>
|
||||
</WorkspacePlanLimitReachedDialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -76,11 +85,13 @@ import {
|
||||
useDebouncedTextInput
|
||||
} from '@speckle/ui-components'
|
||||
import type {
|
||||
PermissionCheckResult,
|
||||
WorkspaceMoveProjectManager_ProjectFragment,
|
||||
WorkspacePermissionChecks
|
||||
WorkspaceMoveProjectManager_WorkspaceFragment
|
||||
} from '~~/lib/common/generated/gql/graphql'
|
||||
import { usePaginatedQuery } from '~/lib/common/composables/graphql'
|
||||
import { workspaceMoveProjectManagerUserQuery } from '~/lib/workspaces/graphql/queries'
|
||||
import { formatName } from '~/lib/billing/helpers/plan'
|
||||
|
||||
const search = defineModel<string>('search')
|
||||
const { on, bind } = useDebouncedTextInput({ model: search })
|
||||
@@ -91,7 +102,7 @@ const emit = defineEmits<{
|
||||
|
||||
const props = defineProps<{
|
||||
workspaceSlug?: string
|
||||
workspacePermissions?: WorkspacePermissionChecks
|
||||
projectPermissions?: PermissionCheckResult
|
||||
}>()
|
||||
|
||||
const {
|
||||
@@ -117,6 +128,9 @@ const {
|
||||
})
|
||||
|
||||
const showLimitDialog = ref(false)
|
||||
const limitReachedWorkspace = ref<WorkspaceMoveProjectManager_WorkspaceFragment | null>(
|
||||
null
|
||||
)
|
||||
|
||||
const userProjects = computed(() => result.value?.activeUser?.projects.items || [])
|
||||
const moveableProjects = computed(() => userProjects.value)
|
||||
@@ -124,19 +138,27 @@ const hasMoveableProjects = computed(() => moveableProjects.value.length > 0)
|
||||
|
||||
const isProjectDisabled = computed(
|
||||
() => (project: WorkspaceMoveProjectManager_ProjectFragment) => {
|
||||
if (!props.workspaceSlug) {
|
||||
return false
|
||||
}
|
||||
if (isProjectLimitReached.value(project)) {
|
||||
if (project.permissions.canMoveToWorkspace.authorized) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
)
|
||||
|
||||
return !canMoveProject.value(project)
|
||||
const getProjectTooltip = computed(
|
||||
() => (project: WorkspaceMoveProjectManager_ProjectFragment) => {
|
||||
if (project.permissions.canMoveToWorkspace.authorized) {
|
||||
return undefined
|
||||
}
|
||||
return project.permissions.canMoveToWorkspace.message
|
||||
}
|
||||
)
|
||||
|
||||
const onMoveClick = (project: WorkspaceMoveProjectManager_ProjectFragment) => {
|
||||
if (props.workspaceSlug && isProjectLimitReached.value(project)) {
|
||||
if (props.workspaceSlug) {
|
||||
limitReachedWorkspace.value = {
|
||||
name: props.workspaceSlug
|
||||
} as WorkspaceMoveProjectManager_WorkspaceFragment
|
||||
showLimitDialog.value = true
|
||||
return
|
||||
}
|
||||
@@ -145,41 +167,4 @@ const onMoveClick = (project: WorkspaceMoveProjectManager_ProjectFragment) => {
|
||||
}
|
||||
|
||||
const showLoading = computed(() => loading.value && userProjects.value.length === 0)
|
||||
|
||||
const getProjectPermission = (project: WorkspaceMoveProjectManager_ProjectFragment) => {
|
||||
return (
|
||||
project.permissions?.canMoveToWorkspace || {
|
||||
authorized: false,
|
||||
code: '',
|
||||
message: ''
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const canMoveProject = computed(
|
||||
() => (project: WorkspaceMoveProjectManager_ProjectFragment) => {
|
||||
const permission = getProjectPermission(project)
|
||||
return permission.authorized
|
||||
}
|
||||
)
|
||||
|
||||
const isProjectLimitReached = computed(
|
||||
() => (project: WorkspaceMoveProjectManager_ProjectFragment) => {
|
||||
const permission = getProjectPermission(project)
|
||||
return permission.code === 'WorkspaceLimitsReached'
|
||||
}
|
||||
)
|
||||
|
||||
const getProjectTooltip = computed(
|
||||
() => (project: WorkspaceMoveProjectManager_ProjectFragment) => {
|
||||
const permission = getProjectPermission(project)
|
||||
if (permission.authorized) {
|
||||
return undefined
|
||||
}
|
||||
if (permission.code === 'WorkspaceLimitsReached') {
|
||||
return undefined
|
||||
}
|
||||
return permission.message
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -80,9 +80,9 @@
|
||||
<script setup lang="ts">
|
||||
import { graphql } from '~~/lib/common/generated/gql'
|
||||
import type {
|
||||
PermissionCheckResult,
|
||||
WorkspaceMoveProjectManager_ProjectFragment,
|
||||
WorkspaceMoveProjectManager_WorkspaceFragment,
|
||||
WorkspacePermissionChecks
|
||||
WorkspaceMoveProjectManager_WorkspaceFragment
|
||||
} from '~~/lib/common/generated/gql/graphql'
|
||||
import { useQuery } from '@vue/apollo-composable'
|
||||
import { UserAvatarGroup } from '@speckle/ui-components'
|
||||
@@ -109,7 +109,7 @@ graphql(`
|
||||
|
||||
const props = defineProps<{
|
||||
project: WorkspaceMoveProjectManager_ProjectFragment
|
||||
workspacePermissions?: WorkspacePermissionChecks
|
||||
workspacePermissions?: PermissionCheckResult
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
||||
Reference in New Issue
Block a user