Skip to content

Show currently logged in users#3349

Open
yusufraji wants to merge 2 commits into
kiesraad:mainfrom
yusufraji:show-user-online-status
Open

Show currently logged in users#3349
yusufraji wants to merge 2 commits into
kiesraad:mainfrom
yusufraji:show-user-online-status

Conversation

@yusufraji

Copy link
Copy Markdown
Contributor

This shows users who are currently logged in.

Changes:

  • adds a new is_logged_in field to the User struct and table on the backend
  • sets the field to false by default
  • sets the field to true after logging in
  • set the field to false after logging out

I still need help working on the frontend for the full implementation.

Resolves #3251

@yusufraji yusufraji requested a review from a team as a code owner May 28, 2026 14:13
@yusufraji

Copy link
Copy Markdown
Contributor Author

Perhaps @Lionqueen94 or @stacktraceghost could have a look.

@ring-ring-ring

Copy link
Copy Markdown
Contributor

This is cool! Thnx @yusufraji

@yusufraji yusufraji force-pushed the show-user-online-status branch 2 times, most recently from 8a7268b to 8a43013 Compare May 28, 2026 22:38
@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.19%. Comparing base (42350ea) to head (5dd6995).
⚠️ Report is 1 commits behind head on main.

@yusufraji yusufraji force-pushed the show-user-online-status branch 2 times, most recently from f4d3506 to 8c0067d Compare May 29, 2026 14:34

@stacktraceghost stacktraceghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your PR! I've reviewed it and have some comments.

Comment thread backend/migrations/11_alter_users.sql Outdated
Comment thread backend/src/repository/user_repo.rs Outdated
@praseodym

Copy link
Copy Markdown
Contributor

@yusufraji Looks good! The only thing remaining to resolve #3251 would be to add the blue indicator dot for users that are logged in. Your initial PR body says you need help with the frontend implementation, are there any specific points you're struggling with?

@yusufraji

Copy link
Copy Markdown
Contributor Author

@yusufraji Looks good! The only thing remaining to resolve #3251 would be to add the blue indicator dot for users that are logged in. Your initial PR body says you need help with the frontend implementation, are there any specific points you're struggling with?

Not necessarily, just a skill issue, since I'm new to react/Typescript and all that's frontend. I looked into it just a little bit before raising the PR. I'll have a look again.

Comment thread backend/src/repository/user_repo.rs Outdated
Comment thread backend/src/api/authentication.rs Outdated
Comment thread backend/src/repository/user_repo.rs Outdated
@praseodym

Copy link
Copy Markdown
Contributor

@yusufraji let us know if you want to spend more time on this, otherwise I'd be happy to fix these last points and merge this PR.

@yusufraji

Copy link
Copy Markdown
Contributor Author

@yusufraji let us know if you want to spend more time on this, otherwise I'd be happy to fix these last points and merge this PR.

No worries, I've committed changes to address some of the review comments. But for the last comment, please go ahead and make the changes since I am not sure of how to resolve that comment.

We should keep the WHERE username = ? COLLATE NOCASE so that this query keeps using the username COLLATE NOCASE index

I look forward to learning how I could have implemented this from your changes.

@praseodym

Copy link
Copy Markdown
Contributor

@yusufraji this has a merge conflict after merging #3432

yusufraji added a commit to yusufraji/abacus that referenced this pull request Jun 23, 2026
There is no state added; Computing on the fly should be cheap enough due to the
relatively low number of users and sessions.

This also adds a uniqe index on `user_id` on the `sessions` table for performance
reasons. This also closes kiesraad#3443.

Co-authored-by: Christian Jaeger <ch@christianjaeger.ch>
yusufraji added a commit to yusufraji/abacus that referenced this pull request Jun 23, 2026
Add a blue indicator dot for logged in users.
@yusufraji yusufraji force-pushed the show-user-online-status branch from 49dd059 to 3f14e0a Compare June 23, 2026 12:42
@praseodym

praseodym commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

I notice that the tests fail because of the session unique constraint. #3458 also adds this constraint and fixes failing tests.

@pflanze

pflanze commented Jun 24, 2026

Copy link
Copy Markdown

I notice that the tests fail because of the session unique constraint. #3458 also adds this constraint and fixes failing tests.

Yes; this PR primarily added the index for performance reasons. Given that your PR is merged, this PR can be rebased on top of the new main again and then doesn't need to add the constraint anymore.

@yusufraji, we should add running the tests to our run-left-hooks script; I didn't realize it didn't do that already. (Explanation to the others: we turned the left hooks into a shell script so we could commit without the hooks running all the time; we run the script when we clean up the history.)

yusufraji and others added 2 commits June 24, 2026 10:44
There is no state added; Computing on the fly should be cheap enough due to the
relatively low number of users and sessions.

This also adds a uniqe index on `user_id` on the `sessions` table for performance
reasons. This also closes kiesraad#3443.

Co-authored-by: Christian Jaeger <ch@christianjaeger.ch>
Add a blue indicator dot for logged in users.
@yusufraji yusufraji force-pushed the show-user-online-status branch from 3f14e0a to 5dd6995 Compare June 24, 2026 08:49
@praseodym

Copy link
Copy Markdown
Contributor

(Explanation to the others: we turned the left hooks into a shell script so we could commit without the hooks running all the time; we run the script when we clean up the history.)

You can always commit using --no-verify to skip the pre-commit hooks.

@pflanze

pflanze commented Jun 24, 2026

Copy link
Copy Markdown

(Explanation to the others: we turned the left hooks into a shell script so we could commit without the hooks running all the time; we run the script when we clean up the history.)

You can always commit using --no-verify to skip the pre-commit hooks.

OK, I wasn't aware of that. I would probably end up just running with that option all the time, though, since my workflow commits very often and then I clean up things, and so will end up still preferring an explicit script.

BTW I'm considering parallelizing the actions (in my/our script) to make use of my many cores when I actually do run the actions; I didn't see anything about lefthook that would do that, have I missed it?

@praseodym

Copy link
Copy Markdown
Contributor

BTW I'm considering parallelizing the actions (in my/our script) to make use of my many cores when I actually do run the actions; I didn't see anything about lefthook that would do that, have I missed it?

Lefthook runs all its commands in parallel in our setup:

parallel: true

Also see https://lefthook.dev/configuration/parallel/.

@pflanze

pflanze commented Jun 24, 2026

Copy link
Copy Markdown

This PR is primarily @yusufraji 's work, so take these comments as ideas, I'm not invested in them:

  • The commit message of the first commit still mentions adding the unique index, maybe worth removing; really minor, though.

  • Given that is_logged_in is a derived value, might it be cleaner to leave struct User as is and instead add a wrapper that holds the User instance and the is_logged_in value? In garbage-collected language there's an incentive against wrapping like that since it costs a memory indirection, but that's not the case with Rust, where doing cleaner abstractions like this has no runtime cost. There's probably no point stopping this PR from being merged, but I could evaluate the feasibility in a separate PR, unless you already have reasons not to want that.

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.

Show online status in users table

6 participants