Skip to content

Commit 3195866

Browse files
committed
fix(SA-675): filter out suspended and archived Google users
- Add query parameter to filter suspended users at API level - Add secondary filter in formatUserList for archived users - Include suspended/archived fields in API response - Add tests for suspended/archived user filtering
1 parent 08ab2ed commit 3195866

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

src/google.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export async function getGithubUsersFromGoogle(): Promise<Set<string>> {
3131
customer: 'my_customer',
3232
maxResults: 250,
3333
projection: 'custom',
34-
fields: 'users(customSchemas/Accounts/github(value))',
34+
query: 'isSuspended=false',
35+
fields: 'users(customSchemas/Accounts/github(value),suspended,archived)',
3536
customFieldMask: 'Accounts',
3637
})
3738

@@ -43,6 +44,7 @@ export async function getGithubUsersFromGoogle(): Promise<Set<string>> {
4344
export function formatUserList(users): Set<string> {
4445
return new Set(
4546
users
47+
.filter((user) => !user.suspended && !user.archived)
4648
.map((user) => user.customSchemas?.Accounts?.github?.map((account) => account.value?.toLowerCase()))
4749
.flat()
4850
.filter(Boolean),

tests/google.spec.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@ import { google } from 'googleapis'
33
import * as mod from '../src/google'
44

55
const fakeUsersResponse = [
6-
{ customSchemas: { Accounts: { github: [{ value: 'chrisns' }] } } },
6+
{ customSchemas: { Accounts: { github: [{ value: 'chrisns' }] } }, suspended: false, archived: false },
77
{
88
customSchemas: {
99
Accounts: { github: [{ value: 'Foo' }, , { value: 'tar' }] },
1010
},
11+
suspended: false,
12+
archived: false,
1113
},
1214
{
1315
customSchemas: {
1416
Accounts: { github: [{ value: 'foo' }, { value: 'bar' }] },
1517
},
18+
suspended: false,
19+
archived: false,
1620
},
1721
]
1822

23+
const fakeUsersResponseWithSuspended = [
24+
{ customSchemas: { Accounts: { github: [{ value: 'activeuser' }] } }, suspended: false, archived: false },
25+
{ customSchemas: { Accounts: { github: [{ value: 'suspendeduser' }] } }, suspended: true, archived: false },
26+
{ customSchemas: { Accounts: { github: [{ value: 'archiveduser' }] } }, suspended: false, archived: true },
27+
{ customSchemas: { Accounts: { github: [{ value: 'botharchivedandsuspended' }] } }, suspended: true, archived: true },
28+
]
29+
1930
describe('google integration', () => {
2031
beforeEach(() => {
2132
process.env.GOOGLE_EMAIL_ADDRESS = 'hello@example.com'
@@ -49,12 +60,26 @@ describe('google integration', () => {
4960
it('formatUserList bad', () =>
5061
expect(
5162
mod.formatUserList([
52-
{},
53-
{ customSchemas: {} },
54-
{ customSchemas: { Accounts: {} } },
55-
{ customSchemas: { Accounts: { github: [] } } },
56-
{ customSchemas: { Accounts: { github: [{}] } } },
57-
{ customSchemas: { Accounts: { github: [{ value: 'chrisns' }] } } },
63+
{ suspended: false, archived: false },
64+
{ customSchemas: {}, suspended: false, archived: false },
65+
{ customSchemas: { Accounts: {} }, suspended: false, archived: false },
66+
{ customSchemas: { Accounts: { github: [] } }, suspended: false, archived: false },
67+
{ customSchemas: { Accounts: { github: [{}] } }, suspended: false, archived: false },
68+
{ customSchemas: { Accounts: { github: [{ value: 'chrisns' }] } }, suspended: false, archived: false },
5869
]),
5970
).toMatchSnapshot())
71+
72+
it('formatUserList filters out suspended users', () => {
73+
const result = mod.formatUserList(fakeUsersResponseWithSuspended)
74+
expect(result).toEqual(new Set(['activeuser']))
75+
})
76+
77+
it('formatUserList filters out archived users', () => {
78+
const users = [
79+
{ customSchemas: { Accounts: { github: [{ value: 'active' }] } }, suspended: false, archived: false },
80+
{ customSchemas: { Accounts: { github: [{ value: 'archived' }] } }, suspended: false, archived: true },
81+
]
82+
const result = mod.formatUserList(users)
83+
expect(result).toEqual(new Set(['active']))
84+
})
6085
})

0 commit comments

Comments
 (0)