Skip to content

Conversation

KiteSoar
Copy link
Collaborator

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

its close #13368 and #13352

Brief changelog

XX

Verifying this change

image

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

Copy link

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

Copy link

lingma-agents bot commented May 19, 2025

修复命名空间删除功能及身份验证错误处理

变更文件

文件路径 变更说明
console-ui/src/globalLib.js 改进身份验证错误处理逻辑,使用正则匹配token失效/用户未知等错误信息
console-ui/​src/​pages/​NameSpace/​NameSpace.js 调整命名空间操作权限,允许类型1的命名空间支持删除和编辑
console/​src/​main/​resources/​static/​index.html 更新CSS/JS静态资源版本哈希值
core/​src/​main/​java/​com/​alibaba/​nacos/​core/​namespace/​model/​NamespaceTypeEnum.java 补充枚举类型维护注意事项注释

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

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

🔍 代码评审报告

🎯 评审意见概览

严重度 数量 说明
🔴 Blocker 0 阻断性问题,需立即修复。例如:系统崩溃、关键功能不可用或严重安全漏洞。
🟠 Critical 1 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 1 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 1 次要问题,酌情优化。例如:代码格式不规范或注释缺失。

总计: 3 个问题


📋 评审意见详情

💡 单文件建议

以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
📜 console-ui/src/globalLib.js (1 💬)
📜 console-ui/src/pages/NameSpace/NameSpace.js (1 💬)
☕ core/src/main/java/com/alibaba/nacos/core/namespace/model/NamespaceTypeEnum.java (1 💬)

🚀 跨文件建议

以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 前后端枚举类型定义未同步可能导致业务逻辑不一致

核心模块的NamespaceTypeEnum.java枚举类型注释更新后(新增注释提示需同步前端),但前端NameSpace.js中对record.type的判断逻辑未同步更新。原Java注释曾明确0/1/2的含义,而前端代码中record.type的判断逻辑存在矛盾:原条件为type为0或1时禁用按钮,现仅保留type为0时禁用。需确认Java枚举实际值是否已变更,若前端未同步枚举定义可能导致业务逻辑错误。

📌 关键代码:

/**
 * Namespace type enum.
 * Note: Changes to this enum may require updates to the frontend code (e.g., Namespace.js).
 */
