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