Skip to content

fix: show org summary page if not entitled #14336

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 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const meta: Meta<typeof OrganizationSettingsPage> = {
decorators: [withAuthProvider, withDashboardProvider],
parameters: {
user: MockUser,
features: ["multiple_organizations"],
permissions: { viewDeploymentValues: true },
queries: [
{
Expand Down Expand Up @@ -61,3 +62,23 @@ export const CanEditOrganization: Story = {
],
},
};

export const CanEditOrganizationNotEntitled: Story = {
parameters: {
reactRouter: reactRouterParameters({
location: { pathParams: { organization: MockDefaultOrganization.name } },
routing: { path: "/organizations/:organization" },
}),
features: [],
queries: [
{
key: ["organizations", [MockDefaultOrganization.id], "permissions"],
data: {
[MockDefaultOrganization.id]: {
editOrganization: true,
},
},
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { screen, within } from "@testing-library/react";
import { http, HttpResponse } from "msw";
import {
MockDefaultOrganization,
MockEntitlementsWithMultiOrg,
MockOrganization2,
} from "testHelpers/entities";
import {
Expand All @@ -24,6 +25,9 @@ const renderPage = async () => {
describe("OrganizationSettingsPage", () => {
it("has no editable organizations", async () => {
server.use(
http.get("/api/v2/entitlements", () => {
return HttpResponse.json(MockEntitlementsWithMultiOrg);
}),
http.get("/api/v2/organizations", () => {
return HttpResponse.json([MockDefaultOrganization, MockOrganization2]);
}),
Expand All @@ -39,6 +43,9 @@ describe("OrganizationSettingsPage", () => {

it("redirects to default organization", async () => {
server.use(
http.get("/api/v2/entitlements", () => {
return HttpResponse.json(MockEntitlementsWithMultiOrg);
}),
http.get("/api/v2/organizations", () => {
// Default always preferred regardless of order.
return HttpResponse.json([MockOrganization2, MockDefaultOrganization]);
Expand All @@ -60,6 +67,9 @@ describe("OrganizationSettingsPage", () => {

it("redirects to non-default organization", async () => {
server.use(
http.get("/api/v2/entitlements", () => {
return HttpResponse.json(MockEntitlementsWithMultiOrg);
}),
http.get("/api/v2/organizations", () => {
return HttpResponse.json([MockDefaultOrganization, MockOrganization2]);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Organization } from "api/typesGenerated";
import { EmptyState } from "components/EmptyState/EmptyState";
import { displaySuccess } from "components/GlobalSnackbar/utils";
import { Loader } from "components/Loader/Loader";
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
import type { FC } from "react";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { Navigate, useNavigate, useParams } from "react-router-dom";
Expand All @@ -22,6 +23,7 @@ const OrganizationSettingsPage: FC = () => {
organization?: string;
};
const { organizations } = useOrganizationSettings();
const feats = useFeatureVisibility();

const navigate = useNavigate();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -69,7 +71,12 @@ const OrganizationSettingsPage: FC = () => {
// The user may not be able to edit this org but they can still see it because
// they can edit members, etc. In this case they will be shown a read-only
// summary page instead of the settings form.
if (!permissions[organization.id]?.editOrganization) {
// Similarly, if the feature is not entitled then the user will not be able to
// edit the organization.
if (
!permissions[organization.id]?.editOrganization ||
!feats.multiple_organizations
) {
return <OrganizationSummaryPageView organization={organization} />;
}

Expand Down
1 change: 1 addition & 0 deletions site/src/testHelpers/storybook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const withDashboardProvider = (

const entitlements: Entitlements = {
...MockEntitlements,
has_license: features.length > 0,
features: withDefaultFeatures(
Object.fromEntries(
features.map((feature) => [
Expand Down
Loading