Fix 403 frontend error when viewing retention without permission

This commit is contained in:
Aurora Lahtela 2024-04-06 21:01:54 +03:00
parent 6a76f8f149
commit 5d109a7877
5 changed files with 22 additions and 24 deletions

View File

@ -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 (
<LoadIn>
{seeTime && <section id={id} className={id}>
<ExtendableRow id={`row-${id}-0`}>
<Col lg={12}>
<JoinAddressGraphCard identifier={identifier}/>
</Col>
</ExtendableRow>
<AddressGroupSelectorRow/>
<JoinAddressListContextProvider identifier={null} isAllowed={seeTime}>
<ExtendableRow id={`row-${id}-0`}>
<Col lg={12}>
<JoinAddressGraphCard identifier={identifier}/>
</Col>
</ExtendableRow>
<AddressGroupSelectorRow/>
</JoinAddressListContextProvider>
</section>}
</LoadIn>
)

View File

@ -11,7 +11,8 @@ const PlayerRetention = ({id, seeRetention, identifier}) => {
return (
<LoadIn>
{seeRetention && <section id={id} className={id}>
<JoinAddressListContextProvider identifier={identifier} loadIndividualAddresses>
<JoinAddressListContextProvider identifier={identifier} isAllowed={seeRetention}
loadIndividualAddresses>
<ExtendableRow id={`row-${id}-0`}>
<Col lg={12}>
<PlayerRetentionGraphCard identifier={identifier}

View File

@ -7,7 +7,7 @@ import {useTranslation} from "react-i18next";
const JoinAddressListContext = createContext({});
export const JoinAddressListContextProvider = ({identifier, children, loadIndividualAddresses}) => {
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]);

View File

@ -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 (
<JoinAddressListContextProvider identifier={null}>
<JoinAddresses id={'network-join-addresses'} identifier={null}
permission={'page.network.join.addresses.graphs.time'}/>
</JoinAddressListContextProvider>
<JoinAddresses id={'network-join-addresses'} identifier={null} seeTime={seeTime}/>
)
};

View File

@ -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 (
<JoinAddressListContextProvider identifier={identifier}>
<JoinAddresses id={'server-join-addresses'} identifier={identifier}
permission={'page.server.join.addresses.graphs.time'}/>
</JoinAddressListContextProvider>
<JoinAddresses id={'server-join-addresses'} identifier={identifier} seeTime={seeTime}/>
)
};