[Zope3-checkins] SVN: Zope3/trunk/ Moved group to zope.app.groupscontainer

Jim Fulton jim at zope.com
Tue Oct 19 18:06:16 EDT 2004


Log message for revision 28219:
  Moved group to zope.app.groupscontainer
  
  (and did some cleanups, like fitting lines in 80 characters and decoy
  removal.)
  

Changed:
  D   Zope3/trunk/package-includes/security-configure.zcml
  U   Zope3/trunk/src/zope/app/groupscontainer/configure.zcml
  A   Zope3/trunk/src/zope/app/groupscontainer/group.py
  A   Zope3/trunk/src/zope/app/groupscontainer/groups_principals.txt
  U   Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt
  U   Zope3/trunk/src/zope/app/groupscontainer/tests.py
  D   Zope3/trunk/src/zope/security/configure.zcml
  D   Zope3/trunk/src/zope/security/group.py
  D   Zope3/trunk/src/zope/security/groupprincipals.txt
  D   Zope3/trunk/src/zope/security/tests/groups_principals.txt
  D   Zope3/trunk/src/zope/security/tests/test_group.py

-=-
Deleted: Zope3/trunk/package-includes/security-configure.zcml
===================================================================
--- Zope3/trunk/package-includes/security-configure.zcml	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/package-includes/security-configure.zcml	2004-10-19 22:06:15 UTC (rev 28219)
@@ -1 +0,0 @@
-<include package="zope.security"/>

Modified: Zope3/trunk/src/zope/app/groupscontainer/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/configure.zcml	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/src/zope/app/groupscontainer/configure.zcml	2004-10-19 22:06:15 UTC (rev 28219)
@@ -4,29 +4,64 @@
     i18n_domain="groupscontainer"
     xmlns:i18n="http://namespaces.zope.org/i18n"
     >
+      
+<content class=".group.Group">
+    <require
+        permission="zope.ManageContent"
+        interface=".interfaces.IGroup"
+        set_schema=".interfaces.IGroup"
+        />
+    <require
+        permission="zope.ManageContent"
+        interface="zope.app.groupscontainer.interfaces.IGroupContained"
+        />
+    <implements
+        interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
+        />
+</content>
     
-  <browser:tool
-      interface=".interfaces.IGroupsFolder"
-      title="Groups Folder"
-      description="Groups Folder"
-      />
+<browser:addMenuItem
+    title="Group"
+    description="A principals group"
+    class=".group.Group"
+    permission="zope.ManageServices"
+    />
+  
+<browser:editform
+    schema=".interfaces.IGroup"
+    label="Change group information"
+    name="edit.html"
+    menu="zmi_views" title="Edit"
+    permission="zope.ManageContent"
+    />
+    
+<subscriber
+    factory="zope.app.groupscontainer.group.setGroupsForPrincipal"
+    for="zope.app.pas.interfaces.IAuthenticatedPrincipalCreated"
+    />
+  
+<browser:tool
+    interface=".interfaces.IGroupsFolder"
+    title="Groups Folder"
+    description="Groups Folder"
+    />
 
-  <localUtility class=".groupsfolder.GroupsFolder">
-    <implements
-        interface=".interfaces.IGroupsFolder" />
-    <implements
-        interface="zope.app.annotation.IAttributeAnnotatable" />
-    <require
-        permission="zope.ManageServices"
-        interface="zope.app.container.interfaces.IContainer" />
-  </localUtility>
+<localUtility class=".groupsfolder.GroupsFolder">
+  <implements
+      interface=".interfaces.IGroupsFolder" />
+  <implements
+      interface="zope.app.annotation.IAttributeAnnotatable" />
+  <require
+      permission="zope.ManageServices"
+      interface="zope.app.container.interfaces.IContainer" />
+</localUtility>
 
-  <browser:addMenuItem
-      title="Groups Folder"
-      description="A Groups folder"
-      class=".groupsfolder.GroupsFolder"
-      permission="zope.ManageServices"
-      />
+<browser:addMenuItem
+    title="Groups Folder"
+    description="A Groups folder"
+    class=".groupsfolder.GroupsFolder"
+    permission="zope.ManageServices"
+    />
       
 <browser:containerViews
      for=".interfaces.IGroupsFolder"

