Skip to content
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
3 changes: 3 additions & 0 deletions api/src/affiliation/mutations/invite-user-to-org.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ able to sign-up and be assigned to that organization in one mutation.`,
name: org.name,
}, // name of resource being acted upon
resourceType: 'user', // user, org, domain
updatedProperties: [
{ name: 'role', oldValue: '', newValue: requestedRole },
],
},
})

Expand Down
2 changes: 1 addition & 1 deletion api/src/affiliation/mutations/remove-user-from-org.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const removeUserFromOrg = new mutationWithClientMutationId({
userName: user.userName,
role: permission,
},
action: 'update',
action: 'remove',
target: {
resource: requestedUser.userName,
organization: {
Expand Down
3 changes: 2 additions & 1 deletion api/src/audit-logs/objects/target-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const targetResourceType = new GraphQLObjectType({
resolve: ({ oldValue }) => {
if (Array.isArray(oldValue)) {
return JSON.stringify(oldValue)
} else return oldValue
}
return oldValue
},
},
newValue: {
Expand Down
21 changes: 21 additions & 0 deletions api/src/domain/mutations/create-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,27 @@ export const createDomain = new mutationWithClientMutationId({
console.info(
`User: ${userKey} successfully created ${returnDomain.domain} in org: ${org.slug}.`,
)

const updatedProperties = []
if (
typeof insertDomain.selectors !== 'undefined' &&
insertDomain.selectors.length > 0
) {
updatedProperties.push({
name: 'selectors',
oldValue: [],
newValue: insertDomain.selectors,
})
}

if (typeof tags !== 'undefined' && tags.length > 0) {
updatedProperties.push({
name: 'tags',
oldValue: [],
newValue: tags,
})
}

await logActivity({
transaction,
collections,
Expand Down
95 changes: 66 additions & 29 deletions api/src/domain/mutations/update-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,29 @@ export const updateDomain = new mutationWithClientMutationId({
throw new Error(i18n._(t`Unable to update domain. Please try again.`))
}

let claimCursor
let currentTags = ''
if (tags) {
try {
claimCursor = await query`
WITH claims
FOR claim IN claims
FILTER claim._from == ${org._id} && claim._to == ${domain._id}
RETURN MERGE({ id: claim._key, _type: "claim" }, claim)
`
} catch (err) {
console.error(
`Database error occurred when user: ${userKey} running loadDomainByKey: ${err}`,
)
}
try {
currentTags = await claimCursor.next()
} catch (err) {
console.error(
`Cursor error occurred when user: ${userKey} running loadDomainByKey: ${err}`,
)
}

try {
await trx.step(
async () =>
Expand Down Expand Up @@ -222,6 +244,7 @@ export const updateDomain = new mutationWithClientMutationId({
const returnDomain = await loadDomainByKey.load(domain._key)

console.info(`User: ${userKey} successfully updated domain: ${domainId}.`)

const updatedProperties = []
if (domainToInsert.domain.toLowerCase() !== domain.domain.toLowerCase()) {
updatedProperties.push({
Expand All @@ -230,37 +253,51 @@ export const updateDomain = new mutationWithClientMutationId({
newValue: domainToInsert.domain,
})
}
if (typeof selectors !== 'undefined') {
if (
JSON.stringify(domainToInsert.selectors) !==
if (
typeof selectors !== 'undefined' &&
JSON.stringify(domainToInsert.selectors) !==
JSON.stringify(domain.selectors)
)
updatedProperties.push({
name: 'selectors',
oldValue: domain.selectors,
newValue: domainToInsert.selectors,
})
) {
updatedProperties.push({
name: 'selectors',
oldValue: domain.selectors,
newValue: domainToInsert.selectors,
})
}

if (
typeof tags !== 'undefined' &&
JSON.stringify(currentTags.tags) !== JSON.stringify(tags)
) {
updatedProperties.push({
name: 'tags',
oldValue: currentTags.tags,
newValue: tags,
})
}

if (updatedProperties.length > 0) {
await logActivity({
transaction,
collections,
query,
initiatedBy: {
id: user._key,
userName: user.userName,
role: permission,
},
action: 'update',
target: {
resource: domain.domain,
organization: {
id: org._key,
name: org.name,
}, // name of resource being acted upon
resourceType: 'domain', // user, org, domain
updatedProperties,
},
})
}
await logActivity({
transaction,
collections,
query,
initiatedBy: {
id: user._key,
userName: user.userName,
role: permission,
},
action: 'update',
target: {
resource: domain.domain,
organization: {
id: org._key,
name: org.name,
}, // name of resource being acted upon
resourceType: 'domain', // user, org, domain
updatedProperties,
},
})

returnDomain.id = returnDomain._key

Expand Down
2 changes: 1 addition & 1 deletion api/src/organization/mutations/remove-organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export const removeOrganization = new mutationWithClientMutationId({
},
action: 'delete',
target: {
resource: organization.orgDetails.en.name, // name of resource being acted upon
resource: organization.name, // name of resource being acted upon
resourceType: 'organization', // user, org, domain
},
})
Expand Down
Loading