Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ea2f6f

Browse files
authored
fix: show paywall and correctly display auto create groups for IDP sync (#14800)
* fix: show paywall and correctly display auto create groups * fix: update stories * fix: format * chore: cleanup * fix: update stories
1 parent 4be5b2f commit 9ea2f6f

File tree

3 files changed

+184
-156
lines changed

3 files changed

+184
-156
lines changed

site/src/pages/ManagementSettingsPage/IdpSyncPage/IdpSyncPage.tsx

+32-36
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import {
55
groupIdpSyncSettings,
66
roleIdpSyncSettings,
77
} from "api/queries/organizations";
8-
import { ErrorAlert } from "components/Alert/ErrorAlert";
8+
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne";
99
import { EmptyState } from "components/EmptyState/EmptyState";
10-
import { Loader } from "components/Loader/Loader";
10+
import { Paywall } from "components/Paywall/Paywall";
1111
import { SettingsHeader } from "components/SettingsHeader/SettingsHeader";
1212
import { Stack } from "components/Stack/Stack";
13+
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
1314
import type { FC } from "react";
1415
import { Helmet } from "react-helmet-async";
1516
import { useQueries } from "react-query";
@@ -24,6 +25,8 @@ export const IdpSyncPage: FC = () => {
2425
const { organization: organizationName } = useParams() as {
2526
organization: string;
2627
};
28+
// IdP sync does not have its own entitlement and is based on templace_rbac
29+
const { template_rbac: isIdpSyncEnabled } = useFeatureVisibility();
2730
const { organizations } = useOrganizationSettings();
2831
const organization = organizations?.find((o) => o.name === organizationName);
2932

@@ -40,26 +43,10 @@ export const IdpSyncPage: FC = () => {
4043
return <EmptyState message="Organization not found" />;
4144
}
4245

43-
if (
44-
groupsQuery.isLoading ||
45-
groupIdpSyncSettingsQuery.isLoading ||
46-
roleIdpSyncSettingsQuery.isLoading
47-
) {
48-
return <Loader />;
49-
}
50-
5146
const error =
5247
groupIdpSyncSettingsQuery.error ||
5348
roleIdpSyncSettingsQuery.error ||
5449
groupsQuery.error;
55-
if (
56-
error ||
57-
!groupIdpSyncSettingsQuery.data ||
58-
!roleIdpSyncSettingsQuery.data ||
59-
!groupsQuery.data
60-
) {
61-
return <ErrorAlert error={error} />;
62-
}
6350

6451
const groupsMap = new Map<string, string>();
6552
if (groupsQuery.data) {
@@ -84,25 +71,34 @@ export const IdpSyncPage: FC = () => {
8471
description="Group and role sync mappings (configured using Coder CLI)."
8572
tooltip={<IdpSyncHelpTooltip />}
8673
/>
87-
<Stack direction="row" spacing={2}>
88-
<Button
89-
startIcon={<LaunchOutlined />}
90-
component="a"
91-
href={docs("/admin/auth#group-sync-enterprise")}
92-
target="_blank"
93-
>
94-
Setup IdP Sync
95-
</Button>
96-
</Stack>
74+
<Button
75+
startIcon={<LaunchOutlined />}
76+
component="a"
77+
href={docs("/admin/auth#group-sync-enterprise")}
78+
target="_blank"
79+
>
80+
Setup IdP Sync
81+
</Button>
9782
</Stack>
98-
99-
<IdpSyncPageView
100-
groupSyncSettings={groupIdpSyncSettingsQuery.data}
101-
roleSyncSettings={roleIdpSyncSettingsQuery.data}
102-
groups={groupsQuery.data}
103-
groupsMap={groupsMap}
104-
organization={organization}
105-
/>
83+
<ChooseOne>
84+
<Cond condition={!isIdpSyncEnabled}>
85+
<Paywall
86+
message="IdP Sync"
87+
description="Configure group and role mappings to manage permissions outside of Coder. You need an Premium license to use this feature."
88+
documentationLink={docs("/admin/groups")}
89+
/>
90+
</Cond>
91+
<Cond>
92+
<IdpSyncPageView
93+
groupSyncSettings={groupIdpSyncSettingsQuery.data}
94+
roleSyncSettings={roleIdpSyncSettingsQuery.data}
95+
groups={groupsQuery.data}
96+
groupsMap={groupsMap}
97+
organization={organization}
98+
error={error}
99+
/>
100+
</Cond>
101+
</ChooseOne>
106102
</>
107103
);
108104
};

site/src/pages/ManagementSettingsPage/IdpSyncPage/IdpSyncPageView.stories.tsx

+31-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
MockGroup2,
55
MockGroupSyncSettings,
66
MockGroupSyncSettings2,
7+
MockOrganization,
78
MockRoleSyncSettings,
89
} from "testHelpers/entities";
910
import { IdpSyncPageView } from "./IdpSyncPageView";
@@ -24,24 +25,52 @@ for (const group of [MockGroup, MockGroup2]) {
2425

2526
export const Empty: Story = {
2627
args: {
27-
groupSyncSettings: undefined,
28-
roleSyncSettings: undefined,
28+
groupSyncSettings: {
29+
field: "",
30+
mapping: {},
31+
regex_filter: "",
32+
auto_create_missing_groups: false,
33+
},
34+
roleSyncSettings: {
35+
field: "",
36+
mapping: {},
37+
},
38+
groups: [],
2939
groupsMap: undefined,
40+
organization: MockOrganization,
41+
error: undefined,
42+
},
43+
};
44+
45+
export const HasError: Story = {
46+
args: {
47+
groupSyncSettings: MockGroupSyncSettings,
48+
roleSyncSettings: MockRoleSyncSettings,
49+
groups: [MockGroup, MockGroup2],
50+
groupsMap,
51+
organization: MockOrganization,
52+
error: "This is a test error",
3053
},
3154
};
3255

3356
export const Default: Story = {
3457
args: {
3558
groupSyncSettings: MockGroupSyncSettings,
3659
roleSyncSettings: MockRoleSyncSettings,
60+
groups: [MockGroup, MockGroup2],
3761
groupsMap,
62+
organization: MockOrganization,
63+
error: undefined,
3864
},
3965
};
4066

4167
export const MissingGroups: Story = {
4268
args: {
4369
groupSyncSettings: MockGroupSyncSettings2,
4470
roleSyncSettings: MockRoleSyncSettings,
71+
groups: [MockGroup, MockGroup2],
4572
groupsMap,
73+
organization: MockOrganization,
74+
error: undefined,
4675
},
4776
};

0 commit comments

Comments
 (0)