Skip to content

Commit

Permalink
Merge c11086b into 0752e01
Browse files Browse the repository at this point in the history
  • Loading branch information
1-alex98 committed Nov 4, 2018
2 parents 0752e01 + c11086b commit d76c969
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Generated by gradle
*.iml

# All log files e.g. by audit
*.log

# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ before_install:
install:
- git clone https://github.com/FAForever/faf-stack.git faf-stack
&& pushd faf-stack
&& git checkout 78c887c
&& git checkout a1ef34cb64343225d6793e7af1d8fa0c93a7b3e6
&& 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
1 change: 0 additions & 1 deletion src/inttest/resources/sql/cleanBanData.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
DELETE FROM ban_revoke;
DELETE FROM ban;
13 changes: 5 additions & 8 deletions src/inttest/resources/sql/prepBanData.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
DELETE FROM ban_revoke;
DELETE FROM ban;

INSERT INTO login (id, login, email, password) VALUES
(4, 'BANNED', 'banned@faforever.com', 'not relevant');

INSERT INTO ban (id, player_id, author_id, reason, expires_at, level) VALUES
(1, 4, 1, 'Test permaban', DATE_ADD(NOW(), INTERVAL 1 DAY), 'GLOBAL'),
(2, 2, 1, 'To be revoked ban', DATE_ADD(NOW(), INTERVAL 1 DAY), 'GLOBAL');

INSERT INTO ban_revoke (ban_id, reason, author_id) VALUES
(2, 'Test revoke', 1);

INSERT INTO ban (id, player_id, author_id, reason, expires_at, level) VALUE
(1, 4, 1, 'Test permaban', DATE_ADD(NOW(), INTERVAL 1 DAY), 'GLOBAL');
INSERT INTO ban (id, player_id, author_id, reason, expires_at, level, revoke_time, revoke_author_id, revoke_reason)
VALUE
(2, 2, 1, 'To be revoked ban', DATE_ADD(NOW(), INTERVAL 1 DAY), 'GLOBAL', NOW(), 1, 'Test revoke');
1 change: 0 additions & 1 deletion src/inttest/resources/sql/prepDefaultUser.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ DELETE FROM updates_faf;
DELETE FROM updates_faf_files;
DELETE FROM avatars;
DELETE FROM avatars_list;
DELETE FROM ban_revoke;
DELETE FROM ban;
DELETE FROM clan_membership;
DELETE FROM clan;
Expand Down
1 change: 0 additions & 1 deletion src/inttest/resources/sql/prepUserNoteData.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DELETE FROM ban_revoke;
DELETE FROM ban;

INSERT INTO login (id, login, email, password) VALUES
Expand Down
55 changes: 43 additions & 12 deletions src/main/java/com/faforever/api/data/domain/BanInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.annotation.OnCreatePreSecurity;
import com.yahoo.elide.annotation.OnUpdatePreSecurity;
import com.yahoo.elide.annotation.ReadPermission;
import com.yahoo.elide.annotation.UpdatePermission;
import com.yahoo.elide.core.RequestScope;
import lombok.Setter;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
Expand All @@ -44,8 +43,10 @@ public class BanInfo extends AbstractEntity {
private String reason;
private OffsetDateTime expiresAt;
private BanLevel level;
private BanRevokeData banRevokeData;
private ModerationReport moderationReport;
private String revokeReason;
private Player revokeAuthor;
private OffsetDateTime revokeTime;

@ManyToOne
@JoinColumn(name = "player_id")
Expand All @@ -55,8 +56,8 @@ public Player getPlayer() {
}

@ManyToOne
@UpdatePermission(expression = "Prefab.Role.None")
@JoinColumn(name = "author_id")
@NotNull
public Player getAuthor() {
return author;
}
Expand All @@ -78,13 +79,6 @@ public BanLevel getLevel() {
return level;
}

// Cascading is needed for Create & Delete
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "id")
public BanRevokeData getBanRevokeData() {
return banRevokeData;
}

