Ok, so it looks I can't replace the store attribute in
PermissionSystem anyway, as it's a python descriptor.
i'm getting the following error:
2007-07-26 14:58:02,723 Trac[main] ERROR: can't set attribute
Traceback (most recent call last):
File "D:\Python24\Lib\site-packages\trac\web\main.py", line 406, in
dispatch_request
dispatcher.dispatch(req)
File "D:\Python24\Lib\site-packages\trac\web\main.py", line 183, in
dispatch
req.perm = PermissionCache(self.env, req.authname)
File "D:\Python24\Lib\site-packages\trac\perm.py", line 263, in
__init__
self.perms = PermissionSystem(env).get_user_permissions(username)
File "D:\Python24\Lib\site-packages\trac\perm.py", line 227, in
get_user_permissions
for perm in self.store.get_user_permissions(username):
File "D:\Python24\Lib\site-packages\trac\config.py", line 376, in
__get__
for impl in self.xtnpt.extensions(instance):
File "D:\Python24\Lib\site-packages\trac\core.py", line 55, in
extensions
return filter(None, [component.compmgr[cls] for cls in
extensions])
File "D:\Python24\Lib\site-packages\trac\core.py", line 179, in
__getitem__
component = cls(self)
File "D:\Python24\Lib\site-packages\trac\core.py", line 98, in
maybe_init
init(self)
File "build\bdist.win32\egg\tracsuperuser\superuser.py", line 25, in
__init__
File "D:\Python24\Lib\site-packages\trac\config.py", line 335, in
__set__
raise AttributeError, 'can\'t set attribute'
AttributeError: can't set attribute
Any idea on how to set the PermissionSystem.store attribute, or should
I try other way? I can think of making a child class of
PermissionSystem and replace the store attribute as needed, but then,
¿How can I replace the existing instance of PermissionSystem component
with my own instance?
Thanks very much.
On 26 jul, 14:16, Álvaro "J. Iradier Muro"
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm working on a small plugin for Trac. We user AccountManager and an
> external htusers.digest file for storing users and passwords for all
> available projects.
>
> I want to have an 'admin' superuser which has TRAC_ADMIN permissions
> without having to give the permission in every existing project.
>
> This is my approach. I'm creating a plugin that implements
> IPermissionStore. I want my plugin to replace the current
> PermissionStore (set on trac.ini), whatever it is. All methods in my
> permission store call the previous permission store methods, except for
> get_user_permissions(), where I check if the username is 'admin', then
> always return 'TRAC_ADMIN'. Also, in get_all_permissions(), I add the
> tuple ('admin', 'TRAC_ADMIN') to the permissions list.
>
> In the __init__ method I try to save the previous PermissionStore, and
> set a new one in PermissionSystem.store, but apparently it doesn't
> work.
>
> Summary:
>
> 1. In trac.ini, permission_store = DefaultPermissionStore (or any
> others, not my own PermissionStore)
> 2. When my plugin loads, save PermissionSystem.store as old_store, and
> set my own PermissionStore (SuperUserPlugin) which will wrap the current
> store methods.
> 3. When IPermissionStore methods are called, my wrapper will invoke the
> old_store methods after checking some conditions.
>
> Problem is: Apparently, the plugin is loaded and active
>
> The code for the plugin is:
>
> -------------- Begin code ------------------
>
> class SuperUserPlugin(Component):
> """ Adds a superuser with TRAC_ADMIN permissions """
> implements(IPermissionStore)
>
> def __init__(self):
>
> #Replace current PermissionStore
> perm_system = PermissionSystem(self.env)
> self.default_store = getattr(perm_system,'store')
> setattr(perm_system, 'store', self)
>
> #The following will fail with "Attribute can't be set"
> #perm_system.store = self
>
> def get_user_permissions(self, username):
> if username == 'admin':
> return ['TRAC_ADMIN']
> return self.default_store.get_user_permissions(username)
>
> def get_all_permissions(self):
> return self.default_store.get_all_permissions() \
> + ('admin', 'TRAC_ADMIN')
>
> def grant_permission(self, username, action):
> return self.default_store.grant_permission(username, action)
>
> def revoke_permission(self, username, action):
> return self.default_store.revoke_permission(username, action)
>
> -------------- End code ------------------
>
> Thanks very much, any help will be appreciated.
>
> --
> --------------------------------------
>
> Álvaro J. Iradier Muro
> [EMAIL PROTECTED]
>
> AM&B - Dept. de Desarrollo e I+D
>
> signature.asc
> 1 KDescargar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en
-~----------~----~----~----~------~----~------~--~---