Mercurial > p > roundup > code
annotate 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 |
| rev | line source |
|---|---|
|
8544
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
1 # HTML pages don't provide a way to change the contents of a file. |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
2 # However REST does allow setting content and the HTML interface can |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
3 # be directed to update the content as well. This detector |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
4 # prevents changes to file content. |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
5 |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
6 from roundup.exceptions import UsageError |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
7 |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
8 def immutable_file_contents(db, cl, nodeid, newvalues): |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
9 ''' Prevent content changes to a file |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
10 ''' |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
11 if 'content' in newvalues: |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
12 raise UsageError("File contents are immutable. " |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
13 "Rejecting change to contents.") |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
14 |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
15 |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
16 def init(db): |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
17 """If you have other FileClass based classes add them here.""" |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
18 |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
19 # fire before changes are made |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
20 db.file.audit('set', immutable_file_contents) |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
21 db.msg.audit('set', immutable_file_contents) |
|
e738377b4ffe
feature: add detector that prevents file content changes by Admin and other users.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
22 |
