This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-2.2] fix: the issue that role display name (#856)
This is an automated cherry-pick of #847 /assign ruibaby ```release-note 优化 Console 端用户角色标识的显示名称。 ```
- Loading branch information
1 parent
11e0876
commit cb055d3
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 }; | ||
}); |