Skip to content

Commit f9fd41b

Browse files
committed
Fix permissions
1 parent 988ac3a commit f9fd41b

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

src/inttest/java/com/faforever/api/data/MatchmakerQueueMapPoolElideTest.java renamed to src/inttest/java/com/faforever/api/data/MapPoolElideTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,59 @@
1515
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/truncateTables.sql")
1616
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultData.sql")
1717
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepMapData.sql")
18-
public class MatchmakerQueueMapPoolElideTest extends AbstractIntegrationTest {
19-
private static final String NEW_LADDER_MAP_BODY = "{\"data\":{\"type\":\"ladder1v1Map\",\"relationships\":{\"mapVersion\":{\"data\":{\"type\":\"mapVersion\",\"id\":\"2\"}}}}}";
18+
public class MapPoolElideTest extends AbstractIntegrationTest {
19+
private static final String NEW_LADDER_MAP_BODY = "{\"data\":{\"type\":\"mapVersion\",\"id\":\"2\"}}}";
2020

2121
@Test
22-
public void cannotCreateLadderMapWithoutScope() throws Exception {
22+
public void cannotCreateMapPoolItemWithoutScope() throws Exception {
2323
mockMvc.perform(
24-
post("/data/ladder1v1Map")
24+
post("/data/mapPool/1/mapVersions")
2525
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP))
2626
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
2727
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
2828
.andExpect(status().isForbidden());
2929
}
3030

3131
@Test
32-
public void cannotCreateLadderMapWithoutRole() throws Exception {
32+
public void cannotCreateMapPoolItemWithoutRole() throws Exception {
3333
mockMvc.perform(
34-
post("/data/ladder1v1Map")
34+
post("/data/mapPool/1/mapVersions")
3535
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES))
3636
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
3737
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
3838
.andExpect(status().isForbidden());
3939
}
4040

4141
@Test
42-
public void canCreateLadderMapWithScopeAndRole() throws Exception {
42+
public void canCreateMapPoolItemWithScopeAndRole() throws Exception {
4343
mockMvc.perform(
44-
post("/data/ladder1v1Map")
44+
post("/data/mapPool/1/mapVersions")
4545
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP))
4646
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
4747
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
4848
.andExpect(status().isCreated());
4949
}
5050

5151
@Test
52-
public void canDeleteLadderMapWithScopeAndRole() throws Exception {
52+
public void canDeleteMapPoolItemWithScopeAndRole() throws Exception {
5353
mockMvc.perform(
54-
delete("/data/ladder1v1Map/1")
54+
delete("/data/mapPool/1/mapVersions/1")
5555
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP))) // magic value from prepMapData.sql
5656
.andExpect(status().isNoContent());
5757
}
5858

5959
@Test
60-
public void cannotDeleteLadderMapWithoutScope() throws Exception {
60+
public void cannotDeleteMapPoolItemWithoutScope() throws Exception {
6161
mockMvc.perform(
62-
delete("/data/ladder1v1Map/1")
62+
delete("/data/mapPool/1/mapVersions/1")
6363
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP))) // magic value from prepMapData.sql
6464
.andExpect(status().isForbidden());
6565
}
6666

6767
@Test
68-
public void cannotDeleteLadderMapWithoutRole() throws Exception {
68+
public void cannotDeleteMapPoolItemWithoutRole() throws Exception {
6969
mockMvc.perform(
70-
delete("/data/ladder1v1Map/1")
70+
delete("/data/mapPool/1")
7171
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES))) // magic value from prepMapData.sql
7272
.andExpect(status().isForbidden());
7373
}

src/main/java/com/faforever/api/data/domain/MapPool.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.faforever.api.data.domain;
22

3+
import com.faforever.api.security.elide.permission.WriteMatchmakerMapCheck;
4+
import com.yahoo.elide.annotation.CreatePermission;
5+
import com.yahoo.elide.annotation.DeletePermission;
36
import com.yahoo.elide.annotation.Include;
7+
import com.yahoo.elide.annotation.SharePermission;
8+
import com.yahoo.elide.annotation.UpdatePermission;
49
import lombok.Setter;
510
import org.hibernate.annotations.Immutable;
611

7-
import javax.persistence.CascadeType;
812
import javax.persistence.Entity;
913
import javax.persistence.JoinColumn;
1014
import javax.persistence.JoinTable;
@@ -17,7 +21,10 @@
1721
@Setter
1822
@Table(name = "map_pool")
1923
@Include(rootLevel = true, type = "mapPool")
20-
@Immutable
24+
@CreatePermission(expression = WriteMatchmakerMapCheck.EXPRESSION)
25+
@UpdatePermission(expression = WriteMatchmakerMapCheck.EXPRESSION)
26+
@DeletePermission(expression = WriteMatchmakerMapCheck.EXPRESSION)
27+
@SharePermission
2128
public class MapPool extends AbstractEntity {
2229
private String name;
2330
private Set<MapVersion> mapVersions;

0 commit comments

Comments
 (0)