Skip to content

Commit

Permalink
Updates to the identifier model and tidy up SSO
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisKSeal committed Feb 22, 2024
1 parent d01397d commit a629c2a
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 11 deletions.
4 changes: 4 additions & 0 deletions tardis/apps/identifiers/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
"experiment",
"facility",
"instrument",
"datafile",
"project",
"user",
"institution",
]
73 changes: 73 additions & 0 deletions tardis/apps/identifiers/migrations/0002_userpid_datafileid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Generated by Django 4.2.7 on 2024-02-22 22:23

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("tardis_portal", "0026_alter_experiment_institution_name"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("identifiers", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="UserPID",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"identifier",
models.CharField(
blank=True, max_length=400, null=True, unique=True
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="identifiers",
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="DatafileID",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"identifier",
models.CharField(
blank=True, max_length=400, null=True, unique=True
),
),
(
"datafile",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="identifiers",
to="tardis_portal.datafile",
),
),
],
),
]
29 changes: 18 additions & 11 deletions tardis/apps/single_sign_on/auth/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@ def configure_user( # type:ignore
request: HttpRequest,
user: User,
) -> User: # type: ignore
logger.debug(f"Configure user called with user: {user}")
try:
email = request.META[settings.REMOTE_AUTH_EMAIL_HEADER] or None
except KeyError:
email = None
first_name = request.META[settings.REMOTE_AUTH_FIRST_NAME_HEADER]
surname = request.META[settings.REMOTE_AUTH_SURNAME_HEADER]
user.first_name = first_name
user.last_name = surname
if email:
updated_flag = False
if user.first_name != first_name:
user.first_name = first_name
updated_flag = True
if user.last_name != surname:
user.last_name = surname
updated_flag = True
if email and user.email != email:
user.email = email
user.save()
user.userprofile.isDjangoAccount = False # type: ignore
user.userprofile.save() # type: ignore
updated_flag = True
if updated_flag:
user.save()
if user.userprofile.isDjangoAccount: #type: ignore
user.userprofile.isDjangoAccount = False # type: ignore
user.userprofile.save() # type: ignore
try:
user_auth = UserAuthentication.objects.get(
userProfile_username=user,
Expand All @@ -62,9 +69,9 @@ def configure_user( # type:ignore
user_auth = UserAuthentication(
userProfile=user.userprofile, # type: ignore
username=user.username,
authMethod=auth_key,
authenticationMethod=auth_key,
)
if user_auth.authMethod != auth_key:
user_auth.authMethod = auth_key
user_auth.save()
if user_auth.authenticationMethod != auth_key:
user_auth.authenticationMethod = auth_key
user_auth.save()
return super().configure_user(request, user)

0 comments on commit a629c2a

Please sign in to comment.