Skip to content

Commit da10e5f

Browse files
committed
Use default org ID in old pages
The 0000 syntax does not work, it has to be the actual org ID. Technically this is probably not necessary since it means only admins can create groups which was already the case, but I think being explicit about the org we are checking is a good idea, even if these pages will eventually go away in favor of the multi-org ones.
1 parent 4a7c9d9 commit da10e5f

File tree

6 files changed

+27
-18
lines changed

6 files changed

+27
-18
lines changed

site/src/pages/GroupsPage/GroupsPage.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import { groups } from "api/queries/groups";
66
import { organizationPermissions } from "api/queries/organizations";
77
import { displayError } from "components/GlobalSnackbar/utils";
88
import { Loader } from "components/Loader/Loader";
9+
import { useDashboard } from "modules/dashboard/useDashboard";
910
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
1011
import { pageTitle } from "utils/page";
1112
import GroupsPageView from "./GroupsPageView";
1213

1314
export const GroupsPage: FC = () => {
15+
const { organizations } = useDashboard();
1416
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility();
15-
const groupsQuery = useQuery(groups("default"));
16-
const permissionsQuery = useQuery(
17-
organizationPermissions("00000000-0000-0000-0000-00000000000"),
18-
);
17+
const organization = organizations.find((o) => o.is_default)
18+
const groupsQuery = useQuery(organization ? groups(organization.id) : { enabled: false });
19+
const permissionsQuery = useQuery(organizationPermissions(organization?.id));
1920

2021
useEffect(() => {
2122
if (groupsQuery.error) {
@@ -33,6 +34,10 @@ export const GroupsPage: FC = () => {
3334
}
3435
}, [permissionsQuery.error]);
3536

37+
if (!organization) {
38+
throw new Error("No default organization")
39+
}
40+
3641
const permissions = permissionsQuery.data;
3742
if (!permissions) {
3843
return <Loader />;

site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getErrorMessage } from "api/errors";
88
import { groups } from "api/queries/groups";
99
import { organizationPermissions } from "api/queries/organizations";
1010
import type { Organization } from "api/typesGenerated";
11+
import { EmptyState } from "components/EmptyState/EmptyState";
1112
import { displayError } from "components/GlobalSnackbar/utils";
1213
import { Loader } from "components/Loader/Loader";
1314
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader";
@@ -25,8 +26,6 @@ export const GroupsPage: FC = () => {
2526
organizationName ? groups(organizationName) : { enabled: false },
2627
);
2728
const { organizations } = useOrganizationSettings();
28-
// TODO: If we could query permissions based on the name then we would not
29-
// have to cascade off the organizations query.
3029
const organization = organizations?.find((o) => o.name === organizationName);
3130
const permissionsQuery = useQuery(organizationPermissions(organization?.id));
3231

@@ -56,7 +55,11 @@ export const GroupsPage: FC = () => {
5655
return <Navigate to={`/organizations/${defaultName}/groups`} replace />;
5756
}
5857
// We expect there to always be a default organization.
59-
throw new Error("No default organization found")
58+
throw new Error("No default organization found");
59+
}
60+
61+
if (!organization) {
62+
return <EmptyState message="Organization not found" />;
6063
}
6164

6265
const permissions = permissionsQuery.data;

site/src/pages/ManagementSettingsPage/ManagementSettingsLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Margins } from "components/Margins/Margins";
88
import { Stack } from "components/Stack/Stack";
99
import { useAuthenticated } from "contexts/auth/RequireAuth";
1010
import { RequirePermission } from "contexts/auth/RequirePermission";
11+
import { useDashboard } from "modules/dashboard/useDashboard";
1112
import { DeploySettingsContext } from "../DeploySettingsPage/DeploySettingsLayout";
1213
import { Sidebar } from "./Sidebar";
1314

site/src/pages/ManagementSettingsPage/OrganizationMembersPage.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ const OrganizationMembersPage: FC = () => {
3535
updateOrganizationMemberRoles(queryClient, organizationName),
3636
);
3737

38-
// TODO: If we could query permissions based on the name then we would not
39-
// have to cascade off the organizations query.
4038
const { organizations } = useOrganizationSettings();
4139
const organization = organizations?.find((o) => o.name === organizationName);
4240
const permissionsQuery = useQuery(organizationPermissions(organization?.id));

site/src/pages/ManagementSettingsPage/OrganizationSettingsPage.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { Organization } from "api/typesGenerated";
1010
import { EmptyState } from "components/EmptyState/EmptyState";
1111
import { displaySuccess } from "components/GlobalSnackbar/utils";
1212
import { Loader } from "components/Loader/Loader";
13-
import { AUDIT_LINK, withFilter } from "modules/navigation";
13+
import { linkToAuditing, withFilter } from "modules/navigation";
1414
import { useOrganizationSettings } from "./ManagementSettingsLayout";
1515
import { OrganizationSettingsPageView } from "./OrganizationSettingsPageView";
1616

@@ -29,8 +29,6 @@ const OrganizationSettingsPage: FC = () => {
2929
deleteOrganization(queryClient),
3030
);
3131

32-
// TODO: If we could query permissions based on the name then we would not
33-
// have to cascade off the organizations query.
3432
const organization =
3533
organizations && organizationName
3634
? getOrganizationByName(organizations, organizationName)
@@ -47,7 +45,8 @@ const OrganizationSettingsPage: FC = () => {
4745
if (defaultOrg) {
4846
return <Navigate to={`/organizations/${defaultOrg.name}`} replace />;
4947
}
50-
return <EmptyState message="No default organization found" />;
48+
// We expect there to always be a default organization.
49+
throw new Error("No default organization found");
5150
}
5251

5352
if (!organization) {
@@ -75,7 +74,7 @@ const OrganizationSettingsPage: FC = () => {
7574
return (
7675
<Navigate
7776
to={`/deployment${withFilter(
78-
AUDIT_LINK,
77+
linkToAuditing,
7978
`organization:${organization.name}`,
8079
)}`}
8180
replace

site/src/pages/UsersPage/UsersLayout.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ import { linkToUsers } from "modules/navigation";
2121

2222
export const UsersLayout: FC = () => {
2323
const { permissions } = useAuthenticated();
24-
const { experiments } = useDashboard();
24+
const { experiments, organizations } = useDashboard();
2525
const navigate = useNavigate();
2626
const feats = useFeatureVisibility();
2727
const location = useLocation();
2828
const activeTab = location.pathname.endsWith("groups") ? "groups" : "users";
29-
const permissionsQuery = useQuery(
30-
organizationPermissions("00000000-0000-0000-0000-00000000000"),
31-
);
29+
const organization = organizations.find((o) => o.is_default)
30+
const permissionsQuery = useQuery(organizationPermissions(organization?.id));
31+
32+
if (!organization) {
33+
throw new Error("No default organization")
34+
}
3235

3336
const canViewOrganizations =
3437
feats.multiple_organizations && experiments.includes("multi-organization");

0 commit comments

Comments
 (0)