Skip to content

Commit 1e4def4

Browse files
committed
feat(api): add validation for deactivated members as approvers
1 parent a5ddcbf commit 1e4def4

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

apps/api/src/policies/policies.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ export class PoliciesService {
793793
throw new NotFoundException('Approver not found');
794794
}
795795

796+
// Cannot assign a deactivated member as approver - they can't log in to approve
797+
if (approver.deactivated) {
798+
throw new BadRequestException('Cannot assign a deactivated member as approver');
799+
}
800+
796801
await db.policy.update({
797802
where: { id: policyId },
798803
data: {

apps/app/src/actions/policies/submit-version-for-approval.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export const submitVersionForApprovalAction = authActionClient
6767
return { success: false, error: 'Approver not found' };
6868
}
6969

70+
// Cannot assign a deactivated member as approver - they can't log in to approve
71+
if (approver.deactivated) {
72+
return { success: false, error: 'Cannot assign a deactivated member as approver' };
73+
}
74+
7075
// Update policy to set pending version and status
7176
await db.policy.update({
7277
where: { id: policyId },

apps/app/src/app/(app)/[orgId]/policies/[policyId]/components/PdfViewer.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,23 @@ interface PdfViewerProps {
4444
isPendingApproval: boolean;
4545
/** Whether the current version is read-only (published or pending) */
4646
isVersionReadOnly?: boolean;
47+
/** Whether viewing the currently active/published version */
48+
isViewingActiveVersion?: boolean;
49+
/** Whether viewing a version pending approval */
50+
isViewingPendingVersion?: boolean;
4751
onMutate?: () => void;
4852
}
4953

50-
export function PdfViewer({ policyId, versionId, pdfUrl, isPendingApproval, isVersionReadOnly = false, onMutate }: PdfViewerProps) {
54+
export function PdfViewer({
55+
policyId,
56+
versionId,
57+
pdfUrl,
58+
isPendingApproval,
59+
isVersionReadOnly = false,
60+
isViewingActiveVersion = false,
61+
isViewingPendingVersion = false,
62+
onMutate
63+
}: PdfViewerProps) {
5164
// Combine both checks - can't modify if pending approval OR version is read-only
5265
const isReadOnly = isPendingApproval || isVersionReadOnly;
5366
const router = useRouter();
@@ -269,7 +282,13 @@ export function PdfViewer({ policyId, versionId, pdfUrl, isPendingApproval, isVe
269282
<div className="space-y-4">
270283
{isVersionReadOnly && pdfUrl && (
271284
<div className="flex items-center gap-4 rounded-lg border border-primary/20 bg-primary/10 px-4 py-3 text-sm text-foreground">
272-
<span>This version is published. Create a new version to make changes.</span>
285+
<span>
286+
{isViewingPendingVersion
287+
? 'This version is pending approval and cannot be edited.'
288+
: isViewingActiveVersion
289+
? 'This version is published. Create a new version to make changes.'
290+
: 'This version cannot be edited.'}
291+
</span>
273292
</div>
274293
)}
275294
{pdfUrl ? (

apps/app/src/app/(app)/[orgId]/policies/[policyId]/editor/components/PolicyDetails.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ export function PolicyContentManager({
681681
pdfUrl={selectedVersion?.pdfUrl}
682682
isPendingApproval={isPendingApproval}
683683
isVersionReadOnly={isVersionReadOnly}
684+
isViewingActiveVersion={isViewingActiveVersion}
685+
isViewingPendingVersion={isViewingPendingVersion}
684686
onMutate={onMutate}
685687
/>
686688
</TabsContent>

0 commit comments

Comments
 (0)