public void GivenRoleStorageReturnsError()
        {
            var currentUser = CreateAUser();

            currentUser.AssignRole(new RoleId("test role"));
            SetCurrentUser(currentUser);

            _rolesStore.Get(Arg.Any <RoleId>()).Returns(Error.InternalError("random test error"));
        }
Exemple #2
0
        public async Task <bool> CheckAccess(Permission permission)
        {
            var user = _currentUserManager.Context.User;

            if (!user.HasRole)
            {
                return(false);
            }

            var role = await _rolesStore.Get(user.Role);

            if (!role.IsSuccessful)
            {
                Log.Warning("Cannot authorize user because RolesStore returned an {Error}", role.Error);
                return(false);
            }

            return(role.Value.HasPermission(permission));
        }
        public async Task <bool> CheckAccess(Permission permission)
        {
            var user = _currentUserManager.Context.User;

            if (!user.HasRole)
            {
                return(false);
            }

            var roleRes = GetSystemRole(user.Role)
                          .ToEither(Error.NotFound())
                          .MapLeft(_ => _rolesStore.Get(user.Role))
                          .Match(EitherAsync <Error, Role> .Right, l => l);

            return((await roleRes.ToEither())
                   .Match(
                       role => role.HasPermission(permission),
                       e =>
            {
                Log.Warning("Cannot authorize user because RolesStore returned an {Error}", e);
                return false;
            }));
        }
 public void MockRoleStoreError()
 {
     _rolesStore.Get(Arg.Any <RoleId>()).Returns(Error.InternalError("random test error"));
 }