Skip to content

Conversation

@lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented Nov 28, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Release Notes

  • Refactor

    • Reorganized internal package structure for improved code organization
    • Optimized regex pattern caching to reduce compilation overhead
  • Chores

    • Removed unused imports and references
    • Applied consistent code formatting standards throughout the codebase

✏️ Tip: You can customize this high-level summary in your review settings.

zhangjuncao and others added 30 commits November 12, 2024 00:12
feat: create component by bundle.json
fix:format code and fix style issue
@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

Walkthrough

This pull request performs a package reorganization from Utils to utils naming convention across login-related utilities, removes unused imports, applies formatting adjustments, renames a ThreadLocal field to constant naming, and optimizes regex pattern compilation with precompiled constants.

Changes

Cohort / File(s) Summary
Package restructuring (Utils → utils)
base/src/main/java/com/tinyengine/it/login/config/SSOInterceptor.java, base/src/main/java/com/tinyengine/it/login/controller/LoginController.java, base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java, base/src/main/java/com/tinyengine/it/login/utils/{JwtUtil, SM2EncryptionUtil, SM3PasswordUtil}.java
Updated import paths and package declarations from capitalized com.tinyengine.it.login.Utils to lowercase com.tinyengine.it.login.utils; moved JwtUtil, SM2EncryptionUtil, SM3PasswordUtil files to new package location.
ThreadLocal field refactoring
base/src/main/java/com/tinyengine/it/login/config/context/DefaultLoginUserContext.java
Renamed private static ThreadLocal from currentUser to CURRENT_USER (constant naming convention); updated all accessor methods (getTenants, getLoginUserId, getPlatformId, setTenants, setCurrentUser, getCurrentUser, clear) to reference the renamed field.
Password validation optimization
base/src/main/java/com/tinyengine/it/login/service/ConfigurablePasswordValidator.java
Introduced precompiled regex pattern constants (LOWERCASE_PATTERN, UPPERCASE_PATTERN, DIGIT_PATTERN, CONSECUTIVE_CHARS_PATTERN) to replace inline Pattern.compile calls; added Locale.ROOT usage in formatted error messages.
Import cleanup
base/src/main/java/com/tinyengine/it/controller/AppTemplateController.java, base/src/main/java/com/tinyengine/it/mapper/AuthUsersUnitsRolesMapper.java, base/src/main/java/com/tinyengine/it/service/app/AppTemplateService.java
Removed unused imports (List, Resource); no functional impact.
Formatting adjustments
base/src/main/java/com/tinyengine/it/controller/TenantController.java, base/src/main/java/com/tinyengine/it/login/model/UserInfo.java, base/src/main/java/com/tinyengine/it/service/app/impl/{AppServiceImpl, AppTemplateServiceImpl}.java, base/src/main/java/com/tinyengine/it/service/platform/impl/TenantServiceImpl.java
Minor whitespace and indentation adjustments; added spacing after control flow keywords (if); reformatted method braces and argument lists.
Miscellaneous
base/src/main/java/com/tinyengine/it/login/utils/JwtUtil.java
Updated EXPIRATION_TIME constant to use explicit long literal suffix (21600000L).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Areas requiring attention:

  • Verify all package import references have been updated consistently across the codebase (particularly the Utils → utils migration in LoginController and related files)
  • Confirm the ThreadLocal renaming in DefaultLoginUserContext doesn't conflict with any other references or subclasses
  • Validate precompiled regex patterns in ConfigurablePasswordValidator are thread-safe and correctly initialized

Poem

🐰 Package names now lowercase, tidy and clean,
ThreadLocal renamed to constants supreme,
Patterns precompiled for speed and grace,
Imports swept out—less clutter in place!
Refactored with care, the code stands so neat!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.16% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Fix/Modify code format' is vague and generic, using non-descriptive terms that don't convey meaningful information about the specific changes made. Consider a more specific title that describes the primary change, such as 'Refactor package structure and standardize code formatting' or 'Reorganize login utilities package and clean up formatting'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
base/src/main/java/com/tinyengine/it/login/controller/LoginController.java (1)

146-149: Missing return on empty user list causes runtime error

In login, when users is empty you call Result.failed(ExceptionEnum.CM004); but do not return, and then immediately do users.get(0), which will throw IndexOutOfBoundsException.

Recommend returning the failure result:

