Esempio n. 1
0
        public async ValueTask <AppSrvResult <bool> > ExistPermissionsAsync(RolePermissionsCheckerDto input)
        {
            var codes = await this.GetPermissionsAsync(input);

            if (codes.IsSuccess && codes.Content.Any())
            {
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        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)));
        }
Esempio n. 3
0
        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);
        }