Public Access
feat(account): send display name in account state to Core
The account state push carries displayName. It is published when the name changes. Contract test updated.
This commit is contained in:
1 parent
1b7bafd9f0
commit
6e7fb1e066
10 files changed
+38
-18
No files matched your search
@@ -3,5 +3,5 @@ package auth_service.modules.account.model;
|
||||
/**
|
||||
* One user as Core copies it.
|
||||
*/
|
||||
public record CoreAccountState(long userId, Long steamId, boolean blocked) {
|
||||
public record CoreAccountState(long userId, Long steamId, String displayName, boolean blocked) {
|
||||
}
|
||||
@@ -60,17 +60,18 @@ public class AccountRepository {
|
||||
}
|
||||
|
||||
private static final RowMapper<CoreAccountState> STATE_ROW = (rs, row) ->
|
||||
new CoreAccountState(rs.getLong("id"), rs.getObject("steam_id", Long.class), !rs.getBoolean("enabled"));
|
||||
new CoreAccountState(rs.getLong("id"), rs.getObject("steam_id", Long.class), rs.getString("display_name"),
|
||||
!rs.getBoolean("enabled"));
|
||||
|
||||
public Optional<CoreAccountState> findState(long userId) {
|
||||
return jdbc.query("SELECT id, steam_id, enabled FROM users WHERE id = ?", STATE_ROW, userId).stream().findFirst();
|
||||
return jdbc.query("SELECT id, steam_id, display_name, enabled FROM users WHERE id = ?", STATE_ROW, userId).stream().findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Every user, also the flagged ones.
|
||||
*/
|
||||
public List<CoreAccountState> findAllStates() {
|
||||
return jdbc.query("SELECT id, steam_id, enabled FROM users ORDER BY id", STATE_ROW);
|
||||
return jdbc.query("SELECT id, steam_id, display_name, enabled FROM users ORDER BY id", STATE_ROW);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,12 +51,17 @@ public class UserService {
|
||||
if (displayName != null && userRepository.isDisplayNameUsedByOtherUser(userId, displayName)) {
|
||||
throw new DisplayNameAlreadyInUseException("The display name is already in use.");
|
||||
}
|
||||
boolean renamed = displayName != null && userRepository.findById(userId)
|
||||
.map(user -> !displayName.equals(user.getDisplayName())).orElse(true);
|
||||
userRepository.update(userId, user -> {
|
||||
user.setDisplayName(displayName);
|
||||
user.getSettings().setLanguage(userSettings.getLanguage());
|
||||
user.getSettings().setTheme(userSettings.getTheme());
|
||||
user.getSettings().setPublicProfile(userSettings.isPublicProfile());
|
||||
});
|
||||
if (renamed) {
|
||||
accountStatePublisher.publish(userId);
|
||||
}
|
||||
log.info("User settings updated for user {}", userId);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,12 @@ class AccountRepositoryTest extends AbstractPersistenceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void findStates_CarryTheSteamIdAndTheBlock() {
|
||||
jdbc.update("update users set enabled = false, steam_id = 76561198000000001 where id = ?", alice);
|
||||
void findStates_CarryTheSteamIdTheDisplayNameAndTheBlock() {
|
||||
jdbc.update("update users set enabled = false, steam_id = 76561198000000001, display_name = 'Alice' where id = ?", alice);
|
||||
|
||||
assertThat(repository.findState(alice)).contains(new CoreAccountState(alice, 76561198000000001L, true));
|
||||
assertThat(repository.findAllStates()).containsExactly(new CoreAccountState(alice, 76561198000000001L, true),
|
||||
new CoreAccountState(bob, null, false));
|
||||
assertThat(repository.findState(alice)).contains(new CoreAccountState(alice, 76561198000000001L, "Alice", true));
|
||||
assertThat(repository.findAllStates()).containsExactly(new CoreAccountState(alice, 76561198000000001L, "Alice", true),
|
||||
new CoreAccountState(bob, null, null, false));
|
||||
assertThat(repository.findState(-1L)).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
class AccountCleanupServiceTest extends AbstractUnitTest {
|
||||
|
||||
private static final List<CoreAccountState> STATES = List.of(new CoreAccountState(1L, 76561198000000001L, true));
|
||||
private static final List<CoreAccountState> STATES = List.of(new CoreAccountState(1L, 76561198000000001L, "lobo", true));
|
||||
|
||||
private static final Duration RETENTION = Duration.ofDays(30);
|
||||
|
||||
|
||||
@@ -71,8 +71,8 @@ class CoreAccountServiceTest extends AbstractUnitTest {
|
||||
expect("applyStates");
|
||||
expect("replaceStates");
|
||||
|
||||
service.applyStates(List.of(new CoreAccountState(42L, 76561198000000001L, true)));
|
||||
service.replaceStates(List.of(new CoreAccountState(42L, null, false)));
|
||||
service.applyStates(List.of(new CoreAccountState(42L, 76561198000000001L, "lobo", true)));
|
||||
service.replaceStates(List.of(new CoreAccountState(42L, null, "lobo", false)));
|
||||
|
||||
core.verify();
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
class CoreAccountStatePublisherTest extends AbstractUnitTest {
|
||||
|
||||
private static final CoreAccountState STATE = new CoreAccountState(7L, 76561198000000001L, true);
|
||||
private static final CoreAccountState STATE = new CoreAccountState(7L, 76561198000000001L, "lobo", true);
|
||||
|
||||
@Mock
|
||||
private AccountRepository accountRepository;
|
||||
|
||||
@@ -93,6 +93,7 @@ class UserServiceTest extends AbstractUnitTest {
|
||||
verify(userRepository, never()).clearSteamId(anyLong());
|
||||
verify(userRepository, never()).setVerifiedSteamId(anyLong(), anyLong());
|
||||
verifyNoInteractions(tokenGenerator);
|
||||
verifyNoInteractions(accountStatePublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,6 +121,18 @@ class UserServiceTest extends AbstractUnitTest {
|
||||
User changed = appliedChanges(1).getFirst();
|
||||
assertEquals("Lobo", changed.getDisplayName());
|
||||
assertEquals("en", changed.getSettings().getLanguage());
|
||||
verify(accountStatePublisher).publish(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserSettings_UnchangedDisplayName_PublishesNothing() {
|
||||
var userSettings = UserSettings.builder().language("en").build();
|
||||
when(userRepository.findById(1L)).thenReturn(Optional.of(User.builder().id(1L).displayName("Lobo").build()));
|
||||
|
||||
userService.updateUserSettings(1L, "Lobo", userSettings);
|
||||
|
||||
appliedChanges(1);
|
||||
verifyNoInteractions(accountStatePublisher);
|
||||
}
|
||||
|
||||
private static final long STEAM_ID = 76561198000000001L;
|
||||
@@ -186,6 +199,7 @@ class UserServiceTest extends AbstractUnitTest {
|
||||
|
||||
assertEquals(appearance, appliedChanges(1).getFirst().getSettings().getAppearance());
|
||||
verifyNoInteractions(tokenGenerator);
|
||||
verifyNoInteractions(accountStatePublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -37,12 +37,12 @@
|
||||
"applyStates": {
|
||||
"method": "POST",
|
||||
"path": "/internal/accounts/states",
|
||||
"request": {"accounts": [{"userId": 42, "steamId": 76561198000000001, "blocked": true}]}
|
||||
"request": {"accounts": [{"userId": 42, "steamId": 76561198000000001, "displayName": "lobo", "blocked": true}]}
|
||||
},
|
||||
"replaceStates": {
|
||||
"method": "PUT",
|
||||
"path": "/internal/accounts/states",
|
||||
"request": {"accounts": [{"userId": 42, "steamId": null, "blocked": false}]}
|
||||
"request": {"accounts": [{"userId": 42, "steamId": null, "displayName": "lobo", "blocked": false}]}
|
||||
},
|
||||
"purge": {
|
||||
"method": "POST",
|
||||
|
||||
Reference in new issue
Block a user