feat(dgsi/models): We assume that the vlan groups are present on kanidm
This commit is contained in:
parent
522e2eb7c7
commit
1763b60ed5
1 changed files with 7 additions and 16 deletions
|
@ -251,27 +251,18 @@ class User(AbstractUser):
|
|||
|
||||
group_name = f"vlan_{self.vlan_id}"
|
||||
|
||||
res = sync_call("group_create", group_name)
|
||||
|
||||
if res.data is not None:
|
||||
if (
|
||||
res.data.get("plugin", {}).get("attrunique")
|
||||
== "duplicate value detected"
|
||||
):
|
||||
logger.info(f"The {group_name} group already exists")
|
||||
group = sync_call("group_get", group_name)
|
||||
|
||||
if group.member != []:
|
||||
raise ValueError(
|
||||
_("Le VLAN {} est déjà attribué.").format(self.vlan_id)
|
||||
)
|
||||
|
||||
# The group is created and should be empty, so we can add the user to it
|
||||
# Add the user to the group requested group
|
||||
sync_call("group_add_members", group_name, [self.username])
|
||||
|
||||
# Check that we succeeded in setting a VLAN that is unique to the current user
|
||||
group = sync_call("group_get", group_name)
|
||||
|
||||
if group.member == []:
|
||||
# Something went wrong
|
||||
self.vlan_id = None
|
||||
self.save(update_fields=["vlan_id"])
|
||||
raise RuntimeError("VLAN attribution failed")
|
||||
|
||||
if group.member != [f"{self.username}@sso.dgnum.eu"]:
|
||||
# Remove the user from the group
|
||||
sync_call("group_delete_members", group_name, [self.username])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue