Add one or more users to a team

@param  {Object}   params { id, users, organizationId }
@param  {Function} cb
975592
function addUsersToTeam (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, users, organizationId } = params
      const tasks = [
        (job, next) => {
          Joi.validate({ id, users, organizationId }, validationRules.addUsersToTeam, (err) => {
            if (err) return next(Boom.badRequest(err))
            next()
          })
        },
        (job, next) => {
          job.teamId = id
          job.organizationId = organizationId
          job.params = params

          next()
        },
        (job, next) => {
          utils.checkUsersOrg(job.client, job.params.users, job.organizationId, next)
        },
        checkTeamExists,
        insertTeamMembers
      ]

      db.withTransaction(tasks, (err, res) => {
        if (err) return cb(err)
        teamOps.readTeam({ id, organizationId }, cb)
      })

      return promise
    }
1116008
function createEvent(params, cb) {
  params.resourcePath = config.addURIParams(constants.EVENTS_BASE_PATH, params);
  params.method = 'POST';
  params.data = params.data || {};
  mbaasRequest.admin(params, cb);
}
809315
function deleteUserPolicy (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { userId, organizationId, policyId, instance } = params
      const tasks = [
        (job, next) => {
          Joi.validate({ userId, organizationId, policyId, instance }, validationRules.deleteUserPolicy, (err) => {
            if (err) return next(Boom.badRequest(err))
            next()
          })
        },
        (job, next) => {
          job.id = userId
          job.policyId = policyId
          job.organizationId = organizationId
          job.instance = instance

          next()
        },
        checkUserOrg,
        removeUserPolicy
      ]

      db.withTransaction(tasks, (err, res) => {
        if (err) return cb(err)

        userOps.readUser({ id: userId, organizationId }, cb)
      })

      return promise
    }
703674
function(params, cb) {
    var correlationId = _cbt.put(offFetchResponse(cb));
    var msg = envelope(offFetch.encode(params.fetchFromCoordinator ? 1 : 0)
                               .correlation(correlationId)
                               .client(_options.clientId)
                               .group(params.group)
                               .topic(params.topic)
                               .partition(params.partition)
                               .end());
    sendMsg(msg, correlationId, cb);
  }
1276999
function listAllUserPolicies ({ userId, organizationId }, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const rootOrgId = config.get('authorization.superUser.organization.id')
      const sql = SQL`
        WITH user_teams AS (
          SELECT id FROM teams WHERE path @> (
            SELECT array_agg(path) FROM teams
            INNER JOIN team_members tm
            ON tm.team_id = teams.id
            WHERE tm.user_id = ${userId}
          )
        ),
        policies_from_teams AS (
          SELECT
            policy_id, variables
          FROM
            team_policies
          WHERE
            team_id IN (SELECT id FROM user_teams)
        ),
        policies_from_user AS (
          SELECT
            policy_id, variables
          FROM
            user_policies
          WHERE
            user_id = ${userId}
        ),
        policies_from_organization AS (
          SELECT
            op.policy_id, variables
          FROM
            organization_policies op
          LEFT JOIN
            users u ON u.org_id = op.org_id
          WHERE
            u.id = ${userId}
        ),
        is_root_user AS (
          SELECT FROM users WHERE id=${userId} AND org_id = ${rootOrgId}
        )
        SELECT
          id,
          version,
          name,
          statements,
          policies_from_user.variables AS variables
        FROM
          policies
        INNER JOIN
          policies_from_user
        ON
          policies.id = policies_from_user.policy_id
        WHERE (
            org_id = ${organizationId}
          OR (
              EXISTS (SELECT FROM is_root_user)
            AND
              org_id = ${rootOrgId}
          )
          OR org_id IS NULL
        )
        UNION
        SELECT
          id,
          version,
          name,
          statements,
          policies_from_teams.variables AS variables
        FROM
          policies
        INNER JOIN
          policies_from_teams
        ON
          policies.id = policies_from_teams.policy_id
        WHERE (
            org_id = ${organizationId}
          OR (
              EXISTS (SELECT FROM is_root_user)
            AND
              org_id = ${rootOrgId}
          )
          OR org_id IS NULL
        )
        UNION
        SELECT
          id,
          version,
          name,
          statements,
          policies_from_organization.variables
        FROM
          policies
        INNER JOIN
          policies_from_organization
        ON
          policies.id = policies_from_organization.policy_id
        WHERE (
            org_id = ${organizationId}
          OR (
              EXISTS (SELECT FROM is_root_user)
            AND
              org_id = ${rootOrgId}
          )
          OR org_id IS NULL
        )
      `

      db.query(sql, function (err, result) {
        if (err) return cb(Boom.badImplementation(err))
        cb(null, result.rows.map(mapping.policy.iam))
      })

      return promise
    }
