From af4c73e941434a4a5d99d302d0d4bc3d283e4bbf Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Wed, 11 Dec 2024 15:13:33 +0100 Subject: [PATCH] Removed non-used pages & queries --- client/src/pages/App.js | 2 - client/src/pages/InvitationOverview.js | 68 ------------------- client/src/tabs/Invitations.js | 3 +- .../java/access/api/InvitationController.java | 8 +-- .../access/api/InvitationControllerTest.java | 9 ++- 5 files changed, 7 insertions(+), 83 deletions(-) delete mode 100644 client/src/pages/InvitationOverview.js diff --git a/client/src/pages/App.js b/client/src/pages/App.js index cadd93b6..99dc0177 100644 --- a/client/src/pages/App.js +++ b/client/src/pages/App.js @@ -23,7 +23,6 @@ import {InvitationForm} from "./InvitationForm"; import {isEmpty} from "../utils/Utils"; import {MissingAttributes} from "./MissingAttributes"; import {Inviter} from "./Inviter"; -import {InvitationOverview} from "./InvitationOverview"; import {Application} from "./Application"; import {System} from "./System"; @@ -100,7 +99,6 @@ export const App = () => { }/> }/> }/> - }/> }/> }/> }/> diff --git a/client/src/pages/InvitationOverview.js b/client/src/pages/InvitationOverview.js deleted file mode 100644 index fe70db50..00000000 --- a/client/src/pages/InvitationOverview.js +++ /dev/null @@ -1,68 +0,0 @@ -import React, {useEffect, useState} from "react"; -import I18n from "../locale/I18n"; -import {Loader} from "@surfnet/sds"; -import {useNavigate, useParams} from "react-router-dom"; -import {allInvitations} from "../api"; -import {useAppStore} from "../stores/AppStore"; -import {INVITATION_STATUS} from "../utils/UserRole"; -import {Page} from "../components/Page"; -import Tabs from "../components/Tabs"; -import {Invitations} from "../tabs/Invitations"; - -export const InvitationOverview = () => { - const navigate = useNavigate(); - const {tab = "pending"} = useParams(); - const {user} = useAppStore(state => state); - const [loading, setLoading] = useState(true); - const [currentTab, setCurrentTab] = useState(tab); - const [tabs, setTabs] = useState([]); - - useEffect(() => { - useAppStore.setState({ - breadcrumbPath: [ - {path: "/inviter", value: I18n.t("tabs.home")}, - {value: I18n.t("tabs.invitations")} - ] - }); - allInvitations().then(res => { - const newTabs = [ - - invitation.status !== INVITATION_STATUS.ACCEPTED)} - standAlone={false} - pending={true} - history={false}/> - , - - invitation.status === INVITATION_STATUS.ACCEPTED)} - standAlone={false} - pending={false} - history={false}/> - , - ]; - setTabs(newTabs.filter(tab => tab !== null)); - setLoading(false); - }) - }, [user]) // eslint-disable-line react-hooks/exhaustive-deps - - const tabChanged = (name) => { - setCurrentTab(name); - navigate(`/invitations/${name}`); - } - - if (loading) { - return - } - return ( - - {tabs} - - ) - -} diff --git a/client/src/tabs/Invitations.js b/client/src/tabs/Invitations.js index e4c66a2d..de0ca407 100644 --- a/client/src/tabs/Invitations.js +++ b/client/src/tabs/Invitations.js @@ -23,7 +23,6 @@ const mineValue = "mine"; export const Invitations = ({ role, - preloadedInvitations, standAlone = false, systemView = false, history = false, @@ -42,7 +41,7 @@ export const Invitations = ({ const [filterValue, setFilterValue] = useState(null); useEffect(() => { - const promise = systemView ? allInvitations() : (isEmpty(role) ? Promise.resolve(preloadedInvitations) : invitationsByRoleId(role.id)); + const promise = systemView ? allInvitations() : invitationsByRoleId(role.id); if (history) { useAppStore.setState({ breadcrumbPath: [ diff --git a/server/src/main/java/access/api/InvitationController.java b/server/src/main/java/access/api/InvitationController.java index 71ae04ee..9ce82a83 100644 --- a/server/src/main/java/access/api/InvitationController.java +++ b/server/src/main/java/access/api/InvitationController.java @@ -135,12 +135,8 @@ public ResponseEntity getInvitation(@RequestParam("hash") String has @GetMapping("all") public ResponseEntity> all(@Parameter(hidden = true) User user) { LOG.debug("/all invitations"); - UserPermissions.assertAuthority(user, Authority.INVITER); - if (user.isSuperUser()) { - return ResponseEntity.ok(invitationRepository.findByStatus(Status.OPEN)); - } - List roles = user.getUserRoles().stream().map(UserRole::getRole).toList(); - return ResponseEntity.ok(invitationRepository.findByRoles_roleIsIn(roles)); + UserPermissions.assertAuthority(user, Authority.SUPER_USER); + return ResponseEntity.ok(invitationRepository.findByStatus(Status.OPEN)); } diff --git a/server/src/test/java/access/api/InvitationControllerTest.java b/server/src/test/java/access/api/InvitationControllerTest.java index e9943deb..027636df 100644 --- a/server/src/test/java/access/api/InvitationControllerTest.java +++ b/server/src/test/java/access/api/InvitationControllerTest.java @@ -566,17 +566,16 @@ void all() throws Exception { } @Test - void allByInviter() throws Exception { + void allByInviterNotAllowed() throws Exception { AccessCookieFilter accessCookieFilter = openIDConnectFlow("/api/v1/users/login", INVITER_SUB); - List invitations = given() + given() .when() .filter(accessCookieFilter.cookieFilter()) .accept(ContentType.JSON) .contentType(ContentType.JSON) .get("/api/v1/invitations/all") - .as(new TypeRef<>() { - }); - assertEquals(2, invitations.size()); + .then() + .statusCode(403); } @Test