Skip to content

Commit

Permalink
Hide map by author
Browse files Browse the repository at this point in the history
Fixes #213
  • Loading branch information
1-alex98 committed May 2, 2018
1 parent 8b2c06c commit 5a60bd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class Inline extends InlineCheck<OwnableEntity> {
public boolean ok(OwnableEntity entity, RequestScope requestScope, Optional<ChangeSpec> changeSpec) {
Object opaqueUser = requestScope.getUser().getOpaqueUser();
return opaqueUser instanceof FafUserDetails
&& entity.getEntityOwner() != null
&& entity.getEntityOwner().getId() == ((FafUserDetails) opaqueUser).getId();
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/faforever/api/data/domain/MapVersion.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.IsEntityOwner;
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 @@ -28,7 +29,7 @@
@EntityListeners(MapVersionEnricher.class)
@Table(name = "map_version")
@Include(rootLevel = true, type = MapVersion.TYPE_NAME)
public class MapVersion extends AbstractEntity {
public class MapVersion extends AbstractEntity implements OwnableEntity {

public static final String TYPE_NAME = "mapVersion";

Expand Down Expand Up @@ -85,7 +86,7 @@ public String getFilename() {
return filename;
}

@UpdatePermission(expression = IsModerator.EXPRESSION)
@UpdatePermission(expression = IsModerator.EXPRESSION + " or " + IsEntityOwner.EXPRESSION)
@Audit(action = Action.UPDATE, logStatement = "Updated map version `{0}` attribute ranked to: {1}", logExpressions = {"${mapVersion.id}", "${mapVersion.ranked}"})
@Column(name = "ranked")
public boolean isRanked() {
Expand Down Expand Up @@ -147,4 +148,10 @@ public List<MapVersionReview> getReviews() {
public MapVersionReviewsSummary getReviewsSummary() {
return reviewsSummary;
}

@Transient
@Override
public Login getEntityOwner() {
return map.getAuthor();
}
}

0 comments on commit 5a60bd9

Please sign in to comment.