Copied: Zope3/trunk/src/zope/app/groupscontainer/group.py (from rev 28212, Zope3/trunk/src/zope/security/group.py)
===================================================================
--- Zope3/trunk/src/zope/security/group.py	2004-10-18 20:01:20 UTC (rev 28212)
+++ Zope3/trunk/src/zope/app/groupscontainer/group.py	2004-10-19 22:06:15 UTC (rev 28219)
@@ -0,0 +1,82 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Zope Group implementation
+
+$Id: group.py 27237 2004-10-12 09:33:00 mriya3 $
+
+"""
+
+from zope.security.interfaces import IGroup
+from zope.app.pas.interfaces import IAuthenticatedPrincipalCreated
+from persistent import Persistent
+from zope.interface import implements, alsoProvides
+from zope.app.groupscontainer.interfaces import IGroupContained, IGroupsFolder
+from zope.security.interfaces import IGroupAwarePrincipal
+from types import StringTypes
+import zope.app.zapi
+from zope.event import notify
+
+
+class Group(Persistent):
+
+    implements(IGroup, IGroupContained)
+    
+    __parent__ = __name__ = None
+    
+    def __init__(self, id='', title='', description='', principalsids=[]):
+        self.id = id
+        self.title = title
+        self.description = description
+        self.__principals = principalsids
+        
+    def addPrincipals(self, *principalIds):
+        tmpNewList = self.__principals
+        for principalId in principalIds:
+            if not principalId in self.__principals:
+                tmpNewList.append(principalId)
+        self.setPrincipals(tmpNewList)
+        if self.__parent__ is not None:
+            self.__parent__.updateMappingForPrincipals(*principalIds)
+
+    def removePrincipals(self, *principalIds):
+        tmpNewList = self.__principals
+        for principalId in principalIds:
+            if principalId in tmpNewList:
+                tmpNewList.remove(principalId)
+        self.setPrincipals(tmpNewList)
+        if self.__parent__ is not None:
+            self.__parent__.updateMappingForPrincipals(*principalIds)
+        
+    def containsPrincipal(self, principalId):
+        return principalId in self.__principals
+        
+    def getPrincipals(self):
+        return self.__principals
+        
+    def setPrincipals(self, prinlist):
+        origprincipals = self.__principals
+        self.__principals = prinlist
+        
+    principals = property(getPrincipals, setPrincipals)
+    
+
+def setGroupsForPrincipal(event):
+    """Set group information when a principal is created"""
+    principal = event.principal
+    alsoProvides(principal, IGroupAwarePrincipal)
+    principal.groups = []
+    groupfolders = zope.app.zapi.getUtilitiesFor(IGroupsFolder)
+    for name, groupfolder in groupfolders:
+        groups = groupfolder.getGroupsForPrincipal(principal.id)
+        principal.groups.extend(groups)

Copied: Zope3/trunk/src/zope/app/groupscontainer/groups_principals.txt (from rev 28212, Zope3/trunk/src/zope/security/tests/groups_principals.txt)
===================================================================
--- Zope3/trunk/src/zope/security/tests/groups_principals.txt	2004-10-18 20:01:20 UTC (rev 28212)
+++ Zope3/trunk/src/zope/app/groupscontainer/groups_principals.txt	2004-10-19 22:06:15 UTC (rev 28219)
@@ -0,0 +1,54 @@
+Groups & Principals
+===================
+
+We import the needed modules
+
+  >>> from zope.app.groupscontainer.group import Group
+  >>> from zope.security.interfaces import IGroupAwarePrincipal
+  >>> from zope.app.groupscontainer.groupsfolder import GroupsFolder
+  >>> from zope.app.groupscontainer.interfaces import IGroupsFolder
+  >>> from zope.app.pas.principalplugins import PrincipalFactory
+  >>> from zope.publisher.tests.httprequest import TestRequest
+  >>> import zope.app.zapi
+
+We first create a group folder and add some groups:
+
+  >>> name, groups = list(zope.app.zapi.getUtilitiesFor(IGroupsFolder))[0]
+  >>> geeks = Group(id='geeks', principalsids=['srichter','jim'])
+  >>> newbies = Group(id='newbies', principalsids=['amos','claudia'])
+  >>> sprinters = Group(id='sprinters', 
+  ...                   principalsids=['srichter', 'jim', 'amos','claudia'])
+  >>> for g in [geeks, sprinters, newbies]: groups[g.id] = g
+
+Now we create some principals and check if they operate correctly:
+
+1) Instantiate a Principal Factory
+
+  >>> pf  = PrincipalFactory()
+    
+2) Get some principals
+
+  >>> srichter = pf.createAuthenticatedPrincipal('srichter', {} , 
+  ...                                            TestRequest())
+  >>> IGroupAwarePrincipal.providedBy(srichter)
+  True
+  >>> groups.getGroupsForPrincipal(srichter.id)
+  ['geeks', 'sprinters']
+  >>> thomas = pf.createAuthenticatedPrincipal('thomas', {} , TestRequest())
+  >>> groups.getGroupsForPrincipal(thomas.id)
+  []
+  >>> amos = pf.createAuthenticatedPrincipal('amos', {} , TestRequest())
+  >>> groups.getGroupsForPrincipal(amos.id)
+  ['sprinters', 'newbies']
+    
+3) Now we add a group and check that getGroupsForPrincipal gets updated but 
+   principal group info gets NOT updated:
+
+  >>> thinkers = Group(id='thinkers', 
+  ...                  principalsids=['srichter', 'jim', 'thomas','robert'])
+  >>> groups[thinkers.id] = thinkers
+  >>> groups.getGroupsForPrincipal(srichter.id)
+  ['geeks', 'sprinters', 'thinkers']
+  >>> srichter.groups
+  ['geeks', 'sprinters']
+    

Modified: Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/src/zope/app/groupscontainer/groupsfolder.txt	2004-10-19 22:06:15 UTC (rev 28219)
@@ -1,139 +1,152 @@
 Groups Folder Implementation
 ============================
 
-The GroupsFolder class offers a groups container that mantains maps between groups and principals as 
-well as maps from principals to groups.
+The GroupsFolder class offers a groups container that mantains maps
+between groups and principals as well as maps from principals to
+groups.
 
-We test that we can add a Group to a GroupsFolder;
-we also check that it is possible to retrieve principals
-from a given group id and, vice-versa, get a list of groups
-a principal belongs to by providing its id.
-   
-      >>> import zope.interface
-      >>> from zope.security.interfaces import IGroupAwarePrincipal, IGroup
-      >>> from zope.security.group import Group
-      >>> from zope.app.groupscontainer.interfaces import IGroupsFolder, IGroupContained
-      >>> from zope.app.groupscontainer.groupsfolder import GroupsFolder
-      >>> from zope.interface import implements
-      >>> class GoldrakePrincipal:
-      ...     implements(IGroupAwarePrincipal)
-      ...     id = '0'
-      ...     title = 'Goldrake'
-      ...     description = 'Ufo robot'
-      ...     groups = ['superheroes', 'robots']
-      >>> class MazingaPrincipal:
-      ...     implements(IGroupAwarePrincipal)
-      ...     id = '1'
-      ...     title = 'Mazinga'
-      ...     description = 'Mazinga Z'
-      ...     groups = ['superheroes', 'robots']
-      >>> class CaptainAmericaPrincipal:
-      ...     implements(IGroupAwarePrincipal)
-      ...     id = '2'
-      ...     title = 'CaptainAmerica'
-      ...     description = 'Captain America'
-      ...     groups = ['superheroes']
+We test that we can add a Group to a GroupsFolder; we also check that
+it is possible to retrieve principals from a given group id and,
+vice-versa, get a list of groups a principal belongs to by providing
+its id.
+
+  >>> import zope.interface
+  >>> from zope.security.interfaces import IGroupAwarePrincipal, IGroup
+  >>> from zope.app.groupscontainer.group import Group
+  >>> from zope.app.groupscontainer.interfaces import IGroupContained
+  >>> from zope.app.groupscontainer.interfaces import IGroupsFolder
+  >>> from zope.app.groupscontainer.groupsfolder import GroupsFolder
+  >>> from zope.interface import implements
+  >>> class GoldrakePrincipal:
+  ...     implements(IGroupAwarePrincipal)
+  ...     id = '0'
+  ...     title = 'Goldrake'
+  ...     description = 'Ufo robot'
+  ...     groups = ['superheroes', 'robots']
+  >>> class MazingaPrincipal:
+  ...     implements(IGroupAwarePrincipal)
+  ...     id = '1'
+  ...     title = 'Mazinga'
+  ...     description = 'Mazinga Z'
+  ...     groups = ['superheroes', 'robots']
+  >>> class CaptainAmericaPrincipal:
+  ...     implements(IGroupAwarePrincipal)
+  ...     id = '2'
+  ...     title = 'CaptainAmerica'
+  ...     description = 'Captain America'
+  ...     groups = ['superheroes']
       
-      Then we create instances of our fake principal classes:
+Then we create instances of our fake principal classes:
       
-      >>> goldrake = GoldrakePrincipal()
-      >>> mazinga = MazingaPrincipal()
-      >>> captainamerica = CaptainAmericaPrincipal()
-      >>> superheroesgroup = Group(id='superheroes', title='Superheroes group', description='The best superheroes', principalsids=['0', '1', '2'])
-      >>> robotsgroup = Group(id='robots', title='Robots group', description='The best robots', principalsids=['0', '1'])
+  >>> goldrake = GoldrakePrincipal()
+  >>> mazinga = MazingaPrincipal()
+  >>> captainamerica = CaptainAmericaPrincipal()
+  >>> superheroesgroup = Group(id='superheroes', title='Superheroes group', 
+  ...                          description='The best superheroes', 
+  ...                          principalsids=['0', '1', '2'])
+  >>> robotsgroup = Group(id='robots', title='Robots group', 
+  ...                     description='The best robots', 
+  ...                     principalsids=['0', '1'])
       
-      A groups folder contains groups:
-      
-      >>> notordinarypeople = GroupsFolder()
-      >>> notordinarypeople[superheroesgroup.id] = superheroesgroup
-      >>> notordinarypeople[robotsgroup.id] = robotsgroup
-      
-      We test that 'getGroupsForPrincipal' returns the groups the provided principal id belongs to:
-      
-      >>> notordinarypeople.getGroupsForPrincipal('1')
-      ['superheroes', 'robots']
-      >>> notordinarypeople.getGroupsForPrincipal('2')
-      ['superheroes']
-      >>> notordinarypeople.getGroupsForPrincipal('99')
-      []
-      
-      The 'getPrincipalsForGroup' returns the principals id contained in a group:
-      
-      >>> notordinarypeople.getPrincipalsForGroup('superheroes')
-      ['0', '1', '2']
-      >>> notordinarypeople.getPrincipalsForGroup('users')
-      []
-      
-      We also test removing a group:
-      
-      >>> del notordinarypeople['superheroes']
-      >>> print list(notordinarypeople.keys())
-      [u'robots']
-      >>> notordinarypeople.getGroupsForPrincipal('1')
-      ['robots']
-      >>> mazinga.groups
-      ['superheroes', 'robots']
-      >>> notordinarypeople.getGroupsForPrincipal('2')
-      []
-      >>> captainamerica.groups
-      ['superheroes']
-      
-    Now we test the search capabilities, as in IQuerySchemaSearch example:
-    
-    We're trying to search groups in the notordinarypeople class, so first we get a view:
-      
-      >>> import zope.schema
-      >>> from zope.app.pas.browser.schemasearch import QuerySchemaSearchView 
-      >>> from zope.publisher.browser import TestRequest
-      >>> request = TestRequest()
-      >>> view = QuerySchemaSearchView(notordinarypeople, request)
-    
-    This allows us to render a search form.
-    
-      >>> print view.render('test') 
-      <div class="row">
-      <div class="label">
-      <label for="test.field.search" title="">
-      Group Search String
-      </label>
-      </div>
-      <div class="field">
-      <input class="textType" id="test.field.search" name="test.field.search" size="20" type="text" value=""  />
-      </div>
-      </div>
-      <br /><input type="submit" name="test.search" value="Search" />
+A groups folder contains groups:
 
-    If we ask for results:
+  >>> notordinarypeople = GroupsFolder()
+  >>> notordinarypeople[superheroesgroup.id] = superheroesgroup
+  >>> notordinarypeople[robotsgroup.id] = robotsgroup
+
+We test that 'getGroupsForPrincipal' returns the groups the provided
+principal id belongs to:
+
+  >>> notordinarypeople.getGroupsForPrincipal('1')
+  ['superheroes', 'robots']
+  >>> notordinarypeople.getGroupsForPrincipal('2')
+  ['superheroes']
+  >>> notordinarypeople.getGroupsForPrincipal('99')
+  []
+
+The 'getPrincipalsForGroup' returns the principals id contained in a group:
+
+  >>> notordinarypeople.getPrincipalsForGroup('superheroes')
+  ['0', '1', '2']
+  >>> notordinarypeople.getPrincipalsForGroup('users')
+  []
+
+We also test removing a group:
+
+  >>> del notordinarypeople['superheroes']
+  >>> print list(notordinarypeople.keys())
+  [u'robots']
+  >>> notordinarypeople.getGroupsForPrincipal('1')
+  ['robots']
+  >>> mazinga.groups
+  ['superheroes', 'robots']
+  >>> notordinarypeople.getGroupsForPrincipal('2')
+  []
+  >>> captainamerica.groups
+  ['superheroes']
+
+Now we test the search capabilities, as in IQuerySchemaSearch example:
+
+We're trying to search groups in the notordinarypeople class, so first
+we get a view:
+
+  >>> import zope.schema
+  >>> from zope.app.pas.browser.schemasearch import QuerySchemaSearchView 
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+  >>> view = QuerySchemaSearchView(notordinarypeople, request)
+
+This allows us to render a search form.
+
+  >>> print view.render('test') # doctest: +NORMALIZE_WHITESPACE
+  <div class="row">
+  <div class="label">
+  <label for="test.field.search" title="">
+  Group Search String
+  </label>
+  </div>
+  <div class="field">
+  <input class="textType" id="test.field.search"
+         name="test.field.search"
+         size="20" type="text" value=""  
+         />
+  </div>
+  </div>
+  <br /><input type="submit" name="test.search" value="Search" />
+
+If we ask for results:
+
+  >>> view.results('test')
+
+We don't get any, since we did not provide any. But if we give input:
+
+  >>> request.form['test.field.search'] = 'bo'
+
+we still don't get any:
+
+  >>> view.results('test')
+
+because we did not press the button. So let's press the button:
+
+  >>> request.form['test.search'] = 'Search'
+
+so that we now get results (!):
+
+  >>> list(view.results('test'))
+  [u'robots']
+  >>> request.form['test.field.search'] = 'eek'
+
+We can also remove a principal from all the groups:
+
+  >>> notordinarypeople.removePrincipalFromAllGroups('1')
+  >>> notordinarypeople.getGroupsForPrincipal('1')
+  []
+  >>> notordinarypeople.getAllMappedPrincipals()
+  ['0']
+
+If we remove the last group there will be no principal mapped anymore:
+
+  >>> del notordinarypeople['robots']
+  >>> notordinarypeople.getAllMappedPrincipals()
+  []
     
-      >>> view.results('test')
-    
-    We don't get any, since we did not provide any. But if we give input:
-    
-      >>> request.form['test.field.search'] = 'bo'
-    
-    we still don't get any:
-    
-      >>> view.results('test')
-    
-    because we did not press the button. So let's press the button:
-    
-      >>> request.form['test.search'] = 'Search'
-    
-    so that we now get results (!):
-    
-      >>> list(view.results('test'))
-      [u'robots']
-      >>> request.form['test.field.search'] = 'eek'
-      
-      We can also remove a principal from all the groups:
-      >>> notordinarypeople.removePrincipalFromAllGroups('1')
-      >>> notordinarypeople.getGroupsForPrincipal('1')
-      []
-      >>> notordinarypeople.getAllMappedPrincipals()
-      ['0']
-      
-      If we remove the last group there will be no principal mapped anymore:
-      >>> del notordinarypeople['robots']
-      >>> notordinarypeople.getAllMappedPrincipals()
-      []
-    

Modified: Zope3/trunk/src/zope/app/groupscontainer/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/groupscontainer/tests.py	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/src/zope/app/groupscontainer/tests.py	2004-10-19 22:06:15 UTC (rev 28219)
@@ -25,36 +25,34 @@
 from zope.app.form.browser import TextWidget
 from zope.app.form.interfaces import IInputWidget
 
+import zope.app.groupscontainer.group
+import zope.app.groupscontainer.groupsfolder
+import zope.app.groupscontainer.interfaces
+import zope.app.pas.interfaces
+
+
+
 def setUp(test):
     placelesssetup.setUp()
     ztapi.browserView(ITextLine, '', TextWidget, providing=IInputWidget)
 
+def setUpGP(test):
+    placelesssetup.setUp(test)
+    ztapi.subscribe([zope.app.pas.interfaces.IAuthenticatedPrincipalCreated],
+                    None,
+                    zope.app.groupscontainer.group.setGroupsForPrincipal)
+    groups = zope.app.groupscontainer.groupsfolder.GroupsFolder()
+    ztapi.provideUtility(zope.app.groupscontainer.interfaces.IGroupsFolder,
+                         groups)
+
 def test_suite():
     return unittest.TestSuite((
         doctest.DocFileSuite('groupsfolder.txt',
                              setUp=setUp, tearDown=placelesssetup.tearDown),
+        doctest.DocFileSuite('groups_principals.txt',
+                             setUp=setUpGP, tearDown=placelesssetup.tearDown),
         ))
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')
 
-
-
-
-
-
-
-
-
-"""
-
-import unittest
-from zope.testing.doctest import DocFileSuite
-
-def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(DocFileSuite('groupsfolder.txt'))
-    return suite
-        
-    
-"""

Deleted: Zope3/trunk/src/zope/security/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/security/configure.zcml	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/src/zope/security/configure.zcml	2004-10-19 22:06:15 UTC (rev 28219)
@@ -1,45 +0,0 @@
-<configure 
-    xmlns='http://namespaces.zope.org/zope'
-    xmlns:browser='http://namespaces.zope.org/browser'
-    i18n_domain="security"
-    xmlns:i18n="http://namespaces.zope.org/i18n"
-    >
-  
-  <browser:addMenuItem
-      title="Group"
-      description="A principals group"
-      class=".group.Group"
-      permission="zope.ManageServices"
-      />
-      
-      
-<content class=".group.Group">
-    <require
-        permission="zope.ManageContent"
-        interface=".interfaces.IGroup"
-        set_schema=".interfaces.IGroup"
-        />
-    <require
-        permission="zope.ManageContent"
-        interface="zope.app.groupscontainer.interfaces.IGroupContained"
-        />
-    <implements
-        interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
-        />
-  </content>
-  
-<browser:editform
-    schema=".interfaces.IGroup"
-    label="Change group information"
-    name="edit.html"
-    menu="zmi_views" title="Edit"
-    permission="zope.ManageContent"
-    />
-    
-  <subscriber
-    factory="zope.security.group.setGroupsForPrincipal"
-    for="zope.app.pas.interfaces.IAuthenticatedPrincipalCreated"
-    />
-  
-
-</configure> 

Deleted: Zope3/trunk/src/zope/security/group.py
===================================================================
--- Zope3/trunk/src/zope/security/group.py	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/src/zope/security/group.py	2004-10-19 22:06:15 UTC (rev 28219)
@@ -1,88 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Zope Group implementation
-
-$Id: group.py 27237 2004-10-12 09:33:00 mriya3 $
-
-"""
-
-from zope.security.interfaces import IGroup
-from zope.app.pas.interfaces import IAuthenticatedPrincipalCreated
-from persistent import Persistent
-from zope.interface import implements, alsoProvides
-from zope.app.groupscontainer.interfaces import IGroupContained, IGroupsFolder
-from zope.security.interfaces import IGroupAwarePrincipal
-from types import StringTypes
-import zope.app.zapi
-from zope.event import notify
-
-
-class Group(Persistent):
-
-    implements(IGroup, IGroupContained)
-    
-    __parent__ = __name__ = None
-    
-    def __init__(self, id='', title='', description='', principalsids=[]):
-        self.id = id
-        self.title = title
-        self.description = description
-        self.__principals = principalsids
-        
-    def addPrincipals(self, *principalIds):
-        tmpNewList = self.__principals
-        for principalId in principalIds:
-            if not principalId in self.__principals:
-                tmpNewList.append(principalId)
-        self.setPrincipals(tmpNewList)
-        if self.__parent__ is not None:
-            self.__parent__.updateMappingForPrincipals(*principalIds)
-
-    def removePrincipals(self, *principalIds):
-        tmpNewList = self.__principals
-        for principalId in principalIds:
-            if principalId in tmpNewList:
-                tmpNewList.remove(principalId)
-        self.setPrincipals(tmpNewList)
-        if self.__parent__ is not None:
-            self.__parent__.updateMappingForPrincipals(*principalIds)
-        
-    def containsPrincipal(self, principalId):
-        return principalId in self.__principals
-        
-    def getPrincipals(self):
-        return self.__principals
-        
-    def setPrincipals(self, prinlist):
-        origprincipals = self.__principals
-        self.__principals = prinlist
-        
-    principals = property(getPrincipals, setPrincipals)
-    
-
-def setGroupsForPrincipal(event):
-    """Set group information when a principal is created"""
-    principal = event.principal
-    alsoProvides(principal, IGroupAwarePrincipal)
-    principal.groups = []
-    groupfolders = zope.app.zapi.getUtilitiesFor(IGroupsFolder)
-    for name, groupfolder in groupfolders:
-        groups = groupfolder.getGroupsForPrincipal(principal.id)
-        principal.groups.extend(groups)
-
-    
-    
-    
-        
-