@ManyToOne
@JoinColumn(name = "report_id")
public ModerationReport getModerationReport() {
Expand All @@ -96,9 +90,26 @@ public BanDurationType getDuration() {
return expiresAt == null ? BanDurationType.PERMANENT : BanDurationType.TEMPORARY;
}

@Column(name = "revoke_reason")
public String getRevokeReason() {
return revokeReason;
}

@ManyToOne
@UpdatePermission(expression = "Prefab.Role.None")
@JoinColumn(name = "revoke_author_id")
public Player getRevokeAuthor() {
return revokeAuthor;
}

@Column(name = "revoke_time")
public OffsetDateTime getRevokeTime() {
return revokeTime;
}

@Transient
public BanStatus getBanStatus() {
if (banRevokeData != null) {
if (revokeTime != null && revokeTime.isBefore(OffsetDateTime.now())) {
return BanStatus.DISABLED;
}
if (getDuration() == BanDurationType.PERMANENT) {
Expand All @@ -119,4 +130,24 @@ public void assignReporter(RequestScope scope) {
this.author = author;
}
}

@OnUpdatePreSecurity("revokeTime")
public void revokeTimeUpdated(RequestScope scope) {
assignRevokeAuthor(scope);
}

@OnUpdatePreSecurity("revokeReason")
public void revokeReasonUpdated(RequestScope scope) {
assignRevokeAuthor(scope);
}

private void assignRevokeAuthor(RequestScope scope) {
final Object caller = scope.getUser().getOpaqueUser();
if (caller instanceof FafUserDetails) {
final FafUserDetails fafUser = (FafUserDetails) caller;
final Player author = new Player();
author.setId(fafUser.getId());
this.revokeAuthor = author;
}
}
}
56 changes: 0 additions & 56 deletions src/main/java/com/faforever/api/data/domain/BanRevokeData.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ public interface GlobalLeaderboardRepository extends Repository<GlobalLeaderboar
" WHERE is_active = 1" +
" AND login.id NOT IN (" +
" SELECT player_id FROM ban" +
" LEFT JOIN ban_revoke on ban.id = ban_revoke.ban_id" +
" WHERE (expires_at is null or expires_at > NOW()) AND ban_revoke.ban_id IS NULL" +
" WHERE (expires_at is null or expires_at > NOW()) AND (revoke_time IS NULL OR revoke_time > NOW())" +
" ) " +
" ORDER BY round(mean - 3 * deviation) DESC LIMIT ?#{#pageable.offset},?#{#pageable.pageSize}",
countQuery = "SELECT count(*) FROM ladder1v1_rating WHERE is_active = 1 AND ladder1v1_rating.numGames > 0" +
" AND id NOT IN (" +
" SELECT player_id FROM ban" +
" LEFT JOIN ban_revoke on ban.id = ban_revoke.ban_id" +
" WHERE (expires_at is null or expires_at > NOW()) AND ban_revoke.ban_id IS NULL" +
" WHERE (expires_at is null or expires_at > NOW()) AND (revoke_time IS NULL OR revoke_time > NOW())" +
" ) -- Dummy placeholder for pageable, prevents 'Unknown parameter position': ?,?,?", nativeQuery = true)
Page<GlobalLeaderboardEntry> getLeaderboardByPage(Pageable pageable);

Expand All @@ -44,8 +42,7 @@ public interface GlobalLeaderboardRepository extends Repository<GlobalLeaderboar
"WHERE is_active = 1\n" +
" AND login.id NOT IN (" +
" SELECT player_id FROM ban" +
" LEFT JOIN ban_revoke on ban.id = ban_revoke.ban_id" +
" WHERE (expires_at is null or expires_at <= NOW()) AND ban_revoke.ban_id IS NULL" +
" WHERE (expires_at is null or expires_at <= NOW()) AND (revoke_time IS NULL OR revoke_time > NOW())" +
" ) " +
"ORDER BY round(mean - 3 * deviation) DESC) as leaderboard WHERE id = :playerId", nativeQuery = true)
GlobalLeaderboardEntry findByPlayerId(@Param("playerId") int playerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ public interface Ladder1v1LeaderboardRepository extends Repository<Ladder1v1Lead
" WHERE is_active = 1 AND ladder1v1_rating.numGames > 0" +
" AND login.id NOT IN (" +
" SELECT player_id FROM ban" +
" LEFT JOIN ban_revoke on ban.id = ban_revoke.ban_id" +
" WHERE (expires_at is null or expires_at > NOW()) AND ban_revoke.ban_id IS NULL" +
" WHERE (expires_at is null or expires_at > NOW()) AND (revoke_time IS NULL OR revoke_time > NOW())" +
" ) " +
" ORDER BY round(mean - 3 * deviation) DESC LIMIT ?#{#pageable.offset},?#{#pageable.pageSize}",
countQuery = "SELECT count(*) FROM ladder1v1_rating WHERE is_active = 1 AND ladder1v1_rating.numGames > 0" +
" AND id NOT IN (" +
" SELECT player_id FROM ban" +
" LEFT JOIN ban_revoke on ban.id = ban_revoke.ban_id" +
" WHERE (expires_at is null or expires_at > NOW()) AND ban_revoke.ban_id IS NULL" +
" WHERE (expires_at is null or expires_at > NOW()) AND (revoke_time IS NULL OR revoke_time > NOW())" +
" ) -- Dummy placeholder for pageable, prevents 'Unknown parameter position': ?,?,?",
nativeQuery = true)
Page<Ladder1v1LeaderboardEntry> getLeaderboardByPage(Pageable pageable);
Expand All @@ -47,8 +45,7 @@ public interface Ladder1v1LeaderboardRepository extends Repository<Ladder1v1Lead
"WHERE is_active = 1\n" +
" AND login.id NOT IN (" +
" SELECT player_id FROM ban" +
" LEFT JOIN ban_revoke on ban.id = ban_revoke.ban_id" +
" WHERE (expires_at is null or expires_at > NOW()) AND ban_revoke.ban_id IS NULL" +
" WHERE (expires_at is null or expires_at > NOW()) AND (revoke_time IS NULL OR revoke_time > NOW())" +
" ) " +
"ORDER BY round(mean - 3 * deviation) DESC) as leaderboard WHERE id = :playerId", nativeQuery = true)
Ladder1v1LeaderboardEntry findByPlayerId(@Param("playerId") int playerId);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ faf-api:
challonge:
key: ${CHALLONGE_KEY:}
database:
schema-version: ${DATABASE_SCHEMA_VERSION:61}
schema-version: ${DATABASE_SCHEMA_VERSION:62}
mautic:
base-url: ${MAUTIC_BASE_URL:false}
client-id: ${MAUTIC_CLIENT_ID:false}
Expand Down

0 comments on commit d76c969

Please sign in to comment.