Ouranosinc / Magpie

AuthN/AuthZ services
https://pavics-magpie.readthedocs.io
Apache License 2.0
1 stars 5 forks source link

[BUG] How to rename an existing username #444

Closed tlvu closed 3 years ago

tlvu commented 3 years ago

Describe the bug From https://github.com/bird-house/birdhouse-deploy/pull/182#issuecomment-884376408 I found out one of the user with duplicate email has trailing space in its username so I was unable to edit the user via UI to change its email.

And there was no way to edit the username to remove the trailing space.

Error in docker logs magpie, notice %20%20 at the end of the username:

[2021-07-23 17:44:55,050] ERROR      [ThreadPoolExecutor-0_2][magpie.ui.utils] Unexpected API error under UI operation. [{'param': {'conditions': {'not_empty': True, 'matches': False}, 'value': 'hnils  ', 'name': 'user_name', 'compare': '^[A-Za-z0-9]+(?:[\\s_\\-\\.][A-Za-z0-9]+)*$'}, 'code': 422, 'detail': 'Invalid value specified.', 'type': 'application/json', 'path': '/users/hnils  ', 'url': 'https://lvupavicsdev.ouranos.ca/magpie/users/hnils%20%20', 'method': 'GET'}]

To Reproduce Steps to reproduce the behavior:

  1. Magpie-3.12.0 (from https://github.com/bird-house/birdhouse-deploy/tree/1.13.12)
  2. Use Pavics production Magpie DB
  3. Navigate to https://lvupavicsdev.ouranos.ca/magpie/ui/users/hnils%20%20/default in order to edit the user
  4. Result HTTPUnprocessableEntity: Unable to process the contained instructions

Expected behavior A recommended way out of this, either to be able to edit that user with trailing space or to be able to rename the username to remove the trailing space.

fmigneault commented 3 years ago

This looks like a side effect of an invalid user-name before #84 was introduced. I don't plan to modify the UI to address this since it should not be allowed in the first place. Maybe it is possible via the API since the PATCH request takes the parameters with an explicit string in the request body?

fmigneault commented 3 years ago

Closing as invalid name should not be possible anymore. Such cases should be modified manually in db.

tlvu commented 3 years ago

Such cases should be modified manually in db.

Documenting for other users if needed:

# POSTGRES_MAGPIE_USERNAME is from env.local
$ echo "update users set user_name = '$FIXED_USERNAME' where email = '$USER_EMAIL'" | docker exec -i postgres-magpie psql -U $POSTGRES_MAGPIE_USERNAME magpiedb
UPDATE 1