summaryrefslogtreecommitdiff
path: root/backend/src/main/kotlin
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2019-02-19 18:09:27 +0100
committerjbion <joffrey.bion@amadeus.com>2019-02-19 19:01:52 +0100
commitcab8a5a83e810d14c97fbb26f0cdfe1b86e88d43 (patch)
treee2e6ce43eca9b20ef82589e174ac411c22a9f318 /backend/src/main/kotlin
parentUpdate repository URLs in README (diff)
downloadseven-wonders-cab8a5a83e810d14c97fbb26f0cdfe1b86e88d43.tar.gz
seven-wonders-cab8a5a83e810d14c97fbb26f0cdfe1b86e88d43.tar.bz2
seven-wonders-cab8a5a83e810d14c97fbb26f0cdfe1b86e88d43.zip
Fix board gold access and cleanup tests
Diffstat (limited to 'backend/src/main/kotlin')
-rw-r--r--backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt16
1 files changed, 4 insertions, 12 deletions
diff --git a/backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt b/backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt
index 138791fb..5f704357 100644
--- a/backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt
+++ b/backend/src/main/kotlin/org/luxons/sevenwonders/validation/DestinationAccessValidator.kt
@@ -3,7 +3,6 @@ package org.luxons.sevenwonders.validation
import org.luxons.sevenwonders.repositories.LobbyRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
-import java.util.regex.Matcher
import java.util.regex.Pattern
@Component
@@ -23,7 +22,7 @@ class DestinationAccessValidator @Autowired constructor(private val lobbyReposit
if (!gameMatcher.matches()) {
return false // no game reference is always OK
}
- val gameId = extractId(gameMatcher)
+ val gameId = gameMatcher.group("id").toLong()
return !isUserInLobby(username, gameId)
}
@@ -32,24 +31,17 @@ class DestinationAccessValidator @Autowired constructor(private val lobbyReposit
if (!lobbyMatcher.matches()) {
return false // no lobby reference is always OK
}
- val lobbyId = extractId(lobbyMatcher)
+ val lobbyId = lobbyMatcher.group("id").toLong()
return !isUserInLobby(username, lobbyId)
}
- private fun isUserInLobby(username: String, lobbyId: Int): Boolean {
- val lobby = lobbyRepository.find(lobbyId.toLong())
- return lobby.containsUser(username)
- }
+ private fun isUserInLobby(username: String, lobbyId: Long): Boolean =
+ lobbyRepository.find(lobbyId).containsUser(username)
companion object {
private val lobbyDestination = Pattern.compile(".*?/lobby/(?<id>\\d+?)(/.*)?")
private val gameDestination = Pattern.compile(".*?/game/(?<id>\\d+?)(/.*)?")
-
- private fun extractId(matcher: Matcher): Int {
- val id = matcher.group("id")
- return Integer.parseInt(id)
- }
}
}
bgstack15