Skip to content

Commit

Permalink
feat: shorten profile name fields to 150 characters
Browse files Browse the repository at this point in the history
First and last name need to be limited to 150 characters on the Profile model.
Updates to name information are also sent to keycloak, which will put the name
information into the API tokens that it produces.

User model has 150 character name fields. Upon receiving an API token
this backend will try to update the user object with the information in
the token. If the name is over 150 characters an error will be produced
and the user will be unable to use the API. Users with this error will
also be unable to resolve the issue by themselves.

Refs: HP-2344
  • Loading branch information
charn committed Apr 17, 2024
1 parent 663947b commit aeea8e4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.9 on 2024-04-17 10:00

from django.db import migrations
from django.db.models.functions import Substr

import utils.fields


def truncate_name_fields(apps, schema_editor):
Profile = apps.get_model("profiles", "Profile")
Profile.objects.update(
first_name=Substr("first_name", 1, 150), last_name=Substr("last_name", 1, 150)
)


class Migration(migrations.Migration):

dependencies = [
("profiles", "0057_remove_profile_id_default_value__noop"),
]

operations = [
migrations.RunPython(truncate_name_fields, migrations.RunPython.noop),
migrations.AlterField(
model_name="profile",
name="first_name",
field=utils.fields.NullToEmptyCharField(
blank=True, db_index=True, max_length=150
),
),
migrations.AlterField(
model_name="profile",
name="last_name",
field=utils.fields.NullToEmptyCharField(
blank=True, db_index=True, max_length=150
),
),
]
4 changes: 2 additions & 2 deletions profiles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

class Profile(UUIDModel, SerializableMixin):
user = models.OneToOneField(User, on_delete=models.PROTECT, null=True, blank=True)
first_name = NullToEmptyCharField(max_length=255, blank=True, db_index=True)
last_name = NullToEmptyCharField(max_length=255, blank=True, db_index=True)
first_name = NullToEmptyCharField(max_length=150, blank=True, db_index=True)
last_name = NullToEmptyCharField(max_length=150, blank=True, db_index=True)
nickname = NullToEmptyCharField(max_length=32, blank=True, db_index=True)
language = models.CharField(
max_length=2,
Expand Down

0 comments on commit aeea8e4

Please sign in to comment.