Skip to content

Commit

Permalink
Merge pull request #8242 from rtibbles/adhoc_group_names
Browse files Browse the repository at this point in the history
Make sure adhoc groups have a name.
  • Loading branch information
rtibbles authored Jul 29, 2021
2 parents ef213be + 48107b3 commit 02fc882
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions kolibri/core/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,15 @@ class AdHocGroup(Collection):
class Meta:
proxy = True

@classmethod
def deserialize(cls, dict_model):
# be defensive against blank names, set to `Ad hoc` if blank
name = dict_model.get("name", "") or ""
if len(name) == 0:
dict_model.update(name="Ad hoc")

return super(AdHocGroup, cls).deserialize(dict_model)

def save(self, *args, **kwargs):
if not self.parent:
raise IntegrityError(
Expand Down
9 changes: 9 additions & 0 deletions kolibri/core/auth/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ def prune_empty_adhoc_groups():
needed. This upgrade task cleans up those empty adhoc groups.
"""
AdHocGroup.objects.filter(membership__isnull=True).delete()


@version_upgrade(old_version="<0.15.0")
def name_unnamed_adhoc_groups():
"""
We started making adhoc groups for every lesson and quiz, even though they were not
needed. This upgrade task cleans up those empty adhoc groups.
"""
AdHocGroup.objects.filter(name="").update(name="Ad hoc")
2 changes: 1 addition & 1 deletion kolibri/core/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def confirm_or_exit(message):


def create_adhoc_group_for_learners(classroom, learners):
adhoc_group = AdHocGroup.objects.create(name="", parent=classroom)
adhoc_group = AdHocGroup.objects.create(name="Ad hoc", parent=classroom)
for learner in learners:
Membership.objects.create(user=learner, collection=adhoc_group)
return adhoc_group
Expand Down

0 comments on commit 02fc882

Please sign in to comment.