AccountHelper
AccountHelper 提供账户管理相关的能力,包括身份(Profile)和角色(Role)的分配与管理,以及人员信息的查询。
概述
在 Chameleon 平台中,一个用户可以拥有多个身份(如"部门经理"、"项目经理")和多个角色(如"管理员"、"普通员工")。AccountHelper 提供了对这些关系的完整 CRUD 操作。
API 方法
当前用户属性
// 当前登录人的组织编码(未登录则使用默认组织)
string CurrentUserOrganization { get; }
// 当前登录人的身份列表(一个人可有多个身份)
string[] CurrentUserProfiles { get; }
// 是否正式人员
bool IsFormalUser { get; }
使用示例:
// 获取当前用户的组织
var org = sdk.AccountHelper.CurrentUserOrganization;
// 获取当前用户的所有身份
var profiles = sdk.AccountHelper.CurrentUserProfiles;
// 判断是否正式人员
if (sdk.AccountHelper.IsFormalUser)
{
// 正式人员的业务逻辑...
}
身份管理
AssignProfileAsync — 分配身份
为指定人员分配身份。
Task AssignProfileAsync(AssignProfileRequest request);
示例:
await sdk.AccountHelper.AssignProfileAsync(new AssignProfileRequest
{
ProfileId = "manager-profile-id",
UserIds = new[] { "user-001", "user-002" }
});
RemoveProfileAsync — 移除身份
移除指定人员的身份。
Task RemoveProfileAsync(AssignProfileRequest request);
示例:
await sdk.AccountHelper.RemoveProfileAsync(new AssignProfileRequest
{
ProfileId = "manager-profile-id",
UserIds = new[] { "user-001" }
});
角色管理
AssignRoleAsync — 分配角色
为指定人员分配角色。
Task AssignRoleAsync(AssignRoleRequest request);
示例:
await sdk.AccountHelper.AssignRoleAsync(new AssignRoleRequest
{
RoleId = "admin-role-id",
UserIds = new[] { "user-001" }
});
RemoveRoleAsync — 移除角色
移除指定人员的角色。
Task RemoveRoleAsync(AssignRoleRequest request);
人员查询
GetUserIdsByProfileIdsAsync — 根据身份查人员
根据身份 ID 集合获取对应的人员信息 ID 集合。
Task<string[]> GetUserIdsByProfileIdsAsync(GetUserIdsByProfileIdsRequest request);
示例:
// 查找具有"经理"身份的所有人员
var userIds = await sdk.AccountHelper.GetUserIdsByProfileIdsAsync(
new GetUserIdsByProfileIdsRequest
{
ProfileIds = new[] { "manager-profile-id", "director-profile-id" }
}
);
GetUserIdsByRoleIdsAsync — 根据角色查人员
根据角色 ID 集合获取对应的人员信息 ID 集合。
Task<string[]> GetUserIdsByRoleIdsAsync(GetUserIdsByRoleIdsRequest request);