Skip to content

Commit 77040ff

Browse files
committed
Check for the view checkins permission before calling the server to get checkins.
1 parent b9244bb commit 77040ff

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

web-ui/src/components/personnel/Personnel.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { UPDATE_CHECKINS } from '../../context/actions';
77
import {
88
selectCurrentUserId,
99
selectMostRecentCheckin,
10-
selectCsrfToken
10+
selectCsrfToken,
11+
selectCanViewCheckinsPermission,
1112
} from '../../context/selectors';
1213
import Card from '@mui/material/Card';
1314
import CardHeader from '@mui/material/CardHeader';
@@ -53,7 +54,7 @@ const Personnel = () => {
5354
// Get checkins per personnel
5455
useEffect(() => {
5556
async function updateCheckins() {
56-
if (personnel) {
57+
if (personnel && selectCanViewCheckinsPermission(state)) {
5758
for (const person of personnel) {
5859
let res = await getCheckinByMemberId(person.id, csrf);
5960
let data =

web-ui/src/context/AppContext.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import {
2121
getAllMembers,
2222
getAllTerminatedMembers
2323
} from '../api/member';
24+
import {
25+
selectCanViewCheckinsPermission,
26+
} from './selectors';
2427
import { getAllRoles, getAllUserRoles } from '../api/roles';
2528
import { getMemberSkills } from '../api/memberskill';
2629
import { BASE_API_URL } from '../api/api';
@@ -188,7 +191,7 @@ const AppContextProvider = props => {
188191
csrf
189192
) {
190193
getAllCheckinsForAdmin(dispatch, csrf);
191-
} else if (id && csrf) {
194+
} else if (id && csrf && selectCanViewCheckinsPermission(state)) {
192195
getCheckins(id, pdlId, dispatch, csrf);
193196
}
194197
}

web-ui/src/context/selectors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ export const selectHasSendEmailPermission = hasPermission(
186186
'CAN_SEND_EMAIL'
187187
);
188188

189+
export const selectCanViewCheckinsPermission = hasPermission(
190+
'CAN_VIEW_CHECKINS'
191+
);
192+
189193
export const selectIsPDL = createSelector(
190194
selectUserProfile,
191195
userProfile =>

web-ui/src/pages/CheckinsPage.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
selectCsrfToken,
1313
selectCheckin,
1414
selectProfile,
15-
selectCheckinsForMember
15+
selectCheckinsForMember,
16+
selectCanViewCheckinsPermission,
1617
} from '../context/selectors';
1718
import { getCheckins, createNewCheckin } from '../context/thunks';
1819
import { UPDATE_CHECKIN, UPDATE_TOAST } from '../context/actions';
@@ -72,7 +73,7 @@ const CheckinsPage = () => {
7273
const [tooltipIsOpen, setTooltipIsOpen] = useState(false);
7374

7475
useEffect(() => {
75-
if (selectedProfile) {
76+
if (selectedProfile && selectCanViewCheckinsPermission(state)) {
7677
getCheckins(memberId, selectedProfile.pdlId, dispatch, csrf);
7778
}
7879
}, [memberId, selectedProfile, csrf, dispatch]);

0 commit comments

Comments
 (0)