Deleted: Zope3/trunk/src/zope/security/groupprincipals.txt
===================================================================
--- Zope3/trunk/src/zope/security/groupprincipals.txt	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/src/zope/security/groupprincipals.txt	2004-10-19 22:06:15 UTC (rev 28219)
@@ -1,32 +0,0 @@
-Groups & Principals
-================
-
-We import the needed modules
-    >>> from zope.security.group import Group
-    >>> from zope.security.principalregistry import Principal
-    >>> from zope.app.groupcontainer.groupfolder import GroupFolder
-    >>> from zope.app.pas.principalsplugins import PrincipalFactory
-    >>> from zope.
-
-
-We first create a group folder and add some groups:
-
-    >>> groups = GroupFolder()
-    >>> geeks = Group(id='geeks', principals=['srichter','jim'])
-    >>> newbies = Group(id='newbies', principals=['amos','claudia'])
-    >>> sprinters = Group(id='sprinters', principals=['srichter', 'jim', 'amos','claudia'])
-    >>> for g in [geeks, sprinters, newbies]: groups[g.id] = g
-
-Now we create some principals:
-1) Instantiate a Principal Factory
-    >>> pf  = PrincipalFactory()
-    >>> srichter = pf.createAuthenticatedPrincipal(id='srichter', {} , TestRequest())
-    >>> groups.getGroupsForPrincipal(srichter.id)
-    ['geeks', 'sprinters']
-    >>> thomas = pf.createAuthenticatedPrincipal(id='thomas', {} , TestRequest())
-    >>> groups.getGroupsForPrincipal(thomas.id)
-    []
-    >>> amos = pf.createAuthenticatedPrincipal(id='amos', {} , TestRequest())
-    >>> groups.getGroupsForPrincipal(amos.id)
-    ['newbies','sprinters']
-    

