/*
This action is also routed for /teams under routes.js
192204
function(req, res, next){

  	// Find teams
  	app.models.Team.find().exec(finishRendering);

  	function finishRendering(err, collection){
  		if(err) return next('Failed to retrieve data');

  		return res.render('team/manage', {
  			path: req.route.path,
  			teams: collection
  		});
  	}
  }
1213267
def filter_teams(self, teams):
		""""""
		return [LeaderboardInstance(x) for x in self._leaderboard if x['faction']['id'] in teams]
1186493
function afterFindMatch(models){
		if(models.length != 1) return next(404);

		model = models[0];

		// Fetch Both Teams
		app.models.Team.findById(model.teamAId).exec(function(err, models){
			model.teamA = models.length ? models[0] : null;
			checkFetch();
		});

		app.models.Team.findById(model.teamBId).exec(function(err, models){
			model.teamB = models.length ? models[0] : null;
			checkFetch();
		});

		// Fetch Group
		app.models.Group.findById(model.groupId).exec(function(err, models){
			model.group = models.length ? models[0] : null;
			checkFetch();
		});
	}
338771
function Routing(app) {
	var config, defaultController;

	/**
	 * Find the action function based on controller name and action name.
	 * If no controller but a model is found, the default controller is taken.
	 * @param  {String} controllerName controller name
	 * @param  {String} actionName     action name
	 * @return {Function}              action function
	 */
	function getAction(controllerName, actionName) {
		controllerName = controllerName.camelize();
		var controller = app.controllers[controllerName];
		if (controller === undefined && app.models[controllerName])
			controller = defaultController;

		if (controller)
			return controller[actionName || 'index'];
		else
			return null;
	}

	/**
	 * adds a single route
	 * @param {String} verb           HTTP verb
	 * @param {String} routePath      routing path
	 * @param {String} controllerName controller name
	 * @param {String} actionName     action name
	 */
	function addSingleRoute(verb, routePath, controllerName, actionName) {
		// add controller and action fields to the request
		var reqExtender = function(req, res, next) {
			req.controller = controllerName;
			req.action = actionName || 'index';
			next();
		};

		var params = [routePath, reqExtender];
		params = params.concat(getPolicies(controllerName, actionName));
		params.push(getAction(controllerName, actionName));

		app[verb].apply(app, params);
	}

	/**
	 * gets the policies in effect for a given controller and action
	 * @param  {String} controller
	 * @param  {String} action
	 * @return {Array}            policies
	 */
	function getPolicies(controller, action) {
		var policies = config.policies;
		var currentPolicies = [];
		if (policies[controller] && policies[controller][action]) {
			currentPolicies = policies[controller][action];
		} else if (Object.isString(policies[controller])) {
			currentPolicies = policies[controller];
		} else if (policies[controller] && policies[controller]['*']) {
			currentPolicies = policies[controller]['*'];
		} else if (policies['*']) {
			currentPolicies = policies['*'];
		}

		if (currentPolicies === true) {
			currentPolicies = [];
		}

		if (!Object.isArray(currentPolicies)) {
			currentPolicies = [currentPolicies];
		}

		currentPolicies = currentPolicies.map(function(policy) {
			var policyPath = path.join(config.rootDir, config.paths.policies, policy);
			return require(policyPath);
		});
		return currentPolicies;
	}

	/**
	 * parse the resource route definitions
	 */
	var resourceRouting;
	function parseResourceRoutes() {
		var routes = config.resourceRouting;
		resourceRouting = [];
		for (var route in routes) {
			var parsedRoute = parseRoute(route, routes[route]);
			// if it's a string it defines the action
			if (Object.isString(parsedRoute.target)) {
				parsedRoute.target = {action: parsedRoute.target};
			}
			resourceRouting.push(parsedRoute);
		}
	}

	/**
	 * add a resource route
	 * @param {String} routePath      route path
	 * @param {String} controllerName controller name
	 */
	function addResourceRoute(routePath, controllerName) {
		resourceRouting.forEach(function(route) {
			var actionPath = route.path.replace(':controller', controllerName);
			route.verbs.forEach(function (verb) {
				addSingleRoute(verb, actionPath, controllerName, route.target.action);
			});
		});
	}

	/**
	 * add a static route
	 * @param {String} routePath route path
	 * @param {String} target    target path (relative to the scarab root)
	 */
	function addStaticRoute(routePath, targets) {
		if (!Object.isArray(targets)) {
			targets = [targets];
		}
		targets.forEach(function(target) {
			if (target)
				app.use(routePath, app.middleware.static(path.resolve(config.rootDir, target)));
		});
	}

	function addRedirectRoute(verb, routePath, target) {
		app[verb](routePath, function(req, res) {
			res.redirect(target);
		});
	}

	/**
	 * apply the path policies (for static routes)
	 */
	function applyPathPolicies() {
		var allPolicies = [];
		for (var routePath in config.policies) {
			if (routePath.charAt(0) === '/') {
				var currentPolicies = config.policies[routePath];
				if (currentPolicies === true) {
					currentPolicies = [];
				}
				if (!Object.isArray(currentPolicies)) {
					currentPolicies = [currentPolicies];
				}
				allPolicies.push({route: routePath, policies: currentPolicies});
			}
		}
		allPolicies.forEach(function(pathPolicy) {
			pathPolicy.policies.forEach(function(policy) {
				var policyPath = path.join(config.rootDir, config.paths.policies, policy);
				app.all(pathPolicy.route, require(policyPath));
			});
		});
	}

	/**
	 * parse a route
	 * @param  {String} route  a route definition
	 * @param  {Object} target target definition
	 * @return {Object}        route parsed into verbs, path and target
	 */
	function parseRoute(route, target) {
		var verbs, routePath, routeParts;

		routeParts = route.split(' ');
		if (routeParts.length === 1) {
			verbs = ['all'];
			routePath = routeParts[0];
		} else {
			verbs = routeParts[0].split(',');
			verbs.map(function (verb) {
				return verb.trim().toLowerCase();
			});
			routePath = routeParts[1];
		}
		return {verbs: verbs, path: routePath, target: target};
	}

	/**
	 * initializes all routes
	 */
	function init() {
		config = app.config;

		defaultController = config.defaultControllerFactory(app.models);

		// load controllers
		var controllerDir = path.join(config.rootDir, config.paths.controllers);
		var controllerFiles = fs.readdirSync(controllerDir);
		controllerFiles.forEach(function(controllerFile) {
			var controllerName = controllerFile.substring(0, controllerFile.indexOf('Controller'));
			var controllerDef = require(path.join(controllerDir, controllerFile));
			var controller;
			if (controllerDef.noDefaultActions) {
				controller = controllerDef;
			} else {
				controller = Object.create(defaultController);
				controller = Object.merge(controller, controllerDef);
			}
			app.controllers[controllerName] = controller;
		});

		applyPathPolicies();

		var routes = config.routes,
			parsed = [];

		parseResourceRoutes();

		for (var route in routes) {
			parsed.push(parseRoute(route, routes[route]));
		}

		parsed.forEach(function(route) {
			if(!route.target)
				return;

			if (Object.isString(route.target)) {
				if (route.verbs[0] !== 'static' && route.target.charAt(0) === '/') {
					route.target = {redirect: route.target};
				} else {
					var parts = route.target.split('.');
					if (parts.length === 2) {
						route.target = {controller: parts[0], action: parts[1]};
					}
				}
			}
			if (!Object.isObject(route.target)) {
				route.target = {controller: route.target};
			}

			route.verbs.forEach(function (verb) {
				if (verb === 'resource') {
					addResourceRoute(route.path, route.target.controller);
				} else if (verb === 'static') {
					addStaticRoute(route.path, route.target.controller);
				} else if (route.target.redirect) {
					addRedirectRoute(verb, route.path, route.target.redirect);
				} else {
					addSingleRoute(verb, route.path, route.target.controller, route.target.action);
				}
			});
		});

		if(config.autoRoute) {
			resourceRouting.forEach(function(route) {
				var actionPath = path.join('/', config.autoRoutePath, route.path);
				route.verbs.forEach(function (verb) {
					app[verb](actionPath, function(req, res, next) {
						var controllerName = req.params.controller.singularize();
						var actionName = route.target.action;
						req.controller = controllerName;
						req.action = actionName;

						var action = getAction(controllerName, actionName);
						if (action) {
							var policies = getPolicies(controllerName, actionName);
							if (policies.length > 0) {
								var policyIdx = 0;
								var nextPolicy = function() {
									policyIdx++;
									if (policyIdx < policies.length) {
										policies[policyIdx](req, res, nextPolicy);
									} else {
										action(req, res, next);
									}
								};
								policies[0](req, res, nextPolicy);
							} else {
								action(req, res, next);
							}
						} else {
							next();
						}
					});
				});
			});
		}
	}

	return {
		init: init
	};
}
193500
def delete_team_iteration(self, team_context, id):
        
        project = None
        team = None
        if team_context is not None:
            if team_context.project_id:
                project = team_context.project_id
            else:
                project = team_context.project
            if team_context.team_id:
                team = team_context.team_id
            else:
                team = team_context.team

        route_values = {}
        if project is not None:
            route_values['project'] = self._serialize.url('project', project, 'string')
        if team is not None:
            route_values['team'] = self._serialize.url('team', team, 'string')
        if id is not None:
            route_values['id'] = self._serialize.url('id', id, 'str')
        self._send(http_method='DELETE',
                   location_id='c9175577-28a1-4b06-9197-8636af9f64ad',
                   version='5.0',
                   route_values=route_values)
