| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2007 John Hampton <pacopablo@pacopablo.com> |
|---|
| 4 | # All rights reserved. |
|---|
| 5 | # |
|---|
| 6 | # This software is licensed as described in the file COPYING, which |
|---|
| 7 | # you should have received as part of this distribution. |
|---|
| 8 | # |
|---|
| 9 | # Author: John Hampton <pacopablo@pacopablo.com> |
|---|
| 10 | |
|---|
| 11 | from trac.perm import DefaultPermissionStore |
|---|
| 12 | |
|---|
| 13 | __all__ = ['UserExtensiblePermissionStore'] |
|---|
| 14 | |
|---|
| 15 | class UserExtensiblePermissionStore(DefaultPermissionStore): |
|---|
| 16 | """ Default Permission Store extended to list all ldap groups """ |
|---|
| 17 | |
|---|
| 18 | def get_all_permissions(self): |
|---|
| 19 | """Return all permissions for all users. |
|---|
| 20 | |
|---|
| 21 | The permissions are returned as a list of (subject, action) |
|---|
| 22 | formatted tuples.""" |
|---|
| 23 | self.log.debug("calling super.get_all_permissions") |
|---|
| 24 | permissions = super(UserExtensiblePermissionStore, self).get_all_permissions() |
|---|
| 25 | self.log.debug("super.get_all_permissions: %s", permissions) |
|---|
| 26 | |
|---|
| 27 | daProvider = None |
|---|
| 28 | for provider in self.group_providers: |
|---|
| 29 | if provider.__class__.__name__ == "DirAuthStore": |
|---|
| 30 | daProvider = provider |
|---|
| 31 | |
|---|
| 32 | if daProvider == None: |
|---|
| 33 | return permissions |
|---|
| 34 | |
|---|
| 35 | filteredPermissions = []; |
|---|
| 36 | for p in permissions: |
|---|
| 37 | if p[1][0:1] != "@": |
|---|
| 38 | filteredPermissions.append(p) |
|---|
| 39 | |
|---|
| 40 | group_nameattr = \ |
|---|
| 41 | self.config.get('account-manager', 'group_nameattr', 'cn') |
|---|
| 42 | all_groups = daProvider.get_all_groups() |
|---|
| 43 | for g in all_groups: |
|---|
| 44 | users = daProvider.get_group_users(g[1][group_nameattr][0]) |
|---|
| 45 | if len(users) == 0: |
|---|
| 46 | users.append("(nobody)") |
|---|
| 47 | for u in users: |
|---|
| 48 | filteredPermissions.append([u, "@%s" % g[1][group_nameattr][0]]) |
|---|
| 49 | |
|---|
| 50 | self.log.debug("permissions: %s", filteredPermissions) |
|---|
| 51 | return filteredPermissions |
|---|