Skip to content

Commit 9e508c2

Browse files
github-actions[bot]Marfuenclaude
authored
fix(vendors): skip assignee validation when assignee hasn't changed
* fix(vendors): skip assignee validation when assignee hasn't changed The form sends the existing assigneeId on every PATCH even when the user only changed a different field (e.g. website). If the vendor's current assignee is a platform admin, every update fails with "Cannot assign a platform admin as assignee" — even though no one is trying to change the assignee. Only run validateAssigneeNotPlatformAdmin when assigneeId is actually being changed to a different value. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(vendors): don't assign platform admins as vendor assignees during onboarding The vendor mitigation task assigned vendors to whoever triggered onboarding (authorId). When a platform admin onboards a customer, all vendors get assigned to the admin. Since platform admins are filtered from the UI assignee list, vendors appear "Unassigned" but the backend still has the admin's member ID — which then blocks all PATCH updates with "Cannot assign a platform admin". Two fixes: - Service: only validate assignee when it's actually changing - Onboarding: skip assignee if author is a platform admin Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Mariano Fuentes <marfuen98@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c7eb66a commit 9e508c2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

apps/api/src/vendors/vendors.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,13 @@ export class VendorsService {
600600
) {
601601
try {
602602
// First check if the vendor exists in the organization
603-
await this.findById(id, organizationId);
603+
const existing = await this.findById(id, organizationId);
604604

605-
if (updateVendorDto.assigneeId) {
605+
// Only validate assignee when it's actually changing
606+
if (
607+
updateVendorDto.assigneeId &&
608+
updateVendorDto.assigneeId !== existing.assigneeId
609+
) {
606610
await this.validateAssigneeNotPlatformAdmin(updateVendorDto.assigneeId, organizationId);
607611
}
608612

apps/app/src/trigger/tasks/onboarding/generate-vendor-mitigation.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ export const generateVendorMitigation = task({
4444

4545
await createVendorRiskComment(vendor, policies, organizationId, authorId);
4646

47-
// Mark vendor as assessed and assign to owner/admin
47+
// Mark vendor as assessed and assign to author (unless they're a platform admin,
48+
// since platform admins are hidden from the assignee UI and would block future updates)
49+
const author = await db.member.findFirst({
50+
where: { id: authorId, organizationId },
51+
include: { user: { select: { role: true } } },
52+
});
53+
const assigneeId = author?.user.role === 'admin' ? null : authorId;
54+
4855
await db.vendor.update({
4956
where: { id: vendor.id, organizationId },
5057
data: {
5158
status: VendorStatus.assessed,
52-
assigneeId: authorId,
59+
assigneeId,
5360
},
5461
});
5562

0 commit comments

Comments
 (0)