46104
function addExtraTeamData (team) {
  team.teamName = team.teamName.trim();
  const splitted = team.teamName.split(" ");
  if (TWO_WORD_TEAMS[team.teamName]) {
    team.simpleName = splitted.splice(-2, 2).join(" ");
  } else {
    team.simpleName = splitted.splice(-1, 1).join();
  }
  team.location = splitted.join(" ");
  return team;
}
1248473
function(company, team, code) {
  debug('preparing url');
  var _url = '';
  if (code) {
    _url = '/' + code;
  }

  return 'otask/v1/tasks/companies/' + company + '/teams/' + team + '/tasks' + _url;
}
1220575
def get_teams():
        
        LOGGER.debug("TeamService.get_teams")
        args = {'http_operation': 'GET', 'operation_path': ''}
        response = TeamService.requester.call(args)
        ret = None
        if response.rc == 0:
            ret = []
            for team in response.response_content['teams']:
                ret.append(Team.json_2_team(team))
        elif response.rc != 404:
            err_msg = 'TeamService.get_teams - Problem while getting teams. ' \
                      '. Reason: ' + str(response.response_content) + '-' + str(response.error_message) + \
                      " (" + str(response.rc) + ")"
            LOGGER.warning(err_msg)
        return ret
1318972
function addTeamPolicies (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId } = params

      Joi.validate({ id, organizationId, policies: params.policies }, validationRules.addTeamPolicies, function (err) {
        if (err) return cb(Boom.badRequest(err))

        const policies = utils.preparePolicies(params.policies)

        utils.checkPoliciesOrg(db, policies, organizationId, (err) => {
          if (err) return cb(err)

          insertTeamPolicies({ client: db, teamId: id, policies }, (err, res) => {
            if (err) return cb(err)
            teamOps.readTeam({ id, organizationId }, cb)
          })
        })
      })

      return promise
    }
