Add solution visibility check to survey

This commit is contained in:
Ramon Wenger 2019-09-09 14:04:47 +02:00
parent 2af5749311
commit e10b577ac1
4 changed files with 18 additions and 5 deletions

View File

@ -3,6 +3,9 @@ query SurveyQuery($id: ID!) {
id
title
data
module {
id
}
answer {
data
}

View File

@ -3,7 +3,7 @@
<h1 class="survey-page__title">{{title}}</h1>
<survey :survey='survey'></survey>
<solution :value="solution"></solution>
<solution :value="solution" v-if="module.solutionsEnabled"></solution>
<div v-if="surveyComplete">
<a class="button button--primary" @click="reopen">Übung bearbeiten</a>
</div>
@ -15,6 +15,7 @@
import {css} from '@/survey.config'
import SURVEY_QUERY from '@/graphql/gql/surveyQuery.gql';
import MODULE_QUERY from '@/graphql/gql/moduleByIdQuery.gql';
import UPDATE_ANSWER from '@/graphql/gql/mutations/updateAnswer.gql';
import Solution from '@/components/content-blocks/Solution';
@ -33,7 +34,8 @@
data() {
return {
survey: this.initSurvey(),
title: ''
title: '',
module: {}
}
},
@ -134,6 +136,14 @@
this.survey = this.initSurvey(json, answer);
this.title = json.title;
const module = data.survey.module;
this.$apollo.addSmartQuery('module', {
query: MODULE_QUERY,
variables: {
id: module.id
}
});
}
},
}

View File

@ -58,4 +58,3 @@ class Module(StrictHierarchyPage):
def get_child_ids(self):
return self.get_children().values_list('id', flat=True)

View File

@ -120,7 +120,8 @@ class ModuleNode(DjangoObjectType):
return self.get_parent().specific
def resolve_solutions_enabled(self, info, **kwargs):
return self.solutions_enabled_by.filter(pk=info.context.user.pk).exists()
teacher = info.context.user.get_teacher()
return self.solutions_enabled_by.filter(pk=teacher.pk).exists() if teacher is not None else False
class TopicNode(DjangoObjectType):
@ -187,7 +188,7 @@ class FilteredChapterNode(DjangoObjectType):
class BookQuery(object):
book = relay.Node.Field(BookNode)
topic = graphene.Field(TopicNode, slug=graphene.String())
module = graphene.Field(ModuleNode, slug=graphene.String())
module = graphene.Field(ModuleNode, slug=graphene.String(), id=graphene.ID())
chapter = relay.Node.Field(FilteredChapterNode)
content_block = relay.Node.Field(ContentBlockNode)