Skip to content

Commit 09e630c

Browse files
authored
Merge pull request #2910 from trycompai/main
[comp] Production Deploy
2 parents 61f052a + df225ad commit 09e630c

2 files changed

Lines changed: 40 additions & 20 deletions

File tree

‎apps/api/src/integration-platform/controllers/sync-gws.controller.spec.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { ConnectionRepository } from '../repositories/connection.repository';
66
import { CredentialVaultService } from '../services/credential-vault.service';
77
import { OAuthCredentialsService } from '../services/oauth-credentials.service';
88
import { IntegrationSyncLoggerService } from '../services/integration-sync-logger.service';
9+
import { GenericEmployeeSyncService } from '../services/generic-employee-sync.service';
10+
import { DynamicIntegrationRepository } from '../repositories/dynamic-integration.repository';
11+
import { CheckRunRepository } from '../repositories/check-run.repository';
912
import { db } from '@db';
1013

1114
jest.mock('@db', () => ({
@@ -99,6 +102,9 @@ describe('SyncController - Google Workspace employees', () => {
99102
provide: IntegrationSyncLoggerService,
100103
useValue: { logSync: jest.fn() },
101104
},
105+
{ provide: GenericEmployeeSyncService, useValue: {} },
106+
{ provide: DynamicIntegrationRepository, useValue: {} },
107+
{ provide: CheckRunRepository, useValue: {} },
102108
],
103109
})
104110
.overrideGuard(HybridAuthGuard)
@@ -596,9 +602,12 @@ describe('SyncController - Google Workspace employees', () => {
596602
// ── Exclude filter mode ────────────────────────────────────────
597603

598604
describe('exclude filter mode', () => {
599-
it('should NOT deactivate excluded members in exclude mode', async () => {
605+
it('should deactivate existing non-privileged members excluded from sync', async () => {
600606
setupSync({
601-
gwUsers: [makeGwUser('kept@example.com')],
607+
gwUsers: [
608+
makeGwUser('kept@example.com'),
609+
makeGwUser('excluded@example.com'),
610+
],
602611
variables: {
603612
sync_user_filter_mode: 'exclude',
604613
sync_excluded_emails: 'excluded@example.com',
@@ -613,7 +622,6 @@ describe('SyncController - Google Workspace employees', () => {
613622
makeMember('kept@example.com', { userId: 'user_kept' }),
614623
);
615624

616-
// Excluded member is in the org but not in the GWS active list
617625
(mockedDb.member.findMany as jest.Mock).mockResolvedValue([
618626
makeMember('kept@example.com'),
619627
makeMember('excluded@example.com'),
@@ -629,7 +637,14 @@ describe('SyncController - Google Workspace employees', () => {
629637
const deactivatedEmails = result.details
630638
.filter((d) => d.status === 'deactivated')
631639
.map((d) => d.email);
632-
expect(deactivatedEmails).not.toContain('excluded@example.com');
640+
expect(deactivatedEmails).toContain('excluded@example.com');
641+
expect(result.details).toContainEqual(
642+
expect.objectContaining({
643+
email: 'excluded@example.com',
644+
status: 'deactivated',
645+
reason: 'User is excluded from Google Workspace sync',
646+
}),
647+
);
633648
});
634649

635650
it('should exclude users from import by email match', async () => {

‎apps/api/src/integration-platform/controllers/sync.controller.ts‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,9 @@ export class SyncController {
444444
},
445445
});
446446

447-
const deactivationGwDomains =
448-
effectiveSyncFilterMode === 'include'
449-
? new Set(
450-
ouFilteredUsers.map((u) =>
451-
u.primaryEmail.split('@')[1]?.toLowerCase(),
452-
),
453-
)
454-
: new Set(
455-
filteredUsers.map((u) =>
456-
u.primaryEmail.split('@')[1]?.toLowerCase(),
457-
),
458-
);
447+
const deactivationGwDomains = new Set(
448+
ouFilteredUsers.map((u) => u.primaryEmail.split('@')[1]?.toLowerCase()),
449+
);
459450
const deactivationSuspendedEmails =
460451
effectiveSyncFilterMode === 'include'
461452
? allSuspendedEmails
@@ -486,12 +477,26 @@ export class SyncController {
486477
continue;
487478
}
488479

489-
// In exclude mode we keep excluded users unchanged and only stop syncing them.
490-
if (
480+
const isExcluded =
491481
effectiveSyncFilterMode === 'exclude' &&
492482
excludedTerms.length > 0 &&
493-
matchesSyncFilterTerms(memberEmail, excludedTerms)
494-
) {
483+
matchesSyncFilterTerms(memberEmail, excludedTerms);
484+
485+
if (isExcluded) {
486+
try {
487+
await db.member.update({
488+
where: { id: member.id },
489+
data: { deactivated: true, isActive: false },
490+
});
491+
results.deactivated++;
492+
results.details.push({
493+
email: member.user.email,
494+
status: 'deactivated',
495+
reason: 'User is excluded from Google Workspace sync',
496+
});
497+
} catch (error) {
498+
this.logger.error(`Error deactivating excluded member: ${error}`);
499+
}
495500
continue;
496501
}
497502

0 commit comments

Comments
 (0)