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

custom user model #63

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 2 additions & 6 deletions docs/_hooks/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ def on_pre_build(config: MkDocsConfig) -> None:
pass


def on_page_markdown(
markdown: str, page: Page, config: MkDocsConfig, files: Files
) -> None:
def on_page_markdown(markdown: str, page: Page, config: MkDocsConfig, files: Files) -> None:
pass


def on_page_context(
context: TemplateContext, nav: Navigation, page: Page, config: MkDocsConfig
) -> None:
def on_page_context(context: TemplateContext, nav: Navigation, page: Page, config: MkDocsConfig) -> None:
context["build_date"] = datetime.now().strftime("%a, %d, %b %Y - %H:%M")
2 changes: 1 addition & 1 deletion src/aurora/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@
ROOT_TOKEN = env("ROOT_TOKEN")
CSRF_FAILURE_VIEW = "aurora.web.views.sites.error_csrf"

AUTH_USER_MODEL = "auth.User"
AUTH_USER_MODEL = "security.User"

LOGIN_URL = "/login"
LOGIN_REDIRECT_URL = "/logged-in/"
Expand Down
2 changes: 1 addition & 1 deletion src/aurora/security/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def ready(self):
smart_register(models.AuroraPermission)(PermissionAdmin)
smart_register(models.Permission)(PermissionAdmin)
smart_register(models.AuroraGroup)(admin.GroupAdmin)
smart_register(models.AuroraUser)(admin.UserAdmin)
smart_register(models.User)(admin.UserAdmin)
smart_register(models.AuroraRole)(admin.AuroraRoleAdmin)
smart_register(models.UserProfile)(admin.UserProfileAdmin)

Expand Down
93 changes: 93 additions & 0 deletions src/aurora/security/migrations/0011_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Generated by Django 5.0.11 on 2025-02-06 11:23

import django.contrib.auth.models
import django.contrib.auth.validators
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
("security", "0010_auto_20230319_0657"),
]

operations = [
migrations.CreateModel(
name="User",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("password", models.CharField(max_length=128, verbose_name="password")),
("last_login", models.DateTimeField(blank=True, null=True, verbose_name="last login")),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"username",
models.CharField(
error_messages={"unique": "A user with that username already exists."},
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
max_length=150,
unique=True,
validators=[django.contrib.auth.validators.UnicodeUsernameValidator()],
verbose_name="username",
),
),
("first_name", models.CharField(blank=True, max_length=150, verbose_name="first name")),
("last_name", models.CharField(blank=True, max_length=150, verbose_name="last name")),
("email", models.EmailField(blank=True, max_length=254, verbose_name="email address")),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. "
"Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
("date_joined", models.DateTimeField(default=django.utils.timezone.now, verbose_name="date joined")),
(
"groups",
models.ManyToManyField(
blank=True,
help_text="The groups this user belongs to. "
"A user will get all permissions granted to each of their groups.",
related_name="user_set",
related_query_name="user",
to="auth.group",
verbose_name="groups",
),
),
(
"user_permissions",
models.ManyToManyField(
blank=True,
help_text="Specific permissions for this user.",
related_name="user_set",
related_query_name="user",
to="auth.permission",
verbose_name="user permissions",
),
),
],
options={
"db_table": "auth_user",
},
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
]
15 changes: 15 additions & 0 deletions src/aurora/security/migrations/0012_delete_aurorauser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 5.0.11 on 2025-02-06 11:23

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("security", "0011_user"),
]

operations = [
migrations.DeleteModel(
name="AuroraUser",
),
]
16 changes: 6 additions & 10 deletions src/aurora/security/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.contrib.auth.models import Group, Permission, AbstractUser
from django.db import models
from django.db.models import JSONField
from django.utils import timezone
Expand All @@ -12,7 +11,11 @@
from aurora.core.models import Organization, Project
from aurora.registration.models import Registration

User = get_user_model()

class User(AbstractUser):
class Meta:
app_label = "security"
db_table = "auth_user"


class UserProfile(models.Model):
Expand Down Expand Up @@ -108,13 +111,6 @@ def natural_key(self):
return (None, None, None, self.user.username, self.role.name)


class AuroraUser(User):
class Meta:
proxy = True
verbose_name = _("user")
verbose_name_plural = _("users")


class AuroraGroup(Group):
class Meta:
proxy = True
Expand Down
Loading