628464
public function insertMulti($docs, $cb = null, $params = null)
    {
        return $this->pool->insertMulti($this->name, $docs, $cb, $params);
    }
857582
function updateUser (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId, name, metadata } = params

      Joi.validate({ id, organizationId, name, metadata }, validationRules.updateUser, function (err) {
        if (err) return cb(Boom.badRequest(err))

        const sqlQuery = SQL`
          UPDATE users
          SET name = ${name},
          metadata = ${metadata}
          WHERE id = ${id}
          AND org_id = ${organizationId}
        `
        db.query(sqlQuery, (err, result) => {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict(err.detail))
          if (err) return cb(Boom.badImplementation(err))
          if (result.rowCount === 0) return cb(Boom.notFound(`User ${id} not found`))

          userOps.readUser({ id, organizationId }, cb)
        })
      })

      return promise
    }
458163
function listTeamPolicies ({ id, page = 1, limit, organizationId }, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      Joi.validate({ id, page, limit, organizationId }, validationRules.listTeamPolicies, function (err) {
        if (err) return cb(Boom.badRequest(err))

        const pageLimit = limit || _.get(config, 'authorization.defaultPageSize')
        const offset = (page - 1) * pageLimit

        const job = {
          id: id,
          organizationId: organizationId,
          offset: offset,
          limit: pageLimit,
          team: {},
          client: db
        }

        loadTeamPolicies(job, (err) => {
          if (err) return cb(err)
          const pageSize = pageLimit || job.totalPoliciesCount
          const result = {
            page: page,
            limit: pageSize,
            total: job.totalPoliciesCount,
            data: job.team.policies
          }
          return cb(null, result)
        })
      })

      return promise
    }
1141933
function deleteTeamMembers (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId } = params

      const tasks = [
        (job, next) => {
          Joi.validate({ id, organizationId }, validationRules.deleteTeamMembers, (err) => {
            if (err) return next(Boom.badRequest(err))

            next()
          })
        },
        (job, next) => {
          job.teamId = id
          job.organizationId = organizationId

          next()
        },
        checkTeamExists,
        deleteTeamUsers
      ]

      db.withTransaction(tasks, (err, res) => {
        if (err) return cb(err)
        cb()
      })

      return promise
    }
1048228
def add_member(self, user):
        
        user = Transform.to_user(user)
        data = {
            'id': user
        }
        extra = {
            'resource': self.__class__.__name__,
            'query': {
                'id': self.id,
                'data': data,
            }
        }
        logger.info('Adding team member using id', extra=extra)
        response = self._api.post(
            url=self._URL['members_query'].format(id=self.id), data=data)
        member_data = response.json()
        return TeamMember(api=self._api, **member_data)
163960
def add_group_users(user_ids)
      raise 'Attempted to add a user to a non-group channel!' unless group?

      user_ids = [user_ids] unless user_ids.is_a? Array
      user_ids.each do |user_id|
        API::Channel.add_group_user(@bot.token, @id, user_id.resolve_id)
      end
      self
    end
400804
public function insertMulti($col, $docs = [], $cb = null, $params = [])
    {
        if (mb_orig_strpos($col, '.') === false) {
            $col = $this->dbname . '.' . $col;
        }

        $ids = [];
        $bson = '';

        foreach ($docs as &$doc) {
            if (!isset($doc['_id'])) {
                $doc['_id'] = new MongoId();
            }
            try {
                $bson .= bson_encode($doc);
            } catch (\MongoException $e) {
                Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString());
                if ($cb !== null) {
                    $cb(['$err' => $e->getMessage(), '$doc' => $doc]);
                }
            }

            $ids[] = $doc['_id'];
        }

        $this->request(
            self::OP_INSERT,
            "\x00\x00\x00\x00" . $col . "\x00" . $bson,
            false,
            null,
            function ($conn, $reqId = null) use ($cb, $col, $params) {
                if ($cb !== null) {
                    $this->lastError($col, $cb, $params, $conn);
                }
            }
        );

        return $ids;
    }
