admin-edit-user.component.js 1.6 KB

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