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