459916
function queueSearcher(data, cb) {
  // validate
  if (data.team && data.team.length > 0 && data.input && data.member && data.categories && data.categories.length > 0) {

    // log the search
    GLOBAL.svc.indexer.saveSearchLog({searchID: GLOBAL.svc.indexer.searchID(data), searchDate: new Date()}, utils.passingError);
    // process it by each member
    data.team.forEach(function(m) {
      var user = auth.getUserByUsername(m), context = { member: user.username, input: data.input, relevance: data.relevance, team: data.team, categories: data.categories};
      // user not found
      if (!user) {
        console.log('queueSearch: user not found', m);
      } else {
        console.log('execing', data, 'user', user);
        // it's a searcher, add links
        if (user.type === 'Searcher') {
          if (user.api) {
            // use query template or just the term
            context.query = (user.template || '$SBQUERY').replace('$SBQUERY', data.input);
            context.targetResults = data.targetResults || 10;
            // one callback per uri
            searchAPIs.exec(user.api, context, function(err, uri, resultContext) {
              console.log('got a link', uri);
              var status;
              if (err) {
                utils.passingError(err);
              } else {
                status = { uri: uri, source: resultContext.referers };
                queueLink(uri, resultContext);
              }
              if (cb) {
                cb(err, status);
              }
            });
          // scrape style location
          } else if (user.locations) {
            user.locations.split('\n').forEach(function(l) {
              l = l.replace('$SBQUERY', data.input);
              GLOBAL.info(' /queueSearch', l);
              queueLink(l, context);
            });
          } else {
            GLOBAL.error('unknown searcher type', user);
          }
        // an annotator or individual
        } else {
          GLOBAL.info(' /queueSearch', data.uri);
          queueLink(data.uri, context);
        }
      }
    });
  } else {
    console.log('missing data', data);
  }
}
999405
function insertOrgAdminUser (job, next) {
    if (job.user) {
      const { id, name } = job.user
      const { id: organizationId } = job.organization

      userOps.insertUser(job.client, { id, name, organizationId }, (err, res) => {
        if (err) return next(err)
        job.user.id = res.rows[0].id

        userOps.insertPolicies(job.client, job.user.id, [{id: job.adminPolicyId, variables: {}}], utils.boomErrorWrapper(next))
      })

      return
    }

    next()
  }
276959
function addUser(req, res, next) {
  res.locals.user = req.user;
  next();
}
1066421
function updateTeam (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, name, description, metadata, organizationId } = params

      Joi.validate({ id, name, description, organizationId, metadata }, Joi.object().keys(validationRules.updateTeam).or('name', 'description'), function (err) {
        if (err) return cb(Boom.badRequest(err))

        const updates = []
        const sql = SQL` UPDATE teams SET `
        if (name) { updates.push(SQL`name = ${name}`) }
        if (description) { updates.push(SQL`description = ${description}`) }
        if (metadata) { updates.push(SQL`metadata = ${metadata}`) }
        sql.append(sql.glue(updates, ' , '))
        sql.append(SQL`
          WHERE id = ${id}
          AND org_id = ${organizationId}
        `)

        db.query(sql, (err, res) => {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict(err.detail))
          if (err) return cb(Boom.badImplementation(err))
          if (res.rowCount === 0) return cb(Boom.notFound(`Team with id ${id} could not be found`))

          teamOps.readTeam({ id, organizationId }, cb)
        })
      })

      return promise
    }
245325
public int addAgent(float[] pos, CrowdAgentParams params) {
        // Find empty slot.
        int idx = -1;
        for (int i = 0; i < m_maxAgents; ++i) {
            if (!m_agents[i].active) {
                idx = i;
                break;
            }
        }
        if (idx == -1) {
            return -1;
        }

        CrowdAgent ag = m_agents[idx];

        updateAgentParameters(idx, params);

        // Find nearest position on navmesh and place the agent there.
        Result<FindNearestPolyResult> nearestPoly = m_navquery.findNearestPoly(pos, m_ext,
                m_filters[ag.params.queryFilterType]);

        float[] nearest = nearestPoly.succeeded() ? nearestPoly.result.getNearestPos() : pos;
        long ref = nearestPoly.succeeded() ? nearestPoly.result.getNearestRef() : 0L;
        ag.corridor.reset(ref, nearest);
        ag.boundary.reset();
        ag.partial = false;

        ag.topologyOptTime = 0;
        ag.targetReplanTime = 0;

        vSet(ag.dvel, 0, 0, 0);
        vSet(ag.nvel, 0, 0, 0);
        vSet(ag.vel, 0, 0, 0);
        vCopy(ag.npos, nearest);

        ag.desiredSpeed = 0;

        if (ref != 0) {
            ag.state = CrowdAgentState.DT_CROWDAGENT_STATE_WALKING;
        } else {
            ag.state = CrowdAgentState.DT_CROWDAGENT_STATE_INVALID;
        }

        ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_NONE;

        ag.active = true;

        return idx;
    }