// hasRoleContext retrieves organization specified on context
// under the organizations.ContextKey
978766
func hasRoleContext(ctx context.Context) (string, bool) {
	// prevents panic in case of nil context
	if ctx == nil {
		return "", false
	}
	role, ok := ctx.Value(roles.ContextKey).(string)
	// should never happen
	if !ok {
		return "", false
	}
	switch role {
	case roles.MemberRoleName, roles.ViewerRoleName, roles.EditorRoleName, roles.AdminRoleName:
		return role, true
	default:
		return "", false
	}
}
540573
func (call *LeaveRoomCall) WithContext(ctx context.Context) *LeaveRoomCall {
	call.ctx = ctx
	return call
}
1016726
func (n *NamedStmt) GetContext(ctx context.Context, dest interface{}, arg interface{}) error {
	r := n.QueryRowxContext(ctx, arg)
	return r.scanAny(dest, false)
}
37685
func (call *GetGroupMemberProfileCall) WithContext(ctx context.Context) *GetGroupMemberProfileCall {
	call.ctx = ctx
	return call
}
946853
func newRoleBindingRestrictionContext(ns string, kc kubernetes.Interface, userClient userclient.UserV1Interface, groupCache GroupCache) (*RoleBindingRestrictionContext, error) {
	return &RoleBindingRestrictionContext{
		namespace:       ns,
		kclient:         kc,
		userClient:      userClient,
		groupCache:      groupCache,
		userToLabelSet:  map[string]labels.Set{},
		groupToLabelSet: map[string]labels.Set{},
	}, nil
}
187486
func (call *CreateRichMenuCall) WithContext(ctx context.Context) *CreateRichMenuCall {
	call.ctx = ctx
	return call
}
789751
func (o *UploadTaskFileParams) WithContext(ctx context.Context) *UploadTaskFileParams {
	o.SetContext(ctx)
	return o
}
213398
func (res *Resource) HasPermission(mode roles.PermissionMode, context *qor.Context) bool {
	if res == nil || res.Permission == nil {
		return true
	}

	var roles = []interface{}{}
	for _, role := range context.Roles {
		roles = append(roles, role)
	}
	return res.Permission.HasPermission(mode, roles...)
}
1282844
func (c *GroupListCall) Context(ctx context.Context) *GroupListCall {
	c.ctx_ = ctx
	return c
}
81220
func (call *LinkUserRichMenuCall) WithContext(ctx context.Context) *LinkUserRichMenuCall {
	call.ctx = ctx
	return call
}
1041165
func (c *Ctx) WithContext(ctx context.Context) {
	c.request = c.request.WithContext(ctx)
}
621407
func (o *AddOneParams) WithContext(ctx context.Context) *AddOneParams {
	o.SetContext(ctx)
	return o
}
984245
func (o *GetTaskDetailsParams) WithContext(ctx context.Context) *GetTaskDetailsParams {
	o.SetContext(ctx)
	return o
}
676315
func (c *GroupRolloutActiveGetCall) Context(ctx context.Context) *GroupRolloutActiveGetCall {
	c.ctx_ = ctx
	return c
}
894619
func (call *GetGroupMemberIDsCall) WithContext(ctx context.Context) *GetGroupMemberIDsCall {
	call.ctx = ctx
	return call
}
845021
func HasRole(token string, scopes []string) (*models.Principal, error) {
	claims, err := parseAndCheckToken(token)
	if err == nil {
		if claims.Issuer == issuerName {
			isInScopes := false
			claimedRoles := []string{}
			for _, scope := range scopes {
				for _, role := range claims.Roles {
					if role == scope {
						isInScopes = true
						// we enrich the principal with all claimed roles within scope (hence: not breaking here)
						claimedRoles = append(claimedRoles, role)
					}
				}
			}
			if isInScopes {
				return &models.Principal{
					Name:  claims.Id,
					Roles: claimedRoles,
				}, nil
			}
			return nil, errors.New(403, "Forbidden: insufficient privileges")
		}
	}
	return nil, errors.New(401, "Unauthorized: invalid Bearer token: %v", err)
}
190613
func (s *Service) hasRoles(ctx context.Context, ts chronograf.TimeSeries) (chronograf.RolesStore, bool) {
	store, err := ts.Roles(ctx)
	if err != nil {
		return nil, false
	}
	return store, true
}