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

Refactor Entities.createVersion #1013

Merged
merged 3 commits into from
Oct 5, 2023
Merged

Conversation

ktuite
Copy link
Member

@ktuite ktuite commented Sep 29, 2023

Addresses some clunkiness in #1005 but I wanted to put it in a separate PR so the meaning of #1005 would be clearer.

There's a 2x2 square of situations and I tried to make the via submission vs. API cases more similar.

[creating entities, updating entities] x [via submission, via API]

Via API:

  • parse data from request
  • entity def source is basic, practically empty
  • creator is inferred from request auth
  • audit logging happens through createNew.audit and createVersion.audit, which checks that submission def was not provided

Via submission:

  • data parsed from submission
  • entity def source is complex, based on submission, def, event, etc.
  • creator is the submission's creator
  • audit logging happens in a submission event processing method because different audit logging kicks in in case of a processing error

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

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

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?

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

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

@ktuite ktuite force-pushed the ktuite/entity_create_version branch from c111d6b to 20573bd Compare October 3, 2023 18:29
Base automatically changed from ktuite/entity_exploration to master October 4, 2023 18:56
@ktuite ktuite force-pushed the ktuite/entity_create_version branch from d0f0680 to 7f59e5d Compare October 4, 2023 19:02
Copy link
Member Author

@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.

interactive review with @matthew-white

@@ -37,15 +49,13 @@ const nextval = sql`nextval(pg_get_serial_sequence('entities', 'id'))`;
const createNew = (dataset, partial, subDef, sourceId, userAgentIn) => ({ one, context }) => {
let creatorId;
let userAgent;
let subDefId;

// Set creatorId and userAgent from submission def if it exists
if (subDef != null && subDef.id != null)
Copy link
Member Author

Choose a reason for hiding this comment

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

Look into why subDef.id != null is checked in the first place. If it is needed, it should be needed in the audit function, too.

let userAgent;

// Set creatorId and userAgent from submission def if it exists
if (subDef != null && subDef.id != null)
Copy link
Member Author

Choose a reason for hiding this comment

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

Check if this is needed subDef.id != null here, too.

@@ -845,6 +845,14 @@ describe('worker: entity', () => {
person.currentVersion.version.should.equal(2);
});

await asAlice.get('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc/audits')
Copy link
Member Author

Choose a reason for hiding this comment

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

This test of audit log content deserves its own test/set of tests.

@ktuite ktuite merged commit 4b8549e into master Oct 5, 2023
5 checks passed
@ktuite ktuite deleted the ktuite/entity_create_version branch October 5, 2023 00:06
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.

2 participants