def effective_principals(userid, request): """Return the list of additional effective principals for this request. Return the list of additional effective principals for the given userid and request (in addition to pyramid.security.Everyone, pyramid.security.Authenticated, and the user's ID which are automatically inserted by Pyramid). """ additional_principals = [] if getattr(request, 'client', None) is not None: consumer_group = 'consumer:{}'.format(request.client.client_id) additional_principals.append(consumer_group) primary_user = models.User.get_by_userid(request.domain, userid) if primary_user is not None: if primary_user.admin: additional_principals.append('group:__admin__') if primary_user.staff: additional_principals.append('group:__staff__') additional_principals.extend(groups.group_principals(primary_user)) return additional_principals
def groupfinder(userid, request): """ Return the list of additional groups of which userid is a member. Returns a list of group principals of which the passed userid is a member, or None if the userid is not known by this application. """ principals = set() user = models.User.get_by_userid(request.domain, userid) if user is None: return if user.admin: principals.add('group:__admin__') if user.staff: principals.add('group:__staff__') principals.update(groups.group_principals(user)) return list(principals)
def groupfinder(userid, request): """ Return the list of additional groups of which userid is a member. Returns a list of group principals of which the passed userid is a member, or None if the userid is not known by this application. """ principals = set() user = accounts.get_user(userid, request) if user is None: return if user.admin: principals.add('group:__admin__') if user.staff: principals.add('group:__staff__') principals.update(groups.group_principals(user)) return list(principals)