-
-
Notifications
You must be signed in to change notification settings - Fork 307
User last activity #3286
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
Open
zomp
wants to merge
22
commits into
tolgee:main
Choose a base branch
from
zomp:user-last-activity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
User last activity #3286
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4722b44
BE lastActivity field added to the UserAccount entity
f35eb83
Update DEVELOPMENT.md
260a148
FE Add last activity to AdministrationUsers.tsx
b9b1fd2
FE Regenerate API schemas
e98ed1c
BE adjust the implementation to work with UserAccountView
f65ece4
chore: Unify last activity UI to existing code & fix UI issues
6a98421
style: correct spelling of strings
9fa7a29
style: format & unify DEVELOPMENT.md
1b153d8
doc: add running backend dependency for schema generation to DEVELOPM…
adbc0a1
chore: rename files in separate commit to keep their history
9881594
feat: implement last activity via new `UserAccountAdministrationView`…
84e9fbf
style: use `{theme.palette.text.secondary}` instead of `'textSecondary'`
bc4f01f
fix: reflect forgotten API schema changes
ff5f0a5
fix: search only within list items (i.e. not in menu)
f21a136
test: E2E for last activity in users administration
c0a1c6e
fix: set user activity time in local timezone
af6393f
test: integration test for last activity in users administration
9670118
fix: make sure forced date is always released
731eb8a
fix: make sure forced date is always released even in integration test
eaff814
Merge branch 'tolgee:main' into user-last-activity
zomp 055045a
fix: use proper server response types
cab9feb
refactor: unify `currentDateProvider.forcedDate` clearance
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| ## Install Prerequisites | ||
|
|
||
| * [Java 21](https://openjdk.org/install) | ||
| * [Docker](https://docs.docker.com/engine/install) | ||
| * [Node.js 18](https://nodejs.org/en/download) (or higher) | ||
| * [Intellij Idea](https://www.jetbrains.com/help/idea/installation-guide.html) (optional) | ||
| - [Java 21](https://openjdk.org/install) | ||
| - [Docker](https://docs.docker.com/engine/install) | ||
| - [Node.js 18](https://nodejs.org/en/download) (or higher) | ||
| - [Intellij Idea](https://www.jetbrains.com/help/idea/installation-guide.html) (optional) | ||
|
|
||
| ## Clone this repo | ||
|
|
||
|
|
@@ -14,14 +14,14 @@ git clone --depth 1 [email protected]:tolgee/tolgee-platform.git | |
| ## Run the stack | ||
|
|
||
| 1. Run backend | ||
| * With the prepared Idea run configuration `Backend localhost` | ||
| * With command line: | ||
| - With the prepared Idea run configuration `Backend localhost`. | ||
| - With command line: | ||
| ```shell | ||
| ./gradlew server-app:bootRun --args='--spring.profiles.active=dev' | ||
| ``` | ||
| 2. Run frontend | ||
| * With the prepared Idea run configuration `Frontend localhost` | ||
| * With command line: | ||
| - With the prepared Idea run configuration `Frontend localhost`. | ||
| - With command line: | ||
| ```shell | ||
| cd webapp && npm ci && npm run start | ||
| ``` | ||
|
|
@@ -33,7 +33,7 @@ The backend of Tolgee is tested with unit and integration tests. | |
|
|
||
| ### Backend testing | ||
|
|
||
| To run backend tests, you can run Gradle test task | ||
| To run backend tests, you can run Gradle test task: | ||
|
|
||
| ```shell | ||
| ./gradlew test | ||
|
|
@@ -62,11 +62,29 @@ tolgee: | |
| file-storage-url: http://localhost:8080 | ||
| ``` | ||
|
|
||
| To enable authentication, add following properties: | ||
|
|
||
| ```yaml | ||
| tolgee: | ||
| authentication: | ||
| enabled: true | ||
| initial-username: <YOUR_REAL_EMAIL> | ||
| initial-password: admin | ||
| ``` | ||
|
|
||
| You can check `application-e2e.yaml` for further inspiration. | ||
| To learn more about externalized configuration in Spring boot, read [the docs](https://docs.spring.io/spring-boot/3.4/reference/features/external-config.html). | ||
| To learn more about externalized configuration in Spring Boot, read [its docs](https://docs.spring.io/spring-boot/3.4/reference/features/external-config.html). | ||
|
|
||
| Since we set the active profile to `dev`, Spring uses the `application-dev.yaml` configuration file. | ||
|
|
||
| ## API schema changes | ||
|
|
||
| After you change the API schema, you need to have backend running and invoke the webapp schema script to update frontend: | ||
|
|
||
| ```shell | ||
| cd webapp && npm run schema | ||
| ``` | ||
|
|
||
| ## Updating the database changelog | ||
|
|
||
| Tolgee uses Liquibase to handle the database migration. The migrations are run on every app startup. To update the changelog, run: | ||
|
|
@@ -77,12 +95,13 @@ Tolgee uses Liquibase to handle the database migration. The migrations are run o | |
|
|
||
| ### Troubleshooting updating the changelog | ||
|
|
||
| If you misspell the command and run diffChangelog, it will find the command, but it would fail, since liquibase changed the command name in the past. | ||
| We have enhanced the diffChangeLog (with capital L) command, so you have to run that. | ||
| If you misspell the command and run `diffChangelog`, it will find the command, but it would fail, since Liquibase changed the command name in the past. | ||
| We have enhanced the `diffChangeLog` (with capital `L`) command, so you have to run that. | ||
|
|
||
| Sometimes, Gradle cannot find a docker command to start the database instance to generate the changelog against. | ||
| This happens due to some issue with setting the paths for Gradle daemon. | ||
| Sometimes, Gradle cannot find a Docker command to start the database instance to generate the changelog against. | ||
| This happens due to some issue with setting the paths for Gradle Daemon. | ||
| Running the command without daemon fixes the issue: | ||
|
|
||
| ```shell | ||
| ./gradlew diffChangeLog --no-daemon | ||
| ``` | ||
|
|
@@ -91,9 +110,9 @@ Running the command without daemon fixes the issue: | |
|
|
||
| For the frontend, there are npm tasks `prettier` and `eslint`, which you should run before every commit. | ||
| Otherwise, the "Frontend static check" workflow will fail. | ||
| You can also use prettier plugins for VS Code, Idea, or WebStorm. | ||
| You can also use Prettier plugins for VS Code, Idea, or WebStorm. | ||
|
|
||
| To fix prettier issues and check everything is fine, run these commands: | ||
| To fix Prettier issues and check everything is fine, run these commands: | ||
|
|
||
| ```shell | ||
| cd webapp | ||
|
|
@@ -102,7 +121,7 @@ npm run tsc | |
| npm run eslint | ||
| ``` | ||
|
|
||
| On the backend, there is Gradle task `ktlintFormat`, which helps you to format Kotlin code. | ||
| On the backend, there is Gradle task `ktlintFormat`, which helps you to format Kotlin code: | ||
|
|
||
| ```shell | ||
| ./gradlew ktlintFormat | ||
|
|
@@ -122,19 +141,20 @@ VITE_APP_TOLGEE_API_KEY=your-tolgee-api-key | |
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Command not found when executing gradle tasks on MacOS | ||
| When running E2e Tests from Idea on Mac, you encounter fails due to command not found. | ||
| ### Command not found when executing Gradle tasks on MacOS | ||
|
|
||
| Apparentrly this happens because IDEA starts the gradle daemon with wrong path. | ||
| When running E2E tests from Idea on Mac, you encounter fails due to command not found. | ||
|
|
||
| The only **workaround** I currently found is killing the gradle daemon and running IDEA from terminal | ||
| Apparently this happens because Idea starts the Gradle Daemon with wrong path. | ||
|
|
||
| ```bash | ||
| The only **workaround** I currently found is killing the Gradle Daemon and running Idea from terminal: | ||
|
|
||
| ```shell | ||
| pkill -f '.*GradleDaemon.*' | ||
| open -a 'IntelliJ IDEA Ultimate' | ||
| ``` | ||
|
|
||
| This way, IDEA is started with correct environment from zsh or bash and so the Gradle Daemon is started correctly. | ||
| This way, Idea is started with correct environment from Zsh or Bash and so the Gradle Daemon is started correctly. | ||
|
|
||
| If you don't like this solution (I don't like it too), you can start looking for better solution. | ||
| This thread is a good starting point: https://discuss.gradle.org/t/exec-execute-in-gradle-doesnt-use-path/25598/3 | ||
|
|
@@ -147,7 +167,8 @@ To monitor business activities in the Tolgee platform, we use PostHog for event | |
|
|
||
| When an activity is stored with a modifying endpoint on the backend, the event is automatically logged. Developers can optionally provide additional metadata using the `businessEventData` property in `ActivityHolder`. | ||
|
|
||
| Usually, you don't need to provide the data, but If you really need to, you can do it this way. | ||
| Usually, you don't need to provide the data, but If you really need to, you can do it this way: | ||
|
|
||
| ```kotlin | ||
| // Example: Adding business event data to an activity | ||
| @Component | ||
|
|
@@ -203,10 +224,10 @@ class YourService( | |
|
|
||
| ### 3. Logging from frontend code | ||
|
|
||
| For logging events from the frontend, use the provided React hooks: | ||
| For logging events from the frontend, use the provided React Hooks: | ||
|
|
||
| ```typescript | ||
| // Example 1: Using useReportEvent hook for event-triggered reporting | ||
| // Example 1: Using useReportEvent Hook for event-triggered reporting | ||
| import { useReportEvent } from 'tg.hooks/useReportEvent'; | ||
|
|
||
| function ExampleComponent() { | ||
|
|
@@ -222,7 +243,7 @@ function ExampleComponent() { | |
| ``` | ||
|
|
||
| ```typescript | ||
| // Example 2: Using useReportOnce hook for reporting on component mount | ||
| // Example 2: Using useReportOnce Hook for reporting on component mount | ||
| import { useReportOnce } from 'tg.hooks/useReportEvent'; | ||
|
|
||
| function AnotherComponent() { | ||
|
|
@@ -233,4 +254,4 @@ function AnotherComponent() { | |
| } | ||
| ``` | ||
|
|
||
| These frontend hooks send events through the backend API, ensuring they aren't blocked by ad blockers. | ||
| These frontend Hooks send events through the backend API, ensuring they aren't blocked by ad blockers. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../src/main/kotlin/io/tolgee/hateoas/userAccount/UserAccountAdministrationModelAssembler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package io.tolgee.hateoas.userAccount | ||
|
|
||
| import io.tolgee.api.isMfaEnabled | ||
| import io.tolgee.api.v2.controllers.V2UserController | ||
| import io.tolgee.dtos.queryResults.UserAccountAdministrationView | ||
| import io.tolgee.model.UserAccount | ||
| import io.tolgee.service.AvatarService | ||
| import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport | ||
| import org.springframework.stereotype.Component | ||
|
|
||
| @Component | ||
| class UserAccountAdministrationModelAssembler( | ||
| private val avatarService: AvatarService, | ||
| ) : RepresentationModelAssemblerSupport<UserAccountAdministrationView, UserAccountAdministrationModel>( | ||
| V2UserController::class.java, | ||
| UserAccountAdministrationModel::class.java, | ||
| ) { | ||
| override fun toModel(view: UserAccountAdministrationView): UserAccountAdministrationModel { | ||
| val avatar = avatarService.getAvatarLinks(view.avatarHash) | ||
|
|
||
| return UserAccountAdministrationModel( | ||
| id = view.id, | ||
| username = view.username, | ||
| name = view.name, | ||
| emailAwaitingVerification = view.emailAwaitingVerification, | ||
| avatar = avatar, | ||
| globalServerRole = view.role ?: UserAccount.Role.USER, | ||
| mfaEnabled = view.isMfaEnabled, | ||
| deleted = view.deletedAt != null, | ||
| disabled = view.disabledAt != null, | ||
| lastActivity = view.lastActivity, | ||
| ) | ||
| } | ||
| } |
32 changes: 0 additions & 32 deletions
32
backend/api/src/main/kotlin/io/tolgee/hateoas/userAccount/UserAccountModelAssembler.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace dbPopulator with test data from AdministrationTestData.
As per previous feedback,
dbPopulatorshould be phased out in favor of using test data. Use the default organization fromAdministrationTestDatainstead of creating a new one.For example:
Based on past review comments.
🤖 Prompt for AI Agents