diff --git a/.travis.yml b/.travis.yml index e961bfb..a4db10e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,10 +25,10 @@ before_install: install: - git clone https://github.com/FAForever/faf-stack.git faf-stack && pushd faf-stack - && git checkout v18.10.4 + && git checkout 7db32d53f757d7cf15441b8c9ff8896b735e9b6b && cp -r config.template config + && ./scripts/init-db.sh && popd - - docker-compose -f faf-stack/docker-compose.yml up -d faf-db script: - chmod +x gradlew && ./gradlew build -Pversion=${APP_VERSION} --info diff --git a/faf-java-server-app/src/main/java/com/faforever/server/integration/legacy/LegacyServicesActivators.java b/faf-java-server-app/src/main/java/com/faforever/server/integration/legacy/LegacyServicesActivators.java index 4608dc3..cc700f0 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/integration/legacy/LegacyServicesActivators.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/integration/legacy/LegacyServicesActivators.java @@ -27,7 +27,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.inject.Inject; -import java.time.Instant; import java.util.Comparator; import static com.faforever.server.integration.MessageHeaders.CLIENT_CONNECTION; @@ -93,7 +92,7 @@ public void loginRequest(LegacyLoginRequest loginRequest, @Header(CLIENT_CONNECT /** Throws an exception if the account has an active ban. */ private void checkBan(FafUserDetails userDetails) { userDetails.getPlayer().getBanDetails().stream() - .filter(banDetail -> !banDetail.isRevoked() && (banDetail.getExpiresAt() == null || banDetail.getExpiresAt().toInstant().isAfter(Instant.now()))) + .filter(BanDetails::isActive) .max(Comparator.comparing(BanDetails::getId)) .ifPresent(banDetails -> { if (banDetails.getExpiresAt() != null) { diff --git a/faf-java-server-app/src/main/java/com/faforever/server/security/BanDetails.java b/faf-java-server-app/src/main/java/com/faforever/server/security/BanDetails.java index c0d1569..49715f1 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/security/BanDetails.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/security/BanDetails.java @@ -3,7 +3,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import org.hibernate.annotations.Formula; import javax.persistence.Column; import javax.persistence.Entity; @@ -13,7 +12,10 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.validation.constraints.NotNull; import java.sql.Timestamp; +import java.time.Instant; +import java.time.OffsetDateTime; @Entity @Table(name = "ban") @@ -28,6 +30,7 @@ public class BanDetails { @ManyToOne @JoinColumn(name = "player_id") + @NotNull private User user; @ManyToOne @@ -35,6 +38,7 @@ public class BanDetails { private User author; @Column(name = "reason") + @NotNull private String reason; @Column(name = "expires_at") @@ -44,8 +48,20 @@ public class BanDetails { @Enumerated(EnumType.STRING) private BanScope scope; - @Formula(value = "(SELECT count(1) FROM ban_revoke WHERE ban_revoke.ban_id = id)") - private boolean revoked; + @Column(name = "revoke_reason") + private String revokeReason; + + @ManyToOne + @JoinColumn(name = "revoke_author_id") + private User revokeAuthor; + + @Column(name = "revoke_time") + private OffsetDateTime revokeTime; + + public boolean isActive() { + return (revokeTime == null || revokeTime.isAfter(OffsetDateTime.now())) + && (expiresAt == null || expiresAt.after(Timestamp.from(Instant.now()))); + } public enum BanScope { CHAT, GLOBAL diff --git a/faf-java-server-app/src/main/java/com/faforever/server/security/FafUserDetails.java b/faf-java-server-app/src/main/java/com/faforever/server/security/FafUserDetails.java index f55225a..62958bd 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/security/FafUserDetails.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/security/FafUserDetails.java @@ -11,8 +11,6 @@ import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; -import java.sql.Timestamp; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -62,9 +60,6 @@ private static List getRoles(User user) { private static boolean isNonLocked(Set banDetails) { return banDetails.stream() - .noneMatch(details -> - !details.isRevoked() - && (details.getExpiresAt() == null || details.getExpiresAt().after(Timestamp.from(Instant.now()))) - ); + .noneMatch(BanDetails::isActive); } } diff --git a/faf-java-server-app/src/main/resources/config/application.yml b/faf-java-server-app/src/main/resources/config/application.yml index 8328d42..fa2137c 100644 --- a/faf-java-server-app/src/main/resources/config/application.yml +++ b/faf-java-server-app/src/main/resources/config/application.yml @@ -18,7 +18,7 @@ faf-server: access-token-uri: ${API_ACCESS_TOKEN_URI} max-page-size: 10000 database: - schema-version: ${DATABASE_SCHEMA_VERSION:59} + schema-version: ${DATABASE_SCHEMA_VERSION:62} ice: twilio: account-sid: ${TWILIO_ACCOUNT_SID:} diff --git a/faf-java-server-app/src/test/resources/config/application.yml b/faf-java-server-app/src/test/resources/config/application.yml index 526cdb6..6c05cca 100644 --- a/faf-java-server-app/src/test/resources/config/application.yml +++ b/faf-java-server-app/src/test/resources/config/application.yml @@ -2,7 +2,7 @@ faf-server: geo-ip: database-url: http://content.faforever.com/GeoLite2-City.mmdb.gz database: - schema-version: ${DATABASE_SCHEMA_VERSION:59} + schema-version: ${DATABASE_SCHEMA_VERSION:62} spring: datasource: