Skip to content

Commit 69f8129

Browse files
committed
feat:updates
1 parent 382450e commit 69f8129

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

app/api/views-dataroom/route.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -729,23 +729,23 @@ export async function POST(request: NextRequest) {
729729
: undefined;
730730

731731
// Get team members for CC
732-
const adminUser = link.team.users.find(
732+
const adminUser = link.team?.users.find(
733733
(u) => u.role === "ADMIN",
734734
);
735735
const adminEmail = adminUser?.user.email || null;
736-
const teamMembers = link.team.users
736+
const teamMembers = link.team?.users
737737
.map((u) => u.user.email)
738738
.filter(
739739
(email): email is string =>
740740
!!email && email !== adminEmail,
741-
);
741+
) || [];
742742

743743
// Send NDA completion email
744744
await sendSignedNDAEmail({
745745
ownerEmail: adminEmail,
746746
viewId: newDataroomView.id,
747747
dataroomId: dataroomId,
748-
agreementName: link.agreement.name,
748+
agreementName: link.agreement?.name || "NDA",
749749
linkName: link.name || `Link #${linkId.slice(-5)}`,
750750
viewerEmail: email ?? null,
751751
viewerName: name ?? null,
@@ -917,23 +917,23 @@ export async function POST(request: NextRequest) {
917917
: undefined;
918918

919919
// Get team members for CC
920-
const adminUser = link.team.users.find(
920+
const adminUser = link.team?.users.find(
921921
(u) => u.role === "ADMIN",
922922
);
923923
const adminEmail = adminUser?.user.email || null;
924-
const teamMembers = link.team.users
924+
const teamMembers = link.team?.users
925925
.map((u) => u.user.email)
926926
.filter(
927927
(email): email is string =>
928928
!!email && email !== adminEmail,
929-
);
929+
) || [];
930930

931931
// Send NDA completion email (for document view within dataroom, link to dataroom)
932932
await sendSignedNDAEmail({
933933
ownerEmail: adminEmail,
934934
viewId: newView.id,
935935
dataroomId: dataroomId, // Link to dataroom even for document views
936-
agreementName: link.agreement.name,
936+
agreementName: link.agreement?.name || "NDA",
937937
linkName: link.name || `Link #${linkId.slice(-5)}`,
938938
viewerEmail: email ?? null,
939939
viewerName: name ?? null,

app/api/views/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,24 +700,24 @@ export async function POST(request: NextRequest) {
700700
: undefined;
701701

702702
// Get team members for CC
703-
const adminUser = link.team.users.find(
703+
const adminUser = link.team?.users.find(
704704
(u) => u.role === "ADMIN",
705705
);
706706
const adminEmail = adminUser?.user.email || null;
707-
const teamMembers = link.team.users
707+
const teamMembers = link.team?.users
708708
.map((u) => u.user.email)
709709
.filter(
710710
(email): email is string =>
711711
!!email && email !== adminEmail,
712-
);
712+
) || [];
713713

714714
// Send NDA completion email
715715
await sendSignedNDAEmail({
716716
ownerEmail: adminEmail,
717717
viewId: newView.id,
718718
documentId: documentId,
719719
dataroomId: undefined, // Document view, not dataroom
720-
agreementName: link.agreement.name,
720+
agreementName: link.agreement?.name || "NDA",
721721
linkName: link.name || `Link #${linkId.slice(-5)}`,
722722
viewerEmail: email ?? null,
723723
viewerName: name ?? null,

pages/api/views/[viewId]/nda-certificate.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,21 @@ export default async function handle(
3434

3535
try {
3636
// Fetch the view with agreement response and related data
37+
// IMPORTANT: We use the agreement from agreementResponse to ensure we get
38+
// the agreement that was actually agreed to, not the current link's agreement
39+
// (which may have been changed after the user agreed)
3740
const view = await prisma.view.findUnique({
3841
where: { id: viewId },
3942
include: {
4043
agreementResponse: {
4144
include: {
4245
agreement: {
4346
select: {
47+
id: true,
4448
name: true,
4549
content: true,
4650
contentType: true,
51+
updatedAt: true, // Track when agreement was last updated
4752
},
4853
},
4954
},
@@ -79,6 +84,23 @@ export default async function handle(
7984
return res.status(400).json({ error: "No agreement response found" });
8085
}
8186

87+
// IMPORTANT: Verify that the agreement hasn't been modified after the user agreed to it
88+
// If the agreement was updated after the response was created, we should warn or handle it
89+
// NOTE: This is a known limitation - if an Agreement is updated after users agree to it,
90+
// the certificate will show the current agreement content, not the original.
91+
// A proper fix would require storing a snapshot of agreement data in AgreementResponse.
92+
const agreementUpdatedAfterResponse =
93+
view.agreementResponse.agreement.updatedAt > view.agreementResponse.createdAt;
94+
95+
if (agreementUpdatedAfterResponse) {
96+
// Log that the agreement was modified after the user agreed
97+
// The certificate will use the current agreement content, which may differ from what was agreed to
98+
log({
99+
message: `Agreement ${view.agreementResponse.agreement.id} was updated after user agreed to it (viewId: ${viewId}). Certificate shows current agreement version, not original.`,
100+
type: "error",
101+
});
102+
}
103+
82104
// Fetch user agent data for location, device, browser, OS
83105
// This is optional - if it fails, we'll use defaults
84106
let userAgentData: {

0 commit comments

Comments
 (0)