Skip to content

Commit

Permalink
Merge branch 'main' into update-project-short-title
Browse files Browse the repository at this point in the history
  • Loading branch information
johndeange authored Feb 4, 2025
2 parents e13be06 + 1f54a8c commit 19c3d0b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 59 deletions.
66 changes: 33 additions & 33 deletions .github/actions/bump-and-tag/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified frontend/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"vite-plugin-svgr": "4.3.0"
},
"overrides": {
"rollup": "4.32.0"
"rollup": "4.34.0"
},
"devDependencies": {
"@testing-library/jest-dom": "6.6.3",
Expand Down
46 changes: 26 additions & 20 deletions frontend/src/pages/agreements/approve/ApproveAgreement.hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const useApproveAgreement = () => {
secondaryButtonText: "",
handleConfirm: () => {}
});
const [hasPermissionToViewPage, setHasPermissionToViewPage] = React.useState(false);
// @ts-ignore
const agreementId = +urlPathParams.id;
const [searchParams] = useSearchParams();
Expand Down Expand Up @@ -199,28 +200,33 @@ const useApproveAgreement = () => {
const userRoles = useSelector((state) => state.auth?.activeUser?.roles) ?? [];
const userIsDivisionDirector = userRoles.includes("REVIEWER_APPROVER") ?? false;

const managingDivisionIds = agreement?.budget_line_items
? agreement.budget_line_items.flatMap(
/** @param {BudgetLine} bli */
(bli) => bli.change_requests_in_review?.map((cr) => cr.managing_division_id) ?? []
)
: [];
const handlePermisssion = () => {
const managingDivisionIds = agreement?.budget_line_items
? agreement.budget_line_items.flatMap(
/** @param {BudgetLine} bli */
(bli) => bli.change_requests_in_review?.map((cr) => cr.managing_division_id) ?? []
)
: [];

const doesAgreementBelongToDivisionDirector = managingDivisionIds.includes(userDivisionId) ?? false;
const agreementHasBLIsUnderReview =
agreement?.budget_line_items?.some(
/** @param {BudgetLine} bli */
(bli) => bli.in_review
) ?? false;
const hasPermissionToViewPage =
userIsDivisionDirector && agreementHasBLIsUnderReview && doesAgreementBelongToDivisionDirector;
const doesAgreementBelongToDivisionDirector = managingDivisionIds.includes(userDivisionId) ?? false;

console.log({
hasPermissionToViewPage,
userIsDivisionDirector,
agreementHasBLIsUnderReview,
doesAgreementBelongToDivisionDirector
});
const agreementHasBLIsUnderReview =
agreement?.budget_line_items?.some(
/** @param {BudgetLine} bli */
(bli) => bli.in_review
) ?? false;

const newHasPermissionToViewPage =
userIsDivisionDirector && agreementHasBLIsUnderReview && doesAgreementBelongToDivisionDirector;

setHasPermissionToViewPage(newHasPermissionToViewPage);
};

React.useEffect(() => {
if (isSuccessAgreement) {
handlePermisssion();
}
}, [agreement, isSuccessAgreement]);

const relevantMessages = React.useMemo(() => {
if (changeRequestType === CHANGE_REQUEST_SLUG_TYPES.BUDGET) {
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/pages/agreements/approve/ApproveAgreement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { BLI_STATUS } from "../../../helpers/budgetLines.helpers";
import { findDescription, findPeriodEnd, findPeriodStart } from "../../../helpers/servicesComponent.helpers";
import { convertCodeForDisplay } from "../../../helpers/utils";
import { document } from "../../../tests/data";
// import ErrorPage from "../../ErrorPage";
import ErrorPage from "../../ErrorPage";
import useApproveAgreement from "./ApproveAgreement.hooks";

const ApproveAgreement = () => {
Expand All @@ -34,7 +34,7 @@ const ApproveAgreement = () => {
groupedUpdatedBudgetLinesByServicesComponent,
handleApproveChangeRequests,
handleCancel,
// hasPermissionToViewPage,
hasPermissionToViewPage,
isLoadingAgreement,
modalProps,
notes,
Expand All @@ -52,9 +52,9 @@ const ApproveAgreement = () => {
urlChangeToStatus
} = useApproveAgreement();

// if (!hasPermissionToViewPage) {
// return <ErrorPage />;
// }
if (!hasPermissionToViewPage) {
return <ErrorPage />;
}
if (isLoadingAgreement) {
return <div>Loading...</div>;
}
Expand Down

0 comments on commit 19c3d0b

Please sign in to comment.