Re: Creating an auditor to prevent some users from deleting issues/messages/files

Ralf Schlatterbeck <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.user
Message-ID <[email protected]>
On Wed, Mar 04, 2015 at 05:34:36PM -0800, Dan Tenenbaum wrote:
> 
> #!/usr/bin/env python
> from roundup.exceptions import Reject
> 
> def auditme(db, cl, nodeid, newvalues):
>     roles = db.getnode("user", db.getuid())['roles'].split(",")
>     roles = [x.strip() for x in roles]
>     if not ("Admin" in roles or "User" in roles):
>         raise Reject("You cannot delete this item.")
> 
> def init(db):
>     db.issue.audit('retire', auditme)
>     db.msg.audit('retire', auditme)
>     db.file.audit('retire', auditme)
> 
> The "auditme" function is never called. I tried changing 'retire' to
> 'remove' but got an error. What are the various verbs that can be
> passed to audit() and where are they defined? 

The actions you can pass to the audit registration method (as well as
the 'react' registration method) are 'set', 'create', 'retire',
'restore'. You find them in the backend implementations (mostly
backends/rdbms_common.py for all the sql backends and back_anydbm.py for
dbm) in the fireAuditors / fireReactors calls. The actual definitions
for which values are allowed are in the 'Class' constructor in
hyperdb.py, you want to look for
actions = "create set retire restore".split()
And they should also be described in the documentation, I've not
checked.

Note that removing a message or a file from an issue does *not*
automagically retire it, that's probably the reason why your auditor
isn't called (but you don't tell us how you're trying to retire the
issue). The message is just unlinked from the 'messages' (or 'files')
multilink property of the issue. This means you should create an auditor
on issue that checks if any messages/files are deleted from the lists.
You would checks this by comparing 'newvalues' (a dictionary with the
changed property names as a key and the new value as the value) to
'cl.get (nodeid, 'messages')'. (I'm qouting 'messages' and 'files' from
memory here, maybe I'm not remembering the names correctly)

Ralf
-- 
Dr. Ralf Schlatterbeck                  Tel:   +43/2243/26465-16
Open Source Consulting                  www:   http://www.runtux.com
Reichergasse 131, A-3411 Weidling       email: [email protected]
allmenda.com member                     email: [email protected]

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.