From 7eb1385f692e3cc6edd85c18f3dad57f64f04a9f Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Wed, 3 Feb 2016 16:40:08 +0100 Subject: [PATCH] SONAR-7266 Project admin can manage project permissions --- .../ws/template/SearchTemplatesAction.java | 5 ++--- .../ws/template/SearchTemplatesActionTest.java | 13 +------------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java index f0147087cf5..1c182c9faa6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java @@ -38,7 +38,6 @@ import org.sonarqube.ws.WsPermissions.SearchTemplatesWsResponse.TemplateIdQualif import org.sonarqube.ws.client.permission.SearchTemplatesWsRequest; import static org.sonar.api.utils.DateUtils.formatDateTime; -import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class SearchTemplatesAction implements PermissionsWsAction { @@ -61,7 +60,7 @@ public class SearchTemplatesAction implements PermissionsWsAction { public void define(WebService.NewController context) { context.createAction("search_templates") .setDescription("List permission templates.
" + - "It requires administration permissions to access.") + "It requires to be authenticated.") .setResponseExample(getClass().getResource("search_templates-example.json")) .setSince("5.2") .addSearchQuery("defau", "permission template names") @@ -70,7 +69,7 @@ public class SearchTemplatesAction implements PermissionsWsAction { @Override public void handle(Request wsRequest, Response wsResponse) throws Exception { - checkGlobalAdminUser(userSession); + userSession.checkLoggedIn(); SearchTemplatesWsResponse searchTemplatesWsResponse = doHandle(toSearchTemplatesWsRequest(wsRequest)); writeProtobuf(searchTemplatesWsResponse, wsRequest, wsResponse); diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java index a7e464a533f..0bad77f9b99 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java @@ -34,14 +34,12 @@ import org.sonar.api.resources.ResourceType; import org.sonar.api.resources.ResourceTypes; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.permission.PermissionTemplateDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; -import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.i18n.I18nRule; import org.sonar.server.tester.UserSessionRule; @@ -53,7 +51,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; -import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN; import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; import static org.sonar.core.util.Uuids.UUID_EXAMPLE_03; @@ -99,7 +96,7 @@ public class SearchTemplatesActionTest { ws = new WsActionTester(underTest); - userSession.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); + userSession.login(); } @Test @@ -174,14 +171,6 @@ public class SearchTemplatesActionTest { ws.newRequest().execute(); } - @Test - public void fail_if_not_global_admin() { - expectedException.expect(ForbiddenException.class); - userSession.login().setGlobalPermissions(QUALITY_PROFILE_ADMIN); - - ws.newRequest().execute(); - } - @Test public void display_all_project_permissions() { String result = newRequest(); -- 2.39.5