Mercurial > p > roundup > code
comparison detectors/immutable_file_contents.py @ 8544:e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
New detector and upgrading announcement. Also example of stripping
content editing from the User role.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 24 Mar 2026 22:11:27 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 8543:1ffa1f42e1da | 8544:e738377b4ffe |
|---|---|
| 1 # HTML pages don't provide a way to change the contents of a file. | |
| 2 # However REST does allow setting content and the HTML interface can | |
| 3 # be directed to update the content as well. This detector | |
| 4 # prevents changes to file content. | |
| 5 | |
| 6 from roundup.exceptions import UsageError | |
| 7 | |
| 8 def immutable_file_contents(db, cl, nodeid, newvalues): | |
| 9 ''' Prevent content changes to a file | |
| 10 ''' | |
| 11 if 'content' in newvalues: | |
| 12 raise UsageError("File contents are immutable. " | |
| 13 "Rejecting change to contents.") | |
| 14 | |
| 15 | |
| 16 def init(db): | |
| 17 """If you have other FileClass based classes add them here.""" | |
| 18 | |
| 19 # fire before changes are made | |
| 20 db.file.audit('set', immutable_file_contents) | |
| 21 db.msg.audit('set', immutable_file_contents) | |
| 22 |
