mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
fix: check for admin in signal endpoints hook (#7642)
This avoids a 403 on `api/admin/signal-endpoints` for non-admins when browsing the integrations page.
This commit is contained in:
parent
47ff73afb2
commit
3acaaf6719
@ -1,10 +1,11 @@
|
|||||||
import { useMemo } from 'react';
|
import { useContext, useMemo } from 'react';
|
||||||
import { formatApiPath } from 'utils/formatPath';
|
import { formatApiPath } from 'utils/formatPath';
|
||||||
import handleErrorResponses from '../httpErrorResponseHandler';
|
import handleErrorResponses from '../httpErrorResponseHandler';
|
||||||
import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR';
|
import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR';
|
||||||
import useUiConfig from '../useUiConfig/useUiConfig';
|
import useUiConfig from '../useUiConfig/useUiConfig';
|
||||||
import type { ISignalEndpoint } from 'interfaces/signal';
|
import type { ISignalEndpoint } from 'interfaces/signal';
|
||||||
import { useUiFlag } from 'hooks/useUiFlag';
|
import { useUiFlag } from 'hooks/useUiFlag';
|
||||||
|
import AccessContext from 'contexts/AccessContext';
|
||||||
|
|
||||||
const ENDPOINT = 'api/admin/signal-endpoints';
|
const ENDPOINT = 'api/admin/signal-endpoints';
|
||||||
|
|
||||||
@ -13,13 +14,14 @@ const DEFAULT_DATA = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useSignalEndpoints = () => {
|
export const useSignalEndpoints = () => {
|
||||||
|
const { isAdmin } = useContext(AccessContext);
|
||||||
const { isEnterprise } = useUiConfig();
|
const { isEnterprise } = useUiConfig();
|
||||||
const signalsEnabled = useUiFlag('signals');
|
const signalsEnabled = useUiFlag('signals');
|
||||||
|
|
||||||
const { data, error, mutate } = useConditionalSWR<{
|
const { data, error, mutate } = useConditionalSWR<{
|
||||||
signalEndpoints: ISignalEndpoint[];
|
signalEndpoints: ISignalEndpoint[];
|
||||||
}>(
|
}>(
|
||||||
isEnterprise() && signalsEnabled,
|
isEnterprise() && isAdmin && signalsEnabled,
|
||||||
DEFAULT_DATA,
|
DEFAULT_DATA,
|
||||||
formatApiPath(ENDPOINT),
|
formatApiPath(ENDPOINT),
|
||||||
fetcher,
|
fetcher,
|
||||||
|
Loading…
Reference in New Issue
Block a user