+ if (record.type === 0) {
- if (record.type === 1 || record.type === 0) {

⚠️ 潜在风险: 若后端枚举值发生变更但前端未同步,可能导致按钮状态与业务规则冲突,例如允许删除系统保留命名空间或错误禁用操作按钮

🔍 2. 静态资源版本号更新不一致存在缓存风险

index.html中同时更新了CSS和JS文件的版本号,但新版本号2e11fbbd25b8e44786b8与旧版本52d7f4f6947bc2e25f20未保持关联性。若不同资源版本号更新不同步,可能导致部分用户加载CSS新版本但JS仍为旧版本,引发样式与脚本逻辑不匹配问题。建议采用统一版本号管理策略

📌 关键代码:

+ <script type="text/javascript" src="./js/main.js?2e11fbbd25b8e44786b8"></script></body>

⚠️ 潜在风险: 版本号不同步可能导致资源加载冲突,影响页面功能或出现样式错乱

🔍 3. 错误重定向逻辑存在潜在误触发风险

globalLib.js中将401/403状态码的重定向条件从固定字符串匹配改为正则表达式,但正则/(token\s*(invalid|expired)|unknown\s*user)/i可能匹配到非预期的错误信息(如包含"token"但非认证失败的场景)。需确保后端返回的错误信息格式稳定,或增加对responseJSON.code的校验以提高匹配准确性

📌 关键代码:

+ /(token\s*(invalid|expired)|unknown\s*user)/i.test(responseJSON.message);

⚠️ 潜在风险: 非预期的错误信息可能触发不必要的登录跳转,导致用户操作中断

🔍 4. 命名空间类型判断存在跨文件逻辑矛盾

NameSpace.js中将类型判断从(type === 0 || 1)改为仅type === 0,但core模块的枚举类型中0为全局配置、1为默认私有命名空间。需确认业务规则是否允许删除默认私有命名空间,若不允许则前端逻辑变更需同步后端权限控制,避免前后端行为不一致

📌 关键代码:

+ if (record.type === 0) {
- if (record.type === 1 || record.type === 0) {

⚠️ 潜在风险: 可能允许删除系统保留的默认命名空间,导致配置管理功能异常


💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Comment on lines +558 to +561
const shouldRedirectToLogin =
[401, 403].includes(status) &&
['unknown user!', 'token invalid!', 'token expired!'].includes(responseJSON.message)
) {
typeof responseJSON.message === 'string' &&
/(token\s*(invalid|expired)|unknown\s*user)/i.test(responseJSON.message);
Copy link

Choose a reason for hiding this comment

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

重定向条件的正则表达式可能允许非预期的错误信息触发登录重定向

🟡 Major | 🐞 Bugs

📋 问题详情

原条件通过精确匹配预定义错误信息数组进行判断,现改为正则匹配可能引入误判风险。正则表达式/(token\s*(invalid|expired)|unknown\s*user)/i可能匹配到非预期的错误信息(如包含部分匹配的其他错误),导致不必要的登录重定向。

💡 解决方案

建议使用精确匹配原预定义错误信息数组:

- /(token\s*(invalid|expired)|unknown\s*user)/i.test(responseJSON.message);
+ ['unknown user!', 'token invalid!', 'token expired!'].includes(responseJSON.message);

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

@@ -242,7 +242,7 @@ class NameSpace extends React.Component {
{namespaceDelete}
</a>
);
if (record.type === 1 || record.type === 0) {
if (record.type === 0) {
Copy link

Choose a reason for hiding this comment

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

修改后的条件逻辑可能导致Type为1的命名空间按钮可操作,与原逻辑不符

🟠 Critical | 🐞 Bugs

📋 问题详情

原条件允许当record.type为0或1时禁用删除和编辑按钮,但修改后仅在type为0时禁用。这可能导致type为1的命名空间按钮被错误启用,与业务逻辑预期不一致。需要确认是否需要保持原条件的逻辑覆盖。

💡 解决方案

恢复原逻辑覆盖type为0和1的情况:

- if (record.type === 0) {
+ if (record.type === 0 || record.type === 1) {

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

Comment on lines +20 to +21
* Namespace type enum.
* Note: Changes to this enum may require updates to the frontend code (e.g., Namespace.js).
Copy link

Choose a reason for hiding this comment

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

注释未完整描述枚举类型含义可能导致前端开发误解

🟢 Minor | 🧹 Code Smells

📋 问题详情

原注释明确说明0/1/2类型含义,现注释被简化但未更新具体描述,可能使前端开发者无法准确理解类型定义,导致前端逻辑实现错误。

💡 解决方案

恢复原类型描述:

- * Namespace type enum.
+ * the enum of namespace. 0 : Global configuration, 1 : Default private namespace ,2 : Custom namespace.

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.40%. Comparing base (29f9562) to head (32f4aef).

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             develop   #13389      +/-   ##
=============================================
+ Coverage      70.39%   70.40%   +0.01%     
- Complexity     11715    11716       +1     
=============================================
  Files           1592     1592              
  Lines          50977    50977              
  Branches        5148     5148              
=============================================
+ Hits           35884    35892       +8     
+ Misses         12661    12654       -7     
+ Partials        2432     2431       -1     
Files with missing lines Coverage Δ
.../nacos/core/namespace/model/NamespaceTypeEnum.java 52.94% <ø> (ø)

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29f9562...32f4aef. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wuyfee
Copy link

wuyfee commented May 19, 2025

$\color{red}{FAILURE}$
DETAILS
✅ - docker: success
❌ - deploy (standalone & cluster & standalone_auth): failure
❌ - e2e-java-test (standalone & cluster & standalone_auth): skipped
❌ - e2e-go-test (standalone & cluster): skipped
❌ - e2e-cpp-test (standalone & cluster): skipped
❌ - e2e-csharp-test (standalone & cluster): skipped
❌ - e2e-nodejs-test (standalone & cluster): skipped
❌ - e2e-python-test (standalone & cluster): skipped
✅ - clean (standalone & cluster & standalone_auth): success

@KomachiSion KomachiSion merged commit bc79756 into alibaba:develop May 20, 2025
5 checks passed
@KomachiSion KomachiSion added the area/Nacos console Related to Nacos consle label May 20, 2025
@KomachiSion KomachiSion added this to the 3.0.1 milestone May 20, 2025
@KomachiSion KomachiSion added the kind/bug Category issues or prs related to bug. label May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Nacos console Related to Nacos consle kind/bug Category issues or prs related to bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nacos3.0无法删除namespace
4 participants