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

Feat: disable settings access if active SSO session is required #3589

Merged
merged 8 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
23 changes: 18 additions & 5 deletions packages/frontend-2/components/settings/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@
workspaceMenuItem.disabled
)
"
:tooltip-text="workspaceMenuItem.tooltipText"
:disabled="workspaceMenuItem.disabled"
:tooltip-text="
needsSsoSession(workspaceItem, itemKey as string)
? 'Log in with your SSO provider to access this page'
: workspaceMenuItem.tooltipText
"
:disabled="
workspaceMenuItem.disabled || needsSsoSession(workspaceItem, itemKey as string)
"
extra-padding
@click="
() =>
Expand Down Expand Up @@ -107,7 +113,7 @@
:is="selectedMenuItem.component"
v-if="selectedMenuItem"
:class="[
'md:bg-foundation md:px-10 md:py-12 md:bg-foundation-page w-full',
'md:px-10 md:py-12 md:bg-foundation-page w-full',
!isMobile && 'simple-scrollbar overflow-y-auto flex-1'
]"
:user="user"
Expand All @@ -125,7 +131,7 @@

<script setup lang="ts">
import { Roles } from '@speckle/shared'
import type { SettingsMenuItem } from '~/lib/settings/helpers/types'
import { type SettingsMenuItem, SettingMenuKeys } from '~/lib/settings/helpers/types'
import { useIsWorkspacesEnabled } from '~/composables/globals'
import { useQuery } from '@vue/apollo-composable'
import { settingsSidebarQuery } from '~/lib/settings/graphql/queries'
Expand All @@ -143,11 +149,13 @@ import { graphql } from '~~/lib/common/generated/gql'
import type { WorkspaceRoles } from '@speckle/shared'
import { useMixpanel } from '~~/lib/core/composables/mp'
import { workspacesRoute } from '~/lib/common/helpers/route'
import type { SettingsMenu_WorkspaceFragment } from '~/lib/common/generated/gql/graphql'
import { WorkspacePlanStatuses } from '~/lib/common/generated/gql/graphql'

