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

Auth: make first_name and last_name optional, add plugin compatibility check #949

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

laundmo
Copy link
Contributor

@laundmo laundmo commented Feb 7, 2025

This PR makes first_name and last_name fields optional, similar to username being optional.

This is useful for:

  • someones real name doesn't matter for the application (a chat for example)
  • the application stores real name in a different table, making it redundant and annoying to store in auth_user

Instead, this introduces 2 Virtual fields: display_name and display_name_full, which contain whichever name is enabled, with this preference order:

display_name: first_name > username > email
display_name_full: first_name last_name > email

This also adds a compatibility check to the Auth plugins.
To do this, all Auth plugins now inherit from BasePlugin, which defines the __str__ and is_auth_compatible methods. Auth now calls the is_auth_compatible method when a plugin is registered, and raises a error if its incompatible (due to username or first_name+last_name being disabled)
I'm not sure if i set all the compatibility checks properly, since i didn't test all plugins.

@mdipierro
Copy link
Contributor

This adds a lot of complexity. When prevents a developer today from deleting the last_name field and renaming the first_name as display_name at the app level? I am afraid we will never be able to cover use cases and we add complexity. Is there perhaps a more minimal change we can make to enables developers to do this at the app level?

@laundmo
Copy link
Contributor Author

laundmo commented Feb 9, 2025

what is the complexity being added here? a Virtual field, or the plugin stuff?

the core is just the boolean param toggling the first_name and last_name field. I also restructured how the auth_user table is sorted because i think this way is more explicit with the order being consistent across different permutations of the optional it fields.

display_name is intended to mitigate confusion when disabling first_name and last_name while all the docs, examples etc assume its there.

the plugin stuff is something i noticed would already cause issues, as some plugins seem to assume auth_user.username exists and it doesn't have to.

i really don't see much complexity here - well, except allowing plugins to fail with a useful error if they need something from auth...

@mdipierro
Copy link
Contributor

mdipierro commented Feb 9, 2025 via email

@mdipierro
Copy link
Contributor

I am going to take most of this but I am considering a minor change. Basically if the the auth_user table exists and has a display_name field, then use it. If the auth_user is not provided, or if it is provided but does not have a display_name field, than add the display_name as a virtual field which is an alias of the username if exists or first_name otherwise. If users want to customize this they can edit the properties of the display_name virtual field. I think this is general, simple, and does not break users' code that may use a custom auth_user table.

@laundmo
Copy link
Contributor Author

laundmo commented Feb 23, 2025

sounds good to me. i can try changing this tomorrow if you want, but i have "allow edits from maintainers" enabled so you should have push permission to my fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants