public ExpectedException expectedException = ExpectedException.none();
private final Random random = new Random();
- private DbClient dbClient = dbTester.getDbClient();
- private NotificationService notificationService = mock(NotificationService.class);
- private ReportAnalysisFailureNotificationSerializer serializer = mock(ReportAnalysisFailureNotificationSerializer.class);
- private System2 system2 = mock(System2.class);
- private DbClient dbClientMock = mock(DbClient.class);
- private CeTask ceTaskMock = mock(CeTask.class);
- private Throwable throwableMock = mock(Throwable.class);
- private CeTaskResult ceTaskResultMock = mock(CeTaskResult.class);
- private ReportAnalysisFailureNotificationExecutionListener fullMockedUnderTest = new ReportAnalysisFailureNotificationExecutionListener(
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final NotificationService notificationService = mock(NotificationService.class);
+ private final ReportAnalysisFailureNotificationSerializer serializer = mock(ReportAnalysisFailureNotificationSerializer.class);
+ private final System2 system2 = mock(System2.class);
+ private final DbClient dbClientMock = mock(DbClient.class);
+ private final CeTask ceTaskMock = mock(CeTask.class);
+ private final Throwable throwableMock = mock(Throwable.class);
+ private final CeTaskResult ceTaskResultMock = mock(CeTaskResult.class);
+ private final ReportAnalysisFailureNotificationExecutionListener fullMockedUnderTest = new ReportAnalysisFailureNotificationExecutionListener(
notificationService, dbClientMock, serializer, system2);
- private ReportAnalysisFailureNotificationExecutionListener underTest = new ReportAnalysisFailureNotificationExecutionListener(
+ private final ReportAnalysisFailureNotificationExecutionListener underTest = new ReportAnalysisFailureNotificationExecutionListener(
notificationService, dbClient, serializer, system2);
@Before
.setTaskType(CeTaskTypes.REPORT)
.setComponentUuid(project.uuid())
.setCreatedAt(createdAt))
- .setExecutedAt(executedAt)
- .setStatus(CeActivityDto.Status.FAILED));
+ .setExecutedAt(executedAt)
+ .setStatus(CeActivityDto.Status.FAILED));
dbTester.getSession().commit();
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.organization;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import static java.util.Objects.requireNonNull;
-
-public class DefaultTemplates {
- // Hold the template uuid for new projects
- private String projectUuid;
- // Hold the template uuid for new applications
- private String applicationsUuid;
- // Hold the template uuid for new portfolios
- private String portfoliosUuid;
-
- public String getProjectUuid() {
- checkProjectNotNull(this.projectUuid);
- return this.projectUuid;
- }
-
- public DefaultTemplates setProjectUuid(String projectUuid) {
- checkProjectNotNull(projectUuid);
- this.projectUuid = projectUuid;
- return this;
- }
-
- private static void checkProjectNotNull(String project) {
- requireNonNull(project, "defaultTemplates.project can't be null");
- }
-
- @CheckForNull
- public String getApplicationsUuid() {
- return applicationsUuid;
- }
-
- public DefaultTemplates setApplicationsUuid(@Nullable String applicationsUuid) {
- this.applicationsUuid = applicationsUuid;
- return this;
- }
-
- @CheckForNull
- public String getPortfoliosUuid() {
- return portfoliosUuid;
- }
-
- public DefaultTemplates setPortfoliosUuid(@Nullable String portfoliosUuid) {
- this.portfoliosUuid = portfoliosUuid;
- return this;
- }
-
- @Override
- public String toString() {
- return "DefaultTemplates{" +
- "projectUuid='" + projectUuid + '\'' +
- ", portfoliosUuid='" + portfoliosUuid + '\'' +
- ", applicationsUuid='" + applicationsUuid + '\'' +
- '}';
- }
-}
import org.sonar.db.Pagination;
import org.sonar.db.alm.ALM;
import org.sonar.db.component.BranchType;
+import org.sonar.db.permission.template.DefaultTemplates;
import org.sonar.db.qualitygate.QGateWithOrgDto;
import org.sonar.db.user.GroupDto;
import org.apache.ibatis.annotations.Param;
import org.sonar.db.Pagination;
import org.sonar.db.component.BranchType;
+import org.sonar.db.permission.template.DefaultTemplates;
public interface OrganizationMapper {
void insert(@Param("organization") OrganizationDto organization, @Param("newProjectPrivate") boolean newProjectPrivate);
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info 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.db.permission.template;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static java.util.Objects.requireNonNull;
+
+public class DefaultTemplates {
+ // Hold the template uuid for new projects
+ private String projectUuid;
+ // Hold the template uuid for new applications
+ private String applicationsUuid;
+ // Hold the template uuid for new portfolios
+ private String portfoliosUuid;
+
+ public DefaultTemplates() {
+ // nothing to do here
+ }
+
+ public String getProjectUuid() {
+ checkProjectNotNull(this.projectUuid);
+ return this.projectUuid;
+ }
+
+ public DefaultTemplates setProjectUuid(String projectUuid) {
+ checkProjectNotNull(projectUuid);
+ this.projectUuid = projectUuid;
+ return this;
+ }
+
+ private static void checkProjectNotNull(String project) {
+ requireNonNull(project, "defaultTemplates.project can't be null");
+ }
+
+ @CheckForNull
+ public String getApplicationsUuid() {
+ return applicationsUuid;
+ }
+
+ public DefaultTemplates setApplicationsUuid(@Nullable String applicationsUuid) {
+ this.applicationsUuid = applicationsUuid;
+ return this;
+ }
+
+ @CheckForNull
+ public String getPortfoliosUuid() {
+ return portfoliosUuid;
+ }
+
+ public DefaultTemplates setPortfoliosUuid(@Nullable String portfoliosUuid) {
+ this.portfoliosUuid = portfoliosUuid;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "DefaultTemplates{" +
+ "projectUuid='" + projectUuid + '\'' +
+ ", portfoliosUuid='" + portfoliosUuid + '\'' +
+ ", applicationsUuid='" + applicationsUuid + '\'' +
+ '}';
+ }
+}
org.uuid = #{uuid, jdbcType=VARCHAR}
</select>
- <select id="selectDefaultTemplatesByUuid" resultType="org.sonar.db.organization.DefaultTemplates">
+ <select id="selectDefaultTemplatesByUuid" resultType="org.sonar.db.permission.template.DefaultTemplates">
select
<include refid="defaultTemplatesColumns"/>
from organizations org
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.organization;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultTemplatesTest {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- private DefaultTemplates underTest = new DefaultTemplates();
-
- @Test
- public void setProject_throws_NPE_if_argument_is_null() {
- expectedException.expect(NullPointerException.class);
- expectedException.expectMessage("defaultTemplates.project can't be null");
-
- underTest.setProjectUuid(null);
- }
-
- @Test
- public void getProject_throws_NPE_if_project_is_null() {
- expectedException.expect(NullPointerException.class);
- expectedException.expectMessage("defaultTemplates.project can't be null");
-
- underTest.getProjectUuid();
- }
-
- @Test
- public void setApplicationsUuid_accepts_null() {
- underTest.setApplicationsUuid(null);
- }
-
- @Test
- public void setPortfoliosUuid_accepts_null() {
- underTest.setPortfoliosUuid(null);
- }
-
- @Test
- public void check_toString() {
- assertThat(underTest.toString()).isEqualTo("DefaultTemplates{projectUuid='null', portfoliosUuid='null', applicationsUuid='null'}");
- underTest
- .setProjectUuid("a project")
- .setApplicationsUuid("an application")
- .setPortfoliosUuid("a portfolio");
- assertThat(underTest.toString()).isEqualTo("DefaultTemplates{projectUuid='a project', portfoliosUuid='a portfolio', applicationsUuid='an application'}");
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info 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.db.permission.template;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DefaultTemplatesTest {
+
+ private final DefaultTemplates underTest = new DefaultTemplates();
+
+ @Test
+ public void setProject_throws_NPE_if_argument_is_null() {
+ assertThatThrownBy(() -> underTest.setProjectUuid(null))
+ .isInstanceOf(NullPointerException.class)
+ .hasMessage("defaultTemplates.project can't be null");
+ }
+
+ @Test
+ public void getProject_throws_NPE_if_project_is_null() {
+ assertThatThrownBy(underTest::getProjectUuid)
+ .isInstanceOf(NullPointerException.class)
+ .hasMessage("defaultTemplates.project can't be null");
+ }
+
+ @Test
+ public void setProjectU() {
+ String uuid = "uuid-1";
+ underTest.setProjectUuid(uuid);
+
+ assertThat(underTest.getProjectUuid()).isEqualTo(uuid);
+ }
+
+ @Test
+ public void setApplicationsUuid_accepts_null() {
+ underTest.setApplicationsUuid(null);
+
+ assertThat(underTest.getApplicationsUuid()).isNull();
+ }
+
+ @Test
+ public void setPortfoliosUuid_accepts_null() {
+ underTest.setPortfoliosUuid(null);
+
+ assertThat(underTest.getPortfoliosUuid()).isNull();
+ }
+
+ @Test
+ public void check_toString() {
+ assertThat(underTest).hasToString("DefaultTemplates{projectUuid='null', portfoliosUuid='null', applicationsUuid='null'}");
+ underTest
+ .setProjectUuid("a project")
+ .setApplicationsUuid("an application")
+ .setPortfoliosUuid("a portfolio");
+ assertThat(underTest).hasToString("DefaultTemplates{projectUuid='a project', portfoliosUuid='a portfolio', applicationsUuid='an application'}");
+ }
+}
.setQualifier(Qualifiers.VIEW);
}
+ public static ComponentDto newApplication() {
+ return newView(Uuids.createFast()).setQualifier(Qualifiers.APP);
+ }
+
public static ComponentDto newApplication(OrganizationDto organizationDto) {
return newApplication(organizationDto.getUuid());
}
import javax.annotation.Nullable;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.permission.template.DefaultTemplates;
import org.sonar.db.user.UserDto;
//TODO remove
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.organization.DefaultTemplates;
+import org.sonar.db.permission.template.DefaultTemplates;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationMemberDto;
import org.sonar.db.permission.GlobalPermission;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.db.DbSession;
-import org.sonar.db.organization.DefaultTemplates;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
import org.sonar.server.es.ProjectIndexers;
/**
- * Add or remove global/project permissions to a group. This class
- * does not verify that caller has administration right on the related
- * organization or project.
+ * Add or remove global/project permissions to a group. This class does not verify that caller has administration right on the related project.
*/
public class PermissionUpdater {
package org.sonar.server.permission.ws;
import java.util.Optional;
-import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
"</ul>")
.setSince("5.2")
.setPost(true)
- .setHandler(this)
- .setChangelog(
- new Change("7.4", "If organizationKey and projectId are both set, the organisationKey must be the key of the organization of the project"));
+ .setHandler(this);
wsParameters.createPermissionParameter(action, "The permission you would like to grant to the user");
createUserLoginParameter(action);
private static class AddProjectCreatorToTemplateRequest {
private final String templateId;
- private final String organization;
private final String templateName;
private final String permission;
private AddProjectCreatorToTemplateRequest(Builder builder) {
this.templateId = builder.templateId;
- this.organization = builder.organization;
this.templateName = builder.templateName;
this.permission = requireNonNull(builder.permission);
}
return templateId;
}
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
@CheckForNull
public String getTemplateName() {
return templateName;
private static class Builder {
private String templateId;
- private String organization;
private String templateName;
private String permission;
return this;
}
- public Builder setOrganization(@Nullable String s) {
- this.organization = s;
- return this;
- }
-
public Builder setTemplateName(@Nullable String templateName) {
this.templateName = templateName;
return this;
private String login;
private String permission;
private String templateId;
- private String organization;
private String templateName;
public String getLogin() {
this.templateName = templateName;
return this;
}
-
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
- public AddUserToTemplateRequest setOrganization(@Nullable String s) {
- this.organization = s;
- return this;
- }
}
}
action.createParam(PARAM_VISIBILITY)
.setDescription("Filter the projects that should be visible to everyone (%s), or only specific user/groups (%s).<br/>" +
- "If no visibility is specified, the default project visibility of the organization will be used.",
+ "If no visibility is specified, the default project visibility will be used.",
Visibility.PUBLIC.getLabel(), Visibility.PRIVATE.getLabel())
.setRequired(false)
.setInternal(true)
private static class BulkApplyTemplateRequest {
private String templateId;
- private String organization;
private String templateName;
private String query;
private Collection<String> qualifiers = singleton(Qualifiers.PROJECT);
return this;
}
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
- public BulkApplyTemplateRequest setOrganization(@Nullable String s) {
- this.organization = s;
- return this;
- }
-
@CheckForNull
public String getTemplateName() {
return templateName;
private String description;
private String name;
private String projectKeyPattern;
- private String organization;
@CheckForNull
public String getDescription() {
this.projectKeyPattern = projectKeyPattern;
return this;
}
-
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
- public CreateTemplateRequest setOrganization(@Nullable String s) {
- this.organization = s;
- return this;
- }
}
}
private static class RemoveProjectCreatorFromTemplateRequest {
private final String templateId;
- private final String organization;
private final String templateName;
private final String permission;
private RemoveProjectCreatorFromTemplateRequest(Builder builder) {
this.templateId = builder.templateId;
- this.organization = builder.organization;
this.templateName = builder.templateName;
this.permission = requireNonNull(builder.permission);
}
return templateId;
}
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
@CheckForNull
public String getTemplateName() {
return templateName;
public static class Builder {
private String templateId;
- private String organization;
private String templateName;
private String permission;
return this;
}
- public Builder setOrganization(@Nullable String s) {
- this.organization = s;
- return this;
- }
-
public Builder setTemplateName(@Nullable String templateName) {
this.templateName = templateName;
return this;
private String login;
private String permission;
private String templateId;
- private String organization;
private String templateName;
public String getLogin() {
return this;
}
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
- public RemoveUserFromTemplateRequest setOrganization(@Nullable String s) {
- this.organization = s;
- return this;
- }
-
@CheckForNull
public String getTemplateName() {
return templateName;
@Rule
public DbTester dbTester = DbTester.create();
- private ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers(PROJECT, VIEW, APP);
- private DefaultTemplatesResolver defaultTemplatesResolver = new DefaultTemplatesResolverImpl(dbTester.getDbClient(), resourceTypesRule);
- private PermissionService permissionService = new PermissionServiceImpl(resourceTypesRule);
- private UserSessionRule userSession = UserSessionRule.standalone();
- private PermissionTemplateDbTester templateDb = dbTester.permissionTemplates();
- private DbSession session = dbTester.getSession();
- private ProjectIndexers projectIndexers = new TestProjectIndexers();
-
- private PermissionTemplateService underTest = new PermissionTemplateService(dbTester.getDbClient(), projectIndexers, userSession, defaultTemplatesResolver,
+ private final ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers(PROJECT, VIEW, APP);
+ private final DefaultTemplatesResolver defaultTemplatesResolver = new DefaultTemplatesResolverImpl(dbTester.getDbClient(), resourceTypesRule);
+ private final PermissionService permissionService = new PermissionServiceImpl(resourceTypesRule);
+ private final UserSessionRule userSession = UserSessionRule.standalone();
+ private final PermissionTemplateDbTester templateDb = dbTester.permissionTemplates();
+ private final DbSession session = dbTester.getSession();
+ private final ProjectIndexers projectIndexers = new TestProjectIndexers();
+ private final PermissionTemplateService underTest = new PermissionTemplateService(dbTester.getDbClient(), projectIndexers, userSession, defaultTemplatesResolver,
new SequenceUuidFactory());
@Test
@Test
public void apply_default_template_on_portfolio() {
- ComponentDto view = dbTester.components().insertPublicPortfolio(dbTester.getDefaultOrganization());
+ ComponentDto view = dbTester.components().insertPublicPortfolio();
PermissionTemplateDto projectPermissionTemplate = dbTester.permissionTemplates().insertTemplate();
PermissionTemplateDto portPermissionTemplate = dbTester.permissionTemplates().insertTemplate();
GroupDto group = dbTester.users().insertGroup();
@Test
public void apply_adds_any_global_permission_to_user() {
- permissionService.getGlobalPermissions().stream()
+ permissionService.getGlobalPermissions()
.forEach(perm -> {
UserPermissionChange change = new UserPermissionChange(ADD, perm.getKey(), null, UserId.from(user1), permissionService);
}
@Test
- public void apply_removes_any_organization_permission_to_user() {
+ public void apply_removes_any_global_permission_to_user() {
// give ADMIN perm to user2 so that user1 is not the only one with this permission and it can be removed from user1
db.users().insertPermissionOnUser(user2, GlobalPermission.ADMINISTER);
- permissionService.getGlobalPermissions().stream()
+ permissionService.getGlobalPermissions()
.forEach(perm -> db.users().insertPermissionOnUser(user1, perm));
assertThat(db.users().selectPermissionsOfUser(user1))
.containsOnly(permissionService.getGlobalPermissions().toArray(new GlobalPermission[0]));
- permissionService.getGlobalPermissions().stream()
+ permissionService.getGlobalPermissions()
.forEach(perm -> {
UserPermissionChange change = new UserPermissionChange(REMOVE, perm.getKey(), null, UserId.from(user1), permissionService);
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubView;
+import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
+import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
import static org.sonar.db.permission.GlobalPermission.SCAN;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
private static final String A_PROJECT_UUID = "project-uuid";
private static final String A_PROJECT_KEY = "project-key";
- private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
- private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
- private WsParameters wsParameters = new WsParameters(permissionService);
+ private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+ private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+ private final WsParameters wsParameters = new WsParameters(permissionService);
@Override
protected AddGroupAction buildWsAction() {
newRequest()
.setParam(PARAM_GROUP_NAME, "sonar-administrators")
- .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
+ .setParam(PARAM_PERMISSION, ADMINISTER.getKey())
.execute();
- assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(SYSTEM_ADMIN);
+ assertThat(db.users().selectGroupPermissions(group, null)).containsOnly("admin");
}
@Test
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
- .setParam(PARAM_PERMISSION, PROVISIONING)
+ .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey())
.execute();
- assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(PROVISIONING);
+ assertThat(db.users().selectGroupPermissions(group, null)).containsOnly("provisioning");
}
@Test
@Test
public void add_permission_to_project_referenced_by_its_id() {
GroupDto group = db.users().insertGroup("sonar-administrators");
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setDbKey(A_PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(A_PROJECT_UUID).setDbKey(A_PROJECT_KEY));
loginAsAdmin();
newRequest()
@Test
public void add_permission_to_project_referenced_by_its_key() {
GroupDto group = db.users().insertGroup("sonar-administrators");
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setDbKey(A_PROJECT_KEY));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto(A_PROJECT_UUID).setDbKey(A_PROJECT_KEY));
loginAsAdmin();
newRequest()
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
- .setParam(PARAM_PERMISSION, PROVISIONING)
+ .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey())
.execute();
}
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
- .setParam(PARAM_PERMISSION, PROVISIONING)
+ .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey())
.setParam(PARAM_PROJECT_KEY, project.getDbKey())
.execute();
}
@Test
public void add_permission_to_view() {
- ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid").setDbKey("view-key"));
+ ComponentDto view = db.components().insertComponent(newView( "view-uuid").setDbKey("view-key"));
loginAsAdmin();
newRequest()
userSession.logIn().addPermission(ADMINISTER);
}
- protected PermissionTemplateDto selectTemplateInDefaultOrganization(String name) {
+ protected PermissionTemplateDto selectPermissionTemplate(String name) {
return db.getDbClient().permissionTemplateDao().selectByName(db.getSession(), name);
}
db.commit();
return dto;
}
-
- protected PermissionTemplateDto addTemplateToDefaultOrganization() {
- return addTemplate();
- }
}
private GroupDto group1;
private GroupDto group2;
- private GroupDto group3;
- private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
- private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
- private WsParameters wsParameters = new WsParameters(permissionService);
+ private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+ private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+ private final WsParameters wsParameters = new WsParameters(permissionService);
@Override
protected GroupsAction buildWsAction() {
public void setUp() {
group1 = db.users().insertGroup("group-1-name");
group2 = db.users().insertGroup("group-2-name");
- group3 = db.users().insertGroup("group-3-name");
+ GroupDto group3 = db.users().insertGroup("group-3-name");
db.users().insertPermissionOnGroup(group1, SCAN);
db.users().insertPermissionOnGroup(group2, SCAN);
db.users().insertPermissionOnGroup(group3, ADMINISTER);
@Test
public void return_only_groups_with_permission_when_no_search_query() {
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto("project-uuid"));
GroupDto group = db.users().insertGroup("project-group-name");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
@Test
public void search_groups_on_views() {
- ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid").setDbKey("view-key"));
+ ComponentDto view = db.components().insertComponent(newView("view-uuid").setDbKey("view-key"));
GroupDto group = db.users().insertGroup("project-group-name");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, view);
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.web.UserRole;
-import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ResourceTypesRule;
public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<SearchProjectPermissionsAction> {
- private ComponentDbTester componentDb = new ComponentDbTester(db);
- private I18nRule i18n = new I18nRule();
- private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
- private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+ private final I18nRule i18n = new I18nRule();
+ private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+ private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
@Before
public void setUp() {
@Test
public void search_project_permissions_with_project_permission() {
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto("project-uuid"));
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
String result = newRequest()
@Test
public void handle_more_than_1000_projects() {
- IntStream.rangeClosed(1, 1001).forEach(i -> {
- db.components().insertPrivateProject("project-uuid-" + i);
- });
+ IntStream.rangeClosed(1, 1001).forEach(i -> db.components().insertPrivateProject("project-uuid-" + i));
String result = newRequest()
.setParam(TEXT_QUERY, "project")
}
private ComponentDto insertView() {
- return db.components().insertComponent(newView(db.getDefaultOrganization())
+ return db.components().insertComponent(newView()
.setUuid("752d8bfd-420c-4a83-a4e5-8ab19b13c8fc")
.setName("Java")
.setDbKey("Java"));
}
- private ComponentDto insertProjectInView(ComponentDto project, ComponentDto view) {
- return db.components().insertComponent(newProjectCopy("project-in-view-uuid", project, view));
+ private void insertProjectInView(ComponentDto project, ComponentDto view) {
+ db.components().insertComponent(newProjectCopy("project-in-view-uuid", project, view));
}
private ComponentDto insertClang() {
- return db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "project-uuid-2")
+ return db.components().insertComponent(newPrivateProjectDto("project-uuid-2")
.setName("Clang")
.setDbKey("clang")
.setUuid("ce4c03d6-430f-40a9-b777-ad877c00aa4d"));
}
private ComponentDto insertJdk7() {
- return db.components().insertComponent(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization())
+ return db.components().insertComponent(ComponentTesting.newPublicProjectDto()
.setName("JDK 7")
.setDbKey("net.java.openjdk:jdk7")
.setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a"));
private GroupDto group1;
private GroupDto group2;
private PermissionTemplateDto template1;
- private PermissionTemplateDto template2;
- private ProjectIndexers projectIndexers = new TestProjectIndexers();
-
- private ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers(PROJECT, VIEW, APP);
- private DefaultTemplatesResolver defaultTemplatesResolver = new DefaultTemplatesResolverImpl(db.getDbClient(), resourceTypesRule);
+ private final ProjectIndexers projectIndexers = new TestProjectIndexers();
+ private final ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers(PROJECT, VIEW, APP);
+ private final DefaultTemplatesResolver defaultTemplatesResolver = new DefaultTemplatesResolverImpl(db.getDbClient(), resourceTypesRule);
@Override
protected BulkApplyTemplateAction buildWsAction() {
addGroupToTemplate(group1, template1, UserRole.ADMIN);
addGroupToTemplate(group2, template1, UserRole.USER);
// template 2
- template2 = db.permissionTemplates().insertTemplate();
+ PermissionTemplateDto template2 = db.permissionTemplates().insertTemplate();
addUserToTemplate(user1, template2, UserRole.USER);
addUserToTemplate(user2, template2, UserRole.USER);
addGroupToTemplate(group1, template2, UserRole.USER);
public void apply_template_by_qualifiers() {
ComponentDto publicProject = db.components().insertPublicProject();
ComponentDto privateProject = db.components().insertPrivateProject();
- ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization()));
- ComponentDto application = db.components().insertComponent(newApplication(db.getDefaultOrganization()));
+ ComponentDto view = db.components().insertComponent(newView());
+ ComponentDto application = db.components().insertComponent(newApplication());
loginAsAdmin();
newRequest()
@Test
public void apply_template_by_query_on_name_and_key_public_project() {
- ComponentDto publicProjectFoundByKey = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("sonar");
+ ComponentDto publicProjectFoundByKey = ComponentTesting.newPublicProjectDto().setDbKey("sonar");
db.components().insertProjectAndSnapshot(publicProjectFoundByKey);
- ComponentDto publicProjectFoundByName = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setName("name-sonar-name");
+ ComponentDto publicProjectFoundByName = ComponentTesting.newPublicProjectDto().setName("name-sonar-name");
db.components().insertProjectAndSnapshot(publicProjectFoundByName);
- ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("new-sona").setName("project-name");
+ ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto().setDbKey("new-sona").setName("project-name");
db.components().insertProjectAndSnapshot(projectUntouched);
loginAsAdmin();
@Test
public void apply_template_by_query_on_name_and_key() {
// partial match on key
- ComponentDto privateProjectFoundByKey = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("sonarqube");
+ ComponentDto privateProjectFoundByKey = ComponentTesting.newPrivateProjectDto().setDbKey("sonarqube");
db.components().insertProjectAndSnapshot(privateProjectFoundByKey);
- ComponentDto privateProjectFoundByName = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setName("name-sonar-name");
+ ComponentDto privateProjectFoundByName = ComponentTesting.newPrivateProjectDto().setName("name-sonar-name");
db.components().insertProjectAndSnapshot(privateProjectFoundByName);
- ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("new-sona").setName("project-name");
+ ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto().setDbKey("new-sona").setName("project-name");
db.components().insertProjectAndSnapshot(projectUntouched);
loginAsAdmin();
assertJson(result.getInput())
.ignoreFields("id")
.isSimilarTo(getClass().getResource("create_template-example.json"));
- PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
+ PermissionTemplateDto finance = selectPermissionTemplate("Finance");
assertThat(finance.getName()).isEqualTo("Finance");
assertThat(finance.getDescription()).isEqualTo("Permissions for financially related projects");
assertThat(finance.getKeyPattern()).isEqualTo(".*\\.finance\\..*");
newRequest("Finance", null, null);
- PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
+ PermissionTemplateDto finance = selectPermissionTemplate("Finance");
assertThat(finance.getName()).isEqualTo("Finance");
assertThat(finance.getDescription()).isNullOrEmpty();
assertThat(finance.getKeyPattern()).isNullOrEmpty();
public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroupsAction> {
- private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
- private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
- private WsParameters wsParameters = new WsParameters(permissionService);
- private RequestValidator requestValidator = new RequestValidator(permissionService);
+ private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+ private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+ private final WsParameters wsParameters = new WsParameters(permissionService);
+ private final RequestValidator requestValidator = new RequestValidator(permissionService);
@Override
protected TemplateGroupsAction buildWsAction() {
@Test
public void template_groups_of_json_example() {
- GroupDto adminGroup = insertGroupOnDefaultOrganization("sonar-administrators", "System administrators");
- GroupDto userGroup = insertGroupOnDefaultOrganization("sonar-users", "Any new users created will automatically join this group");
+ GroupDto adminGroup = insertGroup("sonar-administrators", "System administrators");
+ GroupDto userGroup = insertGroup("sonar-users", "Any new users created will automatically join this group");
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), adminGroup.getUuid()));
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), userGroup.getUuid()));
// Anyone group
@Test
public void return_all_permissions_of_matching_groups() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
GroupDto group1 = db.users().insertGroup("group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getUuid(), group1.getUuid()));
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getUuid(), null));
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
GroupDto group4 = db.users().insertGroup("group-4-name");
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group4.getUuid()));
@Test
public void search_by_permission() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
GroupDto group1 = db.users().insertGroup("group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
// Anyone
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getUuid(), group3.getUuid()));
loginAsAdmin();
GroupDto group2 = db.users().insertGroup("group-2-name");
GroupDto group3 = db.users().insertGroup("group-3-name");
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getUuid(), group2.getUuid()));
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), null));
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getUuid(), group1.getUuid()));
loginAsAdmin();
@Test
public void search_with_pagination() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
GroupDto group1 = db.users().insertGroup("group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
GroupDto group2 = db.users().insertGroup("group-2-name");
@Test
public void search_with_text_query() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
GroupDto group1 = db.users().insertGroup("group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group1.getUuid()));
GroupDto group2 = db.users().insertGroup("group-2-name");
@Test
public void search_with_text_query_return_all_groups_even_when_no_permission_set() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
db.users().insertGroup("group-1-name");
db.users().insertGroup("group-2-name");
db.users().insertGroup("group-3-name");
@Test
public void search_with_text_query_return_anyone_group_even_when_no_permission_set() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
GroupDto group = db.users().insertGroup("group");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getUuid(), group.getUuid()));
loginAsAdmin();
@Test
public void search_ignores_other_template_and_is_ordered_by_groups_with_permission_then_by_name_when_many_groups() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
PermissionTemplateDto otherTemplate = db.permissionTemplates().insertTemplate();
IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> {
GroupDto group = db.users().insertGroup("Group-" + i);
@Test
public void fail_if_not_logged_in() {
- PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template1 = addTemplate();
userSession.anonymous();
expectedException.expect(UnauthorizedException.class);
@Test
public void fail_if_insufficient_privileges() {
- PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template1 = addTemplate();
userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_template_uuid_and_name_provided() {
- PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template1 = addTemplate();
loginAsAdmin();
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_not_a_project_permission() {
loginAsAdmin();
- PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template1 = addTemplate();
expectedException.expect(IllegalArgumentException.class);
.execute();
}
- private GroupDto insertGroupOnDefaultOrganization(String name, String description) {
+ private GroupDto insertGroup(String name, String description) {
return db.users().insertGroup(newGroupDto().setName(name).setDescription(description));
}
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.web.UserRole;
-import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.component.ResourceTypesRule;
+import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.permission.template.PermissionTemplateUserDto;
import org.sonar.db.user.UserDto;
public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersAction> {
- private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
- private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
- private WsParameters wsParameters = new WsParameters(permissionService);
- private RequestValidator requestValidator = new RequestValidator(permissionService);
+ private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
+ private final PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
+ private final WsParameters wsParameters = new WsParameters(permissionService);
+ private final RequestValidator requestValidator = new RequestValidator(permissionService);
@Override
protected TemplateUsersAction buildWsAction() {
assertThat(action.isPost()).isFalse();
assertThat(action.isInternal()).isTrue();
assertThat(action.since()).isEqualTo("5.2");
- assertThat(action.param(PARAM_PERMISSION).isRequired()).isFalse();
+ WebService.Param permissionParam = action.param(PARAM_PERMISSION);
+ assertThat(permissionParam).isNotNull();
+ assertThat(permissionParam.isRequired()).isFalse();
}
@Test
UserDto user1 = insertUser(newUserDto().setLogin("admin").setName("Administrator").setEmail("admin@admin.com"));
UserDto user2 = insertUser(newUserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net"));
- PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template1 = addTemplate();
addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user1));
addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user2));
addUserToTemplate(newPermissionTemplateUser(ADMIN, template1, user2));
UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
Permissions.UsersWsResponse response = newRequest(null, null)
UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
Permissions.UsersWsResponse response = newRequest(null, null)
UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
loginAsAdmin();
UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
loginAsAdmin();
UserDto user2 = insertUser(newUserDto().setLogin("login-3").setName("name-3"));
UserDto user3 = insertUser(newUserDto().setLogin("login-1").setName("name-1"));
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
@Test
public void search_ignores_other_template_and_is_ordered_by_users_with_permission_when_many_users() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
// Add another template having some users with permission to make sure it's correctly ignored
PermissionTemplateDto otherTemplate = db.permissionTemplates().insertTemplate();
IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> {
@Test
public void fail_if_not_a_project_permission() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
loginAsAdmin();
expectedException.expect(IllegalArgumentException.class);
- newRequest(GlobalPermissions.PROVISIONING, template.getUuid())
+ newRequest(GlobalPermission.PROVISION_PROJECTS.getKey(), template.getUuid())
.execute();
}
@Test
public void fail_if_template_uuid_and_name_provided() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
loginAsAdmin();
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_not_logged_in() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
userSession.anonymous();
expectedException.expect(UnauthorizedException.class);
@Test
public void fail_if_insufficient_privileges() {
- PermissionTemplateDto template = addTemplateToDefaultOrganization();
+ PermissionTemplateDto template = addTemplate();
userSession.logIn().addPermission(SCAN);
expectedException.expect(ForbiddenException.class);
public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplateAction> {
- private System2 system = spy(System2.INSTANCE);
+ private final System2 system = spy(System2.INSTANCE);
private PermissionTemplateDto template;
@Override
assertJson(result)
.ignoreFields("id")
.isSimilarTo(getClass().getResource("update_template-example.json"));
- PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
+ PermissionTemplateDto finance = selectPermissionTemplate("Finance");
assertThat(finance.getName()).isEqualTo("Finance");
assertThat(finance.getDescription()).isEqualTo("Permissions for financially related projects");
assertThat(finance.getKeyPattern()).isEqualTo(".*\\.finance\\..*");
call(template.getUuid(), "Finance", null, null);
- PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
+ PermissionTemplateDto finance = selectPermissionTemplate("Finance");
assertThat(finance.getName()).isEqualTo("Finance");
assertThat(finance.getDescription()).isEqualTo(template.getDescription());
assertThat(finance.getKeyPattern()).isEqualTo(template.getKeyPattern());
@Test
public void fail_if_name_already_exists_in_another_template() {
loginAsAdmin();
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("A template with the name '" + anotherTemplate.getName() + "' already exists (case insensitive).");
@Test
public void fail_if_name_already_exists_in_database_case_insensitive() {
loginAsAdmin();
- PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
+ PermissionTemplateDto anotherTemplate = addTemplate();
String nameCaseInsensitive = anotherTemplate.getName().toUpperCase();
expectedException.expect(BadRequestException.class);