示例#1
0
 def getGroupsForPrincipal(self, principal, request=None):
     groups = {}
     # 1. Find adapters from user to a provider giving a list of groups.
     #    for this principal, when this principal is a user.
     providers = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserGroups,
         exact_getUserId=principal.getId())
     # 2. Find adapters from group to a provider giving a list of groups.
     #    for this principal, when this principal is a user.
     providers.extend(findMembraneUserAspect(
         self, group_ifaces.IMembraneGroupGroups,
         exact_getGroupId=principal.getId()))
     if not providers:
         # This used to be number 2.
         # We keep this for backwards compatibility.
         # 3. Find adapters from user to a provider giving a list of groups.
         #    for this principal, when this principal is a group.
         providers.extend(findMembraneUserAspect(
             self, user_ifaces.IMembraneUserGroups,
             exact_getGroupId=principal.getId()))
     # Note: we basically have a list of principals here, which is probably
     # only one user or one group.  And we ask each of those to give us the
     # groups for the principal that we got in the arguments.  So
     # theoretically we could be asking user A to give us the groups of user
     # B, which makes no sense.  But the normal case is that we simply ask
     # user A to give us the groups of user A.  For adapters it is probably
     # safe to assume that in the call a few lines below to
     # provider.getGroupsForPrincipal(principal), provider and principal are
     # the same object (except that one may be an adapter and the other a
     # user object).  Anyway, we will keep the old way of doing this.
     for provider in providers:
         pgroups = dict.fromkeys(provider.getGroupsForPrincipal(principal))
         groups.update(pgroups)
     return tuple(groups.keys())
 def getGroupsForPrincipal(self, principal, request=None):
     groups = {}
     # 1. Find adapters from user to a provider giving a list of groups.
     #    for this principal, when this principal is a user.
     providers = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserGroups,
         exact_getUserId=principal.getId())
     # 2. Find adapters from group to a provider giving a list of groups.
     #    for this principal, when this principal is a user.
     providers.extend(findMembraneUserAspect(
         self, group_ifaces.IMembraneGroupGroups,
         exact_getGroupId=principal.getId()))
     if not providers:
         # This used to be number 2.
         # We keep this for backwards compatibility.
         # 3. Find adapters from user to a provider giving a list of groups.
         #    for this principal, when this principal is a group.
         providers.extend(findMembraneUserAspect(
             self, user_ifaces.IMembraneUserGroups,
             exact_getGroupId=principal.getId()))
     # Note: we basically have a list of principals here, which is probably
     # only one user or one group.  And we ask each of those to give us the
     # groups for the principal that we got in the arguments.  So
     # theoretically we could be asking user A to give us the groups of user
     # B, which makes no sense.  But the normal case is that we simply ask
     # user A to give us the groups of user A.  For adapters it is probably
     # safe to assume that in the call a few lines below to
     # provider.getGroupsForPrincipal(principal), provider and principal are
     # the same object (except that one may be an adapter and the other a
     # user object).  Anyway, we will keep the old way of doing this.
     for provider in providers:
         pgroups = dict.fromkeys(provider.getGroupsForPrincipal(principal))
         groups.update(pgroups)
     return tuple(groups.keys())
 def getGroupsForPrincipal(self, principal, request=None):
     groups = {}
     providers = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserGroups,
         exact_getUserId=principal.getId())
     providers.extend(findMembraneUserAspect(
         self, user_ifaces.IMembraneUserGroups,
         exact_getGroupId=principal.getId()))
     for provider in providers:
         pgroups = dict.fromkeys(provider.getGroupsForPrincipal(principal))
         groups.update(pgroups)
     return tuple(groups.keys())
 def allowDeletePrincipal(self, user_id):
     """
     Check to see if the user can be deleted by trying to adapt
     to an IMembraneUserDeleter
     """
     deleters = findMembraneUserAspect(self, user_ifaces.IMembraneUserDeleter, exact_getUserId=user_id)
     return bool(deleters)
 def allowPasswordSet(self, user_id):
     """
     Check if we have access to set the password.
     We can verify this by checking if we can adapt to an IUserChanger
     """
     changers = findMembraneUserAspect(self, user_ifaces.IMembraneUserChanger, exact_getUserId=user_id)
     return bool(changers)
