mirror of https://github.com/Requarks/wiki.git
8 changed files with 285 additions and 282 deletions
Split View
Diff Options
-
2client/js/app.js
-
122client/js/components/modal-create-user.vue
-
76client/js/components/modal-delete-user.vue
-
74client/js/pages/admin-edit-user.component.js
-
72client/js/pages/admin.js
-
3server/locales/en/common.json
-
4server/views/pages/admin/_layout.pug
-
214server/views/pages/admin/users-edit.pug
@ -0,0 +1,74 @@ |
|||
'use strict' |
|||
|
|||
export default { |
|||
name: 'admin-edit-user', |
|||
props: ['usrdata'], |
|||
data() { |
|||
return { |
|||
id: '', |
|||
email: '', |
|||
password: '********', |
|||
name: '', |
|||
rights: [], |
|||
roleoverride: 'none' |
|||
} |
|||
}, |
|||
methods: { |
|||
addRightsRow() { |
|||
this.rights.push({ |
|||
role: 'write', |
|||
path: '/', |
|||
exact: false, |
|||
deny: false |
|||
}) |
|||
}, |
|||
removeRightsRow(idx) { |
|||
this._.pullAt(this.rights, idx) |
|||
this.$forceUpdate() |
|||
}, |
|||
saveUser() { |
|||
let self = this |
|||
let formattedRights = this._.cloneDeep(this.rights) |
|||
switch (this.roleoverride) { |
|||
case 'admin': |
|||
formattedRights.push({ |
|||
role: 'admin', |
|||
path: '/', |
|||
exact: false, |
|||
deny: false |
|||
}) |
|||
break |
|||
} |
|||
this.$http.post(window.location.href, { |
|||
password: this.password, |
|||
name: this.name, |
|||
rights: JSON.stringify(formattedRights) |
|||
}).then(resp => { |
|||
self.$store.dispatch('alert', { |
|||
style: 'green', |
|||
icon: 'check', |
|||
msg: 'Changes have been applied successfully.' |
|||
}) |
|||
}).catch(err => { |
|||
self.$store.dispatch('alert', { |
|||
style: 'red', |
|||
icon: 'square-cross', |
|||
msg: 'Error: ' + err.body.msg |
|||
}) |
|||
}) |
|||
} |
|||
}, |
|||
mounted() { |
|||
let usr = JSON.parse(this.usrdata) |
|||
this.id = usr._id |
|||
this.email = usr.email |
|||
this.name = usr.name |
|||
|
|||
if (this._.find(usr.rights, { role: 'admin' })) { |
|||
this.rights = this._.reject(usr.rights, ['role', 'admin']) |
|||
this.roleoverride = 'admin' |
|||
} else { |
|||
this.rights = usr.rights |
|||
} |
|||
} |
|||
} |
@ -1,72 +0,0 @@ |
|||
'use strict' |
|||
|
|||
/* global usrData */ |
|||
|
|||
import $ from 'jquery' |
|||
import _ from 'lodash' |
|||
import Vue from 'vue' |
|||
|
|||
module.exports = (alerts) => { |
|||
if ($('#page-type-admin-users-edit').length) { |
|||
let vueEditUser = new Vue({ |
|||
el: '#page-type-admin-users-edit', |
|||
data: { |
|||
id: '', |
|||
email: '', |
|||
password: '********', |
|||
name: '', |
|||
rights: [], |
|||
roleoverride: 'none' |
|||
}, |
|||
methods: { |
|||
addRightsRow: (ev) => { |
|||
vueEditUser.rights.push({ |
|||
role: 'write', |
|||
path: '/', |
|||
exact: false, |
|||
deny: false |
|||
}) |
|||
}, |
|||
removeRightsRow: (idx) => { |
|||
_.pullAt(vueEditUser.rights, idx) |
|||
vueEditUser.$forceUpdate() |
|||
}, |
|||
saveUser: (ev) => { |
|||
let formattedRights = _.cloneDeep(vueEditUser.rights) |
|||
switch (vueEditUser.roleoverride) { |
|||
case 'admin': |
|||
formattedRights.push({ |
|||
role: 'admin', |
|||
path: '/', |
|||
exact: false, |
|||
deny: false |
|||
}) |
|||
break |
|||
} |
|||
$.post(window.location.href, { |
|||
password: vueEditUser.password, |
|||
name: vueEditUser.name, |
|||
rights: JSON.stringify(formattedRights) |
|||
}).done((resp) => { |
|||
alerts.pushSuccess('Saved successfully', 'Changes have been applied.') |
|||
}).fail((jqXHR, txtStatus, resp) => { |
|||
alerts.pushError('Error', resp) |
|||
}) |
|||
} |
|||
}, |
|||
created: function () { |
|||
this.id = usrData._id |
|||
this.email = usrData.email |
|||
this.name = usrData.name |
|||
|
|||
if (_.find(usrData.rights, { role: 'admin' })) { |
|||
this.rights = _.reject(usrData.rights, ['role', 'admin']) |
|||
this.roleoverride = 'admin' |
|||
} else { |
|||
this.rights = usrData.rights |
|||
} |
|||
} |
|||
}) |
|||
require('../modals/admin-users-delete.js')(alerts) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save