Skip to content

Commit

Permalink
Ban Revoke Structure
Browse files Browse the repository at this point in the history
Fixes #95
  • Loading branch information
1-alex98 authored and Alexander von Trostorff committed Nov 11, 2018
1 parent 414b82b commit cddc7a3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand All @@ -28,13 +30,15 @@ public class BanDetails {

@ManyToOne
@JoinColumn(name = "player_id")
@NotNull
private User user;

@ManyToOne
@JoinColumn(name = "author_id")
private User author;

@Column(name = "reason")
@NotNull
private String reason;

@Column(name = "expires_at")
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,9 +60,6 @@ private static List<GrantedAuthority> getRoles(User user) {

private static boolean isNonLocked(Set<BanDetails> banDetails) {
return banDetails.stream()
.noneMatch(details ->
!details.isRevoked()
&& (details.getExpiresAt() == null || details.getExpiresAt().after(Timestamp.from(Instant.now())))
);
.noneMatch(BanDetails::isActive);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cddc7a3

Please sign in to comment.