1 # Copyright (c) 2008 by Florian Friesdorf
3 # GNU Affero General Public License (AGPL)
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation; either version 3 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public
16 # License along with this program. If not, see
17 # <http://www.gnu.org/licenses/>.
20 __author__
= "Florian Friesdorf <flo@chaoflow.net>"
21 __docformat__
= "plaintext"
24 from AccessControl
import ClassSecurityInfo
26 from Globals
import InitializeClass
28 from Products
.PageTemplates
.PageTemplateFile
import PageTemplateFile
30 from Products
.PluggableAuthService
.plugins
.BasePlugin
import BasePlugin
31 from Products
.PluggableAuthService
.interfaces
.plugins \
34 from zope
.app
.security
.interfaces
import IAuthentication
35 from zope
.app
.security
.interfaces
import PrincipalLookupError
36 from zope
.component
import getUtility
37 from zope
.interface
import implements
40 manage_addGroupsPluginForm
= PageTemplateFile(
41 '../www/GroupsPluginForm',
42 globals(), __name__
='manage_addGroupsPluginForm' )
45 def addGroupsPlugin( dispatcher
, id, title
=None, REQUEST
=None ):
46 """Add a paula.plonepas GroupsPlugin to a PluggableAuthService.
48 plugin
= GroupsPlugin(id, title
)
49 dispatcher
._setObject
(plugin
.getId(), plugin
)
51 if REQUEST
is not None:
52 REQUEST
['RESPONSE'].redirect(
54 '?manage_tabs_message='
55 'paula.plonepas.GroupsPlugin+added.'
56 % dispatcher
.absolute_url())
59 class GroupsPlugin(BasePlugin
):
62 security
= ClassSecurityInfo()
64 implements(IGroupsPlugin
)
66 meta_type
= "Paula PAS Groups Plugin"
68 def __init__(self
, id, title
=None):
69 self
._id
= self
.id = id
72 security
.declarePrivate('getGroupsForPrincipal')
73 def getGroupsForPrincipal(self
, principal
, request
=None):
74 """ principal -> ( group_1, ... group_N )
76 o Return a sequence of group names to which the principal
77 (either a user or another group) belongs.
79 o May assign groups based on values in the REQUEST object, if present
81 # get principal from pau
82 pau
= getUtility(IAuthentication
)
84 p
= pau
.getPrincipal(principal
.getId())
85 except PrincipalLookupError
:
91 # eventually we need to return allGroups from an
92 # IGroupClousureAwarePrincipal
93 return tuple(p
.groups
)
96 InitializeClass( GroupsPlugin
)