lookit / lookit-api

Codebase for Lookit v2 and Experimenter v2. Includes an API. Docs: http://lookit.readthedocs.io/
https://lookit.mit.edu/
MIT License
10 stars 18 forks source link

Handle Malformed Usernames #1432

Closed okaycj closed 1 month ago

okaycj commented 1 month ago

Summary

Upon adding a "unsubscribe email" link to the end of our user's emails, showed us that there are some unfortunately messy usernames in our database. It seems that this bug has been fixed, but the data wasn't cleaned up. This PR loosens the restrictions on the unsubscribe email link and we'll have to run some SQL scripts to clean up usernames.

Additionally, there is a "fix" for an error (see below) that celery is generating.

lookit-api-broker  | 2024-07-02 16:03:51.534 [info] <0.779.0> accepting AMQP connection <0.779.0> (172.18.0.5:36826 -> 172.18.0.3:5672)
lookit-api-broker  | 2024-07-02 16:03:51.536 [info] <0.779.0> connection <0.779.0> (172.18.0.5:36826 -> 172.18.0.3:5672): user 'lookit-admin' authenticated and granted access to vhost '/'
lookit-api-broker  | 2024-07-02 16:03:51.550 [warning] <0.779.0> closing AMQP connection <0.779.0> (172.18.0.5:36826 -> 172.18.0.3:5672, vhost: '/', user: 'lookit-admin'):
lookit-api-broker  | client unexpectedly closed TCP connection <-----
lookit-api-broker  | 2024-07-02 16:03:51.551 [info] <0.790.0> Closing all channels from connection '172.18.0.5:36826 -> 172.18.0.3:5672' because it has been closed

SQL

Below are some scripts that will be used in production to clean up usernames.

Find usernames that have whitespace:

select au.username 
from accounts_user au
where au.username like '%' || chr(9) || '%' 
    or au.username like '%' || chr(10) || '%'
    or au.username like '%' || chr(11) || '%' 
    or au.username like '%' || chr(32) || '%'

Find usernames with uppercase characters:

select au.username, au.last_login 
from accounts_user au 
where trim(au.username) != lower(trim(au.username))

Delete "AnonymousUser":

delete from accounts_user au where au.username = 'AnonymousUser'

Update usernames with whitespace:

update accounts_user 
set username = trim(username)
where username in (...,)

Update usernames with uppercase:

update accounts_user 
set username = lower(username)
where username in (...,)
sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud