Skip to content

Commit

Permalink
Merge pull request #1414 from argos-ci/fix-github-light-sso
Browse files Browse the repository at this point in the history
fix(sso): allow to enable GitHub SSO on GitHub light installation
  • Loading branch information
gregberge authored Nov 6, 2024
2 parents 56d7985 + 898e285 commit 81f9da4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
41 changes: 34 additions & 7 deletions apps/frontend/src/containers/Team/GitHubSSO/Configure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ import { Modal } from "@/ui/Modal";
import { Tooltip } from "@/ui/Tooltip";

const query = graphql(`
query ConfigureGitHubSSO_installations {
query ConfigureGitHubSSO_installations($teamAccountId: ID!) {
teamAccount: accountById(id: $teamAccountId) {
id
... on Team {
githubLightInstallation {
id
ghInstallation {
id
...GithubInstallationsSelect_GhApiInstallation
}
}
}
}
me {
id
ghInstallations {
Expand All @@ -51,15 +63,29 @@ const query = graphql(`
}
`);

function GitHubInstallationsSelectControl() {
const { data } = useQuery(query);
function GitHubInstallationsSelectControl(props: { teamAccountId: string }) {
const { data, error } = useQuery(query, {
variables: { teamAccountId: props.teamAccountId },
});
if (error) {
throw error;
}
const installations = (() => {
if (!data) {
return [];
}
invariant(data.me, "Expected me");
return data.me.ghInstallations.edges;
})();

const installationType = (() => {
if (!data) {
return null;
}
invariant(installations, "Expected installations");
invariant(data.teamAccount?.__typename === "Team", "Expected teamAccount");
return data.teamAccount.githubLightInstallation ? "light" : "main";
})();
const form = useFormContext();
const controller = useController({
name: "ghInstallationId",
Expand Down Expand Up @@ -90,9 +116,8 @@ function GitHubInstallationsSelectControl() {
invariant(installation, "Expected installation");
controller.field.onChange(installation.id);
}}
// Could be wrong if the user use GitHub light
// @TODO use the correct app here
app="main"
disabled={!data}
app={installationType ?? "main"}
/>
{controller.fieldState.error?.message && (
<FormError className="mt-2">
Expand Down Expand Up @@ -157,7 +182,9 @@ function ActiveConfigureSSOForm(props: {
from your GitHub organization will be automatically added to your
Argos Team. You will be able to configure role for each Team member.
</DialogText>
<GitHubInstallationsSelectControl />
<GitHubInstallationsSelectControl
teamAccountId={props.teamAccountId}
/>
{props.priced ? (
<>
<div className="my-8">
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const documents = {
"\n fragment TeamGitHubLight_Team on Team {\n id\n githubLightInstallation {\n id\n ghAccount {\n id\n login\n name\n url\n }\n }\n }\n": types.TeamGitHubLight_TeamFragmentDoc,
"\n fragment TeamGitHubSSO_Team on Team {\n id\n plan {\n id\n displayName\n usageBased\n githubSsoIncluded\n }\n subscriptionStatus\n ssoGithubAccount {\n id\n ...GithubAccountLink_GithubAccount\n }\n }\n": types.TeamGitHubSso_TeamFragmentDoc,
"\n mutation ConfigureGitHubSSO_disableGitHubSSOOnTeam($teamAccountId: ID!) {\n disableGitHubSSOOnTeam(input: { teamAccountId: $teamAccountId }) {\n ...TeamGitHubSSO_Team\n }\n }\n": types.ConfigureGitHubSso_DisableGitHubSsoOnTeamDocument,
"\n query ConfigureGitHubSSO_installations {\n me {\n id\n ghInstallations {\n edges {\n id\n account {\n id\n login\n }\n ...GithubInstallationsSelect_GhApiInstallation\n }\n pageInfo {\n totalCount\n }\n }\n }\n }\n": types.ConfigureGitHubSso_InstallationsDocument,
"\n query ConfigureGitHubSSO_installations($teamAccountId: ID!) {\n teamAccount: accountById(id: $teamAccountId) {\n id\n ... on Team {\n githubLightInstallation {\n id\n ghInstallation {\n id\n ...GithubInstallationsSelect_GhApiInstallation\n }\n }\n }\n }\n me {\n id\n ghInstallations {\n edges {\n id\n account {\n id\n login\n }\n ...GithubInstallationsSelect_GhApiInstallation\n }\n pageInfo {\n totalCount\n }\n }\n }\n }\n": types.ConfigureGitHubSso_InstallationsDocument,
"\n mutation ConfigureGitHubSSO_enableGitHubSSOOnTeam(\n $teamAccountId: ID!\n $ghInstallationId: Int!\n ) {\n enableGitHubSSOOnTeam(\n input: {\n teamAccountId: $teamAccountId\n ghInstallationId: $ghInstallationId\n }\n ) {\n ...TeamGitHubSSO_Team\n }\n }\n": types.ConfigureGitHubSso_EnableGitHubSsoOnTeamDocument,
"\n query TeamMembers_teamMembers($id: ID!, $first: Int!, $after: Int!) {\n team: teamById(id: $id) {\n id\n members(first: $first, after: $after, sso: false) {\n edges {\n id\n level\n user {\n id\n ...UserListRow_user\n ...RemoveFromTeamDialog_User\n }\n ...LevelSelect_TeamMember\n }\n pageInfo {\n hasNextPage\n totalCount\n }\n }\n }\n }\n": types.TeamMembers_TeamMembersDocument,
"\n query TeamMembers_githubMembers($id: ID!, $first: Int!, $after: Int!) {\n team: teamById(id: $id) {\n id\n githubMembers(first: $first, after: $after) {\n edges {\n id\n githubAccount {\n id\n login\n avatar {\n ...AccountAvatarFragment\n }\n }\n teamMember {\n id\n level\n user {\n id\n name\n slug\n avatar {\n ...AccountAvatarFragment\n }\n ...RemoveFromTeamDialog_User\n }\n ...LevelSelect_TeamMember\n }\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n }\n": types.TeamMembers_GithubMembersDocument,
Expand Down Expand Up @@ -421,7 +421,7 @@ export function graphql(source: "\n mutation ConfigureGitHubSSO_disableGitHubSS
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query ConfigureGitHubSSO_installations {\n me {\n id\n ghInstallations {\n edges {\n id\n account {\n id\n login\n }\n ...GithubInstallationsSelect_GhApiInstallation\n }\n pageInfo {\n totalCount\n }\n }\n }\n }\n"): (typeof documents)["\n query ConfigureGitHubSSO_installations {\n me {\n id\n ghInstallations {\n edges {\n id\n account {\n id\n login\n }\n ...GithubInstallationsSelect_GhApiInstallation\n }\n pageInfo {\n totalCount\n }\n }\n }\n }\n"];
export function graphql(source: "\n query ConfigureGitHubSSO_installations($teamAccountId: ID!) {\n teamAccount: accountById(id: $teamAccountId) {\n id\n ... on Team {\n githubLightInstallation {\n id\n ghInstallation {\n id\n ...GithubInstallationsSelect_GhApiInstallation\n }\n }\n }\n }\n me {\n id\n ghInstallations {\n edges {\n id\n account {\n id\n login\n }\n ...GithubInstallationsSelect_GhApiInstallation\n }\n pageInfo {\n totalCount\n }\n }\n }\n }\n"): (typeof documents)["\n query ConfigureGitHubSSO_installations($teamAccountId: ID!) {\n teamAccount: accountById(id: $teamAccountId) {\n id\n ... on Team {\n githubLightInstallation {\n id\n ghInstallation {\n id\n ...GithubInstallationsSelect_GhApiInstallation\n }\n }\n }\n }\n me {\n id\n ghInstallations {\n edges {\n id\n account {\n id\n login\n }\n ...GithubInstallationsSelect_GhApiInstallation\n }\n pageInfo {\n totalCount\n }\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

0 comments on commit 81f9da4

Please sign in to comment.