From 85ab28da82de82521a0a8f1d55347fafe96b5bf8 Mon Sep 17 00:00:00 2001 From: lcampbell Date: Fri, 4 Nov 2022 12:13:06 -0300 Subject: [PATCH 1/8] change query first and orderby defaults --- frontend/src/admin/AuditLogTable.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/frontend/src/admin/AuditLogTable.js b/frontend/src/admin/AuditLogTable.js index 6a7aa1647b..b08eee91ce 100644 --- a/frontend/src/admin/AuditLogTable.js +++ b/frontend/src/admin/AuditLogTable.js @@ -29,18 +29,17 @@ import { SearchBox } from '../components/SearchBox' import { RelayPaginationControls } from '../components/RelayPaginationControls' export function AuditLogTable({ orgId = null }) { - const [orderDirection, setOrderDirection] = useState('ASC') + const [orderDirection, setOrderDirection] = useState('DESC') const [orderField, setOrderField] = useState('TIMESTAMP') const [searchTerm, setSearchTerm] = useState('') const [debouncedSearchTerm, setDebouncedSearchTerm] = useState('') - const [logsPerPage, setLogsPerPage] = useState(10) + const [logsPerPage, setLogsPerPage] = useState(20) const [activeResourceFilters, setActiveResourceFilters] = useState([]) const [activeActionFilters, setActiveActionFilters] = useState([]) const memoizedSetDebouncedSearchTermCallback = useCallback(() => { setDebouncedSearchTerm(searchTerm) }, [searchTerm]) useDebouncedFunction(memoizedSetDebouncedSearchTermCallback, 500) - const { loading, isLoadingMore, @@ -109,7 +108,7 @@ export function AuditLogTable({ orgId = null }) { - Time Generated + Time Generated (UTC) Initiated By @@ -144,9 +143,9 @@ export function AuditLogTable({ orgId = null }) { ({ value }) => action.toUpperCase() === value, ) if (typeof reason !== 'undefined') { - if (reason === 'nonexistent') { + if (reason === 'NONEXISTENT') { reason = This domain no longer exists - } else if (reason === 'wrong_org') { + } else if (reason === 'WRONG_ORG') { reason = ( This domain does not belong to this organization From 6755780f1f719e08b1de6b95c939df736535d29e Mon Sep 17 00:00:00 2001 From: lcampbell Date: Fri, 4 Nov 2022 12:13:41 -0300 Subject: [PATCH 2/8] fix typo when logging remove user --- api/src/affiliation/mutations/remove-user-from-org.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/affiliation/mutations/remove-user-from-org.js b/api/src/affiliation/mutations/remove-user-from-org.js index cd8bb89add..e40303c737 100644 --- a/api/src/affiliation/mutations/remove-user-from-org.js +++ b/api/src/affiliation/mutations/remove-user-from-org.js @@ -203,7 +203,7 @@ export const removeUserFromOrg = new mutationWithClientMutationId({ userName: user.userName, role: permission, }, - action: 'update', + action: 'remove', target: { resource: requestedUser.userName, organization: { From 4f52c567a9ea2ced9c99a5928324d7883945b4ce Mon Sep 17 00:00:00 2001 From: lcampbell Date: Fri, 4 Nov 2022 12:26:35 -0300 Subject: [PATCH 3/8] show updated props in logs when adding domains and users --- api/src/affiliation/mutations/invite-user-to-org.js | 3 +++ api/src/domain/mutations/create-domain.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/api/src/affiliation/mutations/invite-user-to-org.js b/api/src/affiliation/mutations/invite-user-to-org.js index 407cb7e521..dd8f881d7c 100644 --- a/api/src/affiliation/mutations/invite-user-to-org.js +++ b/api/src/affiliation/mutations/invite-user-to-org.js @@ -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 }, + ], }, }) diff --git a/api/src/domain/mutations/create-domain.js b/api/src/domain/mutations/create-domain.js index aa5f90366e..680d9bde63 100644 --- a/api/src/domain/mutations/create-domain.js +++ b/api/src/domain/mutations/create-domain.js @@ -299,6 +299,19 @@ 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, + }) + } + await logActivity({ transaction, collections, From a75cd1a06dc1c89993e1eea167fde6363a472403 Mon Sep 17 00:00:00 2001 From: lcampbell Date: Fri, 4 Nov 2022 12:58:42 -0300 Subject: [PATCH 4/8] give filters horizontal styling --- frontend/src/admin/AuditLogTable.js | 227 +++++++++++++--------------- 1 file changed, 108 insertions(+), 119 deletions(-) diff --git a/frontend/src/admin/AuditLogTable.js b/frontend/src/admin/AuditLogTable.js index b08eee91ce..ba62a46a81 100644 --- a/frontend/src/admin/AuditLogTable.js +++ b/frontend/src/admin/AuditLogTable.js @@ -1,13 +1,10 @@ import React, { useCallback, useState } from 'react' import { Box, - Grid, - GridItem, Button, Divider, Tag, Text, - SimpleGrid, Table, Thead, Tbody, @@ -212,123 +209,115 @@ export function AuditLogTable({ orgId = null }) { orderByOptions={orderByOptions} placeholder={t`Search by initiated by, resource name`} /> - - {logTable} - - - - Filters + + + + + Resource: - - - - Resource: - - - {resourceFilters.map(({ value, text }, idx) => { - return ( - { - let optionIdx = activeResourceFilters.indexOf(value) - if (optionIdx < 0) { - setActiveResourceFilters([ - ...activeResourceFilters, - value, - ]) - } else { - setActiveResourceFilters( - activeResourceFilters.filter( - (tag) => tag !== value, - ), - ) - } - }} - > - {text} - - ) - })} - - - Action: - - - {actionFilters.map(({ value, text }, idx) => { - return ( - { - let optionIdx = activeActionFilters.indexOf(value) - if (optionIdx < 0) { - setActiveActionFilters([ - ...activeActionFilters, - value, - ]) - } else { - setActiveActionFilters( - activeActionFilters.filter((tag) => tag !== value), - ) - } - }} - > - {text} - - ) - })} - - - - - - + {resourceFilters.map(({ value, text }, idx) => { + return ( + { + let optionIdx = activeResourceFilters.indexOf(value) + if (optionIdx < 0) { + setActiveResourceFilters([ + ...activeResourceFilters, + value, + ]) + } else { + setActiveResourceFilters( + activeResourceFilters.filter((tag) => tag !== value), + ) + } + }} + > + {text} + + ) + })} + + + + + Action: + + {actionFilters.map(({ value, text }, idx) => { + return ( + { + let optionIdx = activeActionFilters.indexOf(value) + if (optionIdx < 0) { + setActiveActionFilters([...activeActionFilters, value]) + } else { + setActiveActionFilters( + activeActionFilters.filter((tag) => tag !== value), + ) + } + }} + > + {text} + + ) + })} + + + + + {logTable} Date: Fri, 4 Nov 2022 15:07:31 -0300 Subject: [PATCH 5/8] fix error when logging remove-organization --- api/src/organization/mutations/remove-organization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/organization/mutations/remove-organization.js b/api/src/organization/mutations/remove-organization.js index 58654f6784..7bcc7b61a3 100644 --- a/api/src/organization/mutations/remove-organization.js +++ b/api/src/organization/mutations/remove-organization.js @@ -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 }, }) From b79c5321f1ea83a9d6ebbfb27eeab4d502790c85 Mon Sep 17 00:00:00 2001 From: lcampbell Date: Fri, 4 Nov 2022 16:43:50 -0300 Subject: [PATCH 6/8] fix test query --- .../src/admin/__tests__/AuditLogTable.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/admin/__tests__/AuditLogTable.test.js b/frontend/src/admin/__tests__/AuditLogTable.test.js index 7473c47269..863c3ae3a0 100644 --- a/frontend/src/admin/__tests__/AuditLogTable.test.js +++ b/frontend/src/admin/__tests__/AuditLogTable.test.js @@ -209,10 +209,10 @@ function mocks() { request: { query: AUDIT_LOGS, variables: { - first: 10, + first: 20, orderBy: { field: 'TIMESTAMP', - direction: 'ASC', + direction: 'DESC', }, orgId: null, search: '', @@ -310,10 +310,10 @@ function mocks() { request: { query: AUDIT_LOGS, variables: { - first: 10, + first: 20, orderBy: { field: 'TIMESTAMP', - direction: 'ASC', + direction: 'DESC', }, orgId: null, search: '', @@ -361,10 +361,10 @@ function mocks() { request: { query: AUDIT_LOGS, variables: { - first: 10, + first: 20, orderBy: { field: 'TIMESTAMP', - direction: 'ASC', + direction: 'DESC', }, orgId: null, search: '', @@ -412,10 +412,10 @@ function mocks() { request: { query: AUDIT_LOGS, variables: { - first: 10, + first: 20, orderBy: { field: 'TIMESTAMP', - direction: 'ASC', + direction: 'DESC', }, orgId: null, search: '', From d468032decd56c57ad9527c971b1cad4b29d949b Mon Sep 17 00:00:00 2001 From: lcampbell Date: Tue, 8 Nov 2022 16:29:56 -0400 Subject: [PATCH 7/8] add org tags to update logs --- api/src/audit-logs/objects/target-resource.js | 9 +- api/src/domain/mutations/create-domain.js | 8 ++ api/src/domain/mutations/update-domain.js | 95 +++++++++++++------ frontend/src/admin/AuditLogTable.js | 2 +- 4 files changed, 82 insertions(+), 32 deletions(-) diff --git a/api/src/audit-logs/objects/target-resource.js b/api/src/audit-logs/objects/target-resource.js index 8e8b176215..b951096d9e 100644 --- a/api/src/audit-logs/objects/target-resource.js +++ b/api/src/audit-logs/objects/target-resource.js @@ -53,10 +53,15 @@ export const targetResourceType = new GraphQLObjectType({ oldValue: { type: GraphQLString, description: 'Old value of updated property.', - resolve: ({ oldValue }) => { + resolve: ({ name, oldValue }) => { if (Array.isArray(oldValue)) { + if (name === 'tags') { + // TODO translate tags + return JSON.stringify(oldValue) + } return JSON.stringify(oldValue) - } else return oldValue + } + return oldValue }, }, newValue: { diff --git a/api/src/domain/mutations/create-domain.js b/api/src/domain/mutations/create-domain.js index 680d9bde63..d8a11b63af 100644 --- a/api/src/domain/mutations/create-domain.js +++ b/api/src/domain/mutations/create-domain.js @@ -312,6 +312,14 @@ export const createDomain = new mutationWithClientMutationId({ }) } + if (typeof tags !== 'undefined' && tags.length > 0) { + updatedProperties.push({ + name: 'tags', + oldValue: [], + newValue: tags, + }) + } + await logActivity({ transaction, collections, diff --git a/api/src/domain/mutations/update-domain.js b/api/src/domain/mutations/update-domain.js index f613ca8b2c..abf0544908 100644 --- a/api/src/domain/mutations/update-domain.js +++ b/api/src/domain/mutations/update-domain.js @@ -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 () => @@ -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({ @@ -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 diff --git a/frontend/src/admin/AuditLogTable.js b/frontend/src/admin/AuditLogTable.js index ba62a46a81..9a2cbe0850 100644 --- a/frontend/src/admin/AuditLogTable.js +++ b/frontend/src/admin/AuditLogTable.js @@ -100,7 +100,7 @@ export function AuditLogTable({ orgId = null }) { ) } else { logTable = ( - + From be9038a7a0769de54d6af6a22400647ec234b30f Mon Sep 17 00:00:00 2001 From: lcampbell Date: Mon, 14 Nov 2022 09:19:07 -0400 Subject: [PATCH 8/8] remove unused code --- api/src/audit-logs/objects/target-resource.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/api/src/audit-logs/objects/target-resource.js b/api/src/audit-logs/objects/target-resource.js index b951096d9e..9d08b38504 100644 --- a/api/src/audit-logs/objects/target-resource.js +++ b/api/src/audit-logs/objects/target-resource.js @@ -53,12 +53,8 @@ export const targetResourceType = new GraphQLObjectType({ oldValue: { type: GraphQLString, description: 'Old value of updated property.', - resolve: ({ name, oldValue }) => { + resolve: ({ oldValue }) => { if (Array.isArray(oldValue)) { - if (name === 'tags') { - // TODO translate tags - return JSON.stringify(oldValue) - } return JSON.stringify(oldValue) } return oldValue