def testIGroupAdapter(self):
     """Verify all methods of the IGroup adapter to the FacultyStaffDirectory content type
     """
     from Products.membrane.interfaces import IGroup
     from Products.CMFCore.utils import getToolByName
     
     fsd = self.getPopulatedDirectory()
     wf = getToolByName(fsd,'portal_workflow')
     
     #adapt to IGroup
     g = IGroup(fsd)
     
     #group title is the content object title
     fsd.setTitle("My FSD")
     self.failUnless(g.Title()=="My FSD")
     
     #roles are set on the object, but only available when object is published
     fsd.setRoles(('Reviewer',))
     # at first, object is 'visible', but not published, roles should be empty
     self.failIf('Reviewer' in g.getRoles(),"roles are active, but content unpublished\nRoles: %s\nReviewState: %s" % (g.getRoles(), wf.getInfoFor(fsd,'review_state')))
     #publish object
     wf.doActionFor(fsd,'publish')
     # now check again, role should be there
     self.failUnless('Reviewer' in g.getRoles(),"Roles not active, but content published\nRoles: %s\nReviewState: %s" % (g.getRoles(), wf.getInfoFor(fsd,'review_state')))
     
     # group id is set on content object, uniqueness is enforced elsewhere
     self.failUnless(g.getGroupId()==fsd.getId(),"getGroupId returning incorrect value:\nExpected: %s\nReceived: %s" % (fsd.getId(), g.getGroupId()))
     
     #members are obtained correctly
     self.person1 = self.getPerson(id='abc123', firstName="Test", lastName="Person")
     self.person2 = self.getPerson(id='def456', firstName="Testy", lastName="Persons")
     self.person3 = self.getPerson(id='ghi789', firstName="Tester", lastName="Personage")
     members = list(g.getGroupMembers())
     members.sort()
     self.failUnless(members == ['abc123','def456','ghi789'],"incorrect member list: %s" % members)
Esempio n. 2
0
    def testIGroupAdapter(self):
        """Verify all methods of the IGroup adapter to the FacultyStaffDirectory content type
        """
        from Products.membrane.interfaces import IGroup
        from Products.CMFCore.utils import getToolByName

        fsd = self.getPopulatedDirectory()
        wf = getToolByName(fsd, 'portal_workflow')

        #adapt to IGroup
        g = IGroup(fsd)

        #group title is the content object title
        fsd.setTitle("My FSD")
        self.failUnless(g.Title() == "My FSD")

        #roles are set on the object, but only available when object is published
        fsd.setRoles(('Reviewer', ))
        # at first, object is 'visible', but not published, roles should be empty
        self.failIf(
            'Reviewer' in g.getRoles(),
            "roles are active, but content unpublished\nRoles: %s\nReviewState: %s"
            % (g.getRoles(), wf.getInfoFor(fsd, 'review_state')))
        #publish object
        wf.doActionFor(fsd, 'publish')
        # now check again, role should be there
        self.failUnless(
            'Reviewer' in g.getRoles(),
            "Roles not active, but content published\nRoles: %s\nReviewState: %s"
            % (g.getRoles(), wf.getInfoFor(fsd, 'review_state')))

        # group id is set on content object, uniqueness is enforced elsewhere
        self.failUnless(
            g.getGroupId() == fsd.getId(),
            "getGroupId returning incorrect value:\nExpected: %s\nReceived: %s"
            % (fsd.getId(), g.getGroupId()))

        #members are obtained correctly
        self.person1 = self.getPerson(id='abc123',
                                      firstName="Test",
                                      lastName="Person")
        self.person2 = self.getPerson(id='def456',
                                      firstName="Testy",
                                      lastName="Persons")
        self.person3 = self.getPerson(id='ghi789',
                                      firstName="Tester",
                                      lastName="Personage")
        members = list(g.getGroupMembers())
        members.sort()
        self.failUnless(members == ['abc123', 'def456', 'ghi789'],
                        "incorrect member list: %s" % members)
Esempio n. 3
0
File: roles.py Progetto: a25kk/stv2
    def getRolesForPrincipal(self, principal, request=None):
        roles = dict.fromkeys(IUserRoles(self.context).getRoles())

        getGroups = getattr(principal, 'getGroups', lambda: tuple())
        group_ids = getGroups()
        if group_ids:
            mbtool = getToolByName(self.context, TOOLNAME)
            uSR = mbtool.unrestrictedSearchResults
            groups = uSR(exact_getGroupId=group_ids,
                         object_implements=IGroup.__identifier__)
            for g in groups:
                group = IGroup(g._unrestrictedGetObject())
                roles.update(dict.fromkeys(group.getRoles()))

        return roles.keys()