Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag to tag domains as staging in bulk add #4587

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import frenchMessages from '../../../locale/fr/messages'
import { createQuerySchema } from '../../../query'
import { createMutationSchema } from '../../../mutation'
import { cleanseInput } from '../../../validators'
import {
checkPermission,
userRequired,
saltedHash,
verifiedRequired,
tfaRequired,
} from '../../../auth'
import { checkPermission, userRequired, saltedHash, verifiedRequired, tfaRequired } from '../../../auth'
import { loadDomainByDomain } from '../../loaders'
import { loadOrgByKey } from '../../../organization/loaders'
import { loadUserByKey } from '../../../user/loaders'
Expand Down Expand Up @@ -128,6 +122,7 @@ describe('given the addOrganizationsDomains mutation', () => {
domains: ["test.domain.gov", "test.domain2.gov"]
hideNewDomains: false
tagNewDomains: false
tagStagingDomains: false
audit: false
}
) {
Expand Down Expand Up @@ -197,6 +192,7 @@ describe('given the addOrganizationsDomains mutation', () => {
domains: ["test.domain.gov", "test.domain2.gov"]
hideNewDomains: false
tagNewDomains: false
tagStagingDomains: false
audit: true
}
) {
Expand Down Expand Up @@ -343,6 +339,7 @@ describe('given the addOrganizationsDomains mutation', () => {
domains: ["test.domain.gov", "test.domain2.gov"]
hideNewDomains: false
tagNewDomains: false
tagStagingDomains: false
audit: false
}
) {
Expand Down
82 changes: 33 additions & 49 deletions api/src/domain/mutations/add-organizations-domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import { logActivity } from '../../audit-logs/mutations/log-activity'

export const addOrganizationsDomains = new mutationWithClientMutationId({
name: 'AddOrganizationsDomains',
description:
'Mutation used to create multiple new domains for an organization.',
description: 'Mutation used to create multiple new domains for an organization.',
inputFields: () => ({
orgId: {
type: GraphQLNonNull(GraphQLID),
description:
'The global id of the organization you wish to assign this domain to.',
description: 'The global id of the organization you wish to assign this domain to.',
},
domains: {
type: GraphQLNonNull(new GraphQLList(Domain)),
Expand All @@ -28,6 +26,10 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
type: GraphQLBoolean,
description: 'New domains will be tagged with NEW.',
},
tagStagingDomains: {
type: GraphQLBoolean,
description: 'New domains will be tagged with STAGING.',
},
audit: {
type: GraphQLBoolean,
description: 'Audit logs will be created.',
Expand All @@ -36,8 +38,7 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
outputFields: () => ({
result: {
type: bulkModifyDomainsUnion,
description:
'`BulkModifyDomainsUnion` returning either a `DomainBulkResult`, or `DomainErrorType` object.',
description: '`BulkModifyDomainsUnion` returning either a `DomainBulkResult`, or `DomainErrorType` object.',
resolve: (payload) => payload,
},
}),
Expand All @@ -50,13 +51,7 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
collections,
transaction,
userKey,
auth: {
checkPermission,
saltedHash,
userRequired,
verifiedRequired,
tfaRequired,
},
auth: { checkPermission, saltedHash, userRequired, verifiedRequired, tfaRequired },
loaders: { loadDomainByDomain, loadOrgByKey },
validators: { cleanseInput },
},
Expand Down Expand Up @@ -90,9 +85,12 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
} else {
tagNewDomains = false
}
let tags = []
if (tagNewDomains) {
tags = [{ en: 'NEW', fr: 'NOUVEAU' }]

let tagStagingDomains
if (typeof args.tagStagingDomains !== 'undefined') {
tagStagingDomains = args.tagStagingDomains
} else {
tagStagingDomains = false
}

let audit
Expand All @@ -106,9 +104,7 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
const org = await loadOrgByKey.load(orgId)

if (typeof org === 'undefined') {
console.warn(
`User: ${userKey} attempted to add domains to an organization: ${orgId} that does not exist.`,
)
console.warn(`User: ${userKey} attempted to add domains to an organization: ${orgId} that does not exist.`)
return {
_type: 'error',
code: 400,
Expand All @@ -126,12 +122,18 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
return {
_type: 'error',
code: 400,
description: i18n._(
t`Permission Denied: Please contact organization user for help with creating domains.`,
),
description: i18n._(t`Permission Denied: Please contact organization user for help with creating domains.`),
}
}

const tags = []
if (tagNewDomains) {
tags.push({ en: 'NEW', fr: 'NOUVEAU' })
}
if (tagStagingDomains) {
tags.push({ en: 'STAGING', fr: 'DÉV' })
}

const updatedProperties = []
if (typeof tags !== 'undefined' && tags.length > 0) {
updatedProperties.push({
Expand Down Expand Up @@ -180,19 +182,15 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
RETURN MERGE({ _id: org._id, _key: org._key, _rev: org._rev }, TRANSLATE(${request.language}, org.orgDetails))
`
} catch (err) {
console.error(
`Database error occurred while running check to see if domain already exists in an org: ${err}`,
)
console.error(`Database error occurred while running check to see if domain already exists in an org: ${err}`)
continue
}

let checkOrgDomain
try {
checkOrgDomain = await checkDomainCursor.next()
} catch (err) {
console.error(
`Cursor error occurred while running check to see if domain already exists in an org: ${err}`,
)
console.error(`Cursor error occurred while running check to see if domain already exists in an org: ${err}`)
continue
}

Expand Down Expand Up @@ -227,9 +225,7 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
`,
)
} catch (err) {
console.error(
`Transaction step error occurred for user: ${userKey} when inserting new domain: ${err}`,
)
console.error(`Transaction step error occurred for user: ${userKey} when inserting new domain: ${err}`)
continue
}

Expand Down Expand Up @@ -257,9 +253,7 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
`,
)
} catch (err) {
console.error(
`Transaction step error occurred for user: ${userKey} when inserting new domain edge: ${err}`,
)
console.error(`Transaction step error occurred for user: ${userKey} when inserting new domain edge: ${err}`)
continue
}
} else {
Expand All @@ -277,26 +271,20 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
`,
)
} catch (err) {
console.error(
`Transaction step error occurred for user: ${userKey} when inserting domain edge: ${err}`,
)
console.error(`Transaction step error occurred for user: ${userKey} when inserting domain edge: ${err}`)
continue
}
}

try {
await trx.commit()
} catch (err) {
console.error(
`Transaction commit error occurred while user: ${userKey} was creating domains: ${err}`,
)
console.error(`Transaction commit error occurred while user: ${userKey} was creating domains: ${err}`)
throw new Error(i18n._(t`Unable to create domains. Please try again.`))
}

if (audit) {
console.info(
`User: ${userKey} successfully added domain: ${insertDomain.domain} to org: ${org.slug}.`,
)
console.info(`User: ${userKey} successfully added domain: ${insertDomain.domain} to org: ${org.slug}.`)
await logActivity({
transaction,
collections,
Expand All @@ -322,9 +310,7 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({
}

if (!audit) {
console.info(
`User: ${userKey} successfully added ${domainCount} domain(s) to org: ${org.slug}.`,
)
console.info(`User: ${userKey} successfully added ${domainCount} domain(s) to org: ${org.slug}.`)
await logActivity({
transaction,
collections,
Expand All @@ -349,9 +335,7 @@ export const addOrganizationsDomains = new mutationWithClientMutationId({

return {
_type: 'result',
status: i18n._(
t`Successfully added ${domainCount} domain(s) to ${org.slug}.`,
),
status: i18n._(t`Successfully added ${domainCount} domain(s) to ${org.slug}.`),
}
},
})