Пример #1
0
        public async Task <bool> IsAllowedAsync(
            ClaimsPrincipal principal,
            string module,
            string type,
            string action)
        {
            if (await IsAllowedForEveryoneAsync(
                    module,
                    type,
                    action))
            {
                return(true);
            }

            if (principal == null)
            {
                return(false);
            }

            var user = await _userManager.GetUserAsync(principal);

            if (user == null)
            {
                return(false);
            }

            if (await IsAllowedForRegisteredUsersAsync(
                    module,
                    type,
                    action))
            {
                return(true);
            }

            var roles = await _userManager.GetRolesAsync(user);

            foreach (var role in roles)
            {
                var allowed = await _settingService.AllowedAsync(module, type, action, role);

                if (allowed)
                {
                    return(true);
                }
            }

            return(false);
        }