-
Notifications
You must be signed in to change notification settings - Fork 67
fix: modify login set tenant #286
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
Conversation
WalkthroughDatabase schema updated to make tenant English name nullable, JWT utility enhanced to serialize and deserialize the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. Comment |
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.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
base/src/main/java/com/tinyengine/it/service/platform/impl/TenantServiceImpl.java (1)
116-121: Potential bug: Uniqueness check on nullable column may allow duplicates.The uniqueness check now uses
name_cn, but according to the DDL changes,name_cnis now nullable. This creates two issues:
- If
tenant.getNameCn()isnull, this query won't find existing tenants withnullname_cn (sinceNULL != NULLin SQL).- The unique index on
name_cnwill allow multiple rows withNULLvalues in MySQL.This could allow duplicate tenants to be created when
name_cnis not provided.🔎 Suggested fix: Add null check or use name_en for uniqueness
public Integer createTenant(Tenant tenant) { QueryWrapper<Tenant> queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("name_cn", tenant.getNameCn()); + // Use name_en for uniqueness check since it's NOT NULL + queryWrapper.eq("name_en", tenant.getNameEn()); Tenant tenantResult = this.baseMapper.selectOne(queryWrapper);Or if
name_cnis intentionally the uniqueness constraint, ensure it's not nullable:+ if (tenant.getNameCn() == null || tenant.getNameCn().trim().isEmpty()) { + throw new ServiceException(ExceptionEnum.CM001.getResultCode(), "name_cn is required"); + } QueryWrapper<Tenant> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("name_cn", tenant.getNameCn());app/src/main/resources/sql/mysql/01_create_all_tables_ddl_v1.0.0.mysql.sql (1)
583-591: Schema design concern: Unique index on nullable column.With
name_cnbeing nullable and having a unique index, MySQL will allow multiple rows withNULLvalues forname_cn. This may not align with the intended uniqueness constraint inTenantServiceImpl.createTenant().Consider one of these approaches:
- Keep
name_cnasNOT NULLif it's the primary identifier- Change the unique index to
name_enwhich isNOT NULL- Use a composite unique index that includes a non-nullable column
🧹 Nitpick comments (2)
base/src/main/java/com/tinyengine/it/login/utils/JwtUtil.java (1)
186-186: Consider defensive handling for tokens generated before this change.If a token was generated before this change (without
isInUse),map.get("isInUse")returnsnull, which is safely cast toBoolean. However, you may want to explicitly document this backward compatibility or set a sensible default for older tokens.🔎 Optional: Add explicit default handling
- tenant.setIsInUse((Boolean) map.get("isInUse")); + Object isInUseValue = map.get("isInUse"); + tenant.setIsInUse(isInUseValue != null ? (Boolean) isInUseValue : false);base/src/test/java/com/tinyengine/it/service/app/impl/UserServiceImplTest.java (1)
18-18: Unused imports detected.
MockUserContext(line 18) andArrayList(line 30) are imported but not used in this test file. The test usesArrays.asList()instead ofArrayList, andMockUserContextis not referenced anywhere.🔎 Remove unused imports
import cn.hutool.core.util.ReflectUtil; -import com.tinyengine.it.common.handler.MockUserContext; import com.tinyengine.it.login.service.impl.LoginServiceImpl; import com.tinyengine.it.mapper.UserMapper; import com.tinyengine.it.model.entity.User; -import java.util.ArrayList; import java.util.Arrays; import java.util.List;Also applies to: 30-30
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
app/src/main/resources/sql/mysql/01_create_all_tables_ddl_v1.0.0.mysql.sqlbase/src/main/java/com/tinyengine/it/login/utils/JwtUtil.javabase/src/main/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImpl.javabase/src/main/java/com/tinyengine/it/service/platform/impl/TenantServiceImpl.javabase/src/test/java/com/tinyengine/it/service/app/impl/AppServiceImplTest.javabase/src/test/java/com/tinyengine/it/service/app/impl/UserServiceImplTest.java
🧰 Additional context used
🧬 Code graph analysis (2)
base/src/test/java/com/tinyengine/it/service/app/impl/UserServiceImplTest.java (1)
base/src/test/java/com/tinyengine/it/common/handler/MockUserContext.java (1)
MockUserContext(25-71)
base/src/test/java/com/tinyengine/it/service/app/impl/AppServiceImplTest.java (1)
base/src/test/java/com/tinyengine/it/common/handler/MockUserContext.java (1)
MockUserContext(25-71)
🔇 Additional comments (2)
base/src/main/java/com/tinyengine/it/login/utils/JwtUtil.java (1)
119-119: LGTM! isInUse serialization added consistently.The addition of
isInUseto the JWT token payload is symmetric with the deserialization at line 186. This ensures tenant state is preserved during token round-trips.base/src/main/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImpl.java (1)
284-286: Good addition of null-check error handling.This defensive check prevents a
NullPointerExceptionthat would occur downstream (e.g., at line 287 when accessingapp.getPlatformId()). UsingExceptionEnum.CM009provides consistent error messaging.
app/src/main/resources/sql/mysql/01_create_all_tables_ddl_v1.0.0.mysql.sql
Outdated
Show resolved
Hide resolved
base/src/test/java/com/tinyengine/it/service/app/impl/AppServiceImplTest.java
Outdated
Show resolved
Hide resolved
msslulu
left a comment
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.
ok
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.