permissions.js 532 B

12345678910111213141516171819202122232425262728293031323334
  1. const _ = require('lodash')
  2. const permissions = []
  3. const permissionDescriptions = {}
  4. const register = (perm, description) => {
  5. if (!permissions.includes(perm)) {
  6. permissions.push(perm)
  7. permissions.sort()
  8. }
  9. if (description) {
  10. permissionDescriptions[perm] = description
  11. }
  12. }
  13. const list = (req, res) => {
  14. res.status(200).send(
  15. _.chain(permissions)
  16. .sort()
  17. .map(key => ({
  18. key,
  19. description: permissionDescriptions[key]
  20. }))
  21. .value()
  22. )
  23. }
  24. module.exports = {
  25. register,
  26. list
  27. }