<commit_before>_ = require 'underscore'
app = require '../config/app'
{ ensureAdmin, ensureAccess, loadPerson, loadPersonTeam } = require '../lib/route-middleware'
Person = app.db.model 'Person'
Team = app.db.model 'Team'

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

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

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

# create
app.post '/people', [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}"

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

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

# update
app.put '/people/:id', [loadPerson, ensureAccess], (req, res) ->
  unless req.user.admin
    delete req.body[attr] for attr in ['role', 'admin', 'technical']
  else # FIXME
    req.body.admin = !!req.body.admin
    req.body.technical = !!req.body.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}"
<commit_msg>ensureAuth before /people/me<commit_after>_ = require 'underscore'
app = require '../config/app'
m = require '../lib/route-middleware'
Person = app.db.model 'Person'
Team = app.db.model 'Team'

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

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

# 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}"

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

# 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']
  else # FIXME
    req.body.admin = !!req.body.admin
    req.body.technical = !!req.body.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}"

{'fraction_non_alphanumeric': 0.17606299212598425, 'fraction_numerical': 0.003779527559055118, 'mean_word_length': 3.33879781420765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '3275491', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1087, 'n_words': 292}