is-super-admin.js 799 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * is-super-admin
  3. *
  4. * A simple policy that blocks requests from non-super-admins.
  5. *
  6. * For more about how to use policies, see:
  7. * https://sailsjs.com/config/policies
  8. * https://sailsjs.com/docs/concepts/policies
  9. * https://sailsjs.com/docs/concepts/policies/access-control-and-permissions
  10. */
  11. module.exports = async function (req, res, proceed) {
  12. // First, check whether the request comes from a logged-in user.
  13. // > For more about where `req.me` comes from, check out this app's
  14. // > custom hook (`api/hooks/custom/index.js`).
  15. if (!req.me) {
  16. return res.unauthorized();
  17. }//•
  18. // Then check that this user is a "super admin".
  19. if (!req.me.isSuperAdmin) {
  20. return res.forbidden();
  21. }//•
  22. // IWMIH, we've got ourselves a "super admin".
  23. return proceed();
  24. };