Skip to content

Commit

Permalink
frontend/Story.vue: disable editable switch if user is not collaborator
Browse files Browse the repository at this point in the history
Pass camp as function instead of object into campRoleMixin.

Issue: ecamp#1415
  • Loading branch information
BacLuc committed Jun 6, 2021
1 parent 9ac851e commit 6afa4cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 11 additions & 5 deletions frontend/src/mixins/campRoleMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ export const campRoleMixin = {
return this.isMember || this.isManager
},
isGuest () {
return this.camp?.role === 'guest'
return this.role === 'guest'
},
isManager () {
return this.camp?.role === 'manager'
return this.role === 'manager'
},
isMember () {
return this.camp?.role === 'member'
return this.role === 'member'
},
role () {
if (typeof this.camp === 'function') {
return this.camp()?.role
}
return this.camp?.role
}
},
mounted () {
if (typeof this.camp !== 'object') {
throw new Error('User of the campRoleMixin must expose a method/proxy camp()')
if (typeof this.camp !== 'object' && typeof this.camp !== 'function') {
throw new Error('User of the campRoleMixin must expose a camp as object proxy or function')
}
}
}
3 changes: 3 additions & 0 deletions frontend/src/views/camp/Story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Admin screen of a camp: Displays details & periods of a single camp and allows t
<template v-if="$vuetify.breakpoint.smAndUp">
<e-switch v-model="editing" :label="$tc('global.button.editable')"
class="ec-story-editable ml-auto"
:disabled="!isContributor"
@click="$event.preventDefault()" />
</template>
<v-menu v-else offset-y>
Expand Down Expand Up @@ -60,6 +61,7 @@ Admin screen of a camp: Displays details & periods of a single camp and allows t
<script>
import ContentCard from '@/components/layout/ContentCard.vue'
import StoryPeriod from '@/components/camp/StoryPeriod.vue'
import { campRoleMixin } from '@/mixins/campRoleMixin'
const PRINT_SERVER = window.environment.PRINT_SERVER
Expand All @@ -69,6 +71,7 @@ export default {
StoryPeriod,
ContentCard
},
mixins: [campRoleMixin],
props: {
camp: { type: Function, required: true }
},
Expand Down

0 comments on commit 6afa4cb

Please sign in to comment.