Use slug to identify module when toggling solutions
This commit is contained in:
parent
ea95efc23f
commit
00b2b02113
|
|
@ -36,7 +36,7 @@
|
||||||
<toggle-editing v-if="onModulePage"></toggle-editing>
|
<toggle-editing v-if="onModulePage"></toggle-editing>
|
||||||
<toggle-solutions-for-module
|
<toggle-solutions-for-module
|
||||||
v-if="onModulePage && module.id"
|
v-if="onModulePage && module.id"
|
||||||
:module="module.id"
|
:slug="module.slug"
|
||||||
:enabled="module.solutionsEnabled"
|
:enabled="module.solutionsEnabled"
|
||||||
class="module-navigation__solution-toggle"
|
class="module-navigation__solution-toggle"
|
||||||
data-cy="toggle-enable-solutions"></toggle-solutions-for-module>
|
data-cy="toggle-enable-solutions"></toggle-solutions-for-module>
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
||||||
<script>
|
<script>
|
||||||
import Checkbox from '@/components/Checkbox';
|
import Checkbox from '@/components/Checkbox';
|
||||||
import UPDATE_SOLUTION_VISIBILITY_MUTATION from '@/graphql/gql/mutations/updateSolutionVisibility.gql';
|
import UPDATE_SOLUTION_VISIBILITY_MUTATION from '@/graphql/gql/mutations/updateSolutionVisibility.gql';
|
||||||
import MODULE_QUERY from '@/graphql/gql/moduleByIdQuery.gql';
|
import MODULE_FRAGMENT from '@/graphql/gql/fragments/moduleParts.gql';
|
||||||
|
|
||||||
import {meQuery} from '@/graphql/queries';
|
import {meQuery} from '@/graphql/queries';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['module', 'enabled'],
|
props: ['slug', 'enabled'],
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
Checkbox
|
Checkbox
|
||||||
|
|
@ -37,24 +37,22 @@
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
toggleSolutions(enabled) {
|
toggleSolutions(enabled) {
|
||||||
const module = this.module;
|
const slug = this.slug;
|
||||||
this.$apollo.mutate({
|
this.$apollo.mutate({
|
||||||
mutation: UPDATE_SOLUTION_VISIBILITY_MUTATION,
|
mutation: UPDATE_SOLUTION_VISIBILITY_MUTATION,
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
id: this.module,
|
slug,
|
||||||
enabled: enabled
|
enabled
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
update(store, {data: {updateSolutionVisibility: {success, solutionsEnabled}}}) {
|
update(store, {data: {updateSolutionVisibility: {success, solutionsEnabled}}}) {
|
||||||
if (success) {
|
if (success) {
|
||||||
const variables = {
|
const id = `ModuleNode:${slug}`;
|
||||||
id: module
|
const fragment = MODULE_FRAGMENT;
|
||||||
};
|
const data = store.readFragment({fragment, id});
|
||||||
const query = MODULE_QUERY;
|
data.solutionsEnabled = solutionsEnabled;
|
||||||
const data = store.readQuery({query, variables});
|
store.writeFragment({fragment, data, id});
|
||||||
data.module.solutionsEnabled = solutionsEnabled;
|
|
||||||
store.writeQuery({query, data, variables});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from books.schema.queries import ModuleNode
|
||||||
|
|
||||||
class UpdateSolutionVisibility(relay.ClientIDMutation):
|
class UpdateSolutionVisibility(relay.ClientIDMutation):
|
||||||
class Input:
|
class Input:
|
||||||
id = graphene.ID()
|
slug = graphene.String()
|
||||||
enabled = graphene.Boolean()
|
enabled = graphene.Boolean()
|
||||||
|
|
||||||
success = graphene.Boolean()
|
success = graphene.Boolean()
|
||||||
|
|
@ -18,13 +18,13 @@ class UpdateSolutionVisibility(relay.ClientIDMutation):
|
||||||
@classmethod
|
@classmethod
|
||||||
def mutate_and_get_payload(cls, root, info, **args):
|
def mutate_and_get_payload(cls, root, info, **args):
|
||||||
try:
|
try:
|
||||||
id = args.get('id')
|
slug = args.get('slug')
|
||||||
enabled = args.get('enabled')
|
enabled = args.get('enabled')
|
||||||
user = info.context.user
|
user = info.context.user
|
||||||
if 'users.can_manage_school_class_content' not in user.get_role_permissions():
|
if 'users.can_manage_school_class_content' not in user.get_role_permissions():
|
||||||
raise PermissionError()
|
raise PermissionError()
|
||||||
|
|
||||||
module = get_object(Module, id)
|
module = Module.objects.get(slug=slug)
|
||||||
if enabled:
|
if enabled:
|
||||||
module.solutions_enabled_by.add(user)
|
module.solutions_enabled_by.add(user)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue