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

Fix active users metric #3852

Merged
merged 1 commit into from
Aug 22, 2024
Merged

Fix active users metric #3852

merged 1 commit into from
Aug 22, 2024

Conversation

tillprochaska
Copy link
Contributor

@tillprochaska tillprochaska commented Aug 21, 2024

When implementing the active users metric (#3844), I noticed that Aleph currently updates the role.updated_at column every time a user logs in – so I took the shortcut and simply used that to count the number of users that logged in at least once within a specific period of time. But it turns out that updated_at is only updated on login when using password auth. It isn’t updated when signing in via OAuth, and consequently the active users metric is incorrect when OAuth is used for authentication.

I’m fixing this by adding a separate timestamp column that stores when a user last logged in. It’s probably a good idea to make the intent clear (Just reading the name updated_at, most people probably wouldn’t expect that timestamp to be set every time a user logs in.)

Note: This currently doesn’t include a test for the expected behavior when logging in via OAuth. There have been lots of changes to authentication testing on the develop branch that are not present in release/4.0.0, so any changes would lead to annoying merge conflicts later on. I have created a follow-up task to add a separate test for OAuth logins once the 4.0.0 release is out. You can manually test the behavior by configuring your development environment to use an OAuth provider.

When implementing the active users metric, I noticed that Aleph currently updates the role.updated_at column every time a user logs in – so I took the shortcut and simply used that to count the number of users that logged in at least once within a specific period of time. But it turns out that updated_at is only updated on login when using password auth. It isn’t updated when signing in via OAuth, and consequently the active users metric is incorrect when OAuth is used for authentication.

I’m fixing this by adding a separate timestamp column that stores when a user last logged in. It’s probably a good idea to make the intent clear (Just reading the name updated_at, most people probably wouldn’t expect that timestamp to be set every time a user logs in.)

Note: This currently doesn’t include a test for the expected behavior when logging in via OAuth. There have a lot of changes to authentication testing on the `develop` branch that are not present in `release/4.0.0`, so any changes would lead to annoying merge conflicts later on. I have created a follow-up task to add a separate test for OAuth logins once the 4.0.0 release is out. You can manually test the behavior by configuring your development environment to use an OAuth provider: https://docs.aleph.occrp.org/developers/how-to/development/identity-provider/
@tillprochaska tillprochaska marked this pull request as ready for review August 21, 2024 18:27
Copy link
Contributor

@catileptic catileptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me :) LGIM. Thanks for circling back to this!

@catileptic catileptic merged commit e7df928 into release/4.0.0 Aug 22, 2024
2 checks passed
tillprochaska added a commit that referenced this pull request Oct 15, 2024
This is a follow-up to #3852. This PR above didn’t include a test for the expected behavior when logging in via OAuth. There have been a lot of changes to authentication testing on the develop branch that were not present in the 4.0 release branch, so any changes would have lead to annoying merge conflicts down the line.

But now that the 4.0 release is integrated, it’s time to add a proper test :)
tillprochaska added a commit that referenced this pull request Oct 15, 2024
* Add test to cover `last_login_at` timestamp in OAuth workflow

This is a follow-up to #3852. This PR above didn’t include a test for the expected behavior when logging in via OAuth. There have been a lot of changes to authentication testing on the develop branch that were not present in the 4.0 release branch, so any changes would have lead to annoying merge conflicts down the line.

But now that the 4.0 release is integrated, it’s time to add a proper test :)

* Fix OAuth test setup

This was an oversight and should have always called `super().setUp()` instead of `super().setUpClass()`. This didn’t fail when running tests for the entire file (`pytest test_sessions_api.py`), but it did always fail when running individual tests (`pytest test_sessions_api.py -k oauth_callback`).
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