Skip to content

Commit 628f7bb

Browse files
bukajsytlosBrutus5000
authored andcommitted
Fixes #465 Maps without author can be updated by anyone
1 parent 4ea8ae0 commit 628f7bb

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/main/java/com/faforever/api/map/MapService.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import java.util.ArrayList;
4646
import java.util.Arrays;
4747
import java.util.List;
48-
import java.util.Objects;
4948
import java.util.Optional;
5049
import java.util.regex.Pattern;
5150
import java.util.stream.Collectors;
@@ -343,12 +342,10 @@ private Optional<Map> validateMapMetadata(MapLuaAccessor mapLua, MapNameBuilder
343342
Optional<Map> existingMapOptional = mapRepository.findOneByDisplayName(displayName);
344343
existingMapOptional
345344
.ifPresent(existingMap -> {
346-
Optional.ofNullable(existingMap.getAuthor())
347-
.filter(existingMapAuthor -> !Objects.equals(existingMapAuthor, author))
348-
.ifPresent(existingMapAuthor -> {
349-
throw ApiException.of(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, existingMap.getDisplayName());
350-
});
351-
345+
final Player existingMapAuthor = existingMap.getAuthor();
346+
if (existingMapAuthor == null || !existingMapAuthor.equals(author)) {
347+
throw ApiException.of(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, existingMap.getDisplayName());
348+
}
352349
if (existingMap.getVersions().stream()
353350
.anyMatch(mapVersion -> mapVersion.getVersion() == newVersion)) {
354351
throw ApiException.of(ErrorCode.MAP_VERSION_EXISTS, existingMap.getDisplayName(), newVersion);

src/test/java/com/faforever/api/map/MapServiceTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ void notCorrectAuthor() {
282282
uploadFails(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, "command_conquer_rush.v0007.zip");
283283
}
284284

285+
@Test
286+
void annonymousAuthor() {
287+
when(fafApiProperties.getMap()).thenReturn(mapProperties);
288+
289+
Player me = new Player();
290+
me.setId(1);
291+
292+
com.faforever.api.data.domain.Map map = new com.faforever.api.data.domain.Map().setAuthor(null);
293+
when(mapRepository.findOneByDisplayName(any())).thenReturn(Optional.of(map));
294+
295+
uploadFails(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, "command_conquer_rush.v0007.zip");
296+
}
297+
285298
@Test
286299
void versionExistsAlready() {
287300
when(fafApiProperties.getMap()).thenReturn(mapProperties);

0 commit comments

Comments
 (0)