Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure adhoc groups have a name. #8242

Merged
merged 3 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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