You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.0 KiB

  1. /* global wiki */
  2. const gql = require('graphql')
  3. module.exports = {
  4. Query: {
  5. rights(obj, args, context, info) {
  6. return wiki.db.Right.findAll({ where: args })
  7. }
  8. },
  9. Mutation: {
  10. addRightToGroup(obj, args) {
  11. return wiki.db.Group.findById(args.groupId).then(grp => {
  12. if (!grp) {
  13. throw new gql.GraphQLError('Invalid Group ID')
  14. }
  15. return wiki.db.Right.create({
  16. path: args.path,
  17. role: args.role,
  18. exact: args.exact,
  19. allow: args.allow,
  20. group: grp
  21. })
  22. })
  23. },
  24. removeRightFromGroup(obj, args) {
  25. return wiki.db.Right.destroy({
  26. where: {
  27. id: args.rightId
  28. },
  29. limit: 1
  30. })
  31. },
  32. modifyRight(obj, args) {
  33. return wiki.db.Right.update({
  34. path: args.path,
  35. role: args.role,
  36. exact: args.exact,
  37. allow: args.allow
  38. }, {
  39. where: {
  40. id: args.id
  41. }
  42. })
  43. }
  44. },
  45. Right: {
  46. group(rt) {
  47. return rt.getGroup()
  48. }
  49. }
  50. }