Skip to content
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

feat(coral): Add route filter and updated navigtion for superadmin behind feature flag #2303

Merged
merged 12 commits into from
Feb 19, 2024
74 changes: 74 additions & 0 deletions coral/src/app/context-provider/AuthProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from "src/app/context-provider/AuthProvider";
import { waitForElementToBeRemoved } from "@testing-library/react/pure";
import { testAuthUser } from "src/domain/auth-user/auth-user-test-helper";
import { setupFeatureFlagMock } from "src/services/feature-flags/test-helper";
import { FeatureFlag } from "src/services/feature-flags/types";

const getAuthMock = jest.fn();
jest.mock("src/domain/auth-user", () => ({
Expand Down Expand Up @@ -81,4 +83,76 @@ describe("AuthProvider.tsx", () => {
expect(authUserFromContext).toBeVisible();
});
});

describe("does not render the auth provider with given children when auth user is SUPERADMIN", () => {
beforeEach(async () => {
getAuthMock.mockReturnValue({ mockAuthUser, userrole: "SUPERADMIN" });
customRender(
<AuthProvider>
<ChildComponent />
</AuthProvider>,
{
queryClient: true,
}
);

await waitForElementToBeRemoved(screen.getByText("Loading Klaw"));
});

afterEach(() => {
jest.resetAllMocks();
cleanup();
});

it("does not returns context provider with given children", () => {
const childElement = screen.queryByTestId("auth-provider-child");
expect(childElement).not.toBeInTheDocument();
});

it("shows a dialog informing superadmin they can not access coral", async () => {
const dialog = await screen.findByRole("dialog", {
name: "You're currently logged in as superadmin.",
});

expect(dialog).toBeVisible();
});
});

describe("render the auth provider with given children when auth user is SUPERADMIN and feature flag is enabled", () => {
beforeEach(async () => {
setupFeatureFlagMock(
FeatureFlag.FEATURE_FLAG_SUPER_ADMIN_ACCESS_CORAL,
true
);
getAuthMock.mockReturnValue({ mockAuthUser, userrole: "SUPERADMIN" });
customRender(
<AuthProvider>
<ChildComponent />
</AuthProvider>,
{
queryClient: true,
}
);

await waitForElementToBeRemoved(screen.getByText("Loading Klaw"));
});

afterEach(() => {
jest.resetAllMocks();
cleanup();
});

it("returns context provider with given children", () => {
const childElement = screen.getByTestId("auth-provider-child");
expect(childElement).toBeVisible();
});

it("does not show dialog informing superadmin they can not access coral", () => {
const dialog = screen.queryByText(
"You're currently logged in as superadmin."
);

expect(dialog).not.toBeInTheDocument();
});
});
});
13 changes: 12 additions & 1 deletion coral/src/app/context-provider/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { BasePage } from "src/app/layout/page/BasePage";
import { Box, Icon } from "@aivenio/aquarium";
import loading from "@aivenio/aquarium/icons/loading";
import { NoCoralAccessSuperadmin } from "src/app/components/NoCoralAccessSuperadmin";
import useFeatureFlag from "src/services/feature-flags/hook/useFeatureFlag";
import { FeatureFlag } from "src/services/feature-flags/types";

