view detectors/immutable_file_contents.py @ 8586:31a8a6faa2fa

bug: Allow UsageError exception to use more specific error code UsageError exception returned 400 error code but should return 405 when generated for a bad http method. Modified error handler to use 400 error code if self.response_code was less then 400. This should reproduce the standard error of 400 if one was not specified and preserve any other explicitly set response code. Also enhanced a test case to verify the 405 is returned.
author John Rouillard <rouilj@ieee.org>
date Mon, 20 Apr 2026 03:09:30 -0400
parents e738377b4ffe
children
line wrap: on
line source

# HTML pages don't provide a way to change the contents of a file.
# However REST does allow setting content and the HTML interface can
# be directed to update the content as well. This detector
# prevents changes to file content.

from roundup.exceptions import UsageError

def immutable_file_contents(db, cl, nodeid, newvalues):
    ''' Prevent content changes to a file
    '''
    if 'content' in newvalues:
        raise UsageError("File contents are immutable. "
                         "Rejecting change to contents.")


def init(db):
    """If you have other FileClass based classes add them here."""

    # fire before changes are made
    db.file.audit('set', immutable_file_contents)
    db.msg.audit('set', immutable_file_contents)


Roundup Issue Tracker: http://roundup-tracker.org/