Skip to content

Commit

Permalink
Migrate all Elide Prefab roles to constants
Browse files Browse the repository at this point in the history
+ fix one deprecated annotation
  • Loading branch information
Brutus5000 committed Sep 23, 2019
1 parent 01b19e6 commit 9a20cfe
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/faforever/api/data/domain/BanInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Player getPlayer() {
}

@ManyToOne
@UpdatePermission(expression = "Prefab.Role.None")
@UpdatePermission(expression = Prefab.NONE)
@JoinColumn(name = "author_id")
@NotNull
public Player getAuthor() {
Expand Down Expand Up @@ -97,7 +97,7 @@ public String getRevokeReason() {
}

@ManyToOne
@UpdatePermission(expression = "Prefab.Role.None")
@UpdatePermission(expression = Prefab.NONE)
@JoinColumn(name = "revoke_author_id")
public Player getRevokeAuthor() {
return revokeAuthor;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/faforever/api/data/domain/Clan.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.IsEntityOwner;
import com.faforever.api.data.checks.Prefab;
import com.faforever.api.data.listeners.ClanEnricherListener;
import com.faforever.api.data.validation.IsLeaderInClan;
import com.yahoo.elide.annotation.ComputedAttribute;
Expand All @@ -10,7 +11,6 @@
import com.yahoo.elide.annotation.SharePermission;
import com.yahoo.elide.annotation.UpdatePermission;
import lombok.Setter;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.CascadeType;
import javax.persistence.Column;
Expand All @@ -22,6 +22,7 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
Expand All @@ -31,7 +32,7 @@
@Include(rootLevel = true, type = Clan.TYPE_NAME)
@SharePermission
@DeletePermission(expression = IsEntityOwner.EXPRESSION)
@CreatePermission(expression = "Prefab.Role.All")
@CreatePermission(expression = Prefab.ALL)
@Setter
@IsLeaderInClan
@EntityListeners(ClanEnricherListener.class)
Expand Down Expand Up @@ -90,7 +91,7 @@ public String getTagColor() {
// Cascading is needed for Create & Delete
@OneToMany(mappedBy = "clan", cascade = CascadeType.ALL, orphanRemoval = true)
// Permission is managed by ClanMembership class
@UpdatePermission(expression = "Prefab.Role.All")
@UpdatePermission(expression = Prefab.ALL)
@NotEmpty(message = "At least the leader should be in the clan")
public List<ClanMembership> getMemberships() {
return this.memberships;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/faforever/api/data/domain/Game.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.Prefab;
import com.faforever.api.data.listeners.GameEnricher;
import com.yahoo.elide.annotation.ComputedAttribute;
import com.yahoo.elide.annotation.Include;
Expand Down Expand Up @@ -111,14 +112,14 @@ public String getReplayUrl() {
}

@OneToMany(mappedBy = "game")
@UpdatePermission(expression = "Prefab.Role.All")
@UpdatePermission(expression = Prefab.ALL)
public List<GameReview> getReviews() {
return reviews;
}

@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
@UpdatePermission(expression = "Prefab.Role.All")
@UpdatePermission(expression = Prefab.ALL)
@BatchSize(size = 1000)
public GameReviewsSummary getReviewsSummary() {
return reviewsSummary;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/faforever/api/data/domain/GameReview.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.IsEntityOwner;
import com.faforever.api.data.checks.Prefab;
import com.yahoo.elide.annotation.CreatePermission;
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.Include;
Expand All @@ -17,15 +18,15 @@
@Include(rootLevel = true, type = "gameReview")
@Entity
@Table(name = "game_review")
@CreatePermission(expression = "Prefab.Role.All")
@CreatePermission(expression = Prefab.ALL)
@DeletePermission(expression = IsEntityOwner.EXPRESSION)
public class GameReview extends Review {

private Game game;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "game_id")
@UpdatePermission(expression = "Prefab.Role.All and Prefab.Common.UpdateOnCreate")
@UpdatePermission(expression = Prefab.ALL_AND_UPDATE_ON_CREATE)
public Game getGame() {
return game;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/faforever/api/data/domain/MapVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.faforever.api.data.checks.BooleanChange;
import com.faforever.api.data.checks.IsEntityOwner;
import com.faforever.api.data.checks.Prefab;
import com.faforever.api.data.checks.permission.IsModerator;
import com.faforever.api.data.listeners.MapVersionEnricher;
import com.yahoo.elide.annotation.Audit;
Expand Down Expand Up @@ -140,13 +141,13 @@ public String getFolderName() {
}

@OneToMany(mappedBy = "mapVersion")
@UpdatePermission(expression = "Prefab.Role.All")
@UpdatePermission(expression = Prefab.ALL)
public List<MapVersionReview> getReviews() {
return reviews;
}

@OneToOne(mappedBy = "mapVersion")
@UpdatePermission(expression = "Prefab.Role.All")
@UpdatePermission(expression = Prefab.ALL)
public MapVersionReviewsSummary getReviewsSummary() {
return reviewsSummary;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.IsEntityOwner;
import com.faforever.api.data.checks.Prefab;
import com.yahoo.elide.annotation.CreatePermission;
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.Include;
Expand All @@ -17,15 +18,15 @@
@Include(rootLevel = true, type = "mapVersionReview")
@Entity
@Table(name = "map_version_review")
@CreatePermission(expression = "Prefab.Role.All")
@CreatePermission(expression = Prefab.ALL)
@DeletePermission(expression = IsEntityOwner.EXPRESSION)
public class MapVersionReview extends Review {

private MapVersion mapVersion;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "map_version_id")
@UpdatePermission(expression = "Prefab.Role.All and Prefab.Common.UpdateOnCreate")
@UpdatePermission(expression = Prefab.ALL_AND_UPDATE_ON_CREATE)
public MapVersion getMapVersion() {
return mapVersion;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/faforever/api/data/domain/Message.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.Prefab;
import com.faforever.api.data.checks.permission.IsModerator;
import com.faforever.api.data.listeners.MessageReloadListener;
import com.github.jasminb.jsonapi.annotations.Type;
Expand Down Expand Up @@ -29,7 +30,7 @@
@CreatePermission(expression = IsModerator.EXPRESSION)
@Audit(action = Action.DELETE, logStatement = "Message with key `{0}` , ID `{1}`, language `{2}` , region `{3}` and value `{4}` deleted", logExpressions = {"${message.key}", "${message.id}", "${message.language}", "${message.region}", "${message.value}"})
@Audit(action = Action.CREATE, logStatement = "Message with key `{0}` and ID `{1}` created", logExpressions = {"${message.key}", "${message.id}"})
@ReadPermission(expression = "Prefab.Role.All")
@ReadPermission(expression = Prefab.ALL)
@EntityListeners(MessageReloadListener.class)
@Type(Message.TYPE_NAME)
public class Message {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/faforever/api/data/domain/ModVersion.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.Prefab;
import com.faforever.api.data.checks.permission.IsModerator;
import com.faforever.api.data.listeners.ModVersionEnricher;
import com.yahoo.elide.annotation.Audit;
Expand Down Expand Up @@ -137,13 +138,13 @@ public String getDownloadUrl() {
}

@OneToMany(mappedBy = "modVersion")
@UpdatePermission(expression = "Prefab.Role.All")
@UpdatePermission(expression = Prefab.ALL)
public List<ModVersionReview> getReviews() {
return reviews;
}

@OneToOne(mappedBy = "modVersion")
@UpdatePermission(expression = "Prefab.Role.All")
@UpdatePermission(expression = Prefab.ALL)
public ModVersionReviewsSummary getReviewsSummary() {
return reviewsSummary;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.IsEntityOwner;
import com.faforever.api.data.checks.Prefab;
import com.yahoo.elide.annotation.CreatePermission;
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.Include;
Expand All @@ -17,15 +18,15 @@
@Include(rootLevel = true, type = "modVersionReview")
@Entity
@Table(name = "mod_version_review")
@CreatePermission(expression = "Prefab.Role.All")
@CreatePermission(expression = Prefab.ALL)
@DeletePermission(expression = IsEntityOwner.EXPRESSION)
public class ModVersionReview extends Review {

private ModVersion modVersion;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mod_version_id")
@UpdatePermission(expression = "Prefab.Role.All and Prefab.Common.UpdateOnCreate")
@UpdatePermission(expression = Prefab.ALL_AND_UPDATE_ON_CREATE)
public ModVersion getModVersion() {
return modVersion;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/faforever/api/data/domain/NameRecord.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.Prefab;
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.annotation.UpdatePermission;
Expand All @@ -18,8 +19,8 @@
@Entity
@Table(name = "name_history")
@Include(rootLevel = true, type = "nameRecord")
@DeletePermission(expression = "Prefab.Role.None")
@UpdatePermission(expression = "Prefab.Role.None")
@DeletePermission(expression = Prefab.NONE)
@UpdatePermission(expression = Prefab.NONE)
@Setter
public class NameRecord {
private int id;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/faforever/api/data/domain/Review.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.IsEntityOwner;
import com.faforever.api.data.checks.Prefab;
import com.yahoo.elide.annotation.UpdatePermission;
import lombok.Setter;

Expand Down Expand Up @@ -36,7 +37,7 @@ public Byte getScore() {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@UpdatePermission(expression = "Prefab.Role.All and Prefab.Common.UpdateOnCreate")
@UpdatePermission(expression = Prefab.ALL_AND_UPDATE_ON_CREATE)
public Player getPlayer() {
return player;
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/faforever/api/data/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
*/
@SharePermission
// Everybody can read from the api
@ReadPermission(expression = "Prefab.Role.All")
@ReadPermission(expression = Prefab.ALL)
// By default restrict all data manipulation operation
@UpdatePermission(expression = "Prefab.Role.None")
@CreatePermission(expression = "Prefab.Role.None")
@DeletePermission(expression = "Prefab.Role.None")
@UpdatePermission(expression = Prefab.NONE)
@CreatePermission(expression = Prefab.NONE)
@DeletePermission(expression = Prefab.NONE)
package com.faforever.api.data;

import com.faforever.api.data.checks.Prefab;
import com.yahoo.elide.annotation.CreatePermission;
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.ReadPermission;
Expand Down

0 comments on commit 9a20cfe

Please sign in to comment.