135119
function (route) {
	if ( this.safenames ) {
		route = route.split( '/' );
		var name = route.pop();
		name = safename( name );
		route.push( name );
		return route.join( '/' );
	} else {
		return route;
	}
}
768343
@SuppressWarnings("unchecked")
    public List<MappedLdapGroup> getMappedLdapGroups(final Team team) {
        final Query query = pm.newQuery(MappedLdapGroup.class, "team == :team");
        return (List<MappedLdapGroup>) query.execute(team);
    }
114969
def users(self, team, params={}, **options): 
        
        path = "/teams/%s/users" % (team)
        return self.client.get_collection(path, params, **options)
1167643
private function processTeam(int $team_id, int $resource_id, string $method_code, int $action_id, $module_id = null) : int {
		// load all roles from datasource
		if (is_null(self::$cached_teams) && !\Object\Error\Base::$flag_database_tenant_not_found) {
			self::$cached_teams = \Object\ACL\Resources::getStatic('roles', 'teams');
		}
		// if role is not found
		if (empty(self::$cached_teams[$team_id])) return 0;
		// process permissions
		$all_actions = self::$cached_teams[$team_id]['permissions'][$resource_id]['AllActions'][-1] ?? [];
		$actual_action = self::$cached_teams[$team_id]['permissions'][$resource_id][$method_code][$action_id] ?? [];
		$temp = array_merge_hard($all_actions, $actual_action);
		if (!empty($temp)) {
			if (!empty($module_id)) {
				$temp = $temp[$module_id] ?? null;
			} else { // find any active permision
				$temp2 = $temp;
				$temp = null;
				foreach ($temp2 as $k => $v) {
					if ($v === 0) {
						$temp = 0;
						break;
					}
				}
			}
		}
		if ($temp === 0) {
			return 1;
		} else if ($temp === 1) {
			return 2;
		}
		return 0;
	}
