GitLab will be shut down on June 25 to move to a new facility. https://www.eclipsestatus.io/incidents/5ffy27gwcbx7

Commit a77632f0 authored by Zhou Fang's avatar Zhou Fang Committed by Martin Lowe
Browse files

#483 Added permission check for committers and contributors API calls

parent fb88dc94
......@@ -144,11 +144,27 @@ export default function DashboardCommittersAndContributors() {
const [isFetchingContributors, setIsFetchingContributors] = useState(true);
const [isFetchingCBI, setIsFetchingCBI] = useState(true);
const [anchorEle, setAnchorEle] = useState<HTMLElement | null>(null);
const { orgId, setContactFilterRole, committers, setCommitters, contributors, setContributors, cbiData, setCBIData, currentUserPortal } =
useContext(PortalContext);
const {
orgId,
setContactFilterRole,
committers,
setCommitters,
contributors,
setContributors,
cbiData,
setCBIData,
currentUserPortal,
} = useContext(PortalContext);
const open = Boolean(anchorEle);
const canViewCommiters = checkPermission(PERMISSIONS_BASED_ON_ROLES.viewCommitters, currentUserPortal?.relation);
const canViewContributors = checkPermission(PERMISSIONS_BASED_ON_ROLES.viewContributors, currentUserPortal?.relation);
useEffect(() => {
if (!canViewCommiters) {
return;
}
if (!orgId || committers !== null) {
committers !== null && setIsFetchingCommitters(false);
return;
......@@ -179,9 +195,13 @@ export default function DashboardCommittersAndContributors() {
};
fetchWrapper(urlForCommitters, FETCH_METHOD.GET, saveCommittersData, '', () => setIsFetchingCommitters(false));
}, [orgId, committers, setCommitters]);
}, [orgId, committers, setCommitters, canViewCommiters]);
useEffect(() => {
if (!canViewContributors) {
return;
}
if (!orgId || contributors !== null) {
contributors !== null && setIsFetchingContributors(false);
return;
......@@ -215,7 +235,7 @@ export default function DashboardCommittersAndContributors() {
fetchWrapper(urlForContributors, FETCH_METHOD.GET, saveContributorsData, '', () =>
setIsFetchingContributors(false)
);
}, [orgId, contributors, setContributors]);
}, [orgId, contributors, setContributors, canViewContributors]);
useEffect(() => {
if (!orgId || cbiData !== null) {
......@@ -243,9 +263,6 @@ export default function DashboardCommittersAndContributors() {
fetchWrapper(urlForCBIData, FETCH_METHOD.GET, saveCBIData, '', () => setIsFetchingCBI(false));
}, [orgId, cbiData, setCBIData]);
const canViewCommiters = checkPermission(PERMISSIONS_BASED_ON_ROLES.viewCommitters, currentUserPortal?.relation);
const canViewContributors = checkPermission(PERMISSIONS_BASED_ON_ROLES.viewContributors, currentUserPortal?.relation);
return (
<SectionCtn title="Committers and Contributors" id="committers-contributors">
<Grid container spacing={4}>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment