Create revision history entries for secret-changes via API#266
Create revision history entries for secret-changes via API#266JensH0rnung wants to merge 4 commits into
Conversation
| current_data = instance.current_revision.peek_data(self.request.user) | ||
| RevisionService.save_payload(secret=instance, actor=self.request.user, payload=current_data) |
There was a problem hiding this comment.
I think this might be an issue for file secrets, peek_data returns raw bytes, but the payload parameter needs to be json-serializeable.
In the view, we guard it like this:
if secret.content_type == ContentType.FILE and isinstance(current_data, (bytes, bytearray)):
current_data = {'file_content': base64.b64encode(current_data).decode()}There was a problem hiding this comment.
Nice! Though I still think there's an issue here, that I missed on my first review.
peek_data only returns the file contents; if the payload was stored with a file_name, this would erase that on metadata changes. I think the best way around this would be to make the payload optional in the RevisionService.save_payload(), and use secret.current_revision if it's None there.
That way, we don't need all this peek_data and the file-type guard, it just collapses to
elif instance.current_revision:
RevisionService.save_payload(secret=instance, actor=self.request.user, payload=None)
We can then also do the same for the browser view.
Feature:
Changes to a secret via the API now create an entry in the revision history of this secret. Before, entries were only created if changes were made in the browser.
Styling the revision history: