feat: introduce system user for automated changes#37
Merged
GitAddRemote merged 2 commits intomainfrom Dec 3, 2025
Merged
Conversation
Implement dedicated system user record (ID=1) for automated operations such as sync jobs and background tasks. Database changes: - Add isSystemUser column to User entity with index - Create migration to add is_system_user column - Seed system user (ID=1, username: station-system) - Generate unique, unusable password hash for system user Application layer: - Implement SystemUserService with ID caching at startup - Service auto-creates system user in test mode if missing - Service fails fast if system user missing in production - Provide isSystemUser() helper for user identification Query filtering: - Update UsersService to exclude system user from all queries - System user excluded from find operations Authentication protection: - Block system user from authentication in validateUser - System user cannot log in or generate tokens - Log warning if system user attempts authentication Testing: - Add comprehensive unit tests for SystemUserService - Update AuthService tests with SystemUserService mocks - Add E2E test helper for system user seeding - All 101 unit tests passing Closes #16
47ce9d7 to
35b0dc7
Compare
The 'should throw error if system user is missing' test was failing because the service auto-creates the system user in test environments, but the mock repository was missing create/save methods. Changes: - Add create and save methods to mock repository - Set NODE_ENV to 'production' in error test to prevent auto-creation - Add new test case to verify auto-creation works in test environment All 102 tests now pass successfully.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements a dedicated system user (ID=1) for all automated changes, ensuring audit trail integrity and consistent foreign key attribution for background jobs and sync operations.
Changes
Database Schema
isSystemUserboolean column tousertable with indexstation-system, email:system@station.internal)Application Layer
Key Features
Testing
Migration Safety
ON CONFLICT DO NOTHINGFuture Usage
System user will be used for:
Closes
#16
Test Plan