Map provided partner business roles to FOS user roles

For instance, a sales clerk might get multiple roles
174939
public function mapPartnerToUserRoles(array $partnerRoles)
    {
        $userRoles = array();
        foreach ($partnerRoles as $partnerRole) {

            $userRoles[] = $partnerRole;

            if ($partnerRole == Partner::ROLE_EMPLOYEE) {

                $userRoles[] = 'ROLE_ADMIN';
            }

        }
        return $userRoles;
    }
1029364
def get_user_roles(user):
    """"""
    if not hasattr(user, '_role_cache'):
        user._role_cache = list(TenantRole.objects.filter(user=user).values_list(
            'group', 'role', 'tenant'))
    return user._role_cache
132207
public static function applyAppRoleMapByService($user, $serviceId)
    {
        $maps = AppRoleMap::whereServiceId($serviceId)->get();

        foreach ($maps as $map) {
            UserAppRole::whereUserId($user->id)->whereAppId($map->app_id)->delete();
            $userAppRoleData = [
                'user_id' => $user->id,
                'app_id'  => $map->app_id,
                'role_id' => $map->role_id
            ];

            UserAppRole::create($userAppRoleData);
        }
    }
382686
public void map(final RestletUtilUser user, final Role role)
    {
        try
        {
            this.addRoleMapping(new RoleMapping(user, role));
        }
        catch(final RepositoryException e)
        {
            throw new RuntimeException("Found unexpected exception while adding role mapping", e);
        }
    }
1299478
def roles_for_user(request, user, project=None, domain=None):
    """"""
    manager = keystoneclient(request, admin=True).roles
    if VERSIONS.active < 3:
        return manager.roles_for_user(user, project)
    else:
        return manager.list(user=user, domain=domain, project=project)
86459
function (userId, doc, fieldNames, modifier) {
			// only admins can update user roles via the client
			return Users.isAdmin(userId) || (doc._id === userId && fieldNames.indexOf("roles") < 0);
		}
853287
function getRole(user) {
      user = user || getCurrentUser();
      return _.find(userRoles, {role: user.role});
    }
717231
def roles_add(user, role):
    """"""
    user, role = _datastore._prepare_role_modify_args(user, role)
    if user is None:
        raise click.UsageError('Cannot find user.')
    if role is None:
        raise click.UsageError('Cannot find role.')
    if _datastore.add_role_to_user(user, role):
        click.secho('Role "{0}" added to user "{1}" '
                    'successfully.'.format(role, user), fg='green')
    else:
        raise click.UsageError('Cannot add role to user.')
1370319
def configure_roles_on_host(api, host):
  
  for role_ref in host.roleRefs:
    # Mgmt service/role has no cluster name. Skip over those.
    if role_ref.get('clusterName') is None:
      continue

    # Get the role and inspect the role type
    role = api.get_cluster(role_ref['clusterName'])\
              .get_service(role_ref['serviceName'])\
              .get_role(role_ref['roleName'])
    LOG.debug("Evaluating %s (%s)" % (role.name, host.hostname))

    config = None
    if role.type == 'DATANODE':
      config = DATANODE_CONF
    elif role.type == 'TASKTRACKER':
      config = TASKTRACKER_CONF
    elif role.type == 'REGIONSERVER':
      config = REGIONSERVER_CONF
    else:
      continue

    # Set the config
    LOG.info("Configuring %s (%s)" % (role.name, host.hostname))
    role.update_config(config)
344863
def collab_to_group_author_key_map(authors):
    """"""
    collab_map = {}
    for author in authors:
        if author.get("collab"):
            collab_map[author.get("collab")] = author.get("group-author-key")
    return collab_map
851744
def _get_maps_from_user(self, user):
        
        req = Session.query(Map).select_from(join(Map, User))
        return req.filter(User.login==user).all()
397953
def main(role, ou, assume, profile, output, regions, active):
    

    session = get_session(assume, 'c7n-org', profile)
    client = session.client('organizations')
    accounts = []
    for path in ou:
        ou = get_ou_from_path(client, path)
        accounts.extend(get_accounts_for_ou(client, ou, active))

    results = []
    for a in accounts:
        tags = []
        path_parts = a['Path'].strip('/').split('/')
        for idx, _ in enumerate(path_parts):
            tags.append("path:/%s" % "/".join(path_parts[:idx + 1]))

        ainfo = {
            'account_id': a['Id'],
            'email': a['Email'],
            'name': a['Name'],
            'tags': tags,
            'role': role.format(**a)}
        if regions:
            ainfo['regions'] = regions
        results.append(ainfo)

    print(
        yaml.safe_dump(
            {'accounts': results},
            default_flow_style=False),
        file=output)
323873
def get_user_roles(self, user):
        

        # For SQL: user.roles is list of pointers to Role objects
        if isinstance(self.db_adapter, SQLDbAdapter):
            # user.roles is a list of Role IDs
            user_roles = [role.name for role in user.roles]


        # For others: user.roles is a list of role names
        else:
            # user.roles is a list of role names
            user_roles = user.roles

        return user_roles
860729
def add_user_role(self, user, role_name):
        """"""

        # For SQL: user.roles is list of pointers to Role objects
        if isinstance(self.db_adapter, SQLDbAdapter):
            # user.roles is a list of Role IDs
            # Get or add role
            role = self.db_adapter.find_first_object(self.RoleClass, name=role_name)
            if not role:
                role = self.RoleClass(name=role_name)
                self.db_adapter.add_object(role)
            user.roles.append(role)

        # For others: user.roles is a list of role names
        else:
            # user.roles is a list of role names
            user.roles.append(role_name)
1037089
def get_role_mapping(self, name=None, params=None):
        
        return self.transport.perform_request(
            "GET", _make_path("_security", "role_mapping", name), params=params
        )
1306718
def roles(*roles)
      opts = roles.last.is_a?(Hash) ? roles.pop : {}
      self.valid_roles = roles.flatten.map(&:to_sym)
      unless (opts[:dynamic] == false)
        self.define_dynamic_queries(self.valid_roles)
      end
    end
702841
def add_domain_user_role(request, user, role, domain):
    """"""
    manager = keystoneclient(request, admin=True).roles
    return manager.grant(role, user=user, domain=domain)