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

Enhances #664: add logs only when changes are published #931

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

sadiqkhoja
Copy link
Contributor

@sadiqkhoja sadiqkhoja commented Jul 18, 2023

Closes #664 and #811

What has been done to verify that this works as intended?

Integration tests

Why is this the best possible solution? Were any other approaches considered?

NA

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

None

Does this change require updates to the API documentation? If so, please update docs/api.md as part of this PR.

Yes

Before submitting this PR, please make sure you have:

  • run make test-full and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

@sadiqkhoja sadiqkhoja requested a review from ktuite July 18, 2023 13:06
Copy link
Member

@ktuite ktuite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I want to stare at this a little bit longer, but here are some comments.

  1. I'm looking forward to this change!
  2. I left suggestions to update some code comments because they are out of date or this part of the code is still complex (but less so now)
  3. Is this (property list) what we want to log in the audit details for these events? Anything else?

@@ -21,20 +21,14 @@ const { sanitizeOdataIdentifier } = require('../../util/util');
// DATASET CREATE AND UPDATE

// createOrUpdate is called from Forms.createNew and Forms.createVersion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems out of place and i think the name changed to createOrMerge.

UPDATE datasets SET "publishedAt" = clock_timestamp()
WHERE name = ${dataset.name} AND "projectId" = ${dataset.projectId} AND "publishedAt" IS NULL
),
` : sql``}
ds AS (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to double-check my understanding that with the query being simplified a bit, the rest of this should still be here. It's how you determine whether the dataset was freshly inserted (created) or already there (not inserted in ds_ins but found in datasets) to get the create or update action, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clause was updating dataset only if publish was true. The ds CTE just below (line 38-41 left side) tells us whether dataset is newly inserted or it was already there - it has "action" column with 'created' or 'updated' value

Comment on lines +73 to +75
const _createOrMerge = (dataset, fields, acteeId) => sql`
${_insertDatasetDef(dataset, acteeId)}
${isNilOrEmpty(fields) ? sql`` : _insertProperties(fields)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how all these publish flags are going away!

? log('dataset.update.publish', dataset, { properties: dataset.properties.map(p => p.name) })
: null));
createOrMerge.audit.withResult = true;

////////////////////////////////////////////////////////////////////////////
// DATASET (AND DATASET PROPERTY) PUBLISH

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment near here (publishIfExists) that says "createOrMerge may also publish datasets" can change. Instead I'd love a comment reminding me why there's the "ifExists" part.

@@ -2079,13 +2080,28 @@ describe('datasets and entities', () => {
.set('Content-Type', 'text/xml')
.expect(200)));

const audit = await Audits.getLatestByAction('dataset.create').then((o) => o.get());
audit.details.fields.should.eql([['/name', 'first_name'], ['/age', 'age']]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the details of the audit log changed from fields to properties. Ah I guess this is because dataset.update.publish used to return those while the other dataset events returned something else. And now every event is closer in meaning to a publish.

@sadiqkhoja sadiqkhoja merged commit 2d8d20d into getodk:master Aug 3, 2023
@matthew-white matthew-white linked an issue Aug 3, 2023 that may be closed by this pull request
sadiqkhoja added a commit to sadiqkhoja/central-backend that referenced this pull request Sep 1, 2023
…#931)

* Enhances getodk#664: add logs only when changes are published

* updated API doc

* updated comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Datasets.publishIfExists Makes changes to dataset-related logging in audit log
2 participants