Skip to content

Commit

Permalink
Adds department and role fields to user model (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort authored Jul 22, 2024
1 parent 4355e8b commit 466d46a
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 10 deletions.
76 changes: 74 additions & 2 deletions docs/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3965,6 +3965,35 @@ paths:
name: date_joined__year
schema:
type: number
- in: query
name: department
schema:
type: string
- in: query
name: department__contains
schema:
type: string
- in: query
name: department__endswith
schema:
type: string
- in: query
name: department__in
schema:
type: array
items:
type: string
description: Multiple values may be separated by commas.
explode: false
style: form
- in: query
name: department__isnull
schema:
type: boolean
- in: query
name: department__startswith
schema:
type: string
- in: query
name: email
schema:
Expand Down Expand Up @@ -4253,6 +4282,35 @@ paths:
name: password__startswith
schema:
type: string
- in: query
name: role
schema:
type: string
- in: query
name: role__contains
schema:
type: string
- in: query
name: role__endswith
schema:
type: string
- in: query
name: role__in
schema:
type: array
items:
type: string
description: Multiple values may be separated by commas.
explode: false
style: form
- in: query
name: role__isnull
schema:
type: boolean
- in: query
name: role__startswith
schema:
type: string
- in: query
name: username
schema:
Expand Down Expand Up @@ -4872,8 +4930,15 @@ components:
type: string
format: email
nullable: true
title: Email address
maxLength: 254
department:
type: string
nullable: true
maxLength: 1000
role:
type: string
nullable: true
maxLength: 1000
is_active:
type: boolean
readOnly: true
Expand Down Expand Up @@ -5035,8 +5100,15 @@ components:
type: string
format: email
nullable: true
title: Email address
maxLength: 254
department:
type: string
nullable: true
maxLength: 1000
role:
type: string
nullable: true
maxLength: 1000
is_active:
type: boolean
readOnly: true
Expand Down
2 changes: 1 addition & 1 deletion keystone_api/apps/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def deactivate_selected_users(self, request, queryset) -> None:
readonly_fields = ("last_login", "date_joined", "is_ldap_user")
actions = [activate_selected_users, deactivate_selected_users]
fieldsets = (
("User Info", {"fields": ("first_name", "last_name", "email", "last_login", "date_joined", 'is_ldap_user')}),
("User Info", {"fields": ("first_name", "last_name", "email", "department", "role", "last_login", "date_joined", 'is_ldap_user')}),
("Credentials", {"fields": ("username", "password")}),
("Permissions",
{"fields": (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 5.0.4 on 2024-07-22 15:29

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


class Migration(migrations.Migration):

dependencies = [
('users', '0005_alter_user_email_alter_user_first_name_and_more'),
]

operations = [
migrations.AddField(
model_name='user',
name='department',
field=models.CharField(blank=True, max_length=1000, null=True),
),
migrations.AddField(
model_name='user',
name='role',
field=models.CharField(blank=True, max_length=1000, null=True),
),
migrations.AlterField(
model_name='user',
name='date_joined',
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(max_length=254, null=True),
),
migrations.AlterField(
model_name='user',
name='first_name',
field=models.CharField(max_length=150, null=True),
),
migrations.AlterField(
model_name='user',
name='last_login',
field=models.DateTimeField(null=True),
),
migrations.AlterField(
model_name='user',
name='last_name',
field=models.CharField(max_length=150, null=True),
),
migrations.AlterField(
model_name='user',
name='password',
field=models.CharField(max_length=128),
),
migrations.AlterField(
model_name='user',
name='username',
field=models.CharField(max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()]),
),
]
16 changes: 9 additions & 7 deletions keystone_api/apps/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ class User(auth_models.AbstractBaseUser, auth_models.PermissionsMixin):
REQUIRED_FIELDS = []

# User metadata
username = models.CharField('username', max_length=150, unique=True, validators=[UnicodeUsernameValidator()])
password = models.CharField('password', max_length=128)
first_name = models.CharField('first name', max_length=150, null=True)
last_name = models.CharField('last name', max_length=150, null=True)
email = models.EmailField('email address', null=True)
username = models.CharField(max_length=150, unique=True, validators=[UnicodeUsernameValidator()])
password = models.CharField(max_length=128)
first_name = models.CharField(max_length=150, null=True)
last_name = models.CharField(max_length=150, null=True)
email = models.EmailField(null=True)
department = models.CharField(max_length=1000, null=True, blank=True)
role = models.CharField(max_length=1000, null=True, blank=True)

# Administrative values for user management/permissions
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField('staff status', default=False)
is_ldap_user = models.BooleanField('LDAP User', default=False)
date_joined = models.DateTimeField('date joined', default=timezone.now)
last_login = models.DateTimeField('last login', null=True)
date_joined = models.DateTimeField(default=timezone.now)
last_login = models.DateTimeField(null=True)

objects = UserManager()

Expand Down

0 comments on commit 466d46a

Please sign in to comment.