Skip to content

Conversation

@jaeyun0503
Copy link
Contributor

@jaeyun0503 jaeyun0503 commented Aug 5, 2025

Summary

This pr adds a new feature where the admin can keep track of the active/inactive users on the Admin Dashboard. The feature is added in order to give admin users a better use experience and straightforward overview of users' activeness. A ring is added around the avatars and it will turn green whenever a user is active and gray if a user is inactive.

Closes #3624.

For Developers

Please do the following steps to incorporate with new changes:

  • Apply core/scripts/sql/updates/10.sql to your local postgres instance

Change made to Database

A new table time_log is introduced to the db with primary key being uid that references the uid from user table and last_active as an column to store the last active time of the user. The last_active column can be null and when a user is active, one of the following will happen:

  1. If the corresponding uid exists in the time_log table, the last_active will simply be updated.
  2. If the corresponding uid does NOT exist in the time_log table, (uid, last_active) will be added to the table.

Context of the Design

The reasons why we chose to create a separate table time_log instead of adding the information to the user table are as follows:

  1. Too costly to update user table frequently: When a user becomes "active", last_active will be updated. And how we defined a user to be active is that when a user makes a http request and they hold a valid jwt token that has a lifespan of 15 minutes, the user is active. Whenever the user makes a http request the last_active column will have to be updated. And with a scalable system like Texera, it will become more and more costly to update the information when a large number of users are "active" on the system if the last_active is in the user table.
  2. Since there might be more time information that can be added in future regarding user's account creation time, last action time, etc, it is better to bring the time information out and make them as a separate project.

Based on the internal discussions on the design of the tables, we decided to create a time_log table.

Image of Database Diagram

image

Functionality & Explanation of the Feature

When a user makes a http request, the attribute will be updated in the db. Future changes might be made to this table since we are planning to introduce more attributes like account creation time.

Since every http request triggers the jwtFilter, our design is to upsert the user's last login time record whenever the request triggers the jwtFilter. The upsert function will add a new record if the user never logged in before, and will update the last_login attribute. When the admin visits the admin dashboard, the call to the getUserList will now contain a list of users with a new attribute named lastActive, which is a Unix epoch timestamp in seconds. If a user's lastActive attribute is null or the difference between the current timestamp and its lastActive timestamp is larger than the set threshold (a.k.a active window), the user will be inactive, otherwise active. Here we define the active window as 15 minutes. With this threshold, admin users will be able to know which users were active within the last 15 minutes.

The token's expiration time is set to 15 minutes, and refresh time is set to 16 minutes in order to make sure a user is "logged out" when they don't make anymore http requests. As soon as the system detects that the last active time has a 15 minutes difference with the current time, it will mark the user as inactive.

Screenshot of Feature

image

@jaeyun0503 jaeyun0503 marked this pull request as ready for review August 6, 2025 07:29
Copilot AI review requested due to automatic review settings August 6, 2025 07:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a user activity tracking feature to the admin dashboard that allows administrators to visually distinguish between active and inactive users. Active users (those who made HTTP requests within the last 15 minutes) are displayed with a green ring around their avatar, while inactive users have a gray ring.

  • Implements user activity tracking by recording last login timestamps in a new time_log database table
  • Updates JWT token expiration to 15 minutes with 16-minute refresh interval to align with activity window
  • Modifies admin user interface to display visual activity indicators around user avatars

Reviewed Changes

Copilot reviewed 10 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
core/scripts/sql/updates/10.sql Creates new time_log table to store user activity timestamps
core/auth/src/main/scala/edu/uci/ics/texera/auth/JwtAuth.scala Updates JWT token expiration to 15 minutes
core/auth/src/main/scala/edu/uci/ics/texera/auth/JwtAuthFilter.scala Adds logic to upsert user activity on each authenticated request
core/amber/src/main/scala/edu/uci/ics/texera/web/resource/dashboard/admin/user/AdminUserResource.scala Implements new endpoint returning users with last activity data
core/gui/src/app/common/type/user.ts Adds lastActive field to User interface
core/gui/src/app/dashboard/component/admin/user/admin-user.component.* Implements frontend logic and styling for activity indicators
core/gui/src/app/dashboard/service/admin/user/admin-user.service.ts Updates service to use new activity-enabled endpoint
core/gui/src/app/common/service/user/auth.service.ts Adjusts token refresh interval to 16 minutes

@jaeyun0503
Copy link
Contributor Author

@aicam Please help me assign labels, assignee and reviewers. Thank you so much!

@aicam aicam requested review from aglinxinyuan and aicam August 6, 2025 16:50
@apache apache deleted a comment from Copilot AI Aug 6, 2025
@apache apache deleted a comment from Copilot AI Aug 6, 2025
@apache apache deleted a comment from Copilot AI Aug 6, 2025
@apache apache deleted a comment from Copilot AI Aug 6, 2025
@jaeyun0503 jaeyun0503 requested a review from aicam August 9, 2025 21:37
@jaeyun0503
Copy link
Contributor Author

@aicam @aglinxinyuan Made changes to the code. Re-requesting review.

Copy link
Contributor

@aicam aicam left a comment

Choose a reason for hiding this comment

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

LGTM

@aicam aicam enabled auto-merge (squash) August 11, 2025 17:18
Copy link
Contributor

@aglinxinyuan aglinxinyuan left a comment

Choose a reason for hiding this comment

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

LGTM. You don't need to list the files changed.

auto-merge was automatically disabled August 11, 2025 18:26

Head branch was pushed to by a user without write access

@jaeyun0503
Copy link
Contributor Author

@aicam I think an approval is needed from the maintainer's side

@jaeyun0503
Copy link
Contributor Author

@aicam Final approval needed

@aicam aicam merged commit a67da07 into apache:master Aug 11, 2025
10 checks passed
aicam added a commit that referenced this pull request Aug 23, 2025
…thLastLogin (#3682)

## Summary

In effort to improve the naming convention of variables and api
endpoints of previous PR #3625, this PR is raised to change
`UserWithLastLogin` to `UserInfo` and `/listWIthActivity` to `/list`.

## Changes

1. The code inside the api endpoint `/listWithActivity` has been moved
to `/list`. `/listWithActivity` has been removed.
2. The class name `UserWithLastLogin` is changed to `UserInfo`.

## Notes
Fixes Issue #3624.

After discussion, we decided to change the api endpoint as the code in
`/list` was no longer used and `/listWithActivity` has a too specific
name. To make the name more intuitive and generalized, we decided to
move the code into `/list` to make it more clear.
Same thing happens to `UserWithLastLogin`. It has a specific name and we
decided it to change it into `UserInfo` so it can be generally used and
be added with more attributes.

---------

Co-authored-by: ali risheh <ali.risheh876@gmail.com>
aicam pushed a commit that referenced this pull request Oct 20, 2025
### What changes were proposed in this PR?
This PR fixes the active ring size around user's avatar in the admin
dashboard tab to enhance visibility.

### Current Implementation
<img width="132" height="106" alt="image"
src="https://github.com/user-attachments/assets/8b30aff4-87a7-4d34-8bcb-39f8c24430c9"
/>

### Proposed Implementation
<img width="102" height="122" alt="image"
src="https://github.com/user-attachments/assets/d7c9816f-6221-41f2-8a13-30319bd5b1f6"
/>



### Any related issues, documentation, discussions?
Fixes #3625 


### How was this PR tested?
Test was not added to this part as this is a styling-related issue.


### Was this PR authored or co-authored using generative AI tooling?
No.
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.

Adding User's Activeness on Admin Dashboard

3 participants