Trac 0.11: Creating your own permissions

Trac Add comments

To add permissions to Trac 0.11 you simply need to add a myPermissions.py file to your Trac environment plugin folder that looks like this:

from trac.core import Component, implements
from trac.perm import IPermissionRequestor

class MyPermissions(Component):
implements(IPermissionRequestor)

def get_permission_actions(self):
return ('MY_FIRST_PERM', 'MY_SECOND_PERM')

Add your set of permissions to the return command in place of 'MY_FIRST_PERM', 'MY_SECOND_PERM', restart apache and you should be away.

You can now use these permission in your work flow against actionname.permissions entries.

NOTE: you don't need to call the file "myPermissions.py" - its just needs to be a python file with a name of your choosing.

3 responses to “Trac 0.11: Creating your own permissions”

  1. Roberto Says:
    Hi,

    Your sugesttion will be very useful. Although I can't use this script. I have just copy and paste your lines in a new file named myPermissions.py(I know this name is just a suggestion..) inside my plugin folder and restart the server. My server is a standalone application. Could you help me, please?

    Thanks,
  2. PythonGuy Says:
    Probably due to the fact that this web site doesn't allow any formatting or [code] tags.

    if you aren't familiar with python, the following needs to be done:
    class MyPermissions(Component):
    4 spaces->implements(IPermissionRequestor)

    4 spaces->def get_permission_actions(self):
    8 spaces->return ('MY_FIRST_PERM',#39;MY_SECOND_PERM')

    the last line is also a single line like: return (...)
    don't forget the extra indent.

    4/8 spaces are arbitrary, they just has to match that section of code consistently, 3, 6 will work, 2, 5 will work...etc.
  3. Stephen Moretti Says:
    Sorry for not getting back to you before now.

    You are correct. The indentation in python is important and I apologise for the broken code formatting... I'm working on resolving that one as soon as possible.

Leave a Reply





Powered by Mango Blog. Design and Icons by N.Design Studio