<commit_before>_ = require 'underscore'
colors = require 'colors'
app = require '../config/app'
{ ensureAuth } = require '../lib/route-middleware'
Team = app.db.model 'Team'
Vote = app.db.model 'Vote'

# middleware
loadTeam = (req, res, next) ->
  if id = req.param('id')
    Team.findById id, (err, team) ->
      return next err if err
      return next 404 unless team
      req.team = team
      next()
  else
    next()

loadPeople = (req, res, next) ->
  req.team.people (err, people) ->
    return next err if err
    req.people = people
    next()

loadVotes = (req, res, next) ->
  if (!app.enabled('voting') || !req.user)
    return next()
  Vote.findOne { type:'upvote', team_id: req.team.id, person_id: req.user.id }, (err, vote) ->
    return next err if err
    req.user.upvote = vote.upvote
    next()

ensureAccess = (req, res, next) ->
  return next 401 unless req.team.includes(req.user, req.session.team) or req.user.admin
  next()

# index
app.get '/teams', (req, res, next) ->
  Team.find (err, teams) ->
    return next err if err
    res.render2 'teams', teams: teams

# new
app.get '/teams/new', (req, res, next) ->
  Team.canRegister (err, yeah) ->
    return next err if err
    if yeah<commit_msg>always get the logic wrong with unless<commit_after>_ = require 'underscore'
colors = require 'colors'
app = require '../config/app'
{ ensureAuth } = require '../lib/route-middleware'
Team = app.db.model 'Team'
Vote = app.db.model 'Vote'

# middleware
loadTeam = (req, res, next) ->
  if id = req.param('id')
    Team.findById id, (err, team) ->
      return next err if err
      return next 404 unless team
      req.team = team
      next()
  else
    next()

loadPeople = (req, res, next) ->
  req.team.people (err, people) ->
    return next err if err
    req.people = people
    next()

loadVotes = (req, res, next) ->
  if (!app.enabled('voting') || !req.user)
    return next()
  Vote.findOne { type:'upvote', team_id: req.team.id, person_id: req.user.id }, (err, vote) ->
    return next err if err
    req.user.upvote = vote.upvote
    next()

ensureAccess = (req, res, next) ->
  return next 401 if not req.team.includes(req.user, req.session.team) or req.user.admin
  next()

# index
app.get '/teams', (req, res, next) ->
  Team.find (err, teams) ->
    return next err if err
    res.render2 'teams', teams: teams

# new
app.get '/teams/new', (req, res, next) ->
  Team.canRegister (err, yeah) ->
    return next err if err
    if yeah
{'fraction_non_alphanumeric': 0.1528507885159725, 'fraction_numerical': 0.005661140315406389, 'mean_word_length': 2.829721362229102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3676889', 'n_tokens_mistral': 878, 'n_tokens_neox': 863, 'n_words': 270}