edit.vue 3.79 KB
Newer Older
Anton Koch's avatar
Anton Koch committed
1
2
<template lang="pug">
  full-screen
3
    //q-btn(v-if="!isMobile", slot="backButton", @click="$router.push({ name: 'documents.list' })", icon="keyboard_backspace", round, small)
Anton Koch's avatar
Anton Koch committed
4

5
6
7
    content-block(v-if="availableRoles.length", :position="'last'")
      headline(:content="$t('routes.documents.edit.title')")
        | {{ $t('descriptions.access_control_documents') }}
8

9
      content-paragraph(:position="'first'")
10
11
        q-checkbox(v-model="acl.public", :label="$t('labels.public')", dark)

12
      content-paragraph
13
14
15
        q-select(v-model="acl.group", :clearable="true", :clear-value="undefined",
        :float-label="$t('labels.access_control_add_group')", :options="availableRoles", dark)

16
      content-paragraph
17
18
19
20
21
22
        q-select(v-model="acl.group_remove", :clearable="true", :clear-value="undefined",
        :float-label="$t('labels.access_control_remove_group')", :options="availableRoles", dark)

      <!--q-field(dark)-->
        <!--q-checkbox(v-model="acl.recursive", :label="$t('labels.recursive')", dark)-->

23
24
      content-paragraph(:position="'last'")
        .full-width.text-right.q-mt-sm
25
          q-btn(:label="$t('buttons.update_access_control')", @click="updateACL", color="primary")
Anton Koch's avatar
Anton Koch committed
26
27
28
29
30
</template>

<script>
  import { mapGetters } from 'vuex'
  import { ObjectUtil } from 'mbjs-utils'
31
  import Headline from '../../components/shared/elements/Headline'
32
33
  import ContentBlock from '../../components/shared/elements/ContentBlock'
  import ContentParagraph from '../../components/shared/elements/ContentParagraph'
Anton Koch's avatar
Anton Koch committed
34
35

  export default {
36
    components: {
37
38
39
      Headline,
      ContentBlock,
      ContentParagraph
40
    },
Anton Koch's avatar
Anton Koch committed
41
42
43
44
45
46
47
48
49
50
51
52
    data () {
      return {
        acl: {
          public: false,
          group: undefined,
          group_remove: undefined,
          recursive: false
        }
      }
    },
    computed: {
      ...mapGetters({
53
54
        user: 'auth/getUserState',
        isMobile: 'globalSettings/getIsMobile'
Anton Koch's avatar
Anton Koch committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
      }),
      availableRoles () {
        try {
          const roles = this.user[`${process.env.AUTH0_APP_METADATA_PREFIX}roles`]
            .filter(role => role !== 'user')
          return roles.sort().map(role => { return { label: role, value: role } })
        }
        catch (e) {
          return []
        }
      },
      resourceName () {
        return ObjectUtil.uuid5(`${this.$route.params.bucket}/${this.$route.params.asset}`)
      }
    },
    async mounted () {
      const aclQuery = {role: 'public', uuid: this.resourceName, permission: 'get'}
      const permissions = await this.$store.dispatch('acl/isRoleAllowed', aclQuery)
      this.acl.public = permissions.get === true
74
      this.$root.$emit('setBackButton', 'list')
Anton Koch's avatar
Anton Koch committed
75
76
77
78
79
80
81
82
83
84
85
86
    },
    methods: {
      async setACL (action, payload, recursive = false) {
        await this.$store.dispatch(action, payload)
        if (recursive) {
          // TODO: add recursion to asset ACL
          throw new Error('Recursion not implemented')
        }
      },
      async updateACL () {
        this.$q.loading.show()
        if (this.acl.public) {
87
          await this.setACL('acl/set', { role: 'public', id: this.resourceName, permissions: ['get'] }, this.acl.recursive)
Anton Koch's avatar
Anton Koch committed
88
89
        }
        else {
90
          await this.setACL('acl/remove', { role: 'public', id: this.resourceName, permission: 'get' }, this.acl.recursive)
Anton Koch's avatar
Anton Koch committed
91
92
        }
        if (this.acl.group) {
93
          await this.setACL('acl/set', { role: this.acl.group, id: this.resourceName, permissions: ['get'] }, this.acl.recursive)
Anton Koch's avatar
Anton Koch committed
94
95
        }
        if (this.acl.group_remove) {
96
          await this.setACL('acl/remove', { role: this.acl.group_remove, id: this.resourceName, permission: 'get' }, this.acl.recursive)
Anton Koch's avatar
Anton Koch committed
97
98
99
100
101
102
103
104
105
106
        }
        this.$q.loading.hide()
        this.$store.commit('notifications/addMessage', {
          body: 'messages.acl_updated',
          type: 'success'
        })
      }
    }
  }
</script>