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

[Issue #3500] Handle opportunity attachments when opp deleted or is published #3503

Conversation

chouinar
Copy link
Collaborator

Summary

Fixes #3500

Time to review: 10 mins

Changes proposed

Handle the following two cases during the transformation process

  • Opportunity deleted - clean up attachments from s3
  • Opportunity stops being a draft - move all the attachments to the other s3 bucket

Context for reviewers

Mostly just some additional file utils for moving files to handle the above scenarios. Only noteworthy callout is that there isn't really a concept of "moving" a file on s3, it's just a copy+delete.

@@ -53,11 +66,18 @@ def process_opportunity(
extra,
)

# Cleanup the attachments from s3
if target_opportunity is not None:
for attachment in target_opportunity.opportunity_attachments:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just making sure I understand the flow here. target_opportunity is an existing record on our side, that we're replacing due to an update. So this is effectively the "old" attachments and so we're cleaning those out and then we'll put "back" any attachments that are still referenced, and any net new attachments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see now these are deleted Opportunities only so there's no putting back, deleting is the final state.

# If an opportunity went from being a draft to not a draft (published)
# then we need to move all of its attachments to the public bucket
# from the draft s3 bucket.
if was_draft and transformed_opportunity.is_draft is False:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I am mis-understanding in my comment above, because if I'm reading that right, would we not have deleted the draft entries above?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Never mind, I saw in the other review a little more context around the above section and see now that it's only deleting them if the record is marked as deleted.

# Cleanup the attachments from s3
if target_opportunity is not None:
for attachment in target_opportunity.opportunity_attachments:
file_util.delete_file(attachment.file_location)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this delete all revisions of a file (is the bucket using versioning?) If not, we may need to delete all past revisions as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't have versioning on the bucket.

Copy link
Collaborator

@mikehgrantsgov mikehgrantsgov left a comment

Choose a reason for hiding this comment

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

If revisions are not considered / important to delete, then looks good! If not, I would account for this and then merge.

@chouinar chouinar merged commit 4ebfef7 into chouinar/file-attachment-transform Jan 16, 2025
2 checks passed
@chouinar chouinar deleted the chouinar/3500-draft-delete-opp-attachments branch January 16, 2025 17:47
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.

3 participants