-        if (users.isEmpty()) {
-            Result.failed(ExceptionEnum.CM004);
-        }
+        if (users.isEmpty()) {
+            return Result.failed(ExceptionEnum.CM004);
+        }
🧹 Nitpick comments (3)
base/src/main/java/com/tinyengine/it/login/utils/JwtUtil.java (1)

45-52: Avoid hard-coded default JWT secret in production

getSecretString() falls back to a hard-coded DEFAULT_SECRET when SECRET_STRING is unset. If this ever runs in production without the env var, all tokens share a well-known key.

Consider failing fast (e.g., throw on missing env in non-dev profiles) or at least logging a clear warning and requiring a strong, externalized secret.

base/src/main/java/com/tinyengine/it/login/controller/LoginController.java (1)

187-191: Confirm success vs failure contract for invalid new password

In forgotPassword, when the new password fails policy validation you return Result.success(passwordValidationResult), whereas in createUser you return Result.failed(...) on validation failure. The inconsistency may be intentional (front-end expects a successful response with details) but it’s worth double-checking.

base/src/main/java/com/tinyengine/it/login/config/context/DefaultLoginUserContext.java (1)

44-48: Defensively handle null CURRENT_USER in setTenants

setTenants does UserInfo userInfo = CURRENT_USER.get(); userInfo.setTenants(tenants); without a null check. If setTenants is ever called before setCurrentUser, this will NPE.

