mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 07:08:18 +00:00
feat(backoffice): guard routes and actions by permission
Mirrors the new keys in lib/permissions.ts, wraps the warehouse, overview, reports, support and booking-request routes in RequirePermission, and gates the dispatch, mark-paid, invoice pay/cancel, export and support-send actions behind their own keys. Removes duplicate route blocks.
This commit is contained in:
@@ -41,6 +41,8 @@ import {
|
||||
fetchViewableFile,
|
||||
} from "@/services/files.service";
|
||||
import { useContractClearanceMutations } from "@/hooks/contracts/useContracts";
|
||||
import { useAuth } from "@/auth/useAuth";
|
||||
import { FREIGHT_PERMS, hasPermission } from "@/lib/permissions";
|
||||
import { useFileViewer } from "@/hooks/useFileViewer";
|
||||
|
||||
export interface ContractClearanceReviewSectionProps {
|
||||
@@ -123,6 +125,21 @@ export function ContractClearanceReviewSection({
|
||||
} | null>(null);
|
||||
const { view, viewer } = useFileViewer();
|
||||
|
||||
// Mirror the API guards: Path A (self-clearance) actions need
|
||||
// ops_clearance_review; Path B (customs) review needs clearance_review or
|
||||
// the ET phased key. Without the matching key every action would 403 — show
|
||||
// the audit view instead of dead buttons.
|
||||
const { user } = useAuth();
|
||||
const canReviewHere = selfClear
|
||||
? hasPermission(user, FREIGHT_PERMS.contracts.opsClearanceReview)
|
||||
: hasPermission(user, FREIGHT_PERMS.contracts.clearanceReview) ||
|
||||
hasPermission(user, FREIGHT_PERMS.contracts.clearanceEtActions);
|
||||
// Finalize has its own API key on the customs path (contracts:finalize_clearance).
|
||||
const canFinalizeHere = selfClear
|
||||
? hasPermission(user, FREIGHT_PERMS.contracts.opsClearanceReview)
|
||||
: hasPermission(user, FREIGHT_PERMS.contracts.finalizeClearance);
|
||||
readOnly = readOnly || !canReviewHere;
|
||||
|
||||
const reviewerTeam = selfClear ? "Operations" : "Global Logistics";
|
||||
|
||||
const { data: clearance, isLoading } = useQuery({
|
||||
@@ -484,7 +501,7 @@ export function ContractClearanceReviewSection({
|
||||
color="edr-green"
|
||||
radius="md"
|
||||
leftSection={<CheckCircle2 size={16} />}
|
||||
disabled={!clearance.allApproved}
|
||||
disabled={!clearance.allApproved || !canFinalizeHere}
|
||||
loading={finalizeClearance.isPending}
|
||||
onClick={() =>
|
||||
finalizeClearance.mutate(undefined, {
|
||||
|
||||
Reference in New Issue
Block a user