Add better handling for missing groups

This commit is contained in:
Jan Dittberner 2023-05-07 13:45:30 +02:00
parent c7fda0e993
commit 3b04595c7a
2 changed files with 36 additions and 6 deletions

View file

@ -5,6 +5,7 @@ This module contains the hosting package models.
from __future__ import absolute_import
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db import models, transaction
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
@ -370,9 +371,14 @@ class CustomerHostingPackage(HostingPackageBase):
self.copy_template_attributes()
self.osuser = OsUser.objects.create_user(self.customer)
for group in settings.OSUSER_DEFAULT_GROUPS:
AdditionalGroup.objects.create(
user=self.osuser, group=Group.objects.get(groupname=group)
)
try:
AdditionalGroup.objects.create(
user=self.osuser, group=Group.objects.get(groupname=group)
)
except Group.DoesNotExist as e:
raise ImproperlyConfigured(
f"group {group} has not been defined"
) from e
return super(CustomerHostingPackage, self).save(*args, **kwargs)