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.

74 lines
1.6 KiB

  1. 'use strict'
  2. export default {
  3. name: 'admin-edit-user',
  4. props: ['usrdata'],
  5. data() {
  6. return {
  7. id: '',
  8. email: '',
  9. password: '********',
  10. name: '',
  11. rights: [],
  12. roleoverride: 'none'
  13. }
  14. },
  15. methods: {
  16. addRightsRow() {
  17. this.rights.push({
  18. role: 'write',
  19. path: '/',
  20. exact: false,
  21. deny: false
  22. })
  23. },
  24. removeRightsRow(idx) {
  25. this._.pullAt(this.rights, idx)
  26. this.$forceUpdate()
  27. },
  28. saveUser() {
  29. let self = this
  30. let formattedRights = this._.cloneDeep(this.rights)
  31. switch (this.roleoverride) {
  32. case 'admin':
  33. formattedRights.push({
  34. role: 'admin',
  35. path: '/',
  36. exact: false,
  37. deny: false
  38. })
  39. break
  40. }
  41. this.$http.post(window.location.href, {
  42. password: this.password,
  43. name: this.name,
  44. rights: JSON.stringify(formattedRights)
  45. }).then(resp => {
  46. self.$store.dispatch('alert', {
  47. style: 'green',
  48. icon: 'check',
  49. msg: 'Changes have been applied successfully.'
  50. })
  51. }).catch(err => {
  52. self.$store.dispatch('alert', {
  53. style: 'red',
  54. icon: 'square-cross',
  55. msg: 'Error: ' + err.body.msg
  56. })
  57. })
  58. }
  59. },
  60. mounted() {
  61. let usr = JSON.parse(this.usrdata)
  62. this.id = usr._id
  63. this.email = usr.email
  64. this.name = usr.name
  65. if (this._.find(usr.rights, { role: 'admin' })) {
  66. this.rights = this._.reject(usr.rights, ['role', 'admin'])
  67. this.roleoverride = 'admin'
  68. } else {
  69. this.rights = usr.rights
  70. }
  71. }
  72. }