Fix bug Custom objectives in hidden group
This commit is contained in:
parent
4e7443906d
commit
18c6e0ac72
|
|
@ -44,7 +44,7 @@ def migrate_objectives_to_content():
|
|||
else:
|
||||
default_content_block = created_default_content_blocks[default_objectives_ids]
|
||||
|
||||
# set visibility for objective_group
|
||||
# set visibility for objective_group for default content (Verlagsinhalte)
|
||||
if objective_group.hidden_for.exists():
|
||||
default_content_block.hidden_for.add(*objective_group.hidden_for.all())
|
||||
default_content_block.save_revision().publish()
|
||||
|
|
@ -110,19 +110,15 @@ def migrate_objectives_to_content():
|
|||
default_content_block.save_revision().publish()
|
||||
default_content_block.save()
|
||||
|
||||
custom_content_block.visible_for.add(school_class)
|
||||
# make custom content block visible for school class if it is not in hidden list
|
||||
if not objective_group.hidden_for.filter(id=school_class.id).exists():
|
||||
custom_content_block.visible_for.add(school_class)
|
||||
else:
|
||||
custom_content_block.hidden_for.add(school_class)
|
||||
|
||||
custom_content_block.save_revision().publish()
|
||||
custom_content_block.save()
|
||||
|
||||
if objective_group.hidden_for.filter(id=school_class.id).exists():
|
||||
default_content_block.hidden_for.add(school_class)
|
||||
default_content_block.save_revision().publish()
|
||||
default_content_block.save()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
except ValidationError as e:
|
||||
print(f"Error with module {module}")
|
||||
logger.error(e)
|
||||
|
|
|
|||
|
|
@ -31,27 +31,32 @@ class TestObjectivesMigration(SkillboxTestCase):
|
|||
ChapterFactory(parent=self.module, slug='some-other-chapter', owner=self.admin)
|
||||
|
||||
objective_group = ObjectiveGroupFactory(module=self.module, title='Gesellschaft')
|
||||
second_objective_group = ObjectiveGroupFactory(module=self.module, title='Sprache & Kommunikation')
|
||||
third_objective_group = ObjectiveGroupFactory(module=self.module, title='Übergeordnete Lernziele')
|
||||
|
||||
self.visible_objective = ObjectiveFactory(text='visible-objective', group=objective_group)
|
||||
self.hidden_objective = ObjectiveFactory(text='hidden-objective', group=objective_group)
|
||||
self.custom_objective = ObjectiveFactory(text='custom-objective', group=objective_group, owner=self.teacher)
|
||||
self.custom_hidden_objective = ObjectiveFactory(text='custom-hidden-objective', group=objective_group,
|
||||
owner=self.teacher)
|
||||
|
||||
self.visible_objective = ObjectiveFactory(text='objective1', group=second_objective_group)
|
||||
|
||||
self.hidden_objective.hidden_for.add(self.skillbox_class)
|
||||
self.hidden_objective.save()
|
||||
|
||||
self.custom_objective = ObjectiveFactory(text='custom-objective', group=objective_group, owner=self.teacher)
|
||||
self.custom_objective.visible_for.add(self.skillbox_class)
|
||||
self.custom_objective.save()
|
||||
self.custom_hidden_objective = ObjectiveFactory(text='custom-hidden-objective', group=objective_group,
|
||||
owner=self.teacher)
|
||||
self.custom_hidden_objective.visible_for.remove(self.skillbox_class)
|
||||
|
||||
second_objective_group = ObjectiveGroupFactory(module=self.module, title='Sprache & Kommunikation')
|
||||
self.visible_objective = ObjectiveFactory(text='objective1', group=second_objective_group)
|
||||
second_objective_group.hidden_for.add(self.skillbox_class)
|
||||
second_objective_group.save()
|
||||
|
||||
self.custom_hidden_objective.visible_for.remove(self.skillbox_class)
|
||||
third_objective_group = ObjectiveGroupFactory(module=self.module, title='Übergeordnete Lernziele')
|
||||
self.visible_objective_hidden_group_3 = ObjectiveFactory(text='objective1', group=third_objective_group)
|
||||
self.hidden_objective_hidden_group_3 = ObjectiveFactory(text='objective2', group=third_objective_group,
|
||||
owner=self.teacher)
|
||||
self.hidden_objective_hidden_group_3.visible_for.add(self.skillbox_class)
|
||||
self.hidden_objective_hidden_group_3.save()
|
||||
|
||||
third_objective_group.hidden_for.add(self.skillbox_class)
|
||||
third_objective_group.save()
|
||||
|
||||
migrate_objectives_to_content()
|
||||
|
||||
|
|
@ -61,7 +66,7 @@ class TestObjectivesMigration(SkillboxTestCase):
|
|||
})
|
||||
module = result.data['module']
|
||||
chapter1 = module['chapters'][0]
|
||||
_, default_content, _,_ = chapter1['contentBlocks']
|
||||
_, default_content, _, _, _ = chapter1['contentBlocks']
|
||||
|
||||
# default content block (Verlagsinhalte) exists but is hidden (since one objective is hidden for this class)
|
||||
self.assertEqual(default_content['title'], 'Gesellschaft')
|
||||
|
|
@ -76,7 +81,7 @@ class TestObjectivesMigration(SkillboxTestCase):
|
|||
})
|
||||
module = result.data['module']
|
||||
chapter1 = module['chapters'][0]
|
||||
_,_, custom, _ = chapter1['contentBlocks']
|
||||
_, _, custom, _, _ = chapter1['contentBlocks']
|
||||
|
||||
# default content block (Verlagsinhalte) exists but is hidden (since one objective is hidden for this class)
|
||||
self.assertEqual(custom['title'], 'Gesellschaft')
|
||||
|
|
@ -92,7 +97,7 @@ class TestObjectivesMigration(SkillboxTestCase):
|
|||
})
|
||||
module = result.data['module']
|
||||
chapter1 = module['chapters'][0]
|
||||
hidden_default, _, _, _ = chapter1['contentBlocks']
|
||||
hidden_default, _, _, _, _ = chapter1['contentBlocks']
|
||||
|
||||
# default content block (Verlagsinhalte) exists but is hidden (since one objective is hidden for this class)
|
||||
self.assertEqual(hidden_default['title'], 'Sprache & Kommunikation')
|
||||
|
|
@ -114,7 +119,21 @@ class TestObjectivesMigration(SkillboxTestCase):
|
|||
module = result.data['module']
|
||||
chapter1 = module['chapters'][0]
|
||||
titles = [content['title'] for content in chapter1['contentBlocks']]
|
||||
self.assertEqual(titles, ['Sprache & Kommunikation', 'Gesellschaft','Gesellschaft','Übergeordnete Lernziele'])
|
||||
|
||||
self.assertEqual(titles, ['Sprache & Kommunikation', 'Gesellschaft', 'Gesellschaft', 'Übergeordnete Lernziele',
|
||||
'Übergeordnete Lernziele'])
|
||||
|
||||
def test_objectives_migration_hidden_group_custom_content(self):
|
||||
result = self.client.execute(MODULE_QUERY, variables={
|
||||
'slug': self.module.slug
|
||||
})
|
||||
module = result.data['module']
|
||||
chapter1 = module['chapters'][0]
|
||||
_, _, _, _, hidden_custom_group = chapter1['contentBlocks']
|
||||
|
||||
# default content block (Verlagsinhalte) exists but is hidden (since one objective is hidden for this class)
|
||||
self.assertEqual(hidden_custom_group['title'], 'Übergeordnete Lernziele')
|
||||
self.assertTrue(hidden_custom_group['originalCreator'] is not None)
|
||||
self.assertEqual(hidden_custom_group['hiddenFor'], [{'name': 'skillbox'}])
|
||||
self.assertEqual(hidden_custom_group['visibleFor'], [])
|
||||
self.assertEqual(hidden_custom_group['contents'][0]['value']['text'],
|
||||
'<ul><li>objective1</li><li>objective2</li></ul>')
|
||||
|
|
|
|||
Loading…
Reference in New Issue