<commit_before>'use strict'

let _ = require('underscore')
let winston = require('winston')
let Rescue = require('../models/rescue')
let Permission = require('../permission')




// EDIT
// =============================================================================
exports.editRescue = function (request, response) {
  Permission.require('rescue.edit', request.user).then(function () {

  }, function (permission) {

  })

  Rescue.findById(request.params.id)
  .populate('rats firstLimpet')
  .then(function (rescue) {
    rescue.rats.forEach(function (rat) {
      if (rat.CMDRname === rescue.firstLimpet.CMDRname) {
        rat.firstLimpet = true
      }
    })

    response.render('rescue-edit')
  })
}


// LIST
// =============================================================================
exports.listRescues = function (request, response) {
  Permission.require('admin.read', request.user).then(function () {
    let rescues = []
    let renderVars = {}

    if (!request.params.page || request.params.page < 1) {
      request.params.page = 1
    }

    renderVars.page = request.params.page

    if (request.params.page > 1) {
      renderVars.previousPage = request.params.page - 1
    }

    let filter = {
      size: 100,
      sort: 'createdAt:desc'<commit_msg>Restruct rescue edit page to admins<commit_after>'use strict'

let _ = require('underscore')
let winston = require('winston')
let Rescue = require('../models/rescue')
let Permission = require('../permission')




// EDIT
// =============================================================================
exports.editRescue = function (request, response) {
  Permission.require('rescue.edit', request.user).then(function () {
    Rescue.findById(request.params.id)
    .populate('rats firstLimpet')
    .then(function (rescue) {
      rescue.rats.forEach(function (rat) {
        if (rat.CMDRname === rescue.firstLimpet.CMDRname) {
          rat.firstLimpet = true
        }
      })

      response.render('rescue-edit')
    })
  }, function () {
    response.render('errors/403')
  })


}


// LIST
// =============================================================================
exports.listRescues = function (request, response) {
  Permission.require('admin.read', request.user).then(function () {
    let rescues = []
    let renderVars = {}

    if (!request.params.page || request.params.page < 1) {
      request.params.page = 1
    }

    renderVars.page = request.params.page

    if (request.params.page > 1) {
      renderVars.previousPage = request.params.page - 1
    }

    let filter = {
      size: 100,
      sort: 'createdAt:desc'
{'fraction_non_alphanumeric': 0.2518067706352225, 'fraction_numerical': 0.006466337010270064, 'mean_word_length': 3.3687707641196014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5424414', 'n_tokens_mistral': 811, 'n_tokens_neox': 746, 'n_words': 136}