Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve role dependency-related functions and i18n (#5227)
#### What type of PR is this? /area console /area core /milestone 2.12.x #### What this PR does / why we need it: 优化角色模板依赖的相关功能: 1. 修复勾选某个角色模板之后,其下依赖模板没有选中的问题。 2. 修复编辑角色时,模板其下依赖模板没有选中的问题。 3. 修复角色管理列表中,权限数量显示有误的问题。 4. 移除 **允许管理所有文章** 的角色模板,此角色模板与文章管理重复。 5. 优化 i18n。 #### Which issue(s) this PR fixes: Fixes #5222 #### Special notes for your reviewer: 需要测试上诉问题是否还存在。 #### Does this PR introduce a user-facing change? ```release-note 优化角色模板依赖的相关功能,优化文章相关角色的翻译。 ```
- Loading branch information
Showing
9 changed files
with
147 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { rbacAnnotations } from "@/constants/annotations"; | ||
import type { Role } from "@halo-dev/api-client"; | ||
|
||
export function resolveDeepDependencies( | ||
role: Role, | ||
roleTemplates: Role[] | ||
): string[] { | ||
if (!role) { | ||
return []; | ||
} | ||
|
||
const result: string[] = []; | ||
|
||
const dependencies: string[] = JSON.parse( | ||
role.metadata.annotations?.[rbacAnnotations.DEPENDENCIES] || "[]" | ||
); | ||
|
||
dependencies.forEach((depName) => { | ||
result.push(depName); | ||
const dep = roleTemplates.find((item) => item.metadata.name === depName); | ||
|
||
if (!dep) { | ||
return; | ||
} | ||
|
||
resolveDeepDependencies(dep, roleTemplates).forEach((nextDep) => | ||
result.push(nextDep) | ||
); | ||
}); | ||
|
||
return result; | ||
} |