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

Revision history doesn't work for custom components. #64

Open
thejohnbrown opened this issue Aug 25, 2022 · 3 comments
Open

Revision history doesn't work for custom components. #64

thejohnbrown opened this issue Aug 25, 2022 · 3 comments

Comments

@thejohnbrown
Copy link
Contributor

Hello,

I have noticed that the revision history feature does not work for custom components. For example, I have a custom component called Conclusion which is essentially just a two text fields, one for the title and one for the main text. If I make changes to this component and click on the revision history button, it won't have created a new revision and instead just says "Current Text".

Cheers.

@thejohnbrown
Copy link
Contributor Author

I think I have found the source of the problem https://github.com/blacklanternsecurity/writehat/blob/master/writehat/lib/db.py#L261

        if self['type'] == "MarkdownComponent":
            self.updateRevision()

The if statement checks whether the component is of type "MarkdownComponent" when mine is called "CustomComponent" so this if statement is not triggered.

@kerrymilan
Copy link
Collaborator

Correct. This is a known issue we've documented internally but haven't had a chance to patch. There's another layer to it: the updateRevision() function itself assumes the fieldName being changed is named text (see: db.py#236 and db.py#247), which is true for Markdown components but may not be true for custom components.

Revision functionality in general is something we'd like to revisit next time we have a chance. We plan to reimplement most of the current functionality using Django's post_save() signal. This would simplify other efforts (like what you're doing with the API) by limiting the number of places where we're calling our custom code.

For now, changing if self['type'] == "MarkdownComponent": to if "text" in self.keys(): seems to fix the immediate issue without exacerbating the hard-coded fieldName bug. We'll do some additional testing next week and push a fix to that effect once we've confirmed.

@thejohnbrown
Copy link
Contributor Author

Any update on the fix for this?

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

No branches or pull requests

2 participants