Skip to content

Commit 5e794b2

Browse files
authored
feat: add organization data source (#7277)
* feat: add data source for api/src/guidance-tag * fix tests * create data source and add to context * update resolvers to use data source * update mutations to use data source * fix tests * add translations * fix tests
1 parent 6c54ac9 commit 5e794b2

27 files changed

Lines changed: 2422 additions & 7050 deletions

api/src/__tests__/initialize-loaders.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ describe('initializeLoaders', () => {
2727
'loadDomainConnectionsByOrgId',
2828
'loadDomainConnectionsByUserId',
2929
'loadOrgByKey',
30-
'loadOrgBySlug',
31-
'loadOrgConnectionsByDomainId',
32-
'loadOrgConnectionsByUserId',
3330
'loadUserByUserName',
3431
'loadUserByKey',
3532
'loadAffiliationByKey',

api/src/create-context.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { WebScanDataSource } from './web-scan'
1313
import { AuditLogsDataSource } from './audit-logs'
1414
import { AdditionalFindingsDataSource } from './additional-findings'
1515
import { GuidanceTagDataSource } from './guidance-tag'
16+
import { OrganizationDataSource } from './organization'
1617
import { TagsDataSource } from './tags'
1718
import {
1819
AuthDataSource,
@@ -148,6 +149,7 @@ export async function createContext({
148149
auditLogs: new AuditLogsDataSource({ query, userKey, cleanseInput, i18n, transaction, collections }),
149150
dnsScan: new DnsScanDataSource({ query, userKey, cleanseInput, i18n }),
150151
guidanceTag: new GuidanceTagDataSource({ query, userKey, i18n, language: request.language, cleanseInput }),
152+
organization: new OrganizationDataSource({ query, userKey, i18n, language: request.language, cleanseInput, loginRequiredBool, transaction, collections }),
151153
tags: new TagsDataSource({ query, userKey, i18n, language: request.language, transaction, collections }),
152154
webScan: new WebScanDataSource({ query, userKey, cleanseInput, i18n }),
153155
},

api/src/domain/mutations/__tests__/create-domain.test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '../../../auth'
2222
import { loadDkimSelectorsByDomainId, loadDomainByDomain } from '../../loaders'
2323
import { loadOrgByKey, loadOrgConnectionsByDomainId } from '../../../organization/loaders'
24+
import { OrganizationDataSource } from '../../../organization/data-source'
2425
import { loadUserByKey } from '../../../user/loaders'
2526
import dbschema from '../../../../database.json'
2627
import { collectionNames } from '../../../collection-names'
@@ -209,6 +210,16 @@ describe('create a domain', () => {
209210
},
210211
dataSources: {
211212
auth: new AuthDataSource({ query, userKey: user._key }),
213+
organization: new OrganizationDataSource({
214+
query,
215+
userKey: user._key,
216+
i18n,
217+
language: 'en',
218+
cleanseInput,
219+
loginRequiredBool: true,
220+
transaction,
221+
collections: collectionNames,
222+
}),
212223
},
213224
loaders: {
214225
loadDkimSelectorsByDomainId: loadDkimSelectorsByDomainId({
@@ -373,6 +384,16 @@ describe('create a domain', () => {
373384
},
374385
dataSources: {
375386
auth: new AuthDataSource({ query, userKey: user._key }),
387+
organization: new OrganizationDataSource({
388+
query,
389+
userKey: user._key,
390+
i18n,
391+
language: 'en',
392+
cleanseInput,
393+
loginRequiredBool: true,
394+
transaction,
395+
collections: collectionNames,
396+
}),
376397
},
377398
loaders: {
378399
loadDkimSelectorsByDomainId: loadDkimSelectorsByDomainId({
@@ -513,6 +534,16 @@ describe('create a domain', () => {
513534
},
514535
dataSources: {
515536
auth: new AuthDataSource({ query, userKey: user._key }),
537+
organization: new OrganizationDataSource({
538+
query,
539+
userKey: user._key,
540+
i18n,
541+
language: 'en',
542+
cleanseInput,
543+
loginRequiredBool: true,
544+
transaction,
545+
collections: collectionNames,
546+
}),
516547
},
517548
loaders: {
518549
loadDkimSelectorsByDomainId: loadDkimSelectorsByDomainId({
@@ -693,6 +724,16 @@ describe('create a domain', () => {
693724
},
694725
dataSources: {
695726
auth: new AuthDataSource({ query, userKey: user._key }),
727+
organization: new OrganizationDataSource({
728+
query,
729+
userKey: user._key,
730+
i18n,
731+
language: 'en',
732+
cleanseInput,
733+
loginRequiredBool: true,
734+
transaction,
735+
collections: collectionNames,
736+
}),
696737
},
697738
loaders: {
698739
loadDkimSelectorsByDomainId: loadDkimSelectorsByDomainId({
@@ -836,6 +877,16 @@ describe('create a domain', () => {
836877
},
837878
dataSources: {
838879
auth: new AuthDataSource({ query, userKey: user._key }),
880+
organization: new OrganizationDataSource({
881+
query,
882+
userKey: user._key,
883+
i18n,
884+
language: 'en',
885+
cleanseInput,
886+
loginRequiredBool: true,
887+
transaction,
888+
collections: collectionNames,
889+
}),
839890
},
840891
loaders: {
841892
loadDkimSelectorsByDomainId: loadDkimSelectorsByDomainId({
@@ -980,6 +1031,16 @@ describe('create a domain', () => {
9801031
},
9811032
dataSources: {
9821033
auth: new AuthDataSource({ query, userKey: user._key }),
1034+
organization: new OrganizationDataSource({
1035+
query,
1036+
userKey: user._key,
1037+
i18n,
1038+
language: 'en',
1039+
cleanseInput,
1040+
loginRequiredBool: true,
1041+
transaction,
1042+
collections: collectionNames,
1043+
}),
9831044
},
9841045
loaders: {
9851046
loadDkimSelectorsByDomainId: loadDkimSelectorsByDomainId({

api/src/domain/objects/__tests__/domain.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ describe('given the domain object', () => {
306306
{ _id: '1' },
307307
{ first: 1 },
308308
{
309-
loaders: {
310-
loadOrgConnectionsByDomainId: jest.fn().mockReturnValue(expectedResult),
309+
dataSources: {
310+
organization: {
311+
connectionsByDomainId: jest.fn().mockReturnValue(expectedResult),
312+
},
311313
},
312314
auth: {
313315
checkSuperAdmin: jest.fn().mockReturnValue(false),

api/src/domain/objects/domain.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ export const domainType = new GraphQLObjectType({
122122
...connectionArgs,
123123
},
124124
description: 'The organization that this domain belongs to.',
125-
resolve: async ({ _id }, args, { auth: { checkSuperAdmin }, loaders: { loadOrgConnectionsByDomainId } }) => {
125+
resolve: async ({ _id }, args, { auth: { checkSuperAdmin }, dataSources: { organization } }) => {
126126
const isSuperAdmin = await checkSuperAdmin()
127127

128-
return await loadOrgConnectionsByDomainId({
128+
return await organization.connectionsByDomainId({
129129
domainId: _id,
130130
isSuperAdmin,
131131
...args,
@@ -154,11 +154,7 @@ export const domainType = new GraphQLObjectType({
154154
...connectionArgs,
155155
},
156156
description: `DNS scan results.`,
157-
resolve: async (
158-
{ _id },
159-
args,
160-
{ userKey, auth: { userRequired }, dataSources: { auth: authDS, dnsScan } },
161-
) => {
157+
resolve: async ({ _id }, args, { userKey, auth: { userRequired }, dataSources: { auth: authDS, dnsScan } }) => {
162158
await userRequired()
163159
const permitted = await authDS.domainPermissionByDomainId.load(_id)
164160
if (!permitted) {
@@ -200,11 +196,7 @@ export const domainType = new GraphQLObjectType({
200196
},
201197
...connectionArgs,
202198
},
203-
resolve: async (
204-
{ _id },
205-
args,
206-
{ userKey, auth: { userRequired }, dataSources: { auth: authDS, webScan } },
207-
) => {
199+
resolve: async ({ _id }, args, { userKey, auth: { userRequired }, dataSources: { auth: authDS, webScan } }) => {
208200
await userRequired()
209201
const permitted = await authDS.domainPermissionByDomainId.load(_id)
210202
if (!permitted) {
@@ -292,7 +284,7 @@ export const domainType = new GraphQLObjectType({
292284
return {
293285
domainKey: _key,
294286
_id: dmarcSummaryEdge._to,
295-
startDate: startDate,
287+
startDate,
296288
}
297289
},
298290
},

api/src/initialize-loaders.js

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,7 @@ import {
2222
loadDomainConnectionsByUserId,
2323
loadDkimSelectorsByDomainId,
2424
} from './domain/loaders'
25-
import {
26-
loadOrgByKey,
27-
loadOrgBySlug,
28-
loadOrgConnectionsByDomainId,
29-
loadOrgConnectionsByUserId,
30-
loadAllOrganizationDomainStatuses,
31-
loadOrganizationDomainStatuses,
32-
loadOrganizationSummariesByPeriod,
33-
loadOrganizationNamesById,
34-
} from './organization/loaders'
25+
import { loadOrgByKey, loadOrganizationNamesById } from './organization/loaders'
3526
import { loadMyTrackerByUserId, loadUserByUserName, loadUserByKey, loadUserConnectionsByUserId } from './user/loaders'
3627
import {
3728
loadVerifiedDomainsById,
@@ -133,63 +124,8 @@ export function initializeLoaders({ query, userKey, i18n, language, cleanseInput
133124
i18n,
134125
auth: { loginRequiredBool },
135126
}),
136-
loadOrgByKey: loadOrgByKey({
137-
query,
138-
language,
139-
userKey,
140-
i18n,
141-
}),
142-
loadOrgBySlug: loadOrgBySlug({
143-
query,
144-
language,
145-
userKey,
146-
i18n,
147-
}),
148-
loadOrgConnectionsByDomainId: loadOrgConnectionsByDomainId({
149-
query,
150-
language,
151-
userKey,
152-
cleanseInput,
153-
i18n,
154-
auth: { loginRequiredBool },
155-
}),
156-
loadOrgConnectionsByUserId: loadOrgConnectionsByUserId({
157-
query,
158-
userKey,
159-
cleanseInput,
160-
language,
161-
i18n,
162-
auth: { loginRequiredBool },
163-
}),
164-
loadOrganizationSummariesByPeriod: loadOrganizationSummariesByPeriod({
165-
query,
166-
userKey,
167-
cleanseInput,
168-
language,
169-
i18n,
170-
auth: { loginRequiredBool },
171-
}),
172-
loadOrganizationNamesById: loadOrganizationNamesById({
173-
query,
174-
language,
175-
userKey,
176-
i18n,
177-
}),
178-
loadAllOrganizationDomainStatuses: loadAllOrganizationDomainStatuses({
179-
query,
180-
userKey,
181-
cleanseInput,
182-
language,
183-
i18n,
184-
}),
185-
loadOrganizationDomainStatuses: loadOrganizationDomainStatuses({
186-
query,
187-
userKey,
188-
cleanseInput,
189-
language,
190-
i18n,
191-
auth: { loginRequiredBool },
192-
}),
127+
loadOrgByKey: loadOrgByKey({ query, language, userKey, i18n }),
128+
loadOrganizationNamesById: loadOrganizationNamesById({ query, userKey, i18n }),
193129
loadMyTrackerByUserId: loadMyTrackerByUserId({
194130
query,
195131
language,

0 commit comments

Comments
 (0)