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
@@ -350,9 +350,9 @@ nor a database connection waits for Core; a failed call only warns.
|
|||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
participant A as Auth
|
participant A as Auth
|
||||||
participant C as Core
|
participant C as Core
|
||||||
A->>A: link / unlink / block / unblock (commit)
|
A->>A: link / unlink / block / unblock / name change (commit)
|
||||||
A->>C: POST /internal/accounts/states {userId, steamId, blocked}
|
A->>C: POST /internal/accounts/states {userId, steamId, displayName, blocked}
|
||||||
C->>C: blocked_user, Steam ID in user_steam_sync
|
C->>C: blocked_user, Steam ID in user_steam_sync, display name in account_name
|
||||||
Note over A,C: nightly 04:15
|
Note over A,C: nightly 04:15
|
||||||
A->>C: PUT /internal/accounts/states (every user)
|
A->>C: PUT /internal/accounts/states (every user)
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ package auth_service.modules.account.model;
|
|||||||
/**
|
/**
|
||||||
* One user as Core copies it.
|
* 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) ->
|
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) {
|
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.
|
* Every user, also the flagged ones.
|
||||||
*/
|
*/
|
||||||
public List<CoreAccountState> findAllStates() {
|
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)) {
|
if (displayName != null && userRepository.isDisplayNameUsedByOtherUser(userId, displayName)) {
|
||||||
throw new DisplayNameAlreadyInUseException("The display name is already in use.");
|
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 -> {
|
userRepository.update(userId, user -> {
|
||||||
user.setDisplayName(displayName);
|
user.setDisplayName(displayName);
|
||||||
user.getSettings().setLanguage(userSettings.getLanguage());
|
user.getSettings().setLanguage(userSettings.getLanguage());
|
||||||
user.getSettings().setTheme(userSettings.getTheme());
|
user.getSettings().setTheme(userSettings.getTheme());
|
||||||
user.getSettings().setPublicProfile(userSettings.isPublicProfile());
|
user.getSettings().setPublicProfile(userSettings.isPublicProfile());
|
||||||
});
|
});
|
||||||
|
if (renamed) {
|
||||||
|
accountStatePublisher.publish(userId);
|
||||||
|
}
|
||||||
log.info("User settings updated for user {}", userId);
|
log.info("User settings updated for user {}", userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ class AccountRepositoryTest extends AbstractPersistenceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void findStates_CarryTheSteamIdAndTheBlock() {
|
void findStates_CarryTheSteamIdTheDisplayNameAndTheBlock() {
|
||||||
jdbc.update("update users set enabled = false, steam_id = 76561198000000001 where id = ?", alice);
|
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.findState(alice)).contains(new CoreAccountState(alice, 76561198000000001L, "Alice", true));
|
||||||
assertThat(repository.findAllStates()).containsExactly(new CoreAccountState(alice, 76561198000000001L, true),
|
assertThat(repository.findAllStates()).containsExactly(new CoreAccountState(alice, 76561198000000001L, "Alice", true),
|
||||||
new CoreAccountState(bob, null, false));
|
new CoreAccountState(bob, null, null, false));
|
||||||
assertThat(repository.findState(-1L)).isEmpty();
|
assertThat(repository.findState(-1L)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
class AccountCleanupServiceTest extends AbstractUnitTest {
|
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);
|
private static final Duration RETENTION = Duration.ofDays(30);
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ class CoreAccountServiceTest extends AbstractUnitTest {
|
|||||||
expect("applyStates");
|
expect("applyStates");
|
||||||
expect("replaceStates");
|
expect("replaceStates");
|
||||||
|
|
||||||
service.applyStates(List.of(new CoreAccountState(42L, 76561198000000001L, true)));
|
service.applyStates(List.of(new CoreAccountState(42L, 76561198000000001L, "lobo", true)));
|
||||||
service.replaceStates(List.of(new CoreAccountState(42L, null, false)));
|
service.replaceStates(List.of(new CoreAccountState(42L, null, "lobo", false)));
|
||||||
|
|
||||||
core.verify();
|
core.verify();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
class CoreAccountStatePublisherTest extends AbstractUnitTest {
|
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
|
@Mock
|
||||||
private AccountRepository accountRepository;
|
private AccountRepository accountRepository;
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ class UserServiceTest extends AbstractUnitTest {
|
|||||||
verify(userRepository, never()).clearSteamId(anyLong());
|
verify(userRepository, never()).clearSteamId(anyLong());
|
||||||
verify(userRepository, never()).setVerifiedSteamId(anyLong(), anyLong());
|
verify(userRepository, never()).setVerifiedSteamId(anyLong(), anyLong());
|
||||||
verifyNoInteractions(tokenGenerator);
|
verifyNoInteractions(tokenGenerator);
|
||||||
|
verifyNoInteractions(accountStatePublisher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -120,6 +121,18 @@ class UserServiceTest extends AbstractUnitTest {
|
|||||||
User changed = appliedChanges(1).getFirst();
|
User changed = appliedChanges(1).getFirst();
|
||||||
assertEquals("Lobo", changed.getDisplayName());
|
assertEquals("Lobo", changed.getDisplayName());
|
||||||
assertEquals("en", changed.getSettings().getLanguage());
|
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;
|
private static final long STEAM_ID = 76561198000000001L;
|
||||||
@@ -186,6 +199,7 @@ class UserServiceTest extends AbstractUnitTest {
|
|||||||
|
|
||||||
assertEquals(appearance, appliedChanges(1).getFirst().getSettings().getAppearance());
|
assertEquals(appearance, appliedChanges(1).getFirst().getSettings().getAppearance());
|
||||||
verifyNoInteractions(tokenGenerator);
|
verifyNoInteractions(tokenGenerator);
|
||||||
|
verifyNoInteractions(accountStatePublisher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -37,12 +37,12 @@
|
|||||||
"applyStates": {
|
"applyStates": {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"path": "/internal/accounts/states",
|
"path": "/internal/accounts/states",
|
||||||
"request": {"accounts": [{"userId": 42, "steamId": 76561198000000001, "blocked": true}]}
|
"request": {"accounts": [{"userId": 42, "steamId": 76561198000000001, "displayName": "lobo", "blocked": true}]}
|
||||||
},
|
},
|
||||||
"replaceStates": {
|
"replaceStates": {
|
||||||
"method": "PUT",
|
"method": "PUT",
|
||||||
"path": "/internal/accounts/states",
|
"path": "/internal/accounts/states",
|
||||||
"request": {"accounts": [{"userId": 42, "steamId": null, "blocked": false}]}
|
"request": {"accounts": [{"userId": 42, "steamId": null, "displayName": "lobo", "blocked": false}]}
|
||||||
},
|
},
|
||||||
"purge": {
|
"purge": {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
|
|||||||
Reference in new issue
Block a user