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

Privacy notice initial page and redux #2995

Merged
merged 8 commits into from
Apr 6, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The types of changes are:
* Feature flags can be set such that they cannot be modified by the user [#2966](https://github.com/ethyca/fides/pull/2966)
* Added the datamap UI to make it open source [#2988](https://github.com/ethyca/fides/pull/2988)
* Introduced a `FixedLayout` component (from the datamap UI) for pages that need to be a fixed height and scroll within [#2992](https://github.com/ethyca/fides/pull/2992)
* Added preliminary privacy notice page [#2995](https://github.com/ethyca/fides/pull/2995)

### Changed
* Set `privacyDeclarationDeprecatedFields` flags to false and set `userCannotModify` to true [2987](https://github.com/ethyca/fides/pull/2987)
Expand Down
29 changes: 29 additions & 0 deletions clients/admin-ui/cypress/e2e/privacy-notices.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { PRIVACY_NOTICES_ROUTE } from "~/features/common/nav/v2/routes";
import { RoleRegistryEnum } from "~/types/api";

describe("Privacy notices", () => {
beforeEach(() => {
cy.login();
});

describe("permissions", () => {
it("should not be viewable for approvers", () => {
cy.assumeRole(RoleRegistryEnum.APPROVER);
cy.visit(PRIVACY_NOTICES_ROUTE);
// should be redirected to the home page
cy.getByTestId("home-content");
});

it("should be visible to everyone else", () => {
[
RoleRegistryEnum.CONTRIBUTOR,
RoleRegistryEnum.OWNER,
RoleRegistryEnum.VIEWER,
].forEach((role) => {
cy.assumeRole(role);
cy.visit(PRIVACY_NOTICES_ROUTE);
cy.getByTestId("privacy-notices-page");
});
});
});
});
5 changes: 3 additions & 2 deletions clients/admin-ui/src/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from "user-management/index";

import { STORAGE_ROOT_KEY } from "~/constants";
import { authApi, reducer as authReducer } from "~/features/auth";
import { baseApi } from "~/features/common/api.slice";
import { reducer as featuresReducer } from "~/features/common/features";
import { healthApi } from "~/features/common/health.slice";
Expand All @@ -56,11 +57,10 @@ import {
reducer as organizationReducer,
} from "~/features/organization";
import { plusApi } from "~/features/plus/plus.slice";
import { reducer as privacyNoticesReducer } from "~/features/privacy-notices/privacy-notices.slice";
import { reducer as systemReducer } from "~/features/system";
import { reducer as taxonomyReducer, taxonomyApi } from "~/features/taxonomy";

import { authApi, reducer as authReducer } from "../features/auth";

/**
* To prevent the "redux-perist failed to create sync storage. falling back to noop storage"
* console message within Next.js, the following snippet is required.
Expand Down Expand Up @@ -109,6 +109,7 @@ const reducer = {
datastoreConnections: datastoreConnectionReducer,
features: featuresReducer,
organization: organizationReducer,
privacyNotices: privacyNoticesReducer,
subjectRequests: privacyRequestsReducer,
system: systemReducer,
taxonomy: taxonomyReducer,
Expand Down
1 change: 1 addition & 0 deletions clients/admin-ui/src/features/common/api.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const baseApi = createApi({
"Dataset",
"Datasets",
"System",
"PrivacyNotices",
],
endpoints: () => ({}),
});
10 changes: 9 additions & 1 deletion clients/admin-ui/src/features/common/nav/v2/nav-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FlagNames } from "~/features/common/features";
import { ScopeRegistryEnum } from "~/types/api";

import * as routes from "./routes";
Expand All @@ -7,7 +8,7 @@ export type NavConfigRoute = {
path: string;
exact?: boolean;
requiresPlus?: boolean;
requiresFlag?: string;
requiresFlag?: FlagNames;
/** This route is only available if the user has ANY of these scopes */
scopes: ScopeRegistryEnum[];
};
Expand Down Expand Up @@ -48,6 +49,13 @@ export const NAV_CONFIG: NavConfigGroup[] = [
requiresFlag: "privacyRequestsConfiguration",
scopes: [ScopeRegistryEnum.MESSAGING_CREATE_OR_UPDATE],
},
{
title: "Privacy notices",
path: routes.PRIVACY_NOTICES_ROUTE,
requiresFlag: "privacyNotices",
requiresPlus: true,
scopes: [ScopeRegistryEnum.PRIVACY_NOTICE_READ],
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Box, List, ListItem, Text } from "@fidesui/react";

import { useAppSelector } from "~/app/hooks";

import {
selectAllPrivacyNotices,
selectPage,
selectPageSize,
useGetAllPrivacyNoticesQuery,
} from "./privacy-notices.slice";

const PrivacyNoticesTable = () => {
// Subscribe to get all privacy notices
const page = useAppSelector(selectPage);
const pageSize = useAppSelector(selectPageSize);
useGetAllPrivacyNoticesQuery({ page, size: pageSize });
allisonking marked this conversation as resolved.
Show resolved Hide resolved

const privacyNotices = useAppSelector(selectAllPrivacyNotices);

if (privacyNotices.length === 0) {
return <Text>No privacy notices found.</Text>;
}

return (
<Box>
<List>
{privacyNotices.map((notice) => (
<ListItem key={notice.id}>
{notice.name} - {notice.consent_mechanism}
</ListItem>
))}
</List>
</Box>
);
};

export default PrivacyNoticesTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { createSelector, createSlice, PayloadAction } from "@reduxjs/toolkit";

import type { RootState } from "~/app/store";
import { baseApi } from "~/features/common/api.slice";
import {
Page_PrivacyNoticeResponse_,
PrivacyNoticeRegion,
PrivacyNoticeResponse,
} from "~/types/api";

export interface State {
activePrivacyNoticeId?: string;
page?: number;
pageSize?: number;
}

const initialState: State = {
page: 1,
pageSize: 10,
};

interface PrivacyNoticesParams {
show_disabled?: boolean;
region?: PrivacyNoticeRegion;
systems_applicable?: boolean;
page?: number;
size?: number;
}

const privacyNoticesApi = baseApi.injectEndpoints({
endpoints: (build) => ({
getAllPrivacyNotices: build.query<
Page_PrivacyNoticeResponse_,
PrivacyNoticesParams
>({
query: () => ({ url: `privacy-notice/` }),
providesTags: () => ["PrivacyNotices"],
}),
}),
});

export const { useGetAllPrivacyNoticesQuery } = privacyNoticesApi;

export const privacyNoticesSlice = createSlice({
name: "privacyNotices",
initialState,
reducers: {
setActivePrivacyNoticeId: (
draftState,
action: PayloadAction<string | undefined>
) => {
draftState.activePrivacyNoticeId = action.payload;
},
},
});

export const { setActivePrivacyNoticeId } = privacyNoticesSlice.actions;

export const { reducer } = privacyNoticesSlice;

const selectPrivacyNotices = (state: RootState) => state.privacyNotices;
export const selectPage = createSelector(
selectPrivacyNotices,
(state) => state.page
);

export const selectPageSize = createSelector(
selectPrivacyNotices,
(state) => state.pageSize
);

const emptyPrivacyNotices: PrivacyNoticeResponse[] = [];
export const selectAllPrivacyNotices = createSelector(
[(RootState) => RootState, selectPage, selectPageSize],
(RootState, page, pageSize) => {
const data = privacyNoticesApi.endpoints.getAllPrivacyNotices.select({
page,
size: pageSize,
})(RootState)?.data;
return data ? data.items : emptyPrivacyNotices;
}
);
7 changes: 7 additions & 0 deletions clients/admin-ui/src/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
"development": true,
"test": true,
"production": false
},
"privacyNotices": {
"description": "Page to configure consent privacy notices",
"development": true,
"test": true,
"production": false,
"userCannotModify": true
}
}
14 changes: 14 additions & 0 deletions clients/admin-ui/src/pages/consent/privacy-notices.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Box } from "@fidesui/react";

import Layout from "~/features/common/Layout";
import PrivacyNoticesTable from "~/features/privacy-notices/PrivacyNoticesTable";

const PrivacyNoticesPage = () => (
<Layout title="Privacy notices">
<Box data-testid="privacy-notices-page">
<PrivacyNoticesTable />
</Box>
</Layout>
);

export default PrivacyNoticesPage;