Repository navigation
feat(auth2): Bundle auth user operations in AuthUsers class - #3634
Conversation
Do not export the raw database access any longer
|
@coderabbitai review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThis update introduces a new abstraction layer for managing authentication users via the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Endpoint
participant AuthUsers
participant Database
Client->>Endpoint: Register or authenticate user
Endpoint->>AuthUsers: create(session, ...)
AuthUsers->>Database: Insert new AuthUser row
Database-->>AuthUsers: New user data
AuthUsers-->>Endpoint: AuthUserModel
Endpoint-->>Client: Response with AuthUserModel
Client->>Endpoint: Retrieve user by ID
Endpoint->>AuthUsers: get(session, authUserId)
AuthUsers->>Database: Query AuthUser by ID
Database-->>AuthUsers: User data or not found
AuthUsers-->>Endpoint: AuthUserModel or throw AuthUserNotFoundException
Endpoint-->>Client: Response or error
sequenceDiagram
participant Test
participant TestUtils
participant AuthUsers
participant Database
Test->>TestUtils: createAuthUser(session)
TestUtils->>AuthUsers: create(session)
AuthUsers->>Database: Insert new AuthUser row
Database-->>AuthUsers: New user data
AuthUsers-->>TestUtils: AuthUserModel
TestUtils-->>Test: AuthUserModel
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (6)
modules/new_serverpod_auth/serverpod_auth_jwt/serverpod_auth_jwt_server/test/integration/authentication_handler_test.dart (1)
71-73: Consider extracting repeated “create temp user” logic into a test utility
AuthUsers.createAuthUser(session)followed byauthUserId = authUser.idappears twice in this file (lines 71-73 & 157-159).
A tiny helper or asetUpcallback would keep the tests DRY and remove duplication noise.Also applies to: 157-159
modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/serverpod_auth_user_server.dart (1)
5-8: Minor wording nit – double “the” in comment
// We don't want to expose these, but have to for the the generated database code…-// We don't want to expose these, but have to for the the generated database code in consuming packages. +// We don't want to expose these, but have to for the generated database code in consuming packages.modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/business/auth_users.dart (2)
28-46:createAuthUser– avoid unnecessary.nonNulls
scopes.map((s) => s.name)cannot containnullbecauseScope.nameis non-nullable. The extra.nonNullscall is redundant and slightly obscures intent.- scopeNames: scopes.map((final s) => s.name).nonNulls.toSet(), + scopeNames: scopes.map((s) => s.name).toSet(),
51-86: No-op update results in a writeWhen both
scopesandblockedarenull,updateAuthUserstill performs anupdateRowround-trip, even though nothing changed.
A fast path returning early would trim an unnecessary DB call.modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_client/lib/src/protocol/auth_user_model.dart (1)
99-105:copyWithunnecessarily reallocatesscopeNames
this.scopeNames.map((e0) => e0).toSet()allocates even whenscopeNamesisn’t overridden.
You can simply reuse the existing reference –Setin Dart is already mutable-safe in this context.- scopeNames: scopeNames ?? this.scopeNames.map((e0) => e0).toSet(), + scopeNames: scopeNames ?? this.scopeNames,modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/test/integration/auth_users_test.dart (1)
40-44: Assertion description typo
then its removed→then it is removedfor grammatical clarity.- test('when deleting it, then its removed from the database.', () async { + test('when deleting it, then it is removed from the database.', () async {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/generated/auth_user_model.dartis excluded by!**/generated/**modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/generated/auth_user_not_found_exception.dartis excluded by!**/generated/**modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/generated/protocol.dartis excluded by!**/generated/**
📒 Files selected for processing (15)
modules/new_serverpod_auth/serverpod_auth_email/serverpod_auth_email_server/lib/src/endpoints/email_account_endpoint.dart(2 hunks)modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/test/test_utils.dart(2 hunks)modules/new_serverpod_auth/serverpod_auth_jwt/serverpod_auth_jwt_server/test/integration/authentication_handler_test.dart(2 hunks)modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/test/test_utils.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_client/lib/src/protocol/auth_user_model.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_client/lib/src/protocol/auth_user_not_found_exception.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_client/lib/src/protocol/protocol.dart(4 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/serverpod_auth_user_server.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/business/auth_users.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/models/auth_user_model.spy.yaml(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/models/auth_user_not_found_exception.spy.yaml(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/util/auth_user_scopes_extension.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/pubspec.yaml(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/test/integration/auth_users_test.dart(1 hunks)templates/pubspecs/modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/pubspec.yaml(1 hunks)
🔇 Additional comments (15)
modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/models/auth_user_not_found_exception.spy.yaml (1)
1-1: Approve exception declaration.
AuthUserNotFoundExceptionis correctly declared in the spy model, enabling code generation for missing-user errors.modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/pubspec.yaml (2)
13-14: Approve new dependencies.
Addingclock(for timestamp management) andmeta(for visibility annotations) supports theAuthUsersclass.
20-20: Normalize dev dependency syntax.
Switchingtestto unquoted caret syntax aligns with the other version constraints.templates/pubspecs/modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/pubspec.yaml (2)
12-13: Approve template dependencies.
Template pubspec now includesclockandmetaplaceholders for generated modules.
19-19: Normalize template test constraint.
Unquoted caret syntax fortestin the template mirrors the actual pubspec format.modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/models/auth_user_model.spy.yaml (5)
1-2: Approve model declaration.
TheAuthUserModelclass is properly defined with afieldssection for code generation.
3-3: Approveidfield.
UuidValueensures each auth user has a unique identifier.
5-6: Approvecreatedtimestamp field.
The comment andDateTimetype clearly represent creation time.
8-9: ApprovescopeNamesfield.
UsingSet<String>for scopes promotes de-duplication and clarity.
11-12: Approveblockedflag.
The booleanblockedfield effectively signals sign-in restriction.modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/util/auth_user_scopes_extension.dart (1)
4-5: Approve extension update.
Switching the doc comment and extension to targetAuthUserModelaligns with the new abstraction.modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/test/test_utils.dart (1)
4-8: Looks good – helper now uses the sharedAuthUsersAPICreation is correctly delegated and the function type now matches the helper’s
UuidValuereturn. Nothing else to flag.modules/new_serverpod_auth/serverpod_auth_email/serverpod_auth_email_server/lib/src/endpoints/email_account_endpoint.dart (1)
121-124: Pass the active transaction togetAuthUserto stay inside the same DB txn
_createSessionis invoked from within asession.db.transaction, yetAuthUsers.getAuthUseris called without thetransaction:argument.
While Serverpod often reuses the current connection implicitly, being explicit avoids surprises (nested transactions, unexpected locking).- final authUser = await AuthUsers.getAuthUser( - session, - authUserId: authUserId, - ); + final authUser = await AuthUsers.getAuthUser( + session, + authUserId: authUserId, + transaction: session.db.currentTransaction, + );If
getAuthUseralready detects an open transaction automatically, please ignore; otherwise this shields us from subtle isolation bugs.modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/test/integration/auth_users_test.dart (1)
46-51: Single-item assertion is brittle
listAuthUsersreturning exactly one record assumes no previous leakage from other tests.
Safer to assert that the createdauthUser.idis contained in the result set.- expect(authUsers.single.id, authUser.id); + expect(authUsers.map((u) => u.id), contains(authUser.id));modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_client/lib/src/protocol/auth_user_not_found_exception.dart (1)
40-49: LGTM – minimal, serializable marker exceptionImplementation correctly satisfies both
SerializableExceptionandSerializableModelwith no extraneous state.
For consistency
So we don't have to make analyzer exceptions that could break in other configuration
SandPod
left a comment
There was a problem hiding this comment.
LGTM!
Just have a single comment for discussion.
As we did practically already, just without explicit `show`
…in `AuthUsers.delete`
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/business/auth_users.dart (2)
88-99: Consider exposing pagination / filtering forlist
list()currently fetches all auth users in one query.
On a production system this can turn into an unbounded table scan and DOS-size response.Expose optional
limit,offset, or predicate parameters (e.g.blocked: bool?,scope: Scope?) to keep the method usable at scale.
79-86: Avoid needless write when nothing changesIf both
scopesandblockedarenull, the method still issuesupdateRow, producing a no-op write and an extra row-lock.- authUser = await AuthUser.db.updateRow( - session, - authUser, - transaction: transaction, - ); + if (authUser != originalAuthUser) { + authUser = await AuthUser.db.updateRow( + session, + authUser, + transaction: transaction, + ); + }Keeps the DB quieter and eliminates a possible race.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/business/auth_users.dart(1 hunks)modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/test/integration/auth_users_test.dart(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (57)
- GitHub Check: Version change test
- GitHub Check: Flutter unit tests (3.24.0, windows-latest, packages/serverpod_flutter)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server with Flutter 3.32.1
- GitHub Check: Flutter unit tests (3.32.1, windows-latest, packages/serverpod_flutter)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server with Flutter 3.32.1
- GitHub Check: Flutter unit tests (3.32.1, ubuntu-latest, packages/serverpod_flutter)
- GitHub Check: Serverpod integration tests (flutter)
- GitHub Check: Unit tests IO (3.24.0, windows-latest)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_profile/serverpod_auth_profile_server with Flutter 3.24.0
- GitHub Check: Module integration tests in tests/serverpod_test_module/serverpod_test_module_server with Flutter 3.32.1
- GitHub Check: Unit tests IO (3.24.0, ubuntu-latest)
- GitHub Check: Unit tests IO (3.32.1, windows-latest)
- GitHub Check: Unit tests IO (3.32.1, ubuntu-latest)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_jwt/serverpod_auth_jwt_server with Flutter 3.32.1
- GitHub Check: Module integration tests in modules/serverpod_auth/serverpod_auth_server with Flutter 3.32.1
- GitHub Check: Migration e2e tests (3.32.1)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server with Flutter 3.24.0
- GitHub Check: Serverpod E2E web tests (3.24.0)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server with Flutter 3.32.1
- GitHub Check: Migration e2e tests (3.24.0)
- GitHub Check: Module integration tests in modules/serverpod_auth/serverpod_auth_server with Flutter 3.24.0
- GitHub Check: dart analyze downgrade (3.32.1, windows-latest)
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server with Flutter 3.24.0
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_api_tokens/serverpod_auth_api_tokens_server with Flutter 3.32.1
- GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.32.1
- GitHub Check: Module integration tests in modules/new_serverpod_auth/serverpod_auth_jwt/serverpod_auth_jwt_server with Flutter 3.24.0
- GitHub Check: Module integration tests in tests/serverpod_test_module/serverpod_test_module_server with Flutter 3.24.0
- GitHub Check: Serverpod integration tests (server) (3.24.0)
- GitHub Check: Module integration tests in tests/serverpod_test_nonvector/serverpod_test_nonvector_server with Flutter 3.24.0
- GitHub Check: Unit tests Web (3.32.1, windows-latest)
- GitHub Check: dart analyze latest (3.32.1, windows-latest)
- GitHub Check: Unit tests Web (3.32.1, ubuntu-latest)
- GitHub Check: Serverpod integration tests (server) (3.32.1)
- GitHub Check: Serverpod integration tests (3.32.1, packages/serverpod_shared)
- GitHub Check: dart analyze downgrade (3.32.1, ubuntu-latest)
- GitHub Check: Serverpod E2E web tests (3.32.1)
- GitHub Check: Unit tests Web (3.24.0, ubuntu-latest)
- GitHub Check: dart analyze downgrade (3.24.0, windows-latest)
- GitHub Check: update pubspecs (3.24.0)
- GitHub Check: update pubspecs (3.32.1)
- GitHub Check: CLI e2e tests (3.24.0, ubuntu-latest, tests/serverpod_cli_e2e_test)
- GitHub Check: dart analyze latest (3.32.1, ubuntu-latest)
- GitHub Check: Unit tests Web (3.24.0, windows-latest)
- GitHub Check: dart analyze downgrade (3.24.0, ubuntu-latest)
- GitHub Check: CLI e2e tests (3.32.1, ubuntu-latest, tests/serverpod_cli_e2e_test)
- GitHub Check: serverpod generate (3.24.0)
- GitHub Check: Serverpod concurrent integration tests (server) (3.32.1)
- GitHub Check: Bootstrap tests (3.32.1, windows-latest, tests/bootstrap_project)
- GitHub Check: Serverpod concurrent integration tests (server) (3.24.0)
- GitHub Check: Bootstrap tests (3.24.0, ubuntu-latest, tests/bootstrap_project)
- GitHub Check: Serverpod E2E IO tests (3.24.0)
- GitHub Check: serverpod generate (3.32.1)
- GitHub Check: Serverpod E2E IO tests (3.32.1)
- GitHub Check: Bootstrap tests (3.24.0, windows-latest, tests/bootstrap_project)
- GitHub Check: Bootstrap tests (3.32.1, ubuntu-latest, tests/bootstrap_project)
- GitHub Check: dart analyze (3.24.0, windows-latest)
- GitHub Check: dart analyze (3.24.0, ubuntu-latest)
🔇 Additional comments (4)
modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/lib/src/business/auth_users.dart (1)
109-118: Transaction correctly forwarded – nice catchForwarding the
transactionargument todeleteWherefixes the previously reported issue.modules/new_serverpod_auth/serverpod_auth_user/serverpod_auth_user_server/test/integration/auth_users_test.dart (3)
5-5: Relative path import may break outside this folder
'./test_tools/serverpod_test_tools.dart'relies on the test runner’s working directory.
Prefer apackage:import (package:serverpod_test_tools/serverpod_test_tools.dart) or a path relative to the package root to avoid IDE / CI resolution issues.
61-66: UUID helper import missing?
Uuidis used but not imported. Ensure either:import 'package:uuid/uuid.dart';or that
serverpodre-exportsUuid.Also applies to: 71-76, 79-84
13-38: Good coverage of core CRUD pathsThe tests validate default values, update semantics, listing and deletion – a solid baseline.
Also applies to: 40-50
Summary by CodeRabbit
New Features
AuthUserModelandAuthUserNotFoundExceptionfor authentication users.Refactor
Tests
Chores
clockandmetadependencies and updated test version constraint.