[Zope3-checkins]
SVN: Zope3/trunk/src/zope/app/authentication/groupfolder.
Added logic to existing subscriber to mark groups with IGroup
Jim Fulton
jim at zope.com
Mon Jan 24 18:05:06 EST 2005
Log message for revision 28950:
Added logic to existing subscriber to mark groups with IGroup
interface.
Changed:
U Zope3/trunk/src/zope/app/authentication/groupfolder.py
U Zope3/trunk/src/zope/app/authentication/groupfolder.txt
-=-
Modified: Zope3/trunk/src/zope/app/authentication/groupfolder.py
===================================================================
--- Zope3/trunk/src/zope/app/authentication/groupfolder.py 2005-01-24 23:05:03 UTC (rev 28949)
+++ Zope3/trunk/src/zope/app/authentication/groupfolder.py 2005-01-24 23:05:05 UTC (rev 28950)
@@ -26,8 +26,11 @@
from persistent import Persistent
import zope.interface
+from zope.interface import alsoProvides
import zope.schema
+from zope.security.interfaces import IGroup
+
from zope.app import zapi
from zope.app.container.btree import BTreeContainer
import zope.app.container.constraints
@@ -239,3 +242,8 @@
principal.groups.extend(
groupfolder.getGroupsForPrincipal(principal.id),
)
+ id = principal.id
+ prefix = groupfolder.prefix
+ if id.startswith(prefix) and id[len(prefix):] in groupfolder:
+ alsoProvides(principal, IGroup)
+
Modified: Zope3/trunk/src/zope/app/authentication/groupfolder.txt
===================================================================
--- Zope3/trunk/src/zope/app/authentication/groupfolder.txt 2005-01-24 23:05:03 UTC (rev 28949)
+++ Zope3/trunk/src/zope/app/authentication/groupfolder.txt 2005-01-24 23:05:05 UTC (rev 28950)
@@ -22,11 +22,12 @@
To illustrate the group interaction with the authentication service,
we'll create a sample authentication service:
- >>> import zope.interface
- >>> from zope.app.security.interfaces import IAuthentication
+ >>> from zope import interface
+ >>> from zope.app.security.interfaces import IAuthentication, IPrincipal
>>> from zope.app.authentication.groupfolder import setGroupsForPrincipal
>>> class Principal:
+ ... interface.implements(IPrincipal)
... def __init__(self, id, title, description):
... self.id, self.title, self.description = id, title, description
... self.groups = []
@@ -37,7 +38,7 @@
>>> class Principals:
...
- ... zope.interface.implements(IAuthentication)
+ ... interface.implements(IAuthentication)
...
... def __init__(self, groups):
... self.principals = {
@@ -168,3 +169,30 @@
>>> list(groups.search({}))
[]
+
+Identifying groups
+------------------
+
+The function, `setGroupsForPrincipal`, is a subscriber to
+principal-creation events. It adds any group-folder-defined groups to
+users in those groups:
+
+ >>> principal = principals.getPrincipal('p1')
+ >>> principal.groups
+ [u'group.G1', u'group.GA']
+
+Of course, this applies to groups too:
+
+ >>> principal = principals.getPrincipal('group.G1')
+ >>> principal.groups
+ [u'group.G2']
+
+In addition to setting principal groups, the `setGroupsForPrincipal`
+function also declares the `IGroup` interface on groups:
+
+ >>> [iface.__name__ for iface in interface.providedBy(principal)]
+ ['IGroup', 'IPrincipal']
+
+ >>> [iface.__name__
+ ... for iface in interface.providedBy(principals.getPrincipal('p1'))]
+ ['IPrincipal']
More information about the Zope3-Checkins
mailing list