Skip to content

Commit

Permalink
Remove Email model
Browse files Browse the repository at this point in the history
Was used to support multiple emails, which we no longer support.
  • Loading branch information
henrikhorluck committed Apr 6, 2024
1 parent 52bc69d commit cfc41db
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
11 changes: 2 additions & 9 deletions apps/authentication/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from reversion.admin import VersionAdmin

from apps.authentication.models import (
Email,
GroupMember,
GroupRole,
Membership,
Expand All @@ -17,14 +16,8 @@
)


class EmailInline(admin.TabularInline):
model = Email
extra = 1


class OnlineUserAdmin(UserAdmin, VersionAdmin):
model = OnlineUser
inlines = (EmailInline,)
list_display = [
"username",
"first_name",
Expand All @@ -35,7 +28,7 @@ class OnlineUserAdmin(UserAdmin, VersionAdmin):
]
list_filter = ("is_staff", "is_superuser", "is_active", "groups__name")
fieldsets = (
(None, {"fields": ("username", "password")}),
(None, {"fields": ("email", "username", "auth0_subject")}),
(
_("Personlig info"),
{"fields": ("first_name", "last_name", "phone_number", "online_mail")},
Expand Down Expand Up @@ -75,7 +68,7 @@ class OnlineUserAdmin(UserAdmin, VersionAdmin):
)
filter_horizontal = ("groups", "user_permissions")
search_fields = ("first_name", "last_name", "username", "ntnu_username")
readonly_fields = ("mark_rules_accepted", "saldo")
readonly_fields = ("mark_rules_accepted", "saldo", "auth0_subject")

def is_member(self, instance: OnlineUser):
return instance.is_member
Expand Down
19 changes: 19 additions & 0 deletions apps/authentication/migrations/0056_delete_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.4 on 2024-04-06 13:28

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
(
"authentication",
"0055_alter_groupmember_added_alter_groupmember_group_and_more",
),
]

operations = [
migrations.DeleteModel(
name="Email",
),
]
31 changes: 0 additions & 31 deletions apps/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,37 +372,6 @@ class Meta:
default_permissions = ("add", "change", "delete")


class Email(models.Model):
user = models.ForeignKey(
OnlineUser, related_name="email_user", on_delete=models.CASCADE
)
email = models.EmailField(_("epostadresse"), unique=True)
primary = models.BooleanField(_("primær"), default=False)
verified = models.BooleanField(_("verifisert"), default=False, editable=False)

def save(self, *args, **kwargs):
primary_email = self.user.email_object
if not primary_email:
self.primary = True
elif primary_email.email != self.email:
self.primary = False
self.email = self.email.lower()
if self.primary:
self.user.email = self.email
self.user.save()
super().save(*args, **kwargs)

def __str__(self):
return self.email

class Meta:
verbose_name = _("epostadresse")
verbose_name_plural = _("epostadresser")
permissions = (("view_email", "View Email"),)
default_permissions = ("add", "change", "delete")
ordering = ("user", "email")


class Membership(models.Model):
"""
Holds usernames that are considered valid members of Online and the time they expire.
Expand Down

0 comments on commit cfc41db

Please sign in to comment.