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

Bans #501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Bans #501

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions bans/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from collections.abc import Iterable
from django.db import models
from uuid import uuid4

from users.models import UserProfile
from django.db.models.signals import post_save, post_delete, pre_save
# Create your models here.


Expand All @@ -25,7 +27,7 @@ class SSOBan(models.Model):

id = models.UUIDField(primary_key=True, default=uuid4, blank=False)
banned_user = models.ForeignKey(
to="users.UserProfile", related_name="banned_user", on_delete=models.CASCADE
to="users.UserProfile", related_name="banned_user", on_delete=models.CASCADE, null=True, blank=True
)
time_of_creation = models.DateTimeField(auto_now_add=True)
reason = models.CharField(max_length=30, choices=BAN_REASON_CHOICHES)
Expand All @@ -38,3 +40,12 @@ class SSOBan(models.Model):
null=True,
blank=True,
)
banned_user_ldapid = models.CharField(max_length=20, blank=True, null=True)


def save(self, *args, **kwargs) -> None:
if self.banned_user_ldapid:
self.banned_user = UserProfile.objects.get(ldap_id=self.banned_user_ldapid)
return super().save(*args, **kwargs)