public void ThrowWhenRemovingNonAssignedRole() { var authUser = AuthUserTestHelper.User().WithRoles(RegisteredRole).Build(); var nonAssignedRole = AdminRole; Action removing = () => _userRoleService.RemoveRole(authUser, nonAssignedRole); removing.Should().Throw <ManualValidationException>(); }
public void RemoveRole(UserId responsibleUserId, RoleId roleId, UserId userId) { _unitOfWork.WithAuthUserTransaction(tran => { var role = FindRole(roleId); var authUser = _authUserRepository.FindByIdOrNull(userId); if (authUser is null) { throw new ManualValidationException("User not found"); } _userRoleDomainService.RemoveRole(authUser, role); _authUserRepository.Save(authUser); _unitOfWork.Raise(UserLostRole.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); }