blacklanternsecurity/writehat

Revision history doesn't work for custom components.

thejohnbrown opened this issue · 3 comments

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.

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.

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.

Any update on the fix for this?