예제 #1
0
 def testSetGroupsWithSameUserNameAndId(self):
     pas = self.portal['acl_users']
     self.portal.portal_groups.addGroup('Editors', [], [])
     self.setGroups(['Editors'])
     self.login()
     user = getSecurityManager().getUser()
     self.assertTrue('Editors' in getGroupsForPrincipal(user, pas['plugins']))
예제 #2
0
    def getRolesForPrincipal(self, principal, request=None):
        """ See IRolesPlugin.
        """
        roles = set([])
        principal_ids = set([])
        # Some services need to determine the roles obtained from groups
        # while excluding the directly assigned roles.  In this case
        # '__ignore_direct_roles__' = True should be pushed in the request.
        request = aq_get(self, 'REQUEST', None)
        if request is None \
           or not request.get('__ignore_direct_roles__', False):
            principal_ids.add(principal.getId())

        # Some services may need the real roles of an user but **not**
        # the ones he got through his groups. In this case, the
        # '__ignore_group_roles__'= True should be previously pushed
        # in the request.
        plugins = self._getPAS()['plugins']
        if request is None \
           or not request.get('__ignore_group_roles__', False):
            principal_ids.update(
                getGroupsForPrincipal(principal, plugins, request)
            )
        for pid in principal_ids:
            roles.update(self._principal_roles.get(pid, ()))
        return tuple(roles)
예제 #3
0
 def testSetGroupsWithSameUserNameAndId(self):
     pas = self.portal['acl_users']
     self.portal.portal_groups.addGroup('Editors', [], [])
     self.setGroups(['Editors'])
     user = getSecurityManager().getUser()
     self.assertTrue(
         'Editors' in getGroupsForPrincipal(user, pas['plugins']))
 def testSetGroupsWithUserNameIdDifference(self):
     pas = self.portal["acl_users"]
     self.portal.portal_groups.addGroup("Editors", [], [])
     self.setGroups(["Editors"], name=TEST_USER_ID)
     self.login(TEST_USER_NAME)
     user = getSecurityManager().getUser()
     self.assertTrue("Editors" in getGroupsForPrincipal(user, pas["plugins"]))
     self.login()
예제 #5
0
 def testSetGroupsWithUserNameIdDifference(self):
     pas = self.portal['acl_users']
     self.portal.portal_groups.addGroup('Editors', [], [])
     self.setGroups(['Editors'], name=TEST_USER_ID)
     self.login(TEST_USER_NAME)
     user = getSecurityManager().getUser()
     self.assertTrue(
         'Editors' in getGroupsForPrincipal(user, pas['plugins']))
     self.login()
 def testSetGroupsWithUserNameIdDifference(self):
     pas = self.portal['acl_users']
     self.portal.portal_groups.addGroup('Editors', [], [])
     self.portal.acl_users.userSetGroups(TEST_USER_ID, groupnames=['Editors'])
     login(self.portal, TEST_USER_NAME)
     user = getSecurityManager().getUser()
     self.assertTrue(
         'Editors' in getGroupsForPrincipal(user, pas['plugins'])
     )
예제 #7
0
파일: members.py 프로젝트: upiq/uu.qiext
 def groups_for(self, username):
     """
     List all PAS groupnames for username / email; does not
     include indirect membership in nested groups.
     """
     if username not in self:
         if username not in self._uf.source_groups.listGroupIds():
             raise KeyError('Unknown username: %s' % username)
     return getGroupsForPrincipal(self.get(username), self._uf.plugins)
예제 #8
0
 def groups_for(self, username):
     """
     List all PAS groupnames for username / email; does not
     include indirect membership in nested groups.
     """
     username = self.applyTransform(username)
     if username not in self:
         if username not in self._uf.source_groups.listGroupIds():
             msg = 'Unknown principal in SiteMembers.groups_for(): %s' % (
                 username, )
             self._log(msg, logging.ERROR)
             raise KeyError(msg)
     return getGroupsForPrincipal(self.get(username), self._uf.plugins)
예제 #9
0
 def groups_for(self, username):
     """
     List all PAS groupnames for username / email; does not
     include indirect membership in nested groups.
     """
     username = self.applyTransform(username)
     if username not in self:
         if username not in self._uf.source_groups.listGroupIds():
             msg = 'Unknown principal in SiteMembers.groups_for(): %s' % (
                 username,
                 )
             self._log(msg, logging.ERROR)
             raise KeyError(msg)
     return getGroupsForPrincipal(self.get(username), self._uf.plugins)
예제 #10
0
 def testSetGroupsWithUserNameIdDifference(self):
     # XXX these constants can be imported from plone.app.testing later
     TEST_USER_NAME = 'test-user-2'
     TEST_USER_ID = 'test_user_2_'
     TEST_USER_PASSWORD = '******'
     TEST_USER_ROLES = ['Member',]
     pas = self.portal['acl_users']
     pas.source_users.addUser(TEST_USER_ID, TEST_USER_NAME, TEST_USER_PASSWORD)
     for role in TEST_USER_ROLES:
         pas.portal_role_manager.doAssignRoleToPrincipal(TEST_USER_ID, role)
     self.portal.portal_groups.addGroup('Editors', [], [])
     self.setGroups(['Editors'], name=TEST_USER_ID)
     self.login(TEST_USER_ID)
     user = getSecurityManager().getUser()
     self.assertTrue('Editors' in getGroupsForPrincipal(user, pas['plugins']))
     self.login()
예제 #11
0
 def getGroupsForPrincipal(self, principal):
     return getGroupsForPrincipal(principal, self._getPlugins())
예제 #12
0
 def getGroupsForPrincipal(self, principal):
     return getGroupsForPrincipal(principal, self._getPlugins())
예제 #13
0
 def testSetGroupsWithSameUserNameAndId(self):
     pas = self.portal["acl_users"]
     self.portal.portal_groups.addGroup("Editors", [], [])
     self.setGroups(["Editors"])
     user = getSecurityManager().getUser()
     self.assertTrue("Editors" in getGroupsForPrincipal(user, pas["plugins"]))