Show ContentBlock actions only with the right permission
This commit is contained in:
parent
f3bcea7528
commit
bd4a9fded3
|
|
@ -6,8 +6,6 @@
|
|||
{{chapter.description}}
|
||||
</p>
|
||||
|
||||
<add-content-block-button :parent="chapter.id"></add-content-block-button>
|
||||
|
||||
<content-block :contentBlock="contentBlock"
|
||||
:key="contentBlock.id" v-for="contentBlock in filteredContentBlocks">
|
||||
</content-block>
|
||||
|
|
@ -16,14 +14,12 @@
|
|||
|
||||
<script>
|
||||
import ContentBlock from '@/components/ContentBlock';
|
||||
import AddContentBlockButton from '@/components/AddContentBlockButton';
|
||||
|
||||
export default {
|
||||
props: ['chapter', 'index'],
|
||||
|
||||
components: {
|
||||
ContentBlock,
|
||||
AddContentBlockButton
|
||||
},
|
||||
|
||||
computed: {
|
||||
|
|
@ -34,7 +30,7 @@
|
|||
},
|
||||
currentFilter() {
|
||||
return this.$store.state.filterForGroup;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div class="content-block__container">
|
||||
<div class="content-block" :class="specialClass">
|
||||
<div class="content-block__actions">
|
||||
<div v-if="canChangeContentBlock()" class="content-block__actions">
|
||||
<a @click="toggleVisibility()" class="content-block__visibility-button">
|
||||
<eye-icon class="content-block__action-icon"></eye-icon>
|
||||
</a>
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
</div>
|
||||
|
||||
<add-content-block-button :after="contentBlock.id"></add-content-block-button>
|
||||
<add-content-block-button v-if="canChangeContentBlock()" :after="contentBlock.id"></add-content-block-button>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
import VisibilityPopover from '@/components/VisibilityPopover';
|
||||
import EyeIcon from '@/components/icons/EyeIcon';
|
||||
import PenIcon from '@/components/icons/PenIcon';
|
||||
import ME_QUERY from '@/graphql/gql/meQuery.gql';
|
||||
|
||||
export default {
|
||||
props: ['contentBlock'],
|
||||
|
|
@ -77,12 +78,24 @@
|
|||
},
|
||||
editContentBlock() {
|
||||
this.$store.dispatch('editContentBlock', this.contentBlock.id);
|
||||
},
|
||||
canChangeContentBlock() {
|
||||
return this.me.permissions.includes('user.can_edit_modules');
|
||||
}
|
||||
},
|
||||
|
||||
apollo: {
|
||||
me: {
|
||||
query: ME_QUERY,
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
showVisibility: false
|
||||
showVisibility: false,
|
||||
me: {
|
||||
permissions: []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#import "./SchoolClassParts.gql"
|
||||
fragment UserParts on UserNode {
|
||||
id
|
||||
pk
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from faker import Faker
|
|||
from wagtail.documents.models import get_document_model
|
||||
from wagtail.images import get_image_model
|
||||
|
||||
fake = Faker('de_DE')
|
||||
fake = Faker('de_CH')
|
||||
|
||||
|
||||
def fake_title(x=None, min_words=2, max_words=4):
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class Migration(migrations.Migration):
|
|||
('school', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='user.School')),
|
||||
],
|
||||
options={
|
||||
'permissions': (('can_create_contentblocks', 'Can create new contentblocks'),),
|
||||
'permissions': (('can_edit_modules', 'Can create new contentblocks'),),
|
||||
},
|
||||
managers=[
|
||||
('objects', user.models.SchoolRoleManager()),
|
||||
|
|
|
|||
|
|
@ -87,10 +87,10 @@ class SchoolRoleManager(models.Manager):
|
|||
role = self.create(name=value, school=school, key=key)
|
||||
role.save()
|
||||
|
||||
can_create_contentblocks, = self._create_default_permissions()
|
||||
can_edit_modules, = self._create_default_permissions()
|
||||
|
||||
if key == "teacher":
|
||||
role.role_permission.add(can_create_contentblocks.id)
|
||||
role.role_permission.add(can_edit_modules.id)
|
||||
|
||||
# elif key == "school_admin":
|
||||
# role.role_permission.add()
|
||||
|
|
@ -122,9 +122,9 @@ class SchoolRoleManager(models.Manager):
|
|||
#edit_own_comments = Permission.objects.get(content_type=content_type, codename="can_edit_own_comments")
|
||||
#delete_comments = Permission.objects.get(content_type=content_type, codename="can_delete_comments")
|
||||
#admin_school = Permission.objects.get(content_type=content_type, codename="can_admin_school")
|
||||
can_create_contentblocks = Permission.objects.get(content_type=content_type, codename='can_create_contentblocks')
|
||||
can_edit_modules = Permission.objects.get(content_type=content_type, codename='can_edit_modules')
|
||||
|
||||
return can_create_contentblocks,
|
||||
return can_edit_modules,
|
||||
|
||||
|
||||
class SchoolRole(models.Model):
|
||||
|
|
@ -159,7 +159,7 @@ class SchoolRole(models.Model):
|
|||
# ("can_edit_events", "Can edit events"),
|
||||
# ("can_edit_own_comments", "Can edit own comments"),
|
||||
# ("can_delete_comments", "Can delete comments"),
|
||||
('can_create_contentblocks', 'Can create new contentblocks'),
|
||||
('can_edit_modules', 'Can create new contentblocks'),
|
||||
# ("can_admin_school", "Can admin school"),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue