Repository navigation
Allow moderators to delete game, mod and map reviews #1226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff70480
Allow moderators to delete game, mod and map reviews
Brutus5000 a302122
Move review test data into prep SQL scripts
Brutus5000 ef8e453
Attach test reviews to separate versions to keep review summaries intact
Brutus5000 d4df10b
Bump database schema version to 150
Brutus5000 53071fb
Expect ADMIN_REVIEW in group permission count
Brutus5000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/inttest/java/com/faforever/api/data/ReviewElideTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.faforever.api.data; | ||
|
|
||
| import com.faforever.api.AbstractIntegrationTest; | ||
| import com.faforever.api.data.domain.GroupPermission; | ||
| import com.faforever.api.security.OAuthScope; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
| import org.springframework.test.context.jdbc.Sql; | ||
| import org.springframework.test.context.jdbc.Sql.ExecutionPhase; | ||
|
|
||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/truncateTables.sql") | ||
| @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultData.sql") | ||
| @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepModData.sql") | ||
| @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepMapVersion.sql") | ||
| @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepGameData.sql") | ||
| public class ReviewElideTest extends AbstractIntegrationTest { | ||
|
|
||
| // The review with id 1 of each type is owned by user 1, the caller of the admin tests is user 5. | ||
| private static final String TYPES = """ | ||
| gameReview | ||
| modVersionReview | ||
| mapVersionReview"""; | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource(textBlock = TYPES) | ||
| public void moderatorCanDeleteReviewWithScopeAndRole(String type) throws Exception { | ||
| mockMvc.perform(delete("/data/" + type + "/1") | ||
| .with(getOAuthTokenWithActiveUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_ADMIN_REVIEW))) | ||
| .andExpect(status().isNoContent()); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource(textBlock = TYPES) | ||
| public void cannotDeleteReviewWithoutScope(String type) throws Exception { | ||
| mockMvc.perform(delete("/data/" + type + "/1") | ||
| .with(getOAuthTokenWithActiveUser(NO_SCOPE, GroupPermission.ROLE_ADMIN_REVIEW))) | ||
| .andExpect(status().isForbidden()); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource(textBlock = TYPES) | ||
| public void cannotDeleteForeignReviewWithoutRole(String type) throws Exception { | ||
| mockMvc.perform(delete("/data/" + type + "/1") | ||
| .with(getOAuthTokenWithActiveUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES))) | ||
| .andExpect(status().isForbidden()); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource(textBlock = TYPES) | ||
| public void ownerCanStillDeleteOwnReview(String type) throws Exception { | ||
| mockMvc.perform(delete("/data/" + type + "/1") | ||
| .with(getOAuthTokenForUserId(1, NO_SCOPE))) | ||
| .andExpect(status().isNoContent()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| INSERT INTO map (id, display_name, map_type, battle_type, author, recommended, license) VALUES (1, 'display name', 'mtype', 'btype', 1, false, 1); | ||
| INSERT INTO map_version (id, description, max_players, width, height, version, folder_name, map_id, hidden, ranked) | ||
| VALUES (1, 'des', 2, 2, 2, 1, 'ghb', 1, 0, 1); | ||
| VALUES (1, 'des', 2, 2, 2, 1, 'ghb', 1, 0, 1), | ||
| (2, 'des 2', 2, 2, 2, 2, 'ghb2', 1, 0, 1); | ||
| INSERT INTO map_reviews_summary (id, map_id, positive, negative, score, reviews, lower_bound) | ||
| VALUES (1, 1, 0, 0, 2, 1, 0); | ||
| INSERT INTO map_version_reviews_summary (id, map_version_id, positive, negative, score, reviews, lower_bound) | ||
| VALUES (1, 1, 0, 0, 0, 0, 0); | ||
| INSERT INTO map_version_review (id, map_version_id, user_id, score, text) VALUES (1, 2, 1, 5, 'Great map'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/faforever/api/security/elide/permission/AdminReviewCheck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.faforever.api.security.elide.permission; | ||
|
|
||
| import com.faforever.api.data.domain.GroupPermission; | ||
| import com.faforever.api.security.OAuthScope; | ||
| import com.yahoo.elide.annotation.SecurityCheck; | ||
| import com.yahoo.elide.core.security.User; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import static com.faforever.api.security.elide.permission.AdminReviewCheck.EXPRESSION; | ||
|
|
||
| @Slf4j | ||
| @SecurityCheck(EXPRESSION) | ||
| public class AdminReviewCheck extends FafUserCheck { | ||
| public static final String EXPRESSION = "AdminReview"; | ||
|
|
||
| @Override | ||
| public boolean ok(User user) { | ||
| return checkOAuthScopes(OAuthScope.ADMINISTRATIVE_ACTION) && | ||
| checkUserPermission(user, GroupPermission.ROLE_ADMIN_REVIEW); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply the database schema change before this API version starts.
The default minimum is now
150.SchemaVersionVerifiercompares it with the highest recorded database version during bean initialization. A database at 148 or 149 fails that check, and the API fails to start with anIllegalStateException. This applies to any environment that does not setDATABASE_SCHEMA_VERSION.Apply the
FAForever/dbmigration to reach version 150 before deploying this API version. SettingDATABASE_SCHEMA_VERSIONto the current version bypasses the check. Use that override only when the database is known to be compatible with this API version.