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.

54 lines
1.0 KiB

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