{"size": 797, "ext": "js", "max_stars_repo_path": "api/policies/admin.js", "max_stars_repo_name": "Thankalv/easytv_crowdsourcing", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "api/policies/admin.js", "max_issues_repo_name": "Thankalv/easytv_crowdsourcing", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/policies/admin.js", "max_forks_repo_name": "Thankalv/easytv_crowdsourcing", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.7096774194, "max_line_length": 82, "alphanum_fraction": 0.6449184442}
/**
 * Authenticated admin
 */

module.exports = function(req, res, next) 
{
  orgId = req.param('id');
  if (_.isUndefined(orgId)) {
    FlashService.error(req, 'Your request lacks a valid org "id".');
  }
  var isOrgsAdmin = (req.session.User.userOrganisation.id === orgId);

  if (req.session.User && req.session.User.access === "superadmin") {
    return next();
  }

  // Admin of this organisation is allowed, proceed to controller
  if (req.session.User && (req.session.User.access === "admin" && isOrgsAdmin)) {
    return next();
  }
  else  // a no-admin user is NOT allowed
  {
    FlashService.error(req, 'You must be an administrator of this organisation.');

    //TODO: check for req.path functionality
    req.session.returnTo = req.path;
    res.redirect('/');
    return;
  }
};
