From 02be49f71fab024ae046a2654e46ba589c5af0b2 Mon Sep 17 00:00:00 2001 From: Chuck Driesler Date: Fri, 6 Dec 2024 08:24:23 +0000 Subject: [PATCH] fix(automate): redirect github auth flow to workspace if possible (#3632) * fix(automate): redirect to workspace after auth if possible * fix(automate): include session in github auth flow * chore(automate): update props after merge * fix(automate): pick => fragment * fix(automate): use fragments correctly --- .../automate/function/CreateDialog.vue | 27 ++++++++++++++----- .../automate/function/EditDialog.vue | 12 +++++++-- .../function/create-dialog/DetailsStep.vue | 12 ++------- .../automate/functions/page/Header.vue | 8 +++--- .../project/page/automations/Tab.vue | 13 +++++---- .../lib/common/generated/gql/gql.ts | 17 +++++++----- .../lib/common/generated/gql/graphql.ts | 15 ++++++----- .../frontend-2/lib/common/helpers/route.ts | 6 ++++- .../lib/projects/graphql/queries.ts | 2 +- packages/frontend-2/pages/functions/[fid].vue | 1 + .../modules/automate/rest/authGithubApp.ts | 12 +++++++++ .../automate/services/functionManagement.ts | 5 +++- .../modules/core/helpers/routeHelper.ts | 5 ++-- .../server/modules/workspaces/helpers/sso.ts | 1 + 14 files changed, 90 insertions(+), 46 deletions(-) diff --git a/packages/frontend-2/components/automate/function/CreateDialog.vue b/packages/frontend-2/components/automate/function/CreateDialog.vue index ce1d2fba25..8837e11125 100644 --- a/packages/frontend-2/components/automate/function/CreateDialog.vue +++ b/packages/frontend-2/components/automate/function/CreateDialog.vue @@ -61,8 +61,12 @@ import { useUpdateAutomateFunction } from '~/lib/automate/composables/management' import { useMutationLoading } from '@vue/apollo-composable' -import type { AutomateFunctionCreateDialogDoneStep_AutomateFunctionFragment } from '~~/lib/common/generated/gql/graphql' +import type { + AutomateFunctionCreateDialogDoneStep_AutomateFunctionFragment, + AutomateFunctionCreateDialog_WorkspaceFragment +} from '~~/lib/common/generated/gql/graphql' import { useMixpanel } from '~/lib/core/composables/mp' +import { graphql } from '~/lib/common/generated/gql' enum FunctionCreateSteps { Authorize, @@ -73,11 +77,19 @@ enum FunctionCreateSteps { type DetailsFormValues = FunctionDetailsFormValues +graphql(` + fragment AutomateFunctionCreateDialog_Workspace on Workspace { + id + name + slug + } +`) + const props = defineProps<{ isAuthorized: boolean templates: CreatableFunctionTemplate[] githubOrgs: string[] - workspaceId?: string + workspace?: AutomateFunctionCreateDialog_WorkspaceFragment }>() const open = defineModel('open', { required: true }) @@ -114,19 +126,19 @@ const onDetailsSubmit = handleDetailsSubmit(async (values) => { templateId: selectedTemplate.value.id, name: values.name, /* eslint-disable-next-line camelcase */ - workspace_id: props.workspaceId + workspace_id: props.workspace?.id }) createdFunction.value = res step.value++ - if (!props.workspaceId) { + if (!props.workspace?.id) { return } await updateFunction({ input: { id: res.id, - workspaceIds: [props.workspaceId] + workspaceIds: [props.workspace.id] } }) }) @@ -184,7 +196,10 @@ const title = computed(() => { }) const authorizeGithubUrl = computed(() => { - const redirectUrl = new URL(automateGithubAppAuthorizationRoute, apiBaseUrl) + const redirectUrl = new URL( + automateGithubAppAuthorizationRoute(props.workspace?.slug), + apiBaseUrl + ) return redirectUrl.toString() }) diff --git a/packages/frontend-2/components/automate/function/EditDialog.vue b/packages/frontend-2/components/automate/function/EditDialog.vue index d4faaf47f1..794b1c2415 100644 --- a/packages/frontend-2/components/automate/function/EditDialog.vue +++ b/packages/frontend-2/components/automate/function/EditDialog.vue @@ -18,12 +18,20 @@ import { difference, differenceBy } from 'lodash-es' import { useForm } from 'vee-validate' import { useUpdateAutomateFunction } from '~/lib/automate/composables/management' import type { FunctionDetailsFormValues } from '~/lib/automate/helpers/functions' -import type { Workspace } from '~/lib/common/generated/gql/graphql' +import { graphql } from '~/lib/common/generated/gql' +import type { AutomateFunctionEditDialog_WorkspaceFragment } from '~/lib/common/generated/gql/graphql' + +graphql(` + fragment AutomateFunctionEditDialog_Workspace on Workspace { + id + name + } +`) const props = defineProps<{ model: FunctionDetailsFormValues fnId: string - workspaces?: Pick[] + workspaces?: AutomateFunctionEditDialog_WorkspaceFragment[] }>() const open = defineModel('open', { required: true }) const { handleSubmit, setValues } = useForm() diff --git a/packages/frontend-2/components/automate/function/create-dialog/DetailsStep.vue b/packages/frontend-2/components/automate/function/create-dialog/DetailsStep.vue index bf0aa467e4..27945da5cb 100644 --- a/packages/frontend-2/components/automate/function/create-dialog/DetailsStep.vue +++ b/packages/frontend-2/components/automate/function/create-dialog/DetailsStep.vue @@ -109,19 +109,11 @@