Skip to content

Commit c4f1ba1

Browse files
author
Joan Reyero
authored
Impersonate (#1387)
1 parent fa7e44d commit c4f1ba1

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

backend/src/database/repositories/userRepository.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ export default class UserRepository {
372372
})
373373
}
374374

375+
// Exclude help@crowd.dev
376+
whereAnd.push({
377+
email: {
378+
[Op.ne]: '[email protected]',
379+
},
380+
})
381+
375382
if (filter) {
376383
if (filter.id) {
377384
whereAnd.push({
@@ -470,6 +477,12 @@ export default class UserRepository {
470477
},
471478
]
472479

480+
whereAnd.push({
481+
email: {
482+
[Op.ne]: '[email protected]',
483+
},
484+
})
485+
473486
if (query) {
474487
whereAnd.push({
475488
[Op.or]: [

backend/src/segment/identify.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ export default function identify(user) {
77
if (SEGMENT_CONFIG.writeKey) {
88
const analytics = new Analytics(SEGMENT_CONFIG.writeKey)
99
if (API_CONFIG.edition === Edition.CROWD_HOSTED || API_CONFIG.edition === Edition.LFX) {
10-
analytics.identify({
11-
userId: user.id,
12-
traits: {
13-
name: user.fullName,
14-
email: user.email,
15-
createdAt: user.createdAt,
16-
tenants: user.tenants.map((tenantUser) => ({
17-
id: tenantUser.tenant.id,
18-
name: tenantUser.tenant.name,
19-
url: tenantUser.tenant.url,
20-
})),
21-
// Hubspot custom traits
22-
created_an_account: true,
23-
created_an_account__date: user.createdAt,
24-
},
25-
})
10+
if (user.email !== '[email protected]') {
11+
analytics.identify({
12+
userId: user.id,
13+
traits: {
14+
name: user.fullName,
15+
email: user.email,
16+
createdAt: user.createdAt,
17+
tenants: user.tenants.map((tenantUser) => ({
18+
id: tenantUser.tenant.id,
19+
name: tenantUser.tenant.name,
20+
url: tenantUser.tenant.url,
21+
})),
22+
// Hubspot custom traits
23+
created_an_account: true,
24+
created_an_account__date: user.createdAt,
25+
},
26+
})
27+
}
2628
} else if (API_CONFIG.edition === Edition.COMMUNITY) {
2729
if (!user.email.includes('crowd.dev')) {
2830
analytics.identify({

backend/src/segment/identifyTenant.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export default async function identifyTenant(req) {
77
const analytics = new Analytics(SEGMENT_CONFIG.writeKey)
88

99
if (API_CONFIG.edition === Edition.CROWD_HOSTED || API_CONFIG.edition === Edition.LFX) {
10-
analytics.group({
11-
userId: req.currentUser.id,
12-
groupId: req.currentTenant.id,
13-
traits: {
14-
name: req.currentTenant.name,
15-
},
16-
})
10+
if (!req.currentUser.email.includes('[email protected]')) {
11+
analytics.group({
12+
userId: req.currentUser.id,
13+
groupId: req.currentTenant.id,
14+
traits: {
15+
name: req.currentTenant.name,
16+
},
17+
})
18+
}
1719
} else if (API_CONFIG.edition === Edition.COMMUNITY) {
1820
if (!req.currentUser.email.includes('crowd.dev')) {
1921
analytics.group({

backend/src/segment/track.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Edition } from '@crowd/types'
33
import { API_CONFIG, IS_TEST_ENV, SEGMENT_CONFIG } from '../conf'
44
import getTenatUser from './trackHelper'
55
import addProductData, { CROWD_ANALYTICS_PLATORM_NAME } from './addProductDataToCrowdTenant'
6+
import SequelizeRepository from '../database/repositories/sequelizeRepository'
67

78
const log = getServiceChildLogger('segment')
89

@@ -13,11 +14,15 @@ export default async function identify(
1314
userId: any = false,
1415
timestamp: any = false,
1516
) {
17+
const userEmail = SequelizeRepository.getCurrentUser({
18+
...options,
19+
}).email
1620
if (
1721
!IS_TEST_ENV &&
1822
SEGMENT_CONFIG.writeKey &&
1923
// This is only for events in the hosted version. Self-hosted has less telemetry.
20-
(API_CONFIG.edition === Edition.CROWD_HOSTED || API_CONFIG.edition === Edition.LFX)
24+
(API_CONFIG.edition === Edition.CROWD_HOSTED || API_CONFIG.edition === Edition.LFX) &&
25+
userEmail !== '[email protected]'
2126
) {
2227
if (
2328
properties &&

0 commit comments

Comments
 (0)