Skip to content

Commit

Permalink
Check for the view checkins permission before calling the server to g…
Browse files Browse the repository at this point in the history
…et checkins.
  • Loading branch information
ocielliottc committed Oct 22, 2024
1 parent b9244bb commit 77040ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions web-ui/src/components/personnel/Personnel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { UPDATE_CHECKINS } from '../../context/actions';
import {
selectCurrentUserId,
selectMostRecentCheckin,
selectCsrfToken
selectCsrfToken,
selectCanViewCheckinsPermission,
} from '../../context/selectors';
import Card from '@mui/material/Card';
import CardHeader from '@mui/material/CardHeader';
Expand Down Expand Up @@ -53,7 +54,7 @@ const Personnel = () => {
// Get checkins per personnel
useEffect(() => {
async function updateCheckins() {
if (personnel) {
if (personnel && selectCanViewCheckinsPermission(state)) {
for (const person of personnel) {
let res = await getCheckinByMemberId(person.id, csrf);
let data =
Expand Down
5 changes: 4 additions & 1 deletion web-ui/src/context/AppContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
getAllMembers,
getAllTerminatedMembers
} from '../api/member';
import {
selectCanViewCheckinsPermission,
} from './selectors';
import { getAllRoles, getAllUserRoles } from '../api/roles';
import { getMemberSkills } from '../api/memberskill';
import { BASE_API_URL } from '../api/api';
Expand Down Expand Up @@ -188,7 +191,7 @@ const AppContextProvider = props => {
csrf
) {
getAllCheckinsForAdmin(dispatch, csrf);
} else if (id && csrf) {
} else if (id && csrf && selectCanViewCheckinsPermission(state)) {
getCheckins(id, pdlId, dispatch, csrf);
}
}
Expand Down
4 changes: 4 additions & 0 deletions web-ui/src/context/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export const selectHasSendEmailPermission = hasPermission(
'CAN_SEND_EMAIL'
);

export const selectCanViewCheckinsPermission = hasPermission(
'CAN_VIEW_CHECKINS'
);

export const selectIsPDL = createSelector(
selectUserProfile,
userProfile =>
Expand Down
5 changes: 3 additions & 2 deletions web-ui/src/pages/CheckinsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
selectCsrfToken,
selectCheckin,
selectProfile,
selectCheckinsForMember
selectCheckinsForMember,
selectCanViewCheckinsPermission,
} from '../context/selectors';
import { getCheckins, createNewCheckin } from '../context/thunks';
import { UPDATE_CHECKIN, UPDATE_TOAST } from '../context/actions';
Expand Down Expand Up @@ -72,7 +73,7 @@ const CheckinsPage = () => {
const [tooltipIsOpen, setTooltipIsOpen] = useState(false);

useEffect(() => {
if (selectedProfile) {
if (selectedProfile && selectCanViewCheckinsPermission(state)) {
getCheckins(memberId, selectedProfile.pdlId, dispatch, csrf);
}
}, [memberId, selectedProfile, csrf, dispatch]);
Expand Down

0 comments on commit 77040ff

Please sign in to comment.