<commit_before>_ = require 'underscore'
app = require '../config/app'
m = require './middleware'
Person = app.db.model 'Person'
Team = app.db.model 'Team'

# index
app.get '/people', (req, res, next) ->
  Person.find {}, {}, {sort: [['github.followersCount', -1]]}, (err, people) ->
    return next err if err
    res.render2 'people', people: people

# new
app.get '/people/new', [m.ensureAdmin], (req, res, next) ->
  res.render2 'people/new', person: new Person

# create
app.post '/people', [m.ensureAdmin], (req, res) ->
  person = new Person req.body
  person.save (err) ->
    if err
      res.render2 'people/new', person: person
    else
      res.redirect "people/#{person.id}"

# me
app.get '/people/me', [m.ensureAuth], (req, res, next) ->
  res.redirect "/people/#{req.user.id}"

# show
app.get '/people/:id', [m.loadPerson, m.loadPersonTeam, m.loadPersonVotes], (req, res, next) ->
  res.render2 'people/show',
    person: req.person
    team: req.team
    votes: req.votes

# edit
app.get '/people/:id/edit', [m.loadPerson, m.ensureAccess], (req, res, next) ->
  res.render2 'people/edit', person: req.person

# update
app.put '/people/:id', [m.loadPerson, m.ensureAccess], (req, res) ->
  unless req.user.admin
    delete req.body[attr] for attr in ['role', 'admin', 'technical']
  _.extend req.person, req.body
  req.person.save (err) ->
    return next err if err && err.name != 'ValidationError'
    if req.person.errors
      res.render2 'people/edit', person: req.person
    else
      res.redirect "/people/#{req.person.id}"

# delete
app.delete '/people/:id', [m.loadPerson, m.ensureAccess], (req, res, next) ->
  req.person.remove (err) ->
    return next err if err
    res.redirect '/people'<commit_msg>redirect to root if you delete your account<commit_after>_ = require 'underscore'
app = require '../config/app'
m = require './middleware'
Person = app.db.model 'Person'
Team = app.db.model 'Team'

# index
app.get '/people', (req, res, next) ->
  Person.find {}, {}, {sort: [['github.followersCount', -1]]}, (err, people) ->
    return next err if err
    res.render2 'people', people: people

# new
app.get '/people/new', [m.ensureAdmin], (req, res, next) ->
  res.render2 'people/new', person: new Person

# create
app.post '/people', [m.ensureAdmin], (req, res) ->
  person = new Person req.body
  person.save (err) ->
    if err
      res.render2 'people/new', person: person
    else
      res.redirect "people/#{person.id}"

# me
app.get '/people/me', [m.ensureAuth], (req, res, next) ->
  res.redirect "/people/#{req.user.id}"

# show
app.get '/people/:id', [m.loadPerson, m.loadPersonTeam, m.loadPersonVotes], (req, res, next) ->
  res.render2 'people/show',
    person: req.person
    team: req.team
    votes: req.votes

# edit
app.get '/people/:id/edit', [m.loadPerson, m.ensureAccess], (req, res, next) ->
  res.render2 'people/edit', person: req.person

# update
app.put '/people/:id', [m.loadPerson, m.ensureAccess], (req, res) ->
  unless req.user.admin
    delete req.body[attr] for attr in ['role', 'admin', 'technical']
  _.extend req.person, req.body
  req.person.save (err) ->
    return next err if err && err.name != 'ValidationError'
    if req.person.errors
      res.render2 'people/edit', person: req.person
    else
      res.redirect "/people/#{req.person.id}"

# delete
app.delete '/people/:id', [m.loadPerson, m.ensureAccess], (req, res, next) ->
  req.person.remove (err) ->
    return next err if err
    res.redirect '/'
{'fraction_non_alphanumeric': 0.1820792647903504, 'fraction_numerical': 0.00402067777139575, 'mean_word_length': 3.2788697788697787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '4407511', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1214, 'n_words': 329}