示例#6
0
 def getGroupMembers(self, group_id):
     groupmembers = {}
     groups = findMembraneUserAspect(self, group_ifaces.IGroup,
                                     exact_getGroupId=group_id)
     for group in groups:
         groupmembers.update(dict.fromkeys(group.getGroupMembers()))
     return tuple(groupmembers.keys())
 def getGroupMembers(self, group_id):
     groupmembers = {}
     groups = findMembraneUserAspect(self, group_ifaces.IGroup,
                                     exact_getGroupId=group_id)
     for group in groups:
         groupmembers.update(dict.fromkeys(group.getGroupMembers()))
     return tuple(groupmembers.keys())
示例#8
0
 def allowDeletePrincipal(self, user_id):
     """
     Check to see if the user can be deleted by trying to adapt
     to an IMembraneUserDeleter
     """
     deleters = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserDeleter, exact_getUserId=user_id)
     return bool(deleters)
示例#9
0
 def allowPasswordSet(self, user_id):
     """
     Check if we have access to set the password.
     We can verify this by checking if we can adapt to an IUserChanger
     """
     changers = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserChanger, exact_getUserId=user_id)
     return bool(changers)
示例#10
0
 def allowDeletePrincipal(self, login):
     """
     Check to see if the user can be deleted by trying to adapt
     to an IMembraneUserDeleter
     """
     deleters = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserDeleter, getLogin=login)
     return bool(deleters)
示例#11
0
 def getRolesForPrincipal(self, principal, request=None):
     roles = {}
     providers = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserRoles,
         exact_getUserId=principal.getId())
     for provider in providers:
         roles.update(dict.fromkeys(
             provider.getRolesForPrincipal(principal)))
     return tuple(roles.keys())
示例#12
0
 def doChangeUser(self, user_id, password, **kwargs):
     changers = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserChanger, exact_getUserId=user_id)
     if changers:
         changers[0].doChangeUser(user_id, password, **kwargs)
     else:
         raise RuntimeError(
             'No IMembraneUserChanger adapter found for user id: %s'
             % user_id)
示例#13
0
 def getRolesForPrincipal(self, principal, request=None):
     roles = {}
     providers = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserRoles,
         exact_getUserId=principal.getId())
     for provider in providers:
         roles.update(dict.fromkeys(
             provider.getRolesForPrincipal(principal)))
     return tuple(roles.keys())
示例#14
0
 def doDeleteUser(self, login):  # XXX: is it really login, or user_id?
     deleters = findMembraneUserAspect(self,
                                       user_ifaces.IMembraneUserDeleter,
                                       getUserName=login)
     if deleters:
         deleters[0].doDeleteUser(login)
     else:
         raise KeyError(
             'No IMembraneUserDeleter adapter found for user: %s' % login)
示例#15
0
 def doDeleteUser(self, login):  # XXX: is it really login, or user_id?
     deleters = findMembraneUserAspect(
         self, user_ifaces.IMembraneUserDeleter, getUserName=login)
     if deleters:
         deleters[0].doDeleteUser(login)
     else:
         raise KeyError(
             'No IMembraneUserDeleter adapter found for user: %s' %
             login)
示例#16
0
    def _getPropertyProviders(self, user):
        isGroup = getattr(user, 'isGroup', lambda: None)()
        if not isGroup:
            query = dict(exact_getUserId=user.getId())
        else:
            query = dict(exact_getGroupId=user.getId())

        for pp in findMembraneUserAspect(
            self, user_ifaces.IMembraneUserProperties, **query):
            yield pp
示例#17
0
    def _getPropertyProviders(self, user):
        isGroup = getattr(user, 'isGroup', lambda: None)()
        if isGroup:
            query = dict(exact_getGroupId=user.getId())
            iface = group_ifaces.IMembraneGroupProperties
        else:
            query = dict(exact_getUserId=user.getId())
            iface = user_ifaces.IMembraneUserProperties

        for pp in findMembraneUserAspect(self, iface, **query):
            yield pp