Returns a list of primary contributors, with primary being defined as those contributors that have the highest role assigned(in terms of priority). When permitted is set to True only permitted contributors are returned.
186125
def get_primary_contributors(self, permitted=True):
        
        primary_credits = []
        credits = self.credits.exclude(role=None).order_by('role')
        if credits:
            primary_role = credits[0].role
            for credit in credits:
                if credit.role == primary_role:
                    primary_credits.append(credit)

        contributors = []
        for credit in primary_credits:
            contributor = credit.contributor
            if permitted and contributor.is_permitted:
                contributors.append(contributor)
            else:
                contributors.append(contributor)

        return contributors
24449
def user_roles(self):
        
        # We do here some lazy loading.
        if not self._user_roles:
            self._user_roles = UserRoleManager(self)
        return self._user_roles
174856
def get_user_push_restrictions(self):
        
        return github.PaginatedList.PaginatedList(
            github.NamedUser.NamedUser,
            self._requester,
            self.protection_url + "/restrictions/users",
            None
        )
159082
def primary(self, repl_id):
        
        repl = self[repl_id]
        primary = repl.primary()
        return repl.member_info(repl.host2id(primary))
556523
def indexable_role(principal):
    
    principal = unwrap(principal)

    if hasattr(principal, "is_anonymous") and principal.is_anonymous:
        # transform anonymous user to anonymous role
        principal = Anonymous

    if isinstance(principal, Role):
        return f"role:{principal.name}"
    elif isinstance(principal, User):
        fmt = "user:{:d}"
    elif isinstance(principal, Group):
        fmt = "group:{:d}"
    else:
        raise ValueError(repr(principal))

    return fmt.format(principal.id)
1270487
@Override
    public Principal getCallerPrincipal() {
        synchronized (this) {
            if ((state == PRE_CREATE) || (state == CREATING) || (!allowRollbackOnly))
                throw new IllegalStateException();
        }

        return super.getCallerPrincipal();

    }
111728
def user_has(ability, get_user=import_user):
    
    def wrapper(func):
        @wraps(func)
        def inner(*args, **kwargs):
            from .models import Ability
            desired_ability = Ability.query.filter_by(
                name=ability).first()
            user_abilities = []
            current_user = get_user()
            for role in current_user._roles:
                user_abilities += role.abilities
            if desired_ability in user_abilities:
                return func(*args, **kwargs)
            else:
                raise Forbidden("You do not have access")
        return inner
    return wrapper
152103
public List<CmsUser> getVisibleUser() {

        if (!m_fullyLoaded) {
            return m_users;
        }
        if (size() == m_users.size()) {
            return m_users;
        }
        List<CmsUser> directs = new ArrayList<CmsUser>();
        for (CmsUser user : m_users) {
            if (!m_indirects.contains(user)) {
                directs.add(user);
            }
        }
        return directs;
    }
674095
def get_assignees(self):
        
        return github.PaginatedList.PaginatedList(
            github.NamedUser.NamedUser,
            self._requester,
            self.url + "/assignees",
            None
        )
808701
private List<String> getUsersFor(Collection<String> roles){
		List<String> users = new HashList<>();
		for(String role: roles){
			if(roleMembershipRU.containsKey(role))
				users.addAll(roleMembershipRU.get(role));
		}
		return users;
	}
405183
def getPeers(self, offset=0, limit=1000):
        
        select = models.Peer.select().order_by(
            models.Peer.url).limit(limit).offset(offset)
        return [peers.Peer(p.url, record=p) for p in select]
390750
def define_contributor(self, request):
        """"""
        request.data['contributor'] = self.resolve_user(request.user).pk
922253
def get_contributor_sort_value(self, obj):
        """"""
        user = obj.contributor

        if user.first_name or user.last_name:
            contributor = user.get_full_name()
        else:
            contributor = user.username

        return contributor.strip().lower()
966382
def primary_stat
      @primary_stat ||= manifest.stats.filter(primary: true).with_context([self]).map { |name, value| [name, value] }.first&.last
    end
1323997
def which_users_can(self, name):
        
        _roles = self.which_roles_can(name)
        result =  [self.get_role_members(i.get('role')) for i in _roles]
        return result
928359
def get_participants(self, obj):
        
        # we set the many to many serialization to False, because we only want it with retrieve requests
        if self.callback is None:
            return [participant.id for participant in obj.participants.all()]
        else:
            # we do not want user information
            return self.callback(obj)
636153
def accepts_contributor_roles(func):
    
    if inspect.isclass(func):
        apply_function_to_members(func, accepts_contributor_roles)
        return func
    else:
        @functools.wraps(func)
        def decorator(*args, **kwargs):
            return accepts_roles(*ROLES_CONTRIBUTOR)(func)(*args, **kwargs)

        return decorator