1055113
function bbTeamToBotkitTeam (team) {
  return {
    id: team.slack_team_id,
    createdBy: team.slack_user_id,
    url: `https://${team.slack_team_domain}.slack.com/`,
    name: team.slack_team_name,
    bot: {
      name: team.slack_bot_user_name,
      token: team.slack_bot_access_token,
      user_id: team.slack_bot_user_id,
      createdBy: team.slack_user_id,
      app_token: team.slack_access_token
    }
  }
}
997955
def requestTeam(self, team_name):
        
        if not team_name in self.requested:
            self.requested.append(team_name)
396107
function assembleRoutes( { places } ) {
      const routeMap = {};
      forEach( places, ( place, placeId ) => {
         place.id = placeId;
         place.patterns = place.patterns || [ `/${placeId}` ];
         setPath( place, `targets.${TARGET_SELF}`, place.id );

         const { id, patterns, page, redirectTo, redirectToPath } = place;
         availablePlaces[ id ] = place;

         if( redirectTo ) {
            patterns.forEach( pattern => {
               routeMap[ pattern ] = parameters => {
                  navigateToTarget( redirectTo, parameters, null, place );
               };
            } );
            return;
         }

         if( redirectToPath ) {
            patterns.forEach( pattern => {
               routeMap[ pattern ] = () => {
                  navigateToPath( redirectToPath, place );
               };
            } );
            return;
         }

         if( !page ) {
            log.error( `flow: invalid empty place: ${id}` );
            return;
         }

         patterns.forEach( pattern => {
            routeMap[ pattern ] = ( parameters, fragment ) => {
               handleRouteChange( place, parameters, fragment );
            };
         } );
      } );
      return routeMap;
   }
349617
function run(route, index, path, query, res, next) {
    mm.create(route.action).then(
        function (presenter) {
            var ele = new Element('div');

            function finish() {
                var model = presenter.model;
                res.html = ele.outerHTML;
                res.data = model.store;
                res.routeIndex = index;
                next();
            }

            presenter
                .enter(ele, path, query)
                .then(finish, next);
        },
        next
    ).then(null, next);
}