summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/PermissionModuleEdit.vue
diff options
context:
space:
mode:
authorChristian Hofmaier2019-02-25 04:25:08 +0100
committerChristian Hofmaier2019-02-25 04:25:08 +0100
commit7b098c8b969a1d283a94391d9d8050ad0c5a4d13 (patch)
tree82d9f6edbc4503d3419a41626a986c4797478c8d /webapp/src/components/PermissionModuleEdit.vue
parent[webapp/datatable] improved slim mode (diff)
downloadbas-7b098c8b969a1d283a94391d9d8050ad0c5a4d13.tar.gz
bas-7b098c8b969a1d283a94391d9d8050ad0c5a4d13.tar.xz
bas-7b098c8b969a1d283a94391d9d8050ad0c5a4d13.zip
[permissionmanager] rework for blacklist system
- integrate PM into PM itself - wildcard function for hasPermission()
Diffstat (limited to 'webapp/src/components/PermissionModuleEdit.vue')
-rw-r--r--webapp/src/components/PermissionModuleEdit.vue129
1 files changed, 79 insertions, 50 deletions
diff --git a/webapp/src/components/PermissionModuleEdit.vue b/webapp/src/components/PermissionModuleEdit.vue
index fc66e62..4f78c14 100644
--- a/webapp/src/components/PermissionModuleEdit.vue
+++ b/webapp/src/components/PermissionModuleEdit.vue
@@ -1,13 +1,13 @@
<i18n>
{
"en": {
+ "blacklist": "Blacklist",
"description": "Description",
"groupdependent": "Groupdependent",
"groups": "Groups",
"id": "ID",
"name": "Name",
"permissions": "Permissions",
- "recursiveMode": "Select Groups recursive",
"role": "Role",
"roleName": "Role Name",
"roleNameEmptyError": "Role Name can't be empty.",
@@ -17,13 +17,13 @@
"summary": "Summary"
},
"de": {
+ "blacklist": "Blacklist",
"description": "Beschreibung",
"groupdependent": "Gruppengebunden",
"groups": "Gruppen",
"id": "ID",
"name": "Name",
"permissions": "Rechte",
- "recursiveMode": "Gruppen rekursiv auswählen",
"role": "Rolle",
"roleName": "Rollenname",
"roleNameEmptyError": "Rollenname kann nicht leer sein.",
@@ -80,6 +80,15 @@
:editable="stepCompleted >= 3"
edit-icon="check"
>
+ {{ $t('blacklist') }}
+ </v-stepper-step>
+ <v-divider></v-divider>
+ <v-stepper-step
+ :complete="stepCompleted >= 5"
+ step="5"
+ :editable="stepCompleted >= 4"
+ edit-icon="check"
+ >
{{ $t('summary') }}
</v-stepper-step>
</v-stepper-header>
@@ -117,17 +126,14 @@
</v-stepper-content>
<v-stepper-content step="3" class="stepper-padding-0">
- <data-table v-model="groupsSelected" :headers="groupHeaders" :items="groups">
- <div slot="actions" slot-scope="row" style="text-align: right">
- <v-tooltip top :key="row.item" open-delay="800">
- <v-btn slot="activator" :loading="row.item.loadingSubgroups" icon @click.stop @mousedown="loadChilds(row.item)" style="margin: 0"><v-icon>device_hub</v-icon></v-btn>
- <span>{{ $t('selectChildGroups') }}</span>
- </v-tooltip>
- </div>
- </data-table>
+ <data-table v-model="whitelist" :headers="groupHeaders" :items="groups" logging/>
+ </v-stepper-content>
+
+ <v-stepper-content step="4" class="stepper-padding-0">
+ <data-table v-model="blacklist" :headers="groupHeaders" :items="blacklistGroups"/>
</v-stepper-content>
- <v-stepper-content step="4">
+ <v-stepper-content step="5">
<v-text-field
v-model="roleName"
:label="$t('roleName')"
@@ -171,7 +177,23 @@
<v-subheader inset>{{ $t('groups') }}</v-subheader>
<v-divider class="list-header-margin"></v-divider>
<RecycleScroller
- :items="groupsSelected"
+ :items="whitelist"
+ :item-height="48"
+ page-mode
+ >
+ <div slot-scope="{ item }" class="list-item">
+ <div class="list-item-header">{{ item.id }} {{ item.name }}</div>
+ <div class="list-item-subheader">{{ item.description }}</div>
+ </div>
+ </RecycleScroller>
+ </div>
+ </v-flex>
+ <v-flex xs12 sm6>
+ <div>
+ <v-subheader inset>{{ $t('blacklist') }}</v-subheader>
+ <v-divider class="list-header-margin"></v-divider>
+ <RecycleScroller
+ :items="blacklist"
:item-height="48"
page-mode
>
@@ -196,7 +218,8 @@
<v-btn color="primary" v-show="step == 1" @click.native="completeStepOne()">{{ $t('continue') }}</v-btn>
<v-btn color="primary" v-show="step == 2" @click.native="completeStepTwo()">{{ $t('continue') }}</v-btn>
<v-btn color="primary" v-show="step == 3" @click.native="completeStepThree()">{{ $t('continue') }}</v-btn>
- <v-btn class="success" v-show="step == 4" @click="submit" type="submit">{{ $t('submit') }}</v-btn>
+ <v-btn color="primary" v-show="step == 4" @click.native="completeStepFour()">{{ $t('continue') }}</v-btn>
+ <v-btn class="success" v-show="step == 5" @click="submit" type="submit">{{ $t('submit') }}</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
@@ -204,6 +227,7 @@
<script>
import DataTable from '@/components/DataTable'
+import { mapState } from 'vuex'
export default {
name: 'PermissionModuleEdit',
@@ -216,12 +240,10 @@ export default {
valid: true,
step: 1,
stepCompleted: 0,
- permissions: [],
- groups: [],
+ blacklistGroups: [],
permissionsSelected: [],
- groupsSelected: [],
- groupsSummary: [],
- recursiveSwitch: false,
+ whitelist: [],
+ blacklist: [],
permissionHeaders: [
{ text: this.$t('name'), key: 'name' },
{ text: this.$t('description'), key: 'descr' },
@@ -230,8 +252,7 @@ export default {
groupHeaders: [
{ text: this.$t('id'), key: 'id' },
{ text: this.$t('name'), key: 'name' },
- { text: this.$t('description'), key: 'description' },
- { key: 'actions', width: '60px' }
+ { text: this.$t('description'), key: 'description' }
],
roleName: '',
roleDescr: ''
@@ -241,16 +262,17 @@ export default {
submit (event) {
if (this.$refs.form.validate()) {
const filteredPermissions = this.permissionsSelected.map(x => x.id)
- const filteredGroups = this.groupsSelected.map(x => x.id)
+ const filteredGroups = this.whitelist.map(x => x.id)
+ const filteredBlacklist = this.blacklist.map(x => x.id)
this.$http.post('/api/roles' + (this.roleId === 0 ? '' : '/' + this.roleId), {
id: this.roleId,
name: this.roleName,
descr: this.roleDescr,
permissions: filteredPermissions,
groups: filteredGroups,
- recursiveMode: this.recursiveSwitch
+ blacklist: filteredBlacklist
}).then(response => {
- this.$store.commit('newSnackbar', this.$t('roleSavedSuccess'))
+ this.$snackbar({ color: 'success', text: this.$t('roleSavedSuccess'), timeout: 15000 })
this.$store.dispatch('permissions/loadRoleData')
this.$store.commit('permissions/setEdit', false)
}).catch(error => {
@@ -258,13 +280,23 @@ export default {
})
}
},
- loadRole (roleId) {
- this.$http('/api/roles/' + this.roleId).then(response => {
- this.roleName = response.data.name
- this.roleDescr = response.data.descr
- this.permissionsSelected = response.data.permissions
- this.groupsSelected = response.data.groups
- this.recursiveSwitch = response.data.recursiveGroups
+ async loadRole (roleId) {
+ const response = await this.$http('/api/roles/' + this.roleId)
+ this.roleName = response.data.name
+ this.roleDescr = response.data.descr
+ this.permissionsSelected = response.data.permissions
+
+ var blacklistPush = []
+ for (let i = 0; i < response.data.groups.length; i++) {
+ if (response.data.groups[i].role_x_group.blacklist) {
+ blacklistPush.push(response.data.groups[i])
+ } else {
+ this.whitelist.push(response.data.groups[i])
+ }
+ }
+
+ this.loadChilds().then(() => {
+ this.blacklist = this.blacklist.concat(blacklistPush)
})
},
completeStepOne () {
@@ -282,27 +314,26 @@ export default {
completeStepThree () {
this.step = 4
this.stepCompleted = Math.max(3, this.stepCompleted)
+ this.loadChilds()
},
- loadGroups () {
- this.$http('/api/groups').then(response => {
- this.groups = response.data
- })
- },
- loadPermissions () {
- this.$http('/api/permissions').then(response => {
- this.permissions = response.data
- })
+ completeStepFour () {
+ this.step = 5
+ this.stepCompleted = Math.max(4, this.stepCompleted)
},
- loadChilds (group) {
- group.loadingSubgroups = true
- this.groupsSelected.push(group)
- this.$http('/api/groups/' + group.id + '?all').then(response => {
- this.groupsSelected = this.groupsSelected.concat(response.data.subgroups)
- group.loadingSubgroups = false
+ async loadChilds () {
+ this.blacklistGroups = []
+ var promises = []
+ this.whitelist.forEach(group => {
+ promises.push(
+ this.$http('/api/groups/' + group.id + '?all').then(response => {
+ this.blacklistGroups = this.blacklistGroups.concat(response.data.subgroups)
+ }))
})
+ await Promise.all(promises)
}
},
computed: {
+ ...mapState('permissions', ['permissions', 'groups']),
edit: function () {
return this.$store.state.permissions.edit
}
@@ -310,17 +341,15 @@ export default {
watch: {
edit: function (value) {
if (value) {
- this.loadGroups()
- this.loadPermissions()
this.$refs.form.resetValidation()
this.permissionsSelected = []
- this.groupsSelected = []
+ this.whitelist = []
+ this.blacklist = []
this.step = 1
if (this.roleId !== 0) {
this.loadRole(this.roleId)
- this.stepCompleted = 4
+ this.stepCompleted = 5
} else {
- this.recursiveSwitch = true
this.roleName = ''
this.roleDescr = ''
this.stepCompleted = 0