<commit_before>const RoleController = require('../controllers/Roles');
const UserController = require('../controllers/Users');
const DocumentController = require('../controllers/Documents');


require('../App');

module.exports = (app) => {
  /**
   * ROLE routes
   * All require ADMIN credentials to access
   */
  // Add a role
  app.post('/roles/add', UserController.authenticate, UserController.admin, RoleController.create);

  // List, Delete ALL roles
  app.route('/roles')
  .get(UserController.authenticate, UserController.admin, RoleController.listAll)
  .delete(UserController.authenticate, UserController.admin, RoleController.deleteAll);

  // View, Update, Delete ONE role by title
  app.route('/roles/:title')
  .get(UserController.authenticate, UserController.admin, RoleController.listOne)
  .put(UserController.authenticate, UserController.admin, RoleController.update)
  .delete(UserController.authenticate, UserController.admin, RoleController.deleteOne);

  /**
   * USER routes
   */
  // Login a user
  app.post('/users/login', UserController.login);

  // Sign up a new user
  app.post('/users/', UserController.create);

  // Logout user
  app.post('/users/logout', UserController.authenticate, UserController.logout);

  // Paginate and List all users
  app.route('/users/')
  .get(UserController.authenticate, UserController.paginateUsers)

   // Delete ALL users(Admin)
  .delete(UserController.authenticate, UserController.admin, UserController.deleteAll);

    // List All users without pagination
  app.get('/users/all', UserController.authenticate, UserController.listAll);

  // List, Update one user by ID
  app.route('/users/:id')
  .get(UserController.authenticate, UserController.listOne)
  .put(UserController.authenticate, UserController.update)

  // Delete a user (Admin)
  .delete(UserController.authenticate, UserController.admin, UserController.deleteOne);


  // Search for a user
  app.get('/search/users/', UserController.userSearch);

 /**
  * DOCUMENT routes
  */
  // Create a document
  app.post('/documents', UserController.authenticate, DocumentController.create);

  // View ALL user documents regardless of access(Admin)
  app.get('/documents/all', UserController.authenticate, UserController.admin, DocumentController.listAll);

  // View All Public documents
  app.get('/', DocumentController.listPublic);

  // View all of a user's documents
  app.get('/users/:id/documents', UserController.authenticate, DocumentController.listUserDocs);

  // Get or Delete a document by ID
  app.route('/documents/:id')
  .get(UserController.authenticate, DocumentController.listOneDoc)
  .put(UserController.authenticate, DocumentController.update);
<commit_msg>[feature #150154299] enable Cross-Origin Resource Sharing by adding custom HTTP headers to the server<commit_after>const RoleController = require('../controllers/Roles');
const UserController = require('../controllers/Users');
const DocumentController = require('../controllers/Documents');


require('../App');

module.exports = (app) => {
  // Enable Cross-Origin Resource Sharing (CORS)
  app.use((req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
    next();
  });

  /**
   * ROLE routes
   * All require ADMIN credentials to access
   */
  // Add a role
  app.post('/roles/add', UserController.authenticate, UserController.admin, RoleController.create);

  // List, Delete ALL roles
  app.route('/roles')
  .get(UserController.authenticate, UserController.admin, RoleController.listAll)
  .delete(UserController.authenticate, UserController.admin, RoleController.deleteAll);

  // View, Update, Delete ONE role by title
  app.route('/roles/:title')
  .get(UserController.authenticate, UserController.admin, RoleController.listOne)
  .put(UserController.authenticate, UserController.admin, RoleController.update)
  .delete(UserController.authenticate, UserController.admin, RoleController.deleteOne);

  /**
   * USER routes
   */
  // Login a user
  app.post('/users/login', UserController.login);

  // Sign up a new user
  app.post('/users/', UserController.create);

  // Logout user
  app.post('/users/logout', UserController.authenticate, UserController.logout);

  // Paginate and List all users
  app.route('/users/')
  .get(UserController.authenticate, UserController.paginateUsers)

   // Delete ALL users(Admin)
  .delete(UserController.authenticate, UserController.admin, UserController.deleteAll);

    // List All users without pagination
  app.get('/users/all', UserController.authenticate, UserController.listAll);

  // List, Update one user by ID
  app.route('/users/:id')
  .get(UserController.authenticate, UserController.listOne)
  .put(UserController.authenticate, UserController.update)

  // Delete a user (Admin)
  .delete(UserController.authenticate, UserController.admin, UserController.deleteOne);


  // Search for a user
  app.get('/search/users/', UserController.userSearch);

 /**
  * DOCUMENT routes
  */
  // Create a document
  app.post('/documents', UserController.authenticate, DocumentController.create);

  // View ALL user documents regardless of access(Admin)
  app.get('/documents/all', UserController.authenticate, UserController.admin, DocumentController.listAll);

  // View All Public documents
  app.get('/documents/public', DocumentController.listPublic);

  // View all of a user's documents
  app.get('/users/:id/documents', UserController.authenticate, DocumentController.listUserDocs);

  // Get or Delete a document by ID
  app.route('/documents/:id')
  .get(UserController.authenticate, DocumentController.listOneDoc)
  .put(UserController.authenticate, DocumentController.update);

{'fraction_non_alphanumeric': 0.13344887348353554, 'fraction_numerical': 0.001559792027729636, 'mean_word_length': 4.444339622641509, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2814764', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1605, 'n_words': 360}