graphql(`
fragment SettingsDialog_Workspace on Workspace {
...WorkspaceAvatar_Workspace
...SettingsMenu_Workspace
id
slug
role
Expand All @@ -174,13 +182,13 @@ const targetMenuItem = defineModel<string | null>('targetMenuItem', { required:
const targetWorkspaceId = defineModel<string | null>('targetWorkspaceId')

const { activeUser: user } = useActiveUser()
const { userMenuItems, serverMenuItems, workspaceMenuItems } = useSettingsMenu()
const breakpoints = useBreakpoints(TailwindBreakpoints)
const mixpanel = useMixpanel()
const isWorkspacesEnabled = useIsWorkspacesEnabled()
const { result: workspaceResult } = useQuery(settingsSidebarQuery, null, {
enabled: isWorkspacesEnabled.value
})
const { userMenuItems, serverMenuItems, workspaceMenuItems } = useSettingsMenu()

const isMobile = breakpoints.smaller('md')
const showWorkspaceCreateDialog = ref(false)
Expand Down Expand Up @@ -228,6 +236,11 @@ const workspaceMenuItemClasses = (
targetWorkspaceId.value === workspaceId &&
!disabled

const needsSsoSession = (workspace: SettingsMenu_WorkspaceFragment, key: string) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not perfect, but this can be improved when moving to pages

return workspace.sso?.provider?.id && key === SettingMenuKeys.Workspace.General
? !workspace.sso?.session?.validUntil
: false
}
// not ideal, but it works temporarily while this is still a modal
useSetupMenuState({
goToWorkspaceMenuItem: onWorkspaceMenuItemClick
Expand Down
53 changes: 42 additions & 11 deletions packages/frontend-2/components/settings/workspaces/General.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@
name="name"
placeholder="Workspace name"
show-label
:disabled="!isAdmin"
:disabled="!isAdmin || needsSsoSession"
label-position="left"
:rules="[isRequired, isStringOfLength({ maxLength: 512 })]"
validate-on-value-update
:tooltip-text="disabledTooltipText"
@change="save()"
/>

<hr class="my-4 border-outline-3" />
<FormTextInput
v-model="slug"
color="foundation"
label="Short ID"
name="shortId"
:help="slugHelp"
:disabled="!isAdmin"
:disabled="!isAdmin || needsSsoSession"
show-label
label-position="left"
read-only
:right-icon="isAdmin ? IconEdit : undefined"
right-icon-title="Edit short ID"
@right-icon-click="openSlugEditDialog"
:tooltip-text="disabledTooltipText"
@right-icon-click="
!isAdmin || needsSsoSession ? openSlugEditDialog : undefined
"
/>
<hr class="my-4 border-outline-3" />
<FormTextInput
Expand All @@ -41,7 +46,8 @@
placeholder="Workspace description"
show-label
label-position="left"
:disabled="!isAdmin"
:disabled="!isAdmin || needsSsoSession"
:tooltip-text="disabledTooltipText"
:rules="[isStringOfLength({ maxLength: 512 })]"
@change="save()"
/>
Expand All @@ -53,12 +59,14 @@
Upload your logo image or use one from our set of workspace icons.
</span>
</div>
<SettingsWorkspacesGeneralEditAvatar
v-if="workspaceResult?.workspace"
:workspace="workspaceResult?.workspace"
:disabled="!isAdmin"
size="xxl"
/>
<div v-tippy="disabledTooltipText">
<SettingsWorkspacesGeneralEditAvatar
v-if="workspaceResult?.workspace"
:workspace="workspaceResult?.workspace"
:disabled="!isAdmin || needsSsoSession"
size="xxl"
/>
</div>
</div>
</div>
<hr class="my-6 border-outline-2" />
Expand All @@ -79,7 +87,8 @@
label="Project role"
size="md"
:disabled-items="[Roles.Stream.Owner]"
:disabled="!isAdmin"
:disabled="!isAdmin || needsSsoSession"
:tooltip-text="disabledTooltipText"
@update:model-value="save()"
/>
</div>
Expand Down Expand Up @@ -178,6 +187,14 @@ graphql(`
status
name
}
sso {
provider {
id
}
session {
validUntil
}
}
}
`)

Expand Down Expand Up @@ -218,6 +235,7 @@ const isAdmin = computed(
const canDeleteWorkspace = computed(
() =>
isAdmin.value &&
!needsSsoSession.value &&
(!isBillingIntegrationEnabled ||
!(
[
Expand All @@ -230,10 +248,23 @@ const canDeleteWorkspace = computed(
))
)
const deleteWorkspaceTooltip = computed(() => {
if (needsSsoSession.value)
return 'You cannot delete a workspace that requires SSO without an active session'
if (!canDeleteWorkspace.value) return 'You cannot delete an active workspace'
if (!isAdmin.value) return 'Only admins can delete workspaces'
return undefined
})
const needsSsoSession = computed(() => {
return workspaceResult?.value && workspaceResult.value.workspace?.sso?.provider?.id
? !workspaceResult.value.workspace?.sso?.session?.validUntil
: false
})
const disabledTooltipText = computed(() => {
if (!isAdmin.value) return 'Only admins can edit this field'
if (!needsSsoSession.value) return 'Log in with your SSO provider to edit this field'
return undefined
})

const save = handleSubmit(async () => {
if (!workspaceResult.value?.workspace) return

Expand Down
13 changes: 9 additions & 4 deletions packages/frontend-2/lib/common/generated/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const documents = {
"\n fragment ProjectsNewWorkspace_Workspace on Workspace {\n id\n name\n defaultLogoIndex\n logo\n description\n }\n": types.ProjectsNewWorkspace_WorkspaceFragmentDoc,
"\n fragment ProjectsWorkspaceSelect_Workspace on Workspace {\n id\n role\n name\n defaultLogoIndex\n logo\n }\n": types.ProjectsWorkspaceSelect_WorkspaceFragmentDoc,
"\n fragment ProjectsInviteBanner on PendingStreamCollaborator {\n id\n invitedBy {\n ...LimitedUserAvatar\n }\n projectId\n projectName\n token\n user {\n id\n }\n }\n": types.ProjectsInviteBannerFragmentDoc,
"\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n id\n slug\n role\n name\n plan {\n status\n }\n }\n": types.SettingsDialog_WorkspaceFragmentDoc,
"\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n ...SettingsMenu_Workspace\n id\n slug\n role\n name\n plan {\n status\n }\n }\n": types.SettingsDialog_WorkspaceFragmentDoc,
"\n fragment SettingsDialog_User on User {\n id\n workspaces {\n items {\n ...SettingsDialog_Workspace\n }\n }\n }\n": types.SettingsDialog_UserFragmentDoc,
"\n fragment SettingsServerProjects_ProjectCollection on ProjectCollection {\n totalCount\n items {\n ...SettingsSharedProjects_Project\n }\n }\n": types.SettingsServerProjects_ProjectCollectionFragmentDoc,
"\n query SettingsServerRegions {\n serverInfo {\n multiRegion {\n regions {\n id\n ...SettingsServerRegionsTable_ServerRegionItem\n }\n availableKeys\n }\n }\n }\n": types.SettingsServerRegionsDocument,
Expand All @@ -117,7 +117,7 @@ const documents = {
"\n fragment SettingsUserProfileDetails_User on User {\n id\n name\n company\n ...UserProfileEditDialogAvatar_User\n }\n": types.SettingsUserProfileDetails_UserFragmentDoc,
"\n fragment UserProfileEditDialogAvatar_User on User {\n id\n avatar\n ...ActiveUserAvatar\n }\n": types.UserProfileEditDialogAvatar_UserFragmentDoc,
"\n fragment SettingsWorkspacesBilling_Workspace on Workspace {\n ...BillingAlert_Workspace\n id\n role\n plan {\n ...SettingsWorkspacesBillingPricingTable_WorkspacePlan\n name\n status\n }\n subscription {\n billingInterval\n currentBillingCycleEnd\n }\n team {\n items {\n id\n role\n }\n }\n }\n": types.SettingsWorkspacesBilling_WorkspaceFragmentDoc,
"\n fragment SettingsWorkspacesGeneral_Workspace on Workspace {\n ...SettingsWorkspacesGeneralEditAvatar_Workspace\n ...SettingsWorkspaceGeneralDeleteDialog_Workspace\n ...SettingsWorkspacesGeneralEditSlugDialog_Workspace\n id\n name\n slug\n description\n logo\n role\n defaultProjectRole\n plan {\n status\n name\n }\n }\n": types.SettingsWorkspacesGeneral_WorkspaceFragmentDoc,
"\n fragment SettingsWorkspacesGeneral_Workspace on Workspace {\n ...SettingsWorkspacesGeneralEditAvatar_Workspace\n ...SettingsWorkspaceGeneralDeleteDialog_Workspace\n ...SettingsWorkspacesGeneralEditSlugDialog_Workspace\n id\n name\n slug\n description\n logo\n role\n defaultProjectRole\n plan {\n status\n name\n }\n sso {\n provider {\n id\n }\n session {\n validUntil\n }\n }\n }\n": types.SettingsWorkspacesGeneral_WorkspaceFragmentDoc,
"\n fragment SettingsWorkspaceGeneralDeleteDialog_Workspace on Workspace {\n id\n name\n }\n": types.SettingsWorkspaceGeneralDeleteDialog_WorkspaceFragmentDoc,
"\n fragment SettingsWorkspacesGeneralEditAvatar_Workspace on Workspace {\n id\n logo\n name\n defaultLogoIndex\n }\n": types.SettingsWorkspacesGeneralEditAvatar_WorkspaceFragmentDoc,
"\n fragment SettingsWorkspacesGeneralEditSlugDialog_Workspace on Workspace {\n id\n name\n slug\n }\n": types.SettingsWorkspacesGeneralEditSlugDialog_WorkspaceFragmentDoc,
Expand Down Expand Up @@ -286,6 +286,7 @@ const documents = {
"\n query InvitesCount {\n admin {\n inviteList {\n totalCount\n }\n }\n }\n": types.InvitesCountDocument,
"\n mutation InviteServerUser($input: [ServerInviteCreateInput!]!) {\n serverInviteBatchCreate(input: $input)\n }\n": types.InviteServerUserDocument,
"\n fragment AddDomainWorkspace on Workspace {\n slug\n }\n ": types.AddDomainWorkspaceFragmentDoc,
"\n fragment SettingsMenu_Workspace on Workspace {\n id\n sso {\n provider {\n id\n }\n session {\n validUntil\n }\n }\n }\n": types.SettingsMenu_WorkspaceFragmentDoc,
"\n mutation SettingsUpdateWorkspace($input: WorkspaceUpdateInput!) {\n workspaceMutations {\n update(input: $input) {\n ...SettingsWorkspacesGeneral_Workspace\n }\n }\n }\n": types.SettingsUpdateWorkspaceDocument,
"\n mutation SettingsCreateUserEmail($input: CreateUserEmailInput!) {\n activeUserMutations {\n emailMutations {\n create(input: $input) {\n ...SettingsUserEmails_User\n }\n }\n }\n }\n": types.SettingsCreateUserEmailDocument,
"\n mutation SettingsDeleteUserEmail($input: DeleteUserEmailInput!) {\n activeUserMutations {\n emailMutations {\n delete(input: $input) {\n ...SettingsUserEmails_User\n }\n }\n }\n }\n": types.SettingsDeleteUserEmailDocument,
Expand Down Expand Up @@ -736,7 +737,7 @@ export function graphql(source: "\n fragment ProjectsInviteBanner on PendingStr
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n id\n slug\n role\n name\n plan {\n status\n }\n }\n"): (typeof documents)["\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n id\n slug\n role\n name\n plan {\n status\n }\n }\n"];
export function graphql(source: "\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n ...SettingsMenu_Workspace\n id\n slug\n role\n name\n plan {\n status\n }\n }\n"): (typeof documents)["\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n ...SettingsMenu_Workspace\n id\n slug\n role\n name\n plan {\n status\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down Expand Up @@ -800,7 +801,7 @@ export function graphql(source: "\n fragment SettingsWorkspacesBilling_Workspac
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment SettingsWorkspacesGeneral_Workspace on Workspace {\n ...SettingsWorkspacesGeneralEditAvatar_Workspace\n ...SettingsWorkspaceGeneralDeleteDialog_Workspace\n ...SettingsWorkspacesGeneralEditSlugDialog_Workspace\n id\n name\n slug\n description\n logo\n role\n defaultProjectRole\n plan {\n status\n name\n }\n }\n"): (typeof documents)["\n fragment SettingsWorkspacesGeneral_Workspace on Workspace {\n ...SettingsWorkspacesGeneralEditAvatar_Workspace\n ...SettingsWorkspaceGeneralDeleteDialog_Workspace\n ...SettingsWorkspacesGeneralEditSlugDialog_Workspace\n id\n name\n slug\n description\n logo\n role\n defaultProjectRole\n plan {\n status\n name\n }\n }\n"];
export function graphql(source: "\n fragment SettingsWorkspacesGeneral_Workspace on Workspace {\n ...SettingsWorkspacesGeneralEditAvatar_Workspace\n ...SettingsWorkspaceGeneralDeleteDialog_Workspace\n ...SettingsWorkspacesGeneralEditSlugDialog_Workspace\n id\n name\n slug\n description\n logo\n role\n defaultProjectRole\n plan {\n status\n name\n }\n sso {\n provider {\n id\n }\n session {\n validUntil\n }\n }\n }\n"): (typeof documents)["\n fragment SettingsWorkspacesGeneral_Workspace on Workspace {\n ...SettingsWorkspacesGeneralEditAvatar_Workspace\n ...SettingsWorkspaceGeneralDeleteDialog_Workspace\n ...SettingsWorkspacesGeneralEditSlugDialog_Workspace\n id\n name\n slug\n description\n logo\n role\n defaultProjectRole\n plan {\n status\n name\n }\n sso {\n provider {\n id\n }\n session {\n validUntil\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down Expand Up @@ -1473,6 +1474,10 @@ export function graphql(source: "\n mutation InviteServerUser($input: [ServerIn
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment AddDomainWorkspace on Workspace {\n slug\n }\n "): (typeof documents)["\n fragment AddDomainWorkspace on Workspace {\n slug\n }\n "];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment SettingsMenu_Workspace on Workspace {\n id\n sso {\n provider {\n id\n }\n session {\n validUntil\n }\n }\n }\n"): (typeof documents)["\n fragment SettingsMenu_Workspace on Workspace {\n id\n sso {\n provider {\n id\n }\n session {\n validUntil\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading