-
Notifications
You must be signed in to change notification settings - Fork 76
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
#710: Restore Entities, Purge Entities, ability to see deleted Entities #1349
Open
sadiqkhoja
wants to merge
6
commits into
getodk:master
Choose a base branch
from
sadiqkhoja:features/710-entity-restore-purge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,019
−77
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b38616
Features #710: Entity restore
sadiqkhoja 90f985c
Features #710: Add deletedAt in entity Odata feed
sadiqkhoja 0713461
Features #710: Purge entities
sadiqkhoja 0f5d716
Features #710: Return delete restore events in entities/:uuid/audits
sadiqkhoja 813fc25
Update API doc
sadiqkhoja 5be8b33
insert acteeId for the purged entities
sadiqkhoja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,11 +150,19 @@ const getBySubmissionId = (submissionId, options) => ({ all }) => _getBySubmissi | |
// There is a separate query below to assemble full submission details for non-deleted | ||
// submissions, but it was far too slow to have be part of this query. | ||
const _getByEntityId = (fields, options, entityId) => sql` | ||
SELECT ${fields} FROM entity_defs | ||
|
||
LEFT JOIN entity_def_sources on entity_def_sources.id = entity_defs."sourceId" | ||
INNER JOIN audits ON ((audits.details->>'entityDefId')::INTEGER = entity_defs.id OR (audits.details->>'sourceId')::INTEGER = entity_def_sources.id) | ||
|
||
SELECT ${fields} FROM ( | ||
SELECT audits.* FROM audits | ||
JOIN entities ON (audits.details->'entity'->>'uuid') = entities.uuid | ||
WHERE entities.id = ${entityId} | ||
Comment on lines
+154
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fetches all logs of the entity (create, update, delete, restore) |
||
UNION ALL | ||
SELECT audits.* FROM audits | ||
JOIN entity_def_sources ON (audits.details->>'sourceId')::INTEGER = entity_def_sources.id | ||
JOIN entity_defs ON entity_def_sources.id = entity_defs."sourceId" | ||
WHERE entity_defs."entityId" = ${entityId} AND audits.action = 'entity.bulk.create' | ||
Comment on lines
+158
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fetches only entity.bulk.create event |
||
) audits | ||
|
||
LEFT JOIN entity_defs ON (audits.details->>'entityDefId')::INTEGER = entity_defs.id | ||
LEFT JOIN entity_def_sources ON entity_defs."sourceId" = entity_def_sources.id OR (audits.details->>'sourceId')::INTEGER = entity_def_sources.id | ||
LEFT JOIN actors ON actors.id=audits."actorId" | ||
|
||
LEFT JOIN audits triggering_event ON entity_def_sources."auditId" = triggering_event.id | ||
|
@@ -165,7 +173,6 @@ SELECT ${fields} FROM entity_defs | |
LEFT JOIN audits submission_create_event ON (triggering_event.details->'submissionId')::INTEGER = (submission_create_event.details->'submissionId')::INTEGER AND submission_create_event.action = 'submission.create' | ||
LEFT JOIN actors submission_create_event_actor ON submission_create_event_actor.id = submission_create_event."actorId" | ||
|
||
WHERE entity_defs."entityId" = ${entityId} | ||
ORDER BY audits."loggedAt" DESC, audits.id DESC | ||
${page(options)}`; | ||
|
||
|
@@ -253,13 +260,17 @@ const getByEntityId = (entityId, options) => ({ all }) => { | |
|
||
// Look up the full Submission information and attempt to merge it in if it exists. | ||
const subOption = entityDefDict[audit.aux.def.id]; | ||
const fullSubmission = subOption.aux.submission | ||
.map(s => s.withAux('submitter', subOption.aux.submissionActor.orNull())) | ||
.map(s => s.withAux('currentVersion', subOption.aux.currentVersion.map(v => v.withAux('submitter', subOption.aux.currentSubmissionActor.orNull())))) | ||
.map(s => s.forApi()) | ||
.map(s => mergeLeft(s, { xmlFormId: subOption.aux.form.map(f => f.xmlFormId).orNull() })); | ||
let submission; | ||
|
||
if (subOption) { | ||
const fullSubmission = subOption.aux.submission | ||
.map(s => s.withAux('submitter', subOption.aux.submissionActor.orNull())) | ||
.map(s => s.withAux('currentVersion', subOption.aux.currentVersion.map(v => v.withAux('submitter', subOption.aux.currentSubmissionActor.orNull())))) | ||
.map(s => s.forApi()) | ||
.map(s => mergeLeft(s, { xmlFormId: subOption.aux.form.map(f => f.xmlFormId).orNull() })); | ||
|
||
const submission = mergeLeft(baseSubmission, fullSubmission.orElse(undefined)); | ||
submission = mergeLeft(baseSubmission, fullSubmission.orElse(undefined)); | ||
} | ||
|
||
// Note: The source added to each audit event represents the source of the | ||
// corresponding entity _version_, rather than the source of the event. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Objective of the change in this file is to get entity.delete and entity.restore logs as well