public async Task <ResponseMessage <PermissionItem> > GetPermissionItem(string userId, [FromRoute] string id) { ResponseMessage <PermissionItem> response = new ResponseMessage <PermissionItem>(); //if (!await _permissionExpansionManager.HavePermission(userId, "PermissionItemRetrieve")) //{ // response.Code = ResponseCodeDefines.NotAllow; // return response; //} response.Extension = await _permissionItemManager.FindByIdAsync(id, HttpContext.RequestAborted); if (response.Extension == null) { response.Code = ResponseCodeDefines.NotFound; return(response); } return(response); }
private async Task <List <ApplicationPermissionModel> > ConvertToModel(List <RolePermission> permissionList, List <ApplicationPermissionModel> apList, CancellationToken cancellationToken) { //TODO if (permissionList.Count() != 0) { //获取首个权限项的详情 var permission = await _permissionItemManager.FindByIdAsync(permissionList[0].PermissionId, cancellationToken); if (permission != null) { var model = new ApplicationPermissionModel(); model.ApplicationId = permission.ApplicationId; //model.ApplicationName = (await _applicationManager.FindByIdAsync(permission.ApplicationId, cancellationToken)).DisplayName; model.Permissions = new List <PermissionModel>(); //获取该权限项所在应用下的所有权限项 var array = await _permissionItemManager.FindByApplicationAsync(permission.ApplicationId, cancellationToken); for (int i = permissionList.Count - 1; i >= 0; i--) { var r = array.Where(a => a.Id == permissionList[i].PermissionId).FirstOrDefault(); if (r != null) { var permissionOrganizations = await _permissionOrganizationManager.FindByIdAsync(permissionList[i].OrganizationScope, cancellationToken); var pmodel = new PermissionModel() { PermissionId = r.Id, PermissionName = r.Name, Organizations = (from a in permissionOrganizations select new OrganizationScopeModel() { OrganizationId = a.OrganizationId }).ToList() }; model.Permissions.Add(pmodel); permissionList.Remove(permissionList[i]); } } apList.Add(model); await ConvertToModel(permissionList, apList, cancellationToken); } return(apList); } return(new List <ApplicationPermissionModel>()); }