Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-api): revoke the paired desktop invitation with a control admin invitation
Jose Gabriel Ramirez Encinas4bd548b445fa
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex ea36133be..4847ffa76 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.640",+ "version": "0.1.641","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.640",+ "version": "0.1.641","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex f26ce09b6..26cc03598 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.640",+ "version": "0.1.641","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/services/adminAuthService.ts b/control-api/src/services/adminAuthService.tsindex e8e3bc2b3..3339b77a1 100644--- a/control-api/src/services/adminAuthService.ts+++ b/control-api/src/services/adminAuthService.ts@@ -883,14 +883,23 @@ export async function createControlAdminInvitation(}export async function revokeControlAdminInvitation(invitationId: string): Promise<void> {+ // One statement: the admin invitation and the silent desktop invitation the+ // POST route paired with it (same email, purpose admin_desktop_access) are+ // revoked together, so a caller never strands a desktop invitation that would+ // still grant team membership on its own.await pool.query(- `UPDATE control_admin_invitations+ `WITH revoked AS (+ UPDATE control_admin_invitations+ SET status = 'revoked'+ WHERE id = $1+ AND status IN ('pending', 'opened')+ RETURNING email+ )+ UPDATE invitationsSET status = 'revoked'- WHERE id = $1- AND (- status = 'pending'- OR status = 'opened'- )`,+ WHERE purpose = 'admin_desktop_access'+ AND status = 'pending'+ AND lower(email) IN (SELECT lower(email) FROM revoked)`,[invitationId])}diff --git a/control-api/test/services.controlAdminReplaceInviter.realPostgres.integration.test.ts b/control-api/test/services.controlAdminReplaceInviter.realPostgres.integration.test.tsindex cbcc6e3b0..8e0d0f69b 100644--- a/control-api/test/services.controlAdminReplaceInviter.realPostgres.integration.test.ts+++ b/control-api/test/services.controlAdminReplaceInviter.realPostgres.integration.test.ts@@ -184,4 +184,32 @@ describeRealPostgres('control admin replace-inviter invitations on real PostgreSgetPendingControlAdminInvitation(testPool, replacing.id, replacing.email)).resolves.toMatchObject({ replaceInviter: true, invitedByAdminId: inviter.id })})++ it('revokes the same-email desktop invitation with the admin invitation and leaves the inviter untouched', async () => {+ const inviter = await seedAdmin('revoker')+ const inviterDesktopId = await seedDesktopUser(inviter.email)+ const clientEmail = uniqueEmail('revoked-client')+ const invitation = await createControlAdminInvitation(clientEmail, inviter.id, {+ replaceInviter: true,+ })+ if ('error' in invitation) throw new Error(invitation.error)+ const desktopInvitationId = await inviteDesktopAccess(clientEmail)+ const unrelatedDesktopInvitationId = await inviteDesktopAccess(uniqueEmail('unrelated'))++ await revokeControlAdminInvitation(invitation.id)++ expect(await adminInvitationStatus(invitation.id)).toBe('revoked')+ expect(await desktopInvitationStatus(desktopInvitationId)).toBe('revoked')+ expect(await desktopInvitationStatus(unrelatedDesktopInvitationId)).toBe('pending')+ expect(await adminStatus(inviter.id)).toBe('active')+ expect(await desktopLifecycle(inviterDesktopId)).toBe('active')+ await expect(+ completeControlAdminInvitation({+ email: clientEmail,+ invitationId: invitation.id,+ username: `client-${randomUUID().slice(0, 8)}`,+ passwordHash: 'real-pg-replace-client',+ })+ ).resolves.toEqual({ error: 'not_found' })+ })})