Exemplo n.º 1
0
        public void ThrowWhenAssigningDuplicateRoles()
        {
            var authUser      = AuthUserTestHelper.User().WithRoles(RegisteredRole).Build();
            var duplicateRole = RegisteredRole;

            Action assigning = () => _userRoleService.AssignRole(authUser, duplicateRole);

            assigning.Should().Throw <ManualValidationException>();
        }
Exemplo n.º 2
0
        public void AssignRole(UserId responsibleUserId, RoleId roleId, Username username)
        {
            _unitOfWork.WithAuthUserTransaction(tran => {
                var role     = FindRole(roleId);
                var authUser = _authUserRepository.FindOrNull(new UsernameSpecification(username));
                if (authUser is null)
                {
                    throw new ManualValidationException("User not found");
                }

                _userRoleDomainService.AssignRole(authUser, role);
                _authUserRepository.Save(authUser);

                _unitOfWork.Raise(UserGainedRole.Factory(role, authUser, responsibleUserId));

                tran.Commit();
            });
        }
        public void Register(AuthUser authUser, Role registeredUserRole, Role pendingRegistrationRole)
        {
            if (registeredUserRole.Rolename != Role.REGISTERED_USER_ROLENAME)
            {
                throw new ArgumentException("You're supposed to pass the registered user role.",
                                            nameof(registeredUserRole));
            }
            if (pendingRegistrationRole.Rolename != Role.PENDING_REGISTRATION_ROLENAME)
            {
                throw new ArgumentException("You're supposed to pass the pending registration role.",
                                            nameof(pendingRegistrationRole));
            }

            if (!authUser.RoleIds.Contains(pendingRegistrationRole.Id))
            {
                throw new ManualValidationException("This user doesn't have the pending registration role.");
            }

            _userRoleService.RemoveRole(authUser, pendingRegistrationRole);
            _userRoleService.AssignRole(authUser, registeredUserRole);
        }