Consider guarding against null (or explicitly failing fast), for example:

     @Override
     public void setTenants(List<Tenant> tenants) {
-        UserInfo userInfo = CURRENT_USER.get();
-        userInfo.setTenants(tenants);
-        CURRENT_USER.set(userInfo);
+        UserInfo userInfo = CURRENT_USER.get();
+        if (userInfo == null) {
+            // Either no-op or throw an IllegalStateException, depending on desired contract
+            return;
+        }
+        userInfo.setTenants(tenants);
+        CURRENT_USER.set(userInfo);
     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6ea0de and 7ce579f.

📒 Files selected for processing (16)
  • base/src/main/java/com/tinyengine/it/controller/AppTemplateController.java (0 hunks)
  • base/src/main/java/com/tinyengine/it/controller/TenantController.java (2 hunks)
  • base/src/main/java/com/tinyengine/it/login/config/SSOInterceptor.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/login/config/context/DefaultLoginUserContext.java (2 hunks)
  • base/src/main/java/com/tinyengine/it/login/controller/LoginController.java (5 hunks)
  • base/src/main/java/com/tinyengine/it/login/model/UserInfo.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/login/service/ConfigurablePasswordValidator.java (4 hunks)
  • base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/login/utils/JwtUtil.java (2 hunks)
  • base/src/main/java/com/tinyengine/it/login/utils/SM2EncryptionUtil.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/login/utils/SM3PasswordUtil.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/mapper/AuthUsersUnitsRolesMapper.java (0 hunks)
  • base/src/main/java/com/tinyengine/it/service/app/AppTemplateService.java (0 hunks)
  • base/src/main/java/com/tinyengine/it/service/app/impl/AppServiceImpl.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/app/impl/AppTemplateServiceImpl.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/platform/impl/TenantServiceImpl.java (1 hunks)
💤 Files with no reviewable changes (3)
  • base/src/main/java/com/tinyengine/it/service/app/AppTemplateService.java
  • base/src/main/java/com/tinyengine/it/controller/AppTemplateController.java
  • base/src/main/java/com/tinyengine/it/mapper/AuthUsersUnitsRolesMapper.java
🧰 Additional context used
🧬 Code graph analysis (1)
base/src/main/java/com/tinyengine/it/login/controller/LoginController.java (2)
base/src/main/java/com/tinyengine/it/login/utils/SM3PasswordUtil.java (1)
  • SM3PasswordUtil (25-79)
base/src/main/java/com/tinyengine/it/login/utils/SM2EncryptionUtil.java (1)
  • SM2EncryptionUtil (33-129)
🔇 Additional comments (20)
base/src/main/java/com/tinyengine/it/service/app/impl/AppTemplateServiceImpl.java (1)

115-116: Whitespace-only change — behavior preserved

The queryAllAppTemplate call keeps the same arguments and pagination logic; this is a pure formatting tweak and is safe.

base/src/main/java/com/tinyengine/it/service/platform/impl/TenantServiceImpl.java (1)

113-121: Consistent spacing in if condition

The updated if (result == 1) improves readability without changing the createTenant logic.

base/src/main/java/com/tinyengine/it/service/app/impl/AppServiceImpl.java (1)

107-108: Formatting-only change to paged query

The queryAllAppByPage invocation keeps the same parameters and pagination behavior; change is purely stylistic.

base/src/main/java/com/tinyengine/it/login/utils/SM3PasswordUtil.java (1)

13-13: Package path normalization for SM3 utility

Moving SM3PasswordUtil to com.tinyengine.it.login.utils aligns it with the other login utilities without changing behavior. Just ensure all callers now import from the new login.utils package.

base/src/main/java/com/tinyengine/it/login/utils/SM2EncryptionUtil.java (1)

13-13: SM2 utility moved under login.utils package

The package rename to com.tinyengine.it.login.utils simply reorganizes the namespace; all public methods and behavior remain the same.

base/src/main/java/com/tinyengine/it/controller/TenantController.java (3)

43-48: Swagger annotation formatting only

The reflow of @Operation/@ApiResponse content keeps the same schema and response codes, just formatted more cleanly.


51-54: Added blank line for readability

The extra blank line inside getAllTenant is purely cosmetic and does not affect behavior.


62-70: Re-indented createTenant OpenAPI metadata

Parameter and response definitions are unchanged; only indentation and line breaks were adjusted.

base/src/main/java/com/tinyengine/it/login/config/SSOInterceptor.java (1)

15-15: Updated JwtUtil import to new utils package

Switching to com.tinyengine.it.login.utils.JwtUtil matches the package reorganization and keeps SSO validation behavior identical.

base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java (2)

33-37: Static imports updated to login.utils.SM2EncryptionUtil

The static imports now reference the new package while keeping the same SM2 helper methods; downstream encryption logic is unaffected.


42-44: Minor formatting after autowired mapper

The blank line after AuthUsersUnitsRolesMapper improves readability and has no functional effect.

base/src/main/java/com/tinyengine/it/login/utils/JwtUtil.java (1)

13-13: Package rename and explicit long literal are correct

The package move to com.tinyengine.it.login.utils and the EXPIRATION_TIME change to a long literal are consistent with the rest of the PR and behaviorally equivalent.

Also applies to: 45-45

base/src/main/java/com/tinyengine/it/login/model/UserInfo.java (1)

39-66: Accessor reformatting is behavior-preserving

Getters and setters still directly map to the underlying fields; only brace/line formatting changed. No behavioral impact.

base/src/main/java/com/tinyengine/it/login/controller/LoginController.java (2)

19-20: Updated utility imports to .utils look consistent

Imports and static imports now point to com.tinyengine.it.login.utils.*, aligning with the package reorganization (JwtUtil, SM2EncryptionUtil, SM3PasswordUtil). This is consistent with the utils move.

Also applies to: 59-61


115-115: Whitespace-only changes around validations

The added spaces in the if conditions and authenticate call sites are purely cosmetic and do not affect behavior.

Also applies to: 153-153

base/src/main/java/com/tinyengine/it/login/config/context/DefaultLoginUserContext.java (1)

16-16: ThreadLocal rename to CURRENT_USER is consistent

Renaming the ThreadLocal to an uppercase constant and updating all getters/setters/clear methods is applied consistently and keeps behavior the same.

Also applies to: 22-22, 28-28, 34-35, 45-48, 55-56, 63-64, 71-72

base/src/main/java/com/tinyengine/it/login/service/ConfigurablePasswordValidator.java (4)

32-36: Excellent performance optimization with precompiled patterns.

The introduction of precompiled regex patterns as static final constants is a solid optimization that avoids repeated pattern compilation on each validation call. Pattern objects are thread-safe and immutable, making this approach safe for concurrent use. The naming follows Java conventions, and the comment clearly documents the intent.


50-50: Good practice using Locale.ROOT for consistent formatting.

Using Locale.ROOT ensures locale-insensitive number formatting in error messages, which provides consistent and predictable output regardless of the system's default locale.

Also applies to: 55-55


58-75: LGTM! Character type checks correctly use precompiled patterns.

The validation logic now efficiently uses the precompiled pattern constants, maintaining the same behavior while improving performance. The updated comment clearly documents this optimization.


86-91: LGTM! Consecutive character check correctly uses precompiled pattern.

The validation logic now efficiently uses the precompiled CONSECUTIVE_CHARS_PATTERN constant, maintaining the same behavior while improving performance.

@hexqi hexqi merged commit e1e25eb into opentiny:develop Nov 28, 2025
1 check passed
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.

9 participants