Deleted: Zope3/trunk/src/zope/security/tests/groups_principals.txt
===================================================================
--- Zope3/trunk/src/zope/security/tests/groups_principals.txt	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/src/zope/security/tests/groups_principals.txt	2004-10-19 22:06:15 UTC (rev 28219)
@@ -1,46 +0,0 @@
-Groups & Principals
-===================
-
-We import the needed modules
-    >>> from zope.security.group import Group
-    >>> from zope.security.interfaces import IGroupAwarePrincipal
-    >>> from zope.app.groupscontainer.groupsfolder import GroupsFolder
-    >>> from zope.app.groupscontainer.interfaces import IGroupsFolder
-    >>> from zope.app.pas.principalplugins import PrincipalFactory
-    >>> from zope.publisher.tests.httprequest import TestRequest
-    >>> import zope.app.zapi
-
-We first create a group folder and add some groups:
-
-    >>> name, groups = list(zope.app.zapi.getUtilitiesFor(IGroupsFolder))[0]
-    >>> geeks = Group(id='geeks', principalsids=['srichter','jim'])
-    >>> newbies = Group(id='newbies', principalsids=['amos','claudia'])
-    >>> sprinters = Group(id='sprinters', principalsids=['srichter', 'jim', 'amos','claudia'])
-    >>> for g in [geeks, sprinters, newbies]: groups[g.id] = g
-
-Now we create some principals and check if they operate correctly:
-1) Instantiate a Principal Factory
-    >>> pf  = PrincipalFactory()
-    
-2) Get some principals
-    >>> srichter = pf.createAuthenticatedPrincipal('srichter', {} , TestRequest())
-    >>> IGroupAwarePrincipal.providedBy(srichter)
-    True
-    >>> groups.getGroupsForPrincipal(srichter.id)
-    ['geeks', 'sprinters']
-    >>> thomas = pf.createAuthenticatedPrincipal('thomas', {} , TestRequest())
-    >>> groups.getGroupsForPrincipal(thomas.id)
-    []
-    >>> amos = pf.createAuthenticatedPrincipal('amos', {} , TestRequest())
-    >>> groups.getGroupsForPrincipal(amos.id)
-    ['sprinters', 'newbies']
-    
-3) Now we add a group and check that getGroupsForPrincipal gets updated but 
-   principal group info gets NOT updated:
-    >>> thinkers = Group(id='thinkers', principalsids=['srichter', 'jim', 'thomas','robert'])
-    >>> groups[thinkers.id] = thinkers
-    >>> groups.getGroupsForPrincipal(srichter.id)
-    ['geeks', 'sprinters', 'thinkers']
-    >>> srichter.groups
-    ['geeks', 'sprinters']
-    

