On Jul 27, 2007, at 8:16 AM, Álvaro J. Iradier Muro wrote:
> El jue, 26-07-2007 a las 15:32 -0400, Erik Bray escribió: >> PermissionSystem.store is an ExtensionOption, and can't (and >> shouldn't) be set like that, as you've already discovered. What this >> means is that it's an option you set in your trac.ini file. >> Specifically, you should set 'permission_store = SuperUserPlugin' in >> the [trac] section. >> >> That way, your PermissionSystem will use the correct IPermissionStore >> implementation. > > Thanks, I noticed, but I wanted a way to make it transparent to the > user. Just install the plugin, and keep the current permission_store > setting > >> Also, instead of self.default_store...., just have your >> SuperUserPlugin inherit from DefaultPermissionStore. For example: >> >> class SuperUserPlugin(DefaultPermissionStore): >> def get_user_permissions(self, username): >> if username == 'admin': >> return ['TRAC_ADMIN'] >> return DefaultPermissionStore.get_user_permissions(self, >> username) > > Yes, but if the user has permission_store = AnotherPermissionStore, I > want my plugin to wrap that AnotherPermissionStore, not > DefaultPermissionStore. That's why I do the self.default_store trick. > >> And so on and so forth. Something along those lines should work. > > Thanks, I got it working without the transparent PermissionStore > replacement, manually setting permission_store = SuperUserPlugin, > and a > new setting: wrapper_permission_store = DefaultPermissionStore > > I'll upload this and other plugins we've been working on to track- > hacks, > including: > > * SearchAllProjects: adds a new filter to search in all projects > in the > parent path. Similar to MetaSearch, but opening the environments > instead > of using XMLRPC > * CustomCSS: Allows to insert a custom CSS sheet in every request, to > override trac.css style settings. You mean http://trac-hacks.org/wiki/SysCssPlugin? ;-) > > Thanks very much. > >> On 7/26/07, Á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 >>> >>> >> >> >> > -- > -------------------------------------- > > Álvaro J. Iradier Muro > [EMAIL PROTECTED] > > AM&B - Dept. de Desarrollo e I+D --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
