{"size": 486, "ext": "js", "max_stars_repo_path": "Code/RBAC/hasPermission-RBAC.js", "max_stars_repo_name": "0xPhobos/rbac-in-node", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Code/RBAC/hasPermission-RBAC.js", "max_issues_repo_name": "0xPhobos/rbac-in-node", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Code/RBAC/hasPermission-RBAC.js", "max_forks_repo_name": "0xPhobos/rbac-in-node", "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": 27.0, "max_line_length": 67, "alphanum_fraction": 0.5946502058}
const hasPermission = (action) => {
  return async (req, res, next) => {
    const { user } = req.body;
    const { asset } = req.params;
    const userRoles = resolveUserRoles(user);

    const allowed = await userRoles.reduce(async (perms, role) => {
      const acc = await perms;
      if (acc) return true;

      const can = await policy.can(role, action, asset);
      if (can) return true;
    }, false);

    allowed ? next() : res.status(403).send("Forbidden").end();
  };
};