/** We don't do Authentication on Corals side
* at the moment, so we only have a AuthUser
Expand Down Expand Up @@ -56,9 +58,18 @@ const AuthProvider = ({ children }: { children: ReactNode }) => {
getAuth
);

const superAdminAccessCoralEnabled = useFeatureFlag(
FeatureFlag.FEATURE_FLAG_SUPER_ADMIN_ACCESS_CORAL
);

// SUPERADMIN does not have access to coral, so we show a reduced page with
// information about that and nothing else.
if (!isLoading && authUser && isSuperAdmin(authUser)) {
if (
!isLoading &&
authUser &&
isSuperAdmin(authUser) &&
!superAdminAccessCoralEnabled
) {
return (
<BasePage headerContent={<></>} content={<NoCoralAccessSuperadmin />} />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { cleanup, screen, waitFor } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { afterEach } from "node:test";
import ApprovalResourceTabs from "src/app/features/approvals/components/ApprovalResourceTabs";
import { ApprovalsTabEnum } from "src/app/router_utils";

import {
RequestsWaitingForApprovalWithTotal,
getRequestsWaitingForApproval,
} from "src/domain/requests";
import { KlawApiError } from "src/services/api";
import { customRender } from "src/services/test-utils/render-with-wrappers";
import { ApprovalsTabEnum } from "src/services/router-utils/types";

const mockedNavigate = jest.fn();
jest.mock("react-router-dom", () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
APPROVALS_TAB_ID_INTO_PATH,
ApprovalsTabEnum,
Routes,
isApprovalsTabEnum,
} from "src/app/router_utils";
} from "src/services/router-utils/types";
import { isApprovalsTabEnum } from "src/services/router-utils/route-utils";

type Props = {
currentTab: ApprovalsTabEnum;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { cleanup, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import EnvironmentsTabs from "src/app/features/configuration/environments/components/EnvironmentsTabs";
import {
ENVIRONMENT_TAB_ID_INTO_PATH,
EnvironmentsTabEnum,
Routes,
} from "src/app/router_utils";

import {
getPaginatedEnvironmentsForConnector,
getPaginatedEnvironmentsForSchema,
Expand All @@ -15,6 +11,11 @@ import { createMockEnvironmentDTO } from "src/domain/environment/environment-tes

import { EnvironmentPaginatedApiResponse } from "src/domain/environment/environment-types";
import { customRender } from "src/services/test-utils/render-with-wrappers";
import {
ENVIRONMENT_TAB_ID_INTO_PATH,
EnvironmentsTabEnum,
Routes,
} from "src/services/router-utils/types";

const mockedNavigate = jest.fn();
jest.mock("react-router-dom", () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
ENVIRONMENT_TAB_ID_INTO_PATH,
EnvironmentsTabEnum,
Routes,
isEnvironmentsTabEnum,
} from "src/app/router_utils";
} from "src/services/router-utils/types";
import { isEnvironmentsTabEnum } from "src/services/router-utils/route-utils";

type Props = {
currentTab: EnvironmentsTabEnum;
Expand Down
10 changes: 5 additions & 5 deletions coral/src/app/features/connectors/details/ConnectorDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { ClaimBanner } from "src/app/features/components/ClaimBanner";
import { ClaimConfirmationModal } from "src/app/features/components/ClaimConfirmationModal";
import { EntityDetailsHeader } from "src/app/features/components/EntityDetailsHeader";
import { ConnectorOverviewResourcesTabs } from "src/app/features/connectors/details/components/ConnectorOverviewResourcesTabs";
import {
CONNECTOR_OVERVIEW_TAB_ID_INTO_PATH,
ConnectorOverviewTabEnum,
isConnectorsOverviewTabEnum,
} from "src/app/router_utils";
import { ConnectorOverview, requestConnectorClaim } from "src/domain/connector";
import { getConnectorOverview } from "src/domain/connector/connector-api";
import { HTTPError } from "src/services/api";
import { parseErrorMsg } from "src/services/mutation-utils";
import {
CONNECTOR_OVERVIEW_TAB_ID_INTO_PATH,
ConnectorOverviewTabEnum,
} from "src/services/router-utils/types";
import { isConnectorsOverviewTabEnum } from "src/services/router-utils/route-utils";

type ConnectorOverviewProps = {
connectorName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { cleanup, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { ConnectorOverviewResourcesTabs } from "src/app/features/connectors/details/components/ConnectorOverviewResourcesTabs";
import { ConnectorOverviewTabEnum } from "src/app/router_utils";
import { ConnectorOverview } from "src/domain/connector";
import { customRender } from "src/services/test-utils/render-with-wrappers";
import { ConnectorOverviewTabEnum } from "src/services/router-utils/types";

const mockedNavigate = jest.fn();
jest.mock("react-router-dom", () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Alert, Box, Icon, Tabs } from "@aivenio/aquarium";
import loading from "@aivenio/aquarium/icons/loading";
import { NavigateFunction, Outlet, useNavigate } from "react-router-dom";
import { ConnectorOverview } from "src/domain/connector";
import { parseErrorMsg } from "src/services/mutation-utils";
import {
CONNECTOR_OVERVIEW_TAB_ID_INTO_PATH,
ConnectorOverviewTabEnum,
isConnectorsOverviewTabEnum,
} from "src/app/router_utils";
import { ConnectorOverview } from "src/domain/connector";
import { parseErrorMsg } from "src/services/mutation-utils";
} from "src/services/router-utils/types";
import { isConnectorsOverviewTabEnum } from "src/services/router-utils/route-utils";

type Props = {
currentTab: ConnectorOverviewTabEnum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
ConnectorRequestFormSchema,
connectorRequestFormSchema,
} from "src/app/features/connectors/request/schemas/connector-request-form";
import { Routes } from "src/app/router_utils";
import { Routes } from "src/services/router-utils/types";
import {
ConnectorDetailsForEnv,
requestConnectorEdit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cleanup, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import RequestsResourceTabs from "src/app/features/requests/RequestsResourceTabs";
import { RequestsTabEnum } from "src/app/router_utils";
import { customRender } from "src/services/test-utils/render-with-wrappers";
import { RequestsTabEnum } from "src/services/router-utils/types";

const mockedNavigate = jest.fn();
jest.mock("react-router-dom", () => ({
Expand Down
6 changes: 3 additions & 3 deletions coral/src/app/features/requests/RequestsResourceTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Tabs } from "@aivenio/aquarium";
import { NavigateFunction, Outlet, useNavigate } from "react-router-dom";
import {
RequestsTabEnum,
isRequestsTabEnum,
REQUESTS_TAB_ID_INTO_PATH,
} from "src/app/router_utils";
RequestsTabEnum,
} from "src/services/router-utils/types";
import { isRequestsTabEnum } from "src/services/router-utils/route-utils";

type Props = {
currentTab: RequestsTabEnum;
Expand Down
11 changes: 6 additions & 5 deletions coral/src/app/features/topics/details/TopicDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import { ClaimBanner } from "src/app/features/components/ClaimBanner";
import { ClaimConfirmationModal } from "src/app/features/components/ClaimConfirmationModal";
import { EntityDetailsHeader } from "src/app/features/components/EntityDetailsHeader";
import { TopicOverviewResourcesTabs } from "src/app/features/topics/details/components/TopicDetailsResourceTabs";
import {
TOPIC_OVERVIEW_TAB_ID_INTO_PATH,
TopicOverviewTabEnum,
isTopicsOverviewTabEnum,
} from "src/app/router_utils";

import { TopicOverview, TopicSchemaOverview } from "src/domain/topic";
import {
getSchemaOfTopic,
Expand All @@ -25,6 +21,11 @@ import {
} from "src/domain/topic/topic-api";
import { HTTPError } from "src/services/api";
import { parseErrorMsg } from "src/services/mutation-utils";
import {
TOPIC_OVERVIEW_TAB_ID_INTO_PATH,
TopicOverviewTabEnum,
} from "src/services/router-utils/types";
import { isTopicsOverviewTabEnum } from "src/services/router-utils/route-utils";

type TopicOverviewProps = {
topicName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { cleanup, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { TopicOverviewTabEnum } from "src/app/router_utils";
import { customRender } from "src/services/test-utils/render-with-wrappers";
import { TopicOverviewResourcesTabs } from "src/app/features/topics/details/components/TopicDetailsResourceTabs";
import { TopicOverview } from "src/domain/topic";
import { TopicOverviewTabEnum } from "src/services/router-utils/types";

const mockedNavigate = jest.fn();
jest.mock("react-router-dom", () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Alert, Box, Icon, Tabs } from "@aivenio/aquarium";
import loading from "@aivenio/aquarium/icons/loading";
import { NavigateFunction, Outlet, useNavigate } from "react-router-dom";
import {
TOPIC_OVERVIEW_TAB_ID_INTO_PATH,
TopicOverviewTabEnum,
isTopicsOverviewTabEnum,
} from "src/app/router_utils";
import { TopicOverview } from "src/domain/topic";
import { TopicSchemaOverview } from "src/domain/topic/topic-types";
import { parseErrorMsg } from "src/services/mutation-utils";
import {
TOPIC_OVERVIEW_TAB_ID_INTO_PATH,
TopicOverviewTabEnum,
} from "src/services/router-utils/types";
import { isTopicsOverviewTabEnum } from "src/services/router-utils/route-utils";

type Props = {
currentTab: TopicOverviewTabEnum;
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/features/topics/request/TopicEditRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
} from "src/app/features/topics/request/form-schemas/topic-request-form";
import formSchema from "src/app/features/topics/request/form-schemas/topic-request-form";
import { generateTopicNameDescription } from "src/app/features/topics/request/utils";
import { Routes } from "src/app/router_utils";
import { Routes } from "src/services/router-utils/types";
import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment/environment-api";
import {
TopicDetailsPerEnv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SelectOrNumberInput from "src/app/features/topics/request/components/Sele
import type { Schema } from "src/app/features/topics/request/form-schemas/topic-request-form";
import formSchema from "src/app/features/topics/request/form-schemas/topic-request-form";
import { generateTopicNameDescription } from "src/app/features/topics/request/utils";
import { Routes } from "src/app/router_utils";
import { Routes } from "src/services/router-utils/types";
import { Environment } from "src/domain/environment";
import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment/environment-api";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@aivenio/aquarium";
import uniqueId from "lodash/uniqueId";
import { Link } from "react-router-dom";
import { Routes } from "src/app/router_utils";
import { Routes } from "src/services/router-utils/types";

type TeamsOverviewProps = {
teams: string[];
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/layout/header/HeaderNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useNavigate } from "react-router-dom";
import HeaderMenuLink from "src/app/layout/header/HeaderMenuLink";
import { RequestsDropdown } from "src/app/layout/header/RequestsDropdown";
import { ProfileDropdown } from "src/app/layout/header/ProfileDropdown";
import { Routes } from "src/app/router_utils";
import { Routes } from "src/services/router-utils/types";

const requestNewEntityPaths: { [key: string]: string } = {
topic: Routes.TOPIC_REQUEST,
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/layout/header/RequestsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
APPROVALS_TAB_ID_INTO_PATH,
ApprovalsTabEnum,
Routes,
} from "src/app/router_utils";
} from "src/services/router-utils/types";

const approveRequestsPaths: { [key: string]: string } = {
topic: `${Routes.APPROVALS}/${
Expand Down
Loading