LemmyNet / lemmy

🐀 A link aggregator and forum for the fediverse
https://join-lemmy.org
GNU Affero General Public License v3.0
13.28k stars 884 forks source link

[Bug]: Inconsistent application state when switching between open and application mode for registrations #4969

Closed Nothing4You closed 2 months ago

Nothing4You commented 3 months ago

Requirements

Summary

When switching between registration modes, pending applications end up in an unexpected state. This was discovered while working on test cases in #4923.

Solutions to this might include a database migration to address existing cases with inconsistent applications, although in practice this number should be zero for most instances.

It would probably make sense to flip the logic around to always set local_user.accepted_application to true on user creation unless applications are required, and when turning the application requirement off to update not only all local_users, but also update all pending registration_applications admin_ids with the admin disabling the application requirement.

This could also simplify the check on login to not check registration type anymore but simply check if local_user.accepted_application is true.

Steps to Reproduce

  1. Set site to application required
  2. Sign up new user
  3. User can't login, pending application approval
  4. Set site to open registration
  5. Admins still see existing pending applications despite user being able to login, as the application check only happens during, login
  6. Set site to application required
    1. local_user gets set to application accepted (login allowed)
    2. registration_application stays pending, as other logic derives the acceptance state from an admin id being set (does not affect login)
  7. User is still able to login, yet admins see a pending application

Technical Details

Logic to approve users when application state changes from no application required to application required: https://github.com/LemmyNet/lemmy/blob/128e78f7c22279fec27d3213a05b440cb1f8db59/crates/db_schema/src/impls/local_user.rs#L104-L112

Logic for checking pending applications on login: https://github.com/LemmyNet/lemmy/blob/128e78f7c22279fec27d3213a05b440cb1f8db59/crates/api/src/local_user/login.rs#L71-L94

Version

0.19.6-beta.4

Lemmy Instance URL

No response

dessalines commented 2 months ago

Fixed by above PR.