forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: the issue that role display name (halo-dev/console#847)
#### What type of PR is this? /kind improvement #### What this PR does / why we need it: 为系统初始化的角色添加显示名称 #### Which issue(s) this PR fixes: Fixes halo-dev#3257 #### Screenshots: <img width="1668" alt="image" src="https://user-images.githubusercontent.com/21301288/218020794-696420c4-69bb-4422-9409-482bb2aff708.png"> #### Special notes for your reviewer: 测试方式: 1. Halo 需要切换到:halo-dev#3280 2. 检查 Console 端显示的系统角色是否正常。 3. 新建若干自定义角色,检查名称是否正常。 #### Does this PR introduce a user-facing change? ```release-note 优化 Console 端用户角色标识的显示名称。 ```
- Loading branch information
Showing
6 changed files
with
63 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
import { defineStore } from "pinia"; | ||
import type { Role, UserPermission } from "@halo-dev/api-client"; | ||
import { ref } from "vue"; | ||
import { apiClient } from "@/utils/api-client"; | ||
import { roleLabels } from "@/constants/labels"; | ||
import { rbacAnnotations } from "@/constants/annotations"; | ||
|
||
interface RoleStoreState { | ||
roles: Role[]; // all roles | ||
permissions: UserPermission; // current user's permissions | ||
} | ||
|
||
export const useRoleStore = defineStore({ | ||
id: "role", | ||
state: (): RoleStoreState => ({ | ||
export const useRoleStore = defineStore("role", () => { | ||
const roles = ref<Role[]>([]); | ||
const permissions = ref<UserPermission>({ | ||
roles: [], | ||
permissions: { | ||
roles: [], | ||
uiPermissions: [], | ||
}, | ||
}), | ||
uiPermissions: [], | ||
}); | ||
|
||
async function fetchRoles() { | ||
try { | ||
const { data } = await apiClient.extension.role.listv1alpha1Role({ | ||
page: 0, | ||
size: 0, | ||
labelSelector: [`!${roleLabels.TEMPLATE}`], | ||
}); | ||
roles.value = data.items; | ||
} catch (error) { | ||
console.error("Failed to fetch roles", error); | ||
} | ||
} | ||
|
||
function getRoleDisplayName(name: string) { | ||
const role = roles.value.find((role) => role.metadata.name === name); | ||
return role?.metadata.annotations?.[rbacAnnotations.DISPLAY_NAME] || name; | ||
} | ||
|
||
return { roles, permissions, fetchRoles, getRoleDisplayName }; | ||
}); |