def getGroupsForPrincipal(self, principal, request=None): groups = {} # Get all BRefs that implement IGroup - slightly expensive for obj in self.context.getBRefs(): group = IGroup(obj, None) if group is not None: groups[group.getGroupId()] = 1 for parent in aq_chain(aq_inner(self.context)): group = IGroup(parent, None) if group is not None: groups[group.getGroupId()] = 1 return tuple(groups.keys())
def testIGroupAdapter(self): """Verify all methods of the IGroup adapter to the Classification content type """ from Products.membrane.interfaces import IGroup from Products.CMFCore.utils import getToolByName wf = getToolByName(self.classification, 'portal_workflow') #adapt to IGroup g = IGroup(self.classification) #group title is the content object title self.classification.setTitle('New Title') self.failUnless( g.Title() == 'New Title', "IGroup.getTitle is not finding the correct title:\nexpected: %s\nfound: %s" % (self.classification.Title(), g.Title())) # group id is set on content object, uniqueness is enforced elsewhere self.failUnless( g.getGroupId() == self.classification.getId(), "getGroupId returning incorrect value:\nExpected: %s\nReceived: %s" % (self.classification.getId(), g.getGroupId())) #members are obtained correctly, regardless of how the classification was added #added from person object self.person.setClassifications((self.classification, )) self.person2.setClassifications((self.classification, )) members = list(g.getGroupMembers()) members.sort() self.failUnless(members == ['abc123', 'def456'], "incorrect member list: %s" % members) #clear the list self.classification.setPeople(()) self.failIf( self.classification.getPeople(), "there are still people listed in this classification: %s" % self.classification.getPeople()) #added from classification object self.classification.setPeople((self.person, self.person2)) members = list(g.getGroupMembers()) members.sort() self.failUnless(members == ['abc123', 'def456'], "incorrect member list: %s" % members) #deactivate group and verify emptiness wf.doActionFor(self.classification, 'deactivate') members = list(g.getGroupMembers()) members.sort() self.failUnless( members == [], "deactivated group has non-empty member list: %s" % members)
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)
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)
def getGroupsForPrincipal(self, principal, request=None): person = self.context groups = {} for held_position in person.get_held_positions(): group = IGroup(held_position.position.to_object) group_id = group.getGroupId() groups[group_id] = 1 return tuple(groups.keys())
def getGroupsForPrincipal(self, principal, request=None): groups = {} for relationship in self.context.getGroupRelationships(): groups.update(dict.fromkeys([g.getUserId() for g in self.context.getBRefs(relationship)])) for parent in aq_chain(aq_inner(self.context)): group = IGroup(parent, None) if group is not None: groups[group.getGroupId()] = 1 return tuple(groups.keys())
def getGroupsForPrincipal(self, principal, request=None): person = self.context groups = {} for held_position in person.get_held_positions(): position = held_position.position if position: obj = position.to_object if obj: assignable = DexterityBehaviorAssignable(obj) if assignable.supports(IMembraneGroup): group = IGroup(obj) group_id = group.getGroupId() groups[group_id] = 1 return tuple(groups.keys())
def testIGroupAdapter(self): """Verify all methods of the IGroup adapter to the Classification content type """ from Products.membrane.interfaces import IGroup from Products.CMFCore.utils import getToolByName wf = getToolByName(self.committee,'portal_workflow') #adapt to IGroup g = IGroup(self.committee) #group title is the content object title self.committee.setTitle('New Title') self.failUnless(g.Title()=='New Title',"IGroup.getTitle is not finding the correct title:\nexpected: %s\nfound: %s" % (self.committee.Title(),g.Title())) # group id is set on content object, uniqueness is enforced elsewhere self.failUnless(g.getGroupId()==self.committee.getId(),"getGroupId returning incorrect value:\nExpected: %s\nReceived: %s" % (self.committee.getId(), g.getGroupId())) #members are obtained correctly, regardless of how the classification was added #added from person object self.person.setCommittees((self.committee,)) self.person2.setCommittees((self.committee,)) members = list(g.getGroupMembers()) members.sort() self.failUnless(members == ['abc123','def456'], "incorrect member list: %s" % members) #clear the list self.committee.setMembers(()); self.failIf(self.committee.getMembers(), "there are still people listed in this committee: %s" % self.committee.getMembers()) #added from classification object self.committee.setMembers((self.person,self.person2)) members = list(g.getGroupMembers()) members.sort() self.failUnless(members == ['abc123','def456'], "incorrect member list: %s" % members) #deactivate group and verify emptiness wf.doActionFor(self.committee,'deactivate') members = list(g.getGroupMembers()) members.sort() self.failUnless(members == [],"deactivated group has non-empty member list: %s" % members)