From 51f2544c13d2e857153724337046075cea6df595 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 8 Jan 2016 12:44:34 +0100 Subject: [PATCH] SONAR-7174 "Execute Analysis" is now also a project permission --- .../java/org/sonar/server/i18n/I18nRule.java | 3 ++ .../org/sonar/server/i18n/package-info.java | 23 +++++++++++ .../permission/PermissionChangeTest.java | 5 +-- .../ws/SearchGlobalPermissionsActionTest.java | 2 +- .../SearchProjectPermissionsActionTest.java | 17 ++++++++- .../template/SearchTemplatesActionTest.java | 14 ++++++- .../search_global_permissions-example.json | 0 .../display_all_project_permissions.json | 30 +++++++++++++++ .../empty.json | 22 ----------- .../search_project_permissions-example.json | 0 .../display_all_project_permissions.json | 29 ++++++++++++++ .../SearchTemplatesActionTest/empty.json | 22 ----------- .../search_templates-example.json | 22 ----------- .../main/js/apps/permission-templates/main.js | 2 +- .../main/js/apps/project-permissions/main.js | 2 +- .../resources/org/sonar/l10n/core.properties | 2 + .../core/permission/ProjectPermissions.java | 13 ++++--- .../permission/ProjectPermissionsTest.java | 38 +++++++++++++++++++ 18 files changed, 165 insertions(+), 81 deletions(-) create mode 100644 server/sonar-server/src/test/java/org/sonar/server/i18n/package-info.java rename server/sonar-server/src/{main/resources/org/sonar/server/permission/ws => test/resources/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest}/search_global_permissions-example.json (100%) create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/display_all_project_permissions.json rename server/sonar-server/src/{main/resources/org/sonar/server/permission/ws => test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest}/search_project_permissions-example.json (100%) create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/display_all_project_permissions.json rename server/sonar-server/src/{main/resources/org/sonar/server/permission/ws/template => test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest}/search_templates-example.json (67%) create mode 100644 sonar-db/src/test/java/org/sonar/core/permission/ProjectPermissionsTest.java diff --git a/server/sonar-server/src/test/java/org/sonar/server/i18n/I18nRule.java b/server/sonar-server/src/test/java/org/sonar/server/i18n/I18nRule.java index d84f5af8070..a47bbf2dac4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/i18n/I18nRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/i18n/I18nRule.java @@ -47,6 +47,9 @@ public class I18nRule implements I18n { put("projects_role.user.desc", "Ability to access a project, browse its measures, and create/edit issues for it."); put("projects_role.codeviewer", "See Source Code"); put("projects_role.codeviewer.desc", "Ability to view the project's source code. (Users will also need \"Browse\" permission)"); + put("projects_role.scan", "Execute Analysis"); + put("projects_role.scan.desc", + "Ability to execute analyses, and to get all settings required to perform the analysis, even the secured ones like the scm account password, the jira account password, and so on."); } @Override diff --git a/server/sonar-server/src/test/java/org/sonar/server/i18n/package-info.java b/server/sonar-server/src/test/java/org/sonar/server/i18n/package-info.java new file mode 100644 index 00000000000..7496b24b5d0 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/i18n/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube :: Server + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonar.server.i18n; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeTest.java index 74a1d2c2e7f..3f49b085e57 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeTest.java @@ -20,14 +20,13 @@ package org.sonar.server.permission; import com.google.common.collect.Maps; +import java.util.Map; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.core.permission.GlobalPermissions; import org.sonar.server.exceptions.BadRequestException; -import java.util.Map; - import static org.assertj.core.api.Assertions.assertThat; public class PermissionChangeTest { @@ -132,7 +131,7 @@ public class PermissionChangeTest { PermissionChange query = PermissionChange.buildFromParams(inconsistentParams); thrown.expect(BadRequestException.class); - thrown.expectMessage("Invalid component permission key invalid. Valid values are [user, admin, issueadmin, codeviewer]"); + thrown.expectMessage("Invalid component permission key invalid. Valid values are [user, admin, issueadmin, codeviewer, scan]"); query.validate(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java index 0bb33521bed..a62135b767b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java @@ -91,7 +91,7 @@ public class SearchGlobalPermissionsActionTest { String result = ws.newRequest().execute().getInput(); - assertJson(result).isSimilarTo(getClass().getResource("search_global_permissions-example.json")); + assertJson(result).isSimilarTo(getClass().getResource("SearchGlobalPermissionsActionTest/search_global_permissions-example.json")); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java index e75dd0f3cba..4418c01f249 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java @@ -135,14 +135,18 @@ public class SearchProjectPermissionsActionTest { String result = ws.newRequest().execute().getInput(); - assertJson(result).isSimilarTo(getClass().getResource("search_project_permissions-example.json")); + assertJson(result) + .ignoreFields("permissions") + .isSimilarTo(getClass().getResource("SearchProjectPermissionsActionTest/search_project_permissions-example.json")); } @Test public void empty_result() { String result = ws.newRequest().execute().getInput(); - assertJson(result).isSimilarTo(getClass().getResource("SearchProjectPermissionsActionTest/empty.json")); + assertJson(result) + .ignoreFields("permissions") + .isSimilarTo(getClass().getResource("SearchProjectPermissionsActionTest/empty.json")); } @Test @@ -275,6 +279,15 @@ public class SearchProjectPermissionsActionTest { ws.newRequest().execute(); } + @Test + public void display_all_project_permissions() { + String result = ws.newRequest().execute().getInput(); + + assertJson(result) + .ignoreFields("permissions") + .isSimilarTo(getClass().getResource("SearchProjectPermissionsActionTest/display_all_project_permissions.json")); + } + private ComponentDto insertView() { return insertComponent(newView() .setUuid("752d8bfd-420c-4a83-a4e5-8ab19b13c8fc") 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 47be8ed0b8a..b457f74a154 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 @@ -136,7 +136,8 @@ public class SearchTemplatesActionTest { assertJson(result) .withStrictArrayOrder() - .isSimilarTo(getClass().getResource("search_templates-example.json")); + .ignoreFields("permissions") + .isSimilarTo(getClass().getResource("SearchTemplatesActionTest/search_templates-example.json")); } @Test @@ -145,6 +146,7 @@ public class SearchTemplatesActionTest { assertJson(result) .withStrictArrayOrder() + .ignoreFields("permissions") .isSimilarTo(getClass().getResource("SearchTemplatesActionTest/empty.json")); } @@ -180,6 +182,16 @@ public class SearchTemplatesActionTest { ws.newRequest().execute(); } + @Test + public void display_all_project_permissions() { + String result = newRequest(); + + assertJson(result) + .withStrictArrayOrder() + .ignoreFields("defaultTemplates", "permissionTemplates") + .isSimilarTo(getClass().getResource("SearchTemplatesActionTest/display_all_project_permissions.json")); + } + private String newRequest() { return ws.newRequest().execute().getInput(); } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/permission/ws/search_global_permissions-example.json b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest/search_global_permissions-example.json similarity index 100% rename from server/sonar-server/src/main/resources/org/sonar/server/permission/ws/search_global_permissions-example.json rename to server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest/search_global_permissions-example.json diff --git a/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/display_all_project_permissions.json b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/display_all_project_permissions.json new file mode 100644 index 00000000000..5789d2975ed --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/display_all_project_permissions.json @@ -0,0 +1,30 @@ +{ + "projects": [], + "permissions": [ + { + "key": "user", + "name": "Browse", + "description": "Ability to access a project, browse its measures, and create/edit issues for it." + }, + { + "key": "admin", + "name": "Administer", + "description": "Ability to access project settings and perform administration tasks. (Users will also need \"Browse\" permission)" + }, + { + "key": "issueadmin", + "name": "Administer Issues", + "description": "Grants the permission to perform advanced editing on issues: marking an issue False Positive / Won't Fix or changing an Issue's severity. (Users will also need \"Browse\" permission)" + }, + { + "key": "codeviewer", + "name": "See Source Code", + "description": "Ability to view the project's source code. (Users will also need \"Browse\" permission)" + } + ], + "paging": { + "pageIndex": 1, + "pageSize": 25, + "total": 0 + } +} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/empty.json b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/empty.json index 5789d2975ed..acd810938d2 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/empty.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/empty.json @@ -1,27 +1,5 @@ { "projects": [], - "permissions": [ - { - "key": "user", - "name": "Browse", - "description": "Ability to access a project, browse its measures, and create/edit issues for it." - }, - { - "key": "admin", - "name": "Administer", - "description": "Ability to access project settings and perform administration tasks. (Users will also need \"Browse\" permission)" - }, - { - "key": "issueadmin", - "name": "Administer Issues", - "description": "Grants the permission to perform advanced editing on issues: marking an issue False Positive / Won't Fix or changing an Issue's severity. (Users will also need \"Browse\" permission)" - }, - { - "key": "codeviewer", - "name": "See Source Code", - "description": "Ability to view the project's source code. (Users will also need \"Browse\" permission)" - } - ], "paging": { "pageIndex": 1, "pageSize": 25, diff --git a/server/sonar-server/src/main/resources/org/sonar/server/permission/ws/search_project_permissions-example.json b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/search_project_permissions-example.json similarity index 100% rename from server/sonar-server/src/main/resources/org/sonar/server/permission/ws/search_project_permissions-example.json rename to server/sonar-server/src/test/resources/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest/search_project_permissions-example.json diff --git a/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/display_all_project_permissions.json b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/display_all_project_permissions.json new file mode 100644 index 00000000000..c6ae975a7a2 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/display_all_project_permissions.json @@ -0,0 +1,29 @@ +{ + "permissions": [ + { + "key": "user", + "name": "Browse", + "description": "Ability to access a project, browse its measures, and create/edit issues for it." + }, + { + "key": "admin", + "name": "Administer", + "description": "Ability to access project settings and perform administration tasks. (Users will also need \"Browse\" permission)" + }, + { + "key": "issueadmin", + "name": "Administer Issues", + "description": "Grants the permission to perform advanced editing on issues: marking an issue False Positive / Won't Fix or changing an Issue's severity. (Users will also need \"Browse\" permission)" + }, + { + "key": "codeviewer", + "name": "See Source Code", + "description": "Ability to view the project's source code. (Users will also need \"Browse\" permission)" + }, + { + "key": "scan", + "name": "Execute Analysis", + "description": "Ability to execute analyses, and to get all settings required to perform the analysis, even the secured ones like the scm account password, the jira account password, and so on." + } + ] +} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/empty.json b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/empty.json index 985f39eaa92..a3041228330 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/empty.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/empty.json @@ -13,27 +13,5 @@ "templateId": "AU-TpxcA-iU5OvuD2FL0", "qualifier": "DEV" } - ], - "permissions": [ - { - "key": "user", - "name": "Browse", - "description": "Ability to access a project, browse its measures, and create/edit issues for it." - }, - { - "key": "admin", - "name": "Administer", - "description": "Ability to access project settings and perform administration tasks. (Users will also need \"Browse\" permission)" - }, - { - "key": "issueadmin", - "name": "Administer Issues", - "description": "Grants the permission to perform advanced editing on issues: marking an issue False Positive / Won't Fix or changing an Issue's severity. (Users will also need \"Browse\" permission)" - }, - { - "key": "codeviewer", - "name": "See Source Code", - "description": "Ability to view the project's source code. (Users will also need \"Browse\" permission)" - } ] } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/permission/ws/template/search_templates-example.json b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/search_templates-example.json similarity index 67% rename from server/sonar-server/src/main/resources/org/sonar/server/permission/ws/template/search_templates-example.json rename to server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/search_templates-example.json index 523c5ebf1d3..75d69f5b497 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/permission/ws/template/search_templates-example.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/permission/ws/template/SearchTemplatesActionTest/search_templates-example.json @@ -72,27 +72,5 @@ "templateId": "AU-TpxcA-iU5OvuD2FL0", "qualifier": "DEV" } - ], - "permissions": [ - { - "key": "user", - "name": "Browse", - "description": "Ability to access a project, browse its measures, and create/edit issues for it." - }, - { - "key": "admin", - "name": "Administer", - "description": "Ability to access project settings and perform administration tasks. (Users will also need \"Browse\" permission)" - }, - { - "key": "issueadmin", - "name": "Administer Issues", - "description": "Grants the permission to perform advanced editing on issues: marking an issue False Positive / Won\u0027t Fix or changing an Issue\u0027s severity. (Users will also need \"Browse\" permission)" - }, - { - "key": "codeviewer", - "name": "See Source Code", - "description": "Ability to view the project\u0027s source code. (Users will also need \"Browse\" permission)" - } ] } diff --git a/server/sonar-web/src/main/js/apps/permission-templates/main.js b/server/sonar-web/src/main/js/apps/permission-templates/main.js index 122c573dc54..178b99425ed 100644 --- a/server/sonar-web/src/main/js/apps/permission-templates/main.js +++ b/server/sonar-web/src/main/js/apps/permission-templates/main.js @@ -23,7 +23,7 @@ import Header from './header'; import PermissionTemplates from './permission-templates'; import { getPermissionTemplates } from '../../api/permissions'; -const PERMISSIONS_ORDER = ['user', 'codeviewer', 'issueadmin', 'admin']; +const PERMISSIONS_ORDER = ['user', 'codeviewer', 'issueadmin', 'admin', 'scan']; export default React.createClass({ propTypes: { diff --git a/server/sonar-web/src/main/js/apps/project-permissions/main.js b/server/sonar-web/src/main/js/apps/project-permissions/main.js index 7028384ff6a..a3fcacfa7e0 100644 --- a/server/sonar-web/src/main/js/apps/project-permissions/main.js +++ b/server/sonar-web/src/main/js/apps/project-permissions/main.js @@ -28,7 +28,7 @@ import ApplyTemplateView from './apply-template-view'; import { translate } from '../../helpers/l10n'; -const PERMISSIONS_ORDER = ['user', 'codeviewer', 'issueadmin', 'admin']; +const PERMISSIONS_ORDER = ['user', 'codeviewer', 'issueadmin', 'admin', 'scan']; export default React.createClass({ diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 22198010256..a1b3baa9830 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2841,6 +2841,8 @@ projects_role.user=Browse projects_role.user.desc=Access a project, browse its measures, and create/edit issues for it. projects_role.codeviewer=See Source Code projects_role.codeviewer.desc=View the project's source code. (Users will also need "Browse" permission) +projects_role.scan=Execute Analysis +projects_role.scan.desc=Ability to execute analyses, and to get all settings required to perform the analysis, even the secured ones like the scm account password, the jira account password, and so on. projects_role.bulk_change=Bulk Change projects_role.apply_template=Apply Permission Template projects_role.apply_template_to_xxx=Apply Permission Template To "{0}" diff --git a/sonar-db/src/main/java/org/sonar/core/permission/ProjectPermissions.java b/sonar-db/src/main/java/org/sonar/core/permission/ProjectPermissions.java index 0db669d7069..0d46709d912 100644 --- a/sonar-db/src/main/java/org/sonar/core/permission/ProjectPermissions.java +++ b/sonar-db/src/main/java/org/sonar/core/permission/ProjectPermissions.java @@ -30,13 +30,14 @@ import org.sonar.api.web.UserRole; */ public final class ProjectPermissions { - private ProjectPermissions() { - // static constants only - } - /** - * All the component permissions values, ordered from {@link UserRole#USER} to {@link UserRole#CODEVIEWER}. + * All the component permissions values, ordered from {@link UserRole#USER} to {@link GlobalPermissions#SCAN_EXECUTION}. */ - public static final List ALL = ImmutableList.of(UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.CODEVIEWER); + public static final List ALL = ImmutableList.of(UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.CODEVIEWER, GlobalPermissions.SCAN_EXECUTION); + public static final String ALL_ON_ONE_LINE = Joiner.on(", ").join(ProjectPermissions.ALL); + + private ProjectPermissions() { + // static constants only + } } diff --git a/sonar-db/src/test/java/org/sonar/core/permission/ProjectPermissionsTest.java b/sonar-db/src/test/java/org/sonar/core/permission/ProjectPermissionsTest.java new file mode 100644 index 00000000000..7b5d6465924 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/core/permission/ProjectPermissionsTest.java @@ -0,0 +1,38 @@ +/* + * SonarQube :: Database + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.permission; + +import org.junit.Test; +import org.sonar.api.web.UserRole; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ProjectPermissionsTest { + + @Test + public void all_permissions() throws Exception { + assertThat(ProjectPermissions.ALL).containsOnly(UserRole.USER, UserRole.ADMIN, UserRole.ISSUE_ADMIN, UserRole.CODEVIEWER, GlobalPermissions.SCAN_EXECUTION); + } + + @Test + public void all_permissions_as_string() throws Exception { + assertThat(ProjectPermissions.ALL_ON_ONE_LINE).isEqualTo("user, admin, issueadmin, codeviewer, scan"); + } +} -- 2.39.5