From 5d109a7877e5e121013b62a5b9994e9cda8d95e1 Mon Sep 17 00:00:00 2001
From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com>
Date: Sat, 6 Apr 2024 21:01:54 +0300
Subject: [PATCH] Fix 403 frontend error when viewing retention without
permission
---
.../components/cards/common/JoinAddresses.jsx | 20 +++++++++----------
.../cards/common/PlayerRetention.jsx | 3 ++-
.../context/joinAddressListContextHook.jsx | 5 +++--
.../views/network/NetworkJoinAddresses.jsx | 9 ++++-----
.../src/views/server/ServerJoinAddresses.jsx | 9 ++++-----
5 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/Plan/react/dashboard/src/components/cards/common/JoinAddresses.jsx b/Plan/react/dashboard/src/components/cards/common/JoinAddresses.jsx
index 158310225..0225a0f6d 100644
--- a/Plan/react/dashboard/src/components/cards/common/JoinAddresses.jsx
+++ b/Plan/react/dashboard/src/components/cards/common/JoinAddresses.jsx
@@ -3,22 +3,20 @@ import ExtendableRow from "../../layout/extension/ExtendableRow.jsx";
import JoinAddressGraphCard from "../server/graphs/JoinAddressGraphCard.jsx";
import {Col} from "react-bootstrap";
import React from "react";
-import {useAuth} from "../../../hooks/authenticationHook.jsx";
import AddressGroupSelectorRow from "./AddressGroupSelectorRow.jsx";
-const JoinAddresses = ({id, permission, identifier}) => {
- const {hasPermission} = useAuth();
- const seeTime = hasPermission(permission);
-
+const JoinAddresses = ({id, seeTime, identifier}) => {
return (
{seeTime &&
-
-
-
-
-
-
+
+
+
+
+
+
+
+
}
)
diff --git a/Plan/react/dashboard/src/components/cards/common/PlayerRetention.jsx b/Plan/react/dashboard/src/components/cards/common/PlayerRetention.jsx
index d7ecf8e50..ce4679143 100644
--- a/Plan/react/dashboard/src/components/cards/common/PlayerRetention.jsx
+++ b/Plan/react/dashboard/src/components/cards/common/PlayerRetention.jsx
@@ -11,7 +11,8 @@ const PlayerRetention = ({id, seeRetention, identifier}) => {
return (
{seeRetention &&
-
+
{
+export const JoinAddressListContextProvider = ({identifier, children, loadIndividualAddresses, isAllowed}) => {
const {t} = useTranslation();
const {updateRequested} = useNavigation();
const {preferencesLoaded, getKeyedPreference, setSomePreferences} = usePreferences();
@@ -48,10 +48,11 @@ export const JoinAddressListContextProvider = ({identifier, children, loadIndivi
const [allAddresses, setAllAddresses] = useState([]);
const [playerAddresses, setPlayerAddresses] = useState(undefined);
const loadAddresses = useCallback(async () => {
+ if (!isAllowed) return;
const {data, error} = await fetchPlayerJoinAddresses(updateRequested, identifier, !loadIndividualAddresses);
setAllAddresses(data?.joinAddresses || [error]);
setPlayerAddresses(data?.joinAddressByPlayer);
- }, [setAllAddresses, identifier, updateRequested]);
+ }, [setAllAddresses, identifier, updateRequested, isAllowed]);
useEffect(() => {
loadAddresses();
}, [loadAddresses]);
diff --git a/Plan/react/dashboard/src/views/network/NetworkJoinAddresses.jsx b/Plan/react/dashboard/src/views/network/NetworkJoinAddresses.jsx
index 586ede325..263c78bdc 100644
--- a/Plan/react/dashboard/src/views/network/NetworkJoinAddresses.jsx
+++ b/Plan/react/dashboard/src/views/network/NetworkJoinAddresses.jsx
@@ -1,13 +1,12 @@
import React from 'react';
import JoinAddresses from "../../components/cards/common/JoinAddresses.jsx";
-import {JoinAddressListContextProvider} from "../../hooks/context/joinAddressListContextHook.jsx";
+import {useAuth} from "../../hooks/authenticationHook.jsx";
const NetworkJoinAddresses = () => {
+ const {hasPermission} = useAuth();
+ const seeTime = hasPermission('page.network.join.addresses.graphs.time');
return (
-
-
-
+
)
};
diff --git a/Plan/react/dashboard/src/views/server/ServerJoinAddresses.jsx b/Plan/react/dashboard/src/views/server/ServerJoinAddresses.jsx
index 316eb30f1..ad29d3cdd 100644
--- a/Plan/react/dashboard/src/views/server/ServerJoinAddresses.jsx
+++ b/Plan/react/dashboard/src/views/server/ServerJoinAddresses.jsx
@@ -1,15 +1,14 @@
import React from 'react';
import {useParams} from "react-router-dom";
-import {JoinAddressListContextProvider} from "../../hooks/context/joinAddressListContextHook.jsx";
import JoinAddresses from "../../components/cards/common/JoinAddresses.jsx";
+import {useAuth} from "../../hooks/authenticationHook.jsx";
const ServerJoinAddresses = () => {
const {identifier} = useParams();
+ const {hasPermission} = useAuth();
+ const seeTime = hasPermission('page.server.join.addresses.graphs.time');
return (
-
-
-
+
)
};