Fix 403 frontend error when viewing retention without permission
This commit is contained in:
parent
6a76f8f149
commit
5d109a7877
|
@ -3,22 +3,20 @@ import ExtendableRow from "../../layout/extension/ExtendableRow.jsx";
|
||||||
import JoinAddressGraphCard from "../server/graphs/JoinAddressGraphCard.jsx";
|
import JoinAddressGraphCard from "../server/graphs/JoinAddressGraphCard.jsx";
|
||||||
import {Col} from "react-bootstrap";
|
import {Col} from "react-bootstrap";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import {useAuth} from "../../../hooks/authenticationHook.jsx";
|
|
||||||
import AddressGroupSelectorRow from "./AddressGroupSelectorRow.jsx";
|
import AddressGroupSelectorRow from "./AddressGroupSelectorRow.jsx";
|
||||||
|
|
||||||
const JoinAddresses = ({id, permission, identifier}) => {
|
const JoinAddresses = ({id, seeTime, identifier}) => {
|
||||||
const {hasPermission} = useAuth();
|
|
||||||
const seeTime = hasPermission(permission);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LoadIn>
|
<LoadIn>
|
||||||
{seeTime && <section id={id} className={id}>
|
{seeTime && <section id={id} className={id}>
|
||||||
<ExtendableRow id={`row-${id}-0`}>
|
<JoinAddressListContextProvider identifier={null} isAllowed={seeTime}>
|
||||||
<Col lg={12}>
|
<ExtendableRow id={`row-${id}-0`}>
|
||||||
<JoinAddressGraphCard identifier={identifier}/>
|
<Col lg={12}>
|
||||||
</Col>
|
<JoinAddressGraphCard identifier={identifier}/>
|
||||||
</ExtendableRow>
|
</Col>
|
||||||
<AddressGroupSelectorRow/>
|
</ExtendableRow>
|
||||||
|
<AddressGroupSelectorRow/>
|
||||||
|
</JoinAddressListContextProvider>
|
||||||
</section>}
|
</section>}
|
||||||
</LoadIn>
|
</LoadIn>
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,7 +11,8 @@ const PlayerRetention = ({id, seeRetention, identifier}) => {
|
||||||
return (
|
return (
|
||||||
<LoadIn>
|
<LoadIn>
|
||||||
{seeRetention && <section id={id} className={id}>
|
{seeRetention && <section id={id} className={id}>
|
||||||
<JoinAddressListContextProvider identifier={identifier} loadIndividualAddresses>
|
<JoinAddressListContextProvider identifier={identifier} isAllowed={seeRetention}
|
||||||
|
loadIndividualAddresses>
|
||||||
<ExtendableRow id={`row-${id}-0`}>
|
<ExtendableRow id={`row-${id}-0`}>
|
||||||
<Col lg={12}>
|
<Col lg={12}>
|
||||||
<PlayerRetentionGraphCard identifier={identifier}
|
<PlayerRetentionGraphCard identifier={identifier}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {useTranslation} from "react-i18next";
|
||||||
|
|
||||||
const JoinAddressListContext = createContext({});
|
const JoinAddressListContext = createContext({});
|
||||||
|
|
||||||
export const JoinAddressListContextProvider = ({identifier, children, loadIndividualAddresses}) => {
|
export const JoinAddressListContextProvider = ({identifier, children, loadIndividualAddresses, isAllowed}) => {
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
const {updateRequested} = useNavigation();
|
const {updateRequested} = useNavigation();
|
||||||
const {preferencesLoaded, getKeyedPreference, setSomePreferences} = usePreferences();
|
const {preferencesLoaded, getKeyedPreference, setSomePreferences} = usePreferences();
|
||||||
|
@ -48,10 +48,11 @@ export const JoinAddressListContextProvider = ({identifier, children, loadIndivi
|
||||||
const [allAddresses, setAllAddresses] = useState([]);
|
const [allAddresses, setAllAddresses] = useState([]);
|
||||||
const [playerAddresses, setPlayerAddresses] = useState(undefined);
|
const [playerAddresses, setPlayerAddresses] = useState(undefined);
|
||||||
const loadAddresses = useCallback(async () => {
|
const loadAddresses = useCallback(async () => {
|
||||||
|
if (!isAllowed) return;
|
||||||
const {data, error} = await fetchPlayerJoinAddresses(updateRequested, identifier, !loadIndividualAddresses);
|
const {data, error} = await fetchPlayerJoinAddresses(updateRequested, identifier, !loadIndividualAddresses);
|
||||||
setAllAddresses(data?.joinAddresses || [error]);
|
setAllAddresses(data?.joinAddresses || [error]);
|
||||||
setPlayerAddresses(data?.joinAddressByPlayer);
|
setPlayerAddresses(data?.joinAddressByPlayer);
|
||||||
}, [setAllAddresses, identifier, updateRequested]);
|
}, [setAllAddresses, identifier, updateRequested, isAllowed]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadAddresses();
|
loadAddresses();
|
||||||
}, [loadAddresses]);
|
}, [loadAddresses]);
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import JoinAddresses from "../../components/cards/common/JoinAddresses.jsx";
|
import JoinAddresses from "../../components/cards/common/JoinAddresses.jsx";
|
||||||
import {JoinAddressListContextProvider} from "../../hooks/context/joinAddressListContextHook.jsx";
|
import {useAuth} from "../../hooks/authenticationHook.jsx";
|
||||||
|
|
||||||
const NetworkJoinAddresses = () => {
|
const NetworkJoinAddresses = () => {
|
||||||
|
const {hasPermission} = useAuth();
|
||||||
|
const seeTime = hasPermission('page.network.join.addresses.graphs.time');
|
||||||
return (
|
return (
|
||||||
<JoinAddressListContextProvider identifier={null}>
|
<JoinAddresses id={'network-join-addresses'} identifier={null} seeTime={seeTime}/>
|
||||||
<JoinAddresses id={'network-join-addresses'} identifier={null}
|
|
||||||
permission={'page.network.join.addresses.graphs.time'}/>
|
|
||||||
</JoinAddressListContextProvider>
|
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {useParams} from "react-router-dom";
|
import {useParams} from "react-router-dom";
|
||||||
import {JoinAddressListContextProvider} from "../../hooks/context/joinAddressListContextHook.jsx";
|
|
||||||
import JoinAddresses from "../../components/cards/common/JoinAddresses.jsx";
|
import JoinAddresses from "../../components/cards/common/JoinAddresses.jsx";
|
||||||
|
import {useAuth} from "../../hooks/authenticationHook.jsx";
|
||||||
|
|
||||||
const ServerJoinAddresses = () => {
|
const ServerJoinAddresses = () => {
|
||||||
const {identifier} = useParams();
|
const {identifier} = useParams();
|
||||||
|
const {hasPermission} = useAuth();
|
||||||
|
const seeTime = hasPermission('page.server.join.addresses.graphs.time');
|
||||||
return (
|
return (
|
||||||
<JoinAddressListContextProvider identifier={identifier}>
|
<JoinAddresses id={'server-join-addresses'} identifier={identifier} seeTime={seeTime}/>
|
||||||
<JoinAddresses id={'server-join-addresses'} identifier={identifier}
|
|
||||||
permission={'page.server.join.addresses.graphs.time'}/>
|
|
||||||
</JoinAddressListContextProvider>
|
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue