Skip to content

feat(site): allow creating a workspace without connecting optional external auth providers #12251

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

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
support optional external auth providers in the frontend
  • Loading branch information
aslilac committed Feb 21, 2024
commit c04cd378cf352aa201f8fe0c94e4fb038db2a4b7
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ describe("CreateWorkspacePage", () => {
renderCreateWorkspacePage();
await waitForLoaderToBeRemoved();

await screen.findByText(
"To create a workspace using the selected template, please ensure you are authenticated with all the external providers listed below.",
);
await screen.findByText(/connect to all required/i);
});

it("auto create a workspace if uses mode=auto", async () => {
Expand Down Expand Up @@ -312,7 +310,7 @@ describe("CreateWorkspacePage", () => {
route: `/templates/${MockWorkspace.name}/workspace?${params.toString()}`,
});

const warningMessage = await screen.findByRole("alert");
const warningMessage = await screen.findByTestId("duplication-warning");
const nameInput = await screen.findByRole("textbox", {
name: "Workspace Name",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,80 @@ export const ExternalAuth: Story = {
authenticate_url: "",
display_icon: "/icon/gitlab.svg",
display_name: "GitLab",
optional: true,
},
],
},
};

export const ExternalAuthError: Story = {
args: {
error: true,
externalAuth: [
{
id: "github",
type: "github",
authenticated: false,
authenticate_url: "",
display_icon: "/icon/github.svg",
display_name: "GitHub",
},
{
id: "gitlab",
type: "gitlab",
authenticated: false,
authenticate_url: "",
display_icon: "/icon/gitlab.svg",
display_name: "GitLab",
optional: true,
},
],
},
};

export const ExternalAuthAllRequiredConnected: Story = {
args: {
externalAuth: [
{
id: "github",
type: "github",
authenticated: true,
authenticate_url: "",
display_icon: "/icon/github.svg",
display_name: "GitHub",
},
{
id: "gitlab",
type: "gitlab",
authenticated: false,
authenticate_url: "",
display_icon: "/icon/gitlab.svg",
display_name: "GitLab",
optional: true,
},
],
},
};

export const ExternalAuthAllConnected: Story = {
args: {
externalAuth: [
{
id: "github",
type: "github",
authenticated: true,
authenticate_url: "",
display_icon: "/icon/github.svg",
display_name: "GitHub",
},
{
id: "gitlab",
type: "gitlab",
authenticated: true,
authenticate_url: "",
display_icon: "/icon/gitlab.svg",
display_name: "GitLab",
optional: true,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
{Boolean(error) && <ErrorAlert error={error} />}

{mode === "duplicate" && (
<Alert severity="info" dismissible>
<Alert severity="info" dismissible data-testid="duplication-warning">
{Language.duplicationWarning}
</Alert>
)}
Expand Down Expand Up @@ -252,7 +252,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
{externalAuth && externalAuth.length > 0 && (
<FormSection
title="External Authentication"
description="This template requires authentication to external services."
description="This template uses external services for authentication."
>
<FormFields>
{hasAllRequiredExternalAuth ? (
Expand All @@ -261,14 +261,15 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
providers listed below.
</Alert>
) : (
<Alert severity="error">
<Alert severity={error ? "error" : "info"}>
To create a workspace using this template, please connect to
all required external authentication providers listed below.
</Alert>
)}
{externalAuth.map((auth) => (
<ExternalAuthButton
key={auth.id}
error={error}
auth={auth}
isLoading={externalAuthPollingState === "polling"}
onStartPolling={startPollingExternalAuth}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const MockExternalAuth: TemplateVersionExternalAuth = {
};

const meta: Meta<typeof ExternalAuthButton> = {
title: "pages/CreateWorkspacePage/ExternalAuth",
title: "pages/CreateWorkspacePage/ExternalAuthButton",
component: ExternalAuthButton,
};

Expand All @@ -25,6 +25,15 @@ export const Github: Story = {
},
};

export const GithubOptional: Story = {
args: {
auth: {
...MockExternalAuth,
optional: true,
},
},
};

export const GithubWithRetry: Story = {
args: {
auth: MockExternalAuth,
Expand All @@ -48,6 +57,7 @@ export const Gitlab: Story = {
display_icon: "/icon/gitlab.svg",
display_name: "GitLab",
authenticated: false,
optional: true,
},
},
};
Expand All @@ -70,6 +80,7 @@ export const AzureDevOps: Story = {
display_icon: "/icon/azure-devops.svg",
display_name: "Azure DevOps",
authenticated: false,
optional: true,
},
},
};
Expand All @@ -92,6 +103,7 @@ export const Bitbucket: Story = {
display_icon: "/icon/bitbucket.svg",
display_name: "Bitbucket",
authenticated: false,
optional: true,
},
},
};
Expand Down
20 changes: 13 additions & 7 deletions site/src/pages/CreateWorkspacePage/ExternalAuthButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export interface ExternalAuthButtonProps {
displayRetry: boolean;
isLoading: boolean;
onStartPolling: () => void;
error?: unknown;
}

export const ExternalAuthButton: FC<ExternalAuthButtonProps> = ({
auth,
displayRetry,
isLoading,
onStartPolling,
error,
}) => {
return (
<>
Expand Down Expand Up @@ -49,13 +51,17 @@ export const ExternalAuthButton: FC<ExternalAuthButtonProps> = ({
onStartPolling();
}}
>
{auth.authenticated
? `Authenticated with ${auth.display_name}`
: `Login with ${auth.display_name}`}
{!auth.optional && !auth.authenticated && (
<Pill type="error" css={{ marginLeft: 8 }}>
Required
</Pill>
{auth.authenticated ? (
`Authenticated with ${auth.display_name}`
) : (
<>
Login with {auth.display_name}
{!auth.optional && (
<Pill type={error ? "error" : "info"} css={{ marginLeft: 8 }}>
Required
</Pill>
)}
</>
)}
</LoadingButton>

Expand Down