public async ValueTask <AppSrvResult <bool> > ExistPermissionsAsync(RolePermissionsCheckerDto input) { var codes = await this.GetPermissionsAsync(input); if (codes.IsSuccess && codes.Content.Any()) { return(true); } return(false); }
public async Task <ActionResult <List <string> > > GetCurrenUserPermissions([FromRoute] long id, [FromQuery] string[] permissions) { //throw new System.Exception("测试"); var inputDto = new RolePermissionsCheckerDto() { RoleIds = _userContext.RoleIds , Permissions = permissions }; return(Result(await _roleService.GetPermissionsAsync(inputDto))); }
public async Task <AppSrvResult <List <string> > > GetPermissionsAsync(RolePermissionsCheckerDto input) { var cahceValue = await _cache.GetAsync(EasyCachingConsts.MenuCodesCacheKey, async() => { var allMenus = await _relationRepository.GetAll(writeDb: true) .Where(x => x.Menu.Status == true) .Select(x => new RoleMenuCodesDto { RoleId = x.RoleId, Code = x.Menu.Code }) .ToListAsync(); return(allMenus.Distinct().ToArray()); }, TimeSpan.FromSeconds(EasyCachingConsts.OneYear)); var codes = cahceValue.Value?.Where(x => input.RoleIds.Contains(x.RoleId)).Select(x => x.Code.ToUpper()); if (codes != null && codes.Any()) { var result = codes.Intersect(input.Permissions.Select(x => x.ToUpper())); return(result.ToList()); } return(null); }