Deleted: Zope3/trunk/src/zope/security/tests/test_group.py
===================================================================
--- Zope3/trunk/src/zope/security/tests/test_group.py	2004-10-19 19:17:06 UTC (rev 28218)
+++ Zope3/trunk/src/zope/security/tests/test_group.py	2004-10-19 22:06:15 UTC (rev 28219)
@@ -1,39 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Groups folder tests.
-
-$Id: tests_group.py 27237 2004-10-12 10:49:00 mriya3 $
-"""
-
-
-import unittest
-from zope.testing.doctest import DocFileSuite
-from zope.app.tests import placelesssetup, ztapi
-import zope.security.group
-import zope.app.groupscontainer.groupsfolder
-import zope.app.groupscontainer.interfaces
-import zope.app.pas.interfaces
-
-def setUp(test):
-    placelesssetup.setUp(test)
-    ztapi.subscribe([zope.app.pas.interfaces.IAuthenticatedPrincipalCreated], None, zope.security.group.setGroupsForPrincipal)
-    groups = zope.app.groupscontainer.groupsfolder.GroupsFolder()
-    ztapi.provideUtility(zope.app.groupscontainer.interfaces.IGroupsFolder, groups)
-
-def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(DocFileSuite('groups_principals.txt', setUp=setUp, tearDown=placelesssetup.tearDown))
-    return suite
-        
-    



More information about the Zope3-Checkins mailing list