Skip to content

Commit e777fde

Browse files
authored
Merge pull request #1569 from Northeastern-Electric-Racing/#1568-finance-members-all-permissions
#1568 - all finance members have all perms
2 parents c284b2e + 2c62cf0 commit e777fde

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed

src/backend/src/services/reimbursement-requests.services.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
removeDeletedReceiptPictures,
2525
updateReimbursementProducts,
2626
validateReimbursementProducts,
27-
validateUserIsHeadOfFinanceTeam,
2827
validateUserIsPartOfFinanceTeam
2928
} from '../utils/reimbursement-requests.utils';
3029
import {
@@ -334,7 +333,7 @@ export default class ReimbursementRequestService {
334333
* @returns reimbursement requests with no advisor approved reimbursement status
335334
*/
336335
static async getPendingAdvisorList(requester: User): Promise<ReimbursementRequest[]> {
337-
await validateUserIsHeadOfFinanceTeam(requester);
336+
await validateUserIsPartOfFinanceTeam(requester);
338337

339338
const requestsPendingAdvisors = await prisma.reimbursement_Request.findMany({
340339
where: {
@@ -360,7 +359,7 @@ export default class ReimbursementRequestService {
360359
* @param saboNumbers the sabo numbers of the reimbursement requests to send
361360
*/
362361
static async sendPendingAdvisorList(sender: User, saboNumbers: number[]) {
363-
await validateUserIsHeadOfFinanceTeam(sender);
362+
await validateUserIsPartOfFinanceTeam(sender);
364363

365364
if (saboNumbers.length === 0) throw new HttpException(400, 'Need to send at least one Sabo #!');
366365

src/backend/src/utils/reimbursement-requests.utils.ts

-12
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,3 @@ export const isAuthUserHeadOfFinance = (user: Prisma.UserGetPayload<typeof authU
233233
const isTeamIdInList = (teamId: string, teamsList: Team[]) => {
234234
return teamsList.map((team) => team.teamId).includes(teamId);
235235
};
236-
237-
export const validateUserIsHeadOfFinanceTeam = async (user: User) => {
238-
const financeTeam = await prisma.team.findUnique({
239-
where: { teamId: process.env.FINANCE_TEAM_ID }
240-
});
241-
242-
if (!financeTeam) throw new HttpException(500, 'Finance team does not exist!');
243-
244-
if (!(financeTeam.headId === user.userId)) {
245-
throw new AccessDeniedException('You are not the head of the finance team!');
246-
}
247-
};

src/backend/tests/reimbursement-requests.test.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,21 @@ describe('Reimbursement Requests', () => {
143143
// assert
144144
expect(prismaFindTeamSpy).toBeCalledTimes(1);
145145
expect(prismaFindTeamSpy).toBeCalledWith({
146-
where: { teamId: process.env.FINANCE_TEAM_ID }
146+
where: { teamId: process.env.FINANCE_TEAM_ID },
147+
include: { head: true, leads: true, members: true }
147148
});
148149
});
149150

150-
test('fails if user is not head of finance team', async () => {
151+
test('fails if user is not on finance team', async () => {
151152
// mock prisma calls
152153
const prismaGetManySpy = vi.spyOn(prisma.reimbursement_Request, 'findMany').mockResolvedValue([findManyResult]);
153-
const prismaFindTeamSpy = vi.spyOn(prisma.team, 'findUnique').mockResolvedValue(prismaTeam1);
154+
vi.spyOn(prisma.team, 'findUnique').mockResolvedValue({ ...primsaTeam2, headId: 1 });
154155

155156
// act
156-
const action = async () => await ReimbursementRequestService.getPendingAdvisorList(batman);
157-
await expect(action).rejects.toEqual(new AccessDeniedException('You are not the head of the finance team!'));
157+
const action = async () => await ReimbursementRequestService.getPendingAdvisorList(alfred);
158+
await expect(action).rejects.toEqual(new AccessDeniedException(`You are not a member of the finance team!`));
158159

159160
// assert
160-
expect(prismaFindTeamSpy).toBeCalledTimes(1);
161-
expect(prismaFindTeamSpy).toBeCalledWith({
162-
where: { teamId: process.env.FINANCE_TEAM_ID }
163-
});
164161
expect(prismaGetManySpy).toBeCalledTimes(0);
165162
});
166163
});

src/frontend/src/pages/FinancePage/FinancePage.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const FinancePage = () => {
5151
error: allPendingAdvisorListError
5252
} = useGetPendingAdvisorList();
5353

54-
const { isFinance, isHeadOfFinance } = user;
54+
const { isFinance } = user;
5555

5656
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
5757

@@ -60,16 +60,16 @@ const FinancePage = () => {
6060

6161
if (isFinance && allReimbursementRequestsIsError) return <ErrorPage message={allReimbursementRequestsError?.message} />;
6262
if (userReimbursementRequestIsError) return <ErrorPage message={userReimbursementRequestError?.message} />;
63-
if (isHeadOfFinance && allPendingAdvisorListIsError) return <ErrorPage message={allPendingAdvisorListError?.message} />;
63+
if (isFinance && allPendingAdvisorListIsError) return <ErrorPage message={allPendingAdvisorListError?.message} />;
6464
if (
6565
(isFinance && (allReimbursementRequestsIsLoading || !allReimbursementRequests)) ||
6666
userReimbursementRequestIsLoading ||
6767
!userReimbursementRequests ||
68-
(isHeadOfFinance && !allPendingAdvisorList)
68+
(isFinance && !allPendingAdvisorList)
6969
)
7070
return <LoadingIndicator />;
7171

72-
if (isHeadOfFinance && (!allPendingAdvisorList || allPendingAdvisorListIsLoading)) return <LoadingIndicator />;
72+
if (isFinance && (!allPendingAdvisorList || allPendingAdvisorListIsLoading)) return <LoadingIndicator />;
7373

7474
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
7575
setAnchorEl(event.currentTarget);
@@ -112,7 +112,7 @@ const FinancePage = () => {
112112
handleDropdownClose();
113113
setShowPendingAdvisorListModal(true);
114114
}}
115-
disabled={!isHeadOfFinance}
115+
disabled={!isFinance}
116116
>
117117
<ListItemIcon>
118118
<ListAltIcon fontSize="small" />
@@ -131,7 +131,7 @@ const FinancePage = () => {
131131

132132
return (
133133
<PageLayout title="Finance" headerRight={financeActionsDropdown}>
134-
{isHeadOfFinance && (
134+
{isFinance && (
135135
<PendingAdvisorModal
136136
open={showPendingAdvisorListModal}
137137
saboNumbers={allPendingAdvisorList!.map((reimbursementRequest) => reimbursementRequest.saboId!)}

0 commit comments

Comments
 (0)