OrganizationDto org = findOrganization(dbSession, ref.getOrganization());
return checkFound(
dbClient.permissionTemplateDao().selectByName(dbSession, org.getUuid(), ref.name()),
- "Permission template with name '%s' is not found (case insensitive)", ref.name());
+ "Permission template with name '%s' is not found (case insensitive) in organization with key '%s'", ref.name(), org.getKey());
}
}
}
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(
request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
+ checkGlobalAdmin(userSession, template.getOrganizationUuid());
+
ComponentQuery componentQuery = ComponentQuery.builder()
.setNameOrKeyQuery(request.getQuery())
.setQualifiers(qualifiers(request.getQualifier()))
.build();
- List<ComponentDto> projects = dbClient.componentDao().selectByQuery(dbSession, componentQuery, 0, Integer.MAX_VALUE);
+ List<ComponentDto> projects = dbClient.componentDao().selectByQuery(dbSession, template.getOrganizationUuid(), componentQuery, 0, Integer.MAX_VALUE);
- checkGlobalAdmin(userSession, template.getOrganizationUuid());
permissionTemplateService.apply(dbSession, template, projects);
}
}
@Test
public void add_permission_to_group_referenced_by_its_name() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, "sonar-administrators")
@Test
public void add_permission_to_group_referenced_by_its_id() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_ID, group.getId().toString())
public void add_permission_to_project_referenced_by_its_id() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
public void add_permission_to_project_referenced_by_its_key() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
OrganizationDto organizationDto = db.getDefaultOrganization();
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto view = db.components().insertComponent(newView(organizationDto, "view-uuid").setKey("view-key"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
@Test
public void fail_if_project_uuid_is_not_found() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
newRequest()
@Test
public void adding_a_project_permission_fails_if_project_is_not_set() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
GroupDto group = db.users().insertGroup(organizationDto, "sonar-administrators");
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, A_PROJECT_UUID).setKey(A_PROJECT_KEY));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project, null, "file-uuid"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_get_request() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(ServerException.class);
@Test
public void fail_when_group_name_and_group_id_are_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Group name or group id must be provided");
@Test
public void fail_when_permission_is_missing() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_not_administrator_of_organization() throws Exception {
GroupDto group = db.users().insertGroup();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception {
GroupDto group = db.users().insertGroup();
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Project id or project key can be provided, not both.");
UserDto notRootUser = db.users().insertUser();
UserDto notInGroupUser = db.users().insertUser();
db.users().insertMembers(group, rootByUserPermissionUser, rootByGroupPermissionUser, notRootUser);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
executeRequest(group, SYSTEM_ADMIN);
UserDto notRootUser = db.users().insertUser();
UserDto notInGroupUser = db.users().insertUser();
db.users().insertMembers(group, rootByUserPermissionUser, rootByGroupPermissionUser, notRootUser);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
executeRequest(group, db.getDefaultOrganization(), SYSTEM_ADMIN);
@Test
public void add_permission_to_user() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
public void add_permission_to_project_referenced_by_its_id() throws Exception {
ComponentDto project = db.components().insertProject();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, project.uuid())
public void add_permission_to_project_referenced_by_its_key() throws Exception {
ComponentDto project = db.components().insertProject();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_KEY, project.getKey())
public void add_permission_to_view() throws Exception {
ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid").setKey("view-key"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, view.uuid())
@Test
public void fail_when_project_uuid_is_unknown() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
@Test
public void fail_when_project_permission_without_project() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_component_is_not_a_project() throws Exception {
db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert(), "project-uuid"), null, "file-uuid"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_get_request() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(ServerException.class);
@Test
public void fail_when_user_login_is_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_when_permission_is_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
@Test
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception {
db.components().insertProject();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Project id or project key can be provided, not both.");
UserDto rootByUserPermissionUser = db.users().insertRootByUserPermission();
UserDto rootByGroupPermissionUser = db.users().insertRootByGroupPermission();
UserDto notRootUser = db.users().insertUser();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
executeRequest(notRootUser, SYSTEM_ADMIN);
db.rootFlag().verify(notRootUser, true);
UserDto rootByUserPermissionUser = db.users().insertRootByUserPermission();
UserDto rootByGroupPermissionUser = db.users().insertRootByGroupPermission();
UserDto notRootUser = db.users().insertUser();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
executeRequest(notRootUser, SYSTEM_ADMIN, db.getDefaultOrganization());
db.rootFlag().verify(notRootUser, true);
@Test
public void organization_parameter_must_not_be_set_on_project_permissions() {
ComponentDto project = db.components().insertProject();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Organization must not be set when project is set.");
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
-import org.sonar.db.permission.template.PermissionTemplateTesting;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.permission.GroupPermissionChanger;
return wsTester.newRequest().setMethod("POST");
}
- protected PermissionTemplateDto insertTemplate() {
- PermissionTemplateDto dto = PermissionTemplateTesting.newPermissionTemplateDto()
- .setOrganizationUuid(db.getDefaultOrganization().getUuid());
- dto = db.getDbClient().permissionTemplateDao().insert(db.getSession(), dto);
- db.commit();
- return dto;
- }
-
- protected void loginAsAdminOnDefaultOrganization() {
- loginAsAdmin(db.getDefaultOrganization());
- }
-
protected void loginAsAdmin(OrganizationDto org, OrganizationDto... otherOrgs) {
userSession.logIn().addOrganizationPermission(org.getUuid(), SYSTEM_ADMIN);
for (OrganizationDto otherOrg : otherOrgs) {
@Test
public void search_for_groups_with_one_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String json = newRequest()
.setParam(PARAM_PERMISSION, SCAN_EXECUTION)
@Test
public void search_with_selection() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam(PARAM_PERMISSION, SCAN_EXECUTION)
.execute()
@Test
public void search_groups_with_pagination() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam(PARAM_PERMISSION, SCAN_EXECUTION)
.setParam(PAGE_SIZE, "1")
@Test
public void search_groups_with_query() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam(PARAM_PERMISSION, SCAN_EXECUTION)
.setParam(TEXT_QUERY, "group-")
GroupDto groupWithoutPermission = db.users().insertGroup(organizationDto, "group-without-permission");
GroupDto anotherGroup = db.users().insertGroup(organizationDto, "another-group");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, "project-uuid")
GroupDto groupWithoutPermission = db.users().insertGroup(db.getDefaultOrganization(), "group-without-permission");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, project.uuid())
GroupDto group = db.users().insertGroup(organizationDto, "group-with-permission");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam(PARAM_PROJECT_ID, project.uuid())
.setParam(TEXT_QUERY, "nyo")
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "project-group-name");
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, view);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, "view-uuid")
expectedException.expect(BadRequestException.class);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_PERMISSION, SCAN_EXECUTION)
.setParam(PARAM_PROJECT_ID, "project-uuid")
public void remove_permission_using_group_name() throws Exception {
db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN);
db.users().insertPermissionOnGroup(aGroup, PROVISIONING);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, aGroup.getName())
public void remove_permission_using_group_id() throws Exception {
db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN);
db.users().insertPermissionOnGroup(aGroup, PROVISIONING);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_ID, aGroup.getId().toString())
db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN);
db.users().insertProjectPermissionOnGroup(aGroup, ADMIN, project);
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, project);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, aGroup.getName())
db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN);
db.users().insertProjectPermissionOnGroup(aGroup, ADMIN, view);
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, view);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, aGroup.getName())
db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN);
db.users().insertProjectPermissionOnGroup(aGroup, ADMIN, project);
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, project);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, aGroup.getName())
public void fail_to_remove_last_admin_permission() throws Exception {
db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN);
db.users().insertPermissionOnGroup(aGroup, PROVISIONING);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Last group with permission 'admin'. Permission cannot be removed.");
@Test
public void fail_when_project_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Project id 'unknown-project-uuid' not found");
@Test
public void fail_when_project_project_permission_without_project() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Invalid global permission 'issueadmin'. Valid values are [admin, profileadmin, gateadmin, scan, provisioning]");
@Test
public void fail_when_component_is_not_a_project() throws Exception {
ComponentDto file = db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert()), null, "file-uuid"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Component 'KEY_file-uuid' (id: file-uuid) must be a project or a module.");
@Test
public void fail_when_group_name_is_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Group name or group id must be provided");
@Test
public void fail_when_permission_name_and_id_are_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The 'permission' parameter is missing");
@Test
public void fail_when_group_id_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("No group with id '42'");
@Test
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception {
ComponentDto project = db.components().insertProject();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Project id or project key can be provided, not both.");
GroupDto adminGroup = db.users().insertAdminGroup();
UserDto user1 = db.users().insertRootByGroupPermission("user1", adminGroup);
UserDto user2 = db.users().insertRootByGroupPermission("user2", adminGroup);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
executeRequest(adminGroup, SYSTEM_ADMIN);
GroupDto adminGroup = db.users().insertAdminGroup();
UserDto user1 = db.users().insertRootByGroupPermission("user1", adminGroup);
UserDto user2 = db.users().insertRootByGroupPermission("user2", adminGroup);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
executeRequest(adminGroup, db.getDefaultOrganization(), SYSTEM_ADMIN);
public void remove_permission_from_user() throws Exception {
db.users().insertPermissionOnUser(user, PROVISIONING);
db.users().insertPermissionOnUser(user, QUALITY_GATE_ADMIN);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
public void fail_to_remove_admin_permission_if_last_admin() throws Exception {
db.users().insertPermissionOnUser(user, CODEVIEWER);
db.users().insertPermissionOnUser(user, ADMIN);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Last user with permission 'admin'. Permission cannot be removed.");
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
ComponentDto view = db.components().insertComponent(newView(db.organizations().insert(), "view-uuid").setKey("view-key"));
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, view);
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, view);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
@Test
public void fail_when_project_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
@Test
public void fail_when_project_permission_without_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_component_is_not_a_project() throws Exception {
db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert()), null, "file-uuid"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_get_request() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(ServerException.class);
@Test
public void fail_when_user_login_is_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_when_permission_is_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception {
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Project id or project key can be provided, not both.");
public void sets_root_flag_to_false_when_removing_user_admin_permission_of_default_organization_without_org_parameter() throws Exception {
UserDto lastAdminUser = db.users().insertRootByUserPermission();
UserDto adminUser = db.users().insertRootByUserPermission();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
executeRequest(adminUser, SYSTEM_ADMIN);
public void sets_root_flag_to_false_when_removing_user_admin_permission_of_default_organization_with_org_parameter() throws Exception {
UserDto lastAdminUser = db.users().insertRootByUserPermission();
UserDto adminUser = db.users().insertRootByUserPermission();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
executeRequest(adminUser, db.getDefaultOrganization(), SYSTEM_ADMIN);
@Test
public void supports_protobuf_response() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
WsPermissions.WsSearchGlobalPermissionsResponse result = WsPermissions.WsSearchGlobalPermissionsResponse.parseFrom(
newRequest()
@Test
public void fail_if_not_admin_of_specified_organization() throws Exception {
OrganizationDto org = db.organizations().insert();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(ForbiddenException.class);
db.users().insertPermissionOnUser(user1, QUALITY_PROFILE_ADMIN);
db.users().insertPermissionOnUser(user2, SCAN_EXECUTION);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest().execute().getInput();
assertJson(result).withStrictArrayOrder().isSimilarTo(getClass().getResource("users-example.json"));
public void search_for_users_with_one_permission() throws Exception {
insertUsersHavingGlobalPermissions();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest().setParam("permission", "scan").execute().getInput();
assertJson(result).withStrictArrayOrder().isSimilarTo(getClass().getResource("UsersActionTest/users.json"));
// User has no permission
UserDto withoutPermission = db.users().insertUser();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam(PARAM_PROJECT_ID, project.uuid())
.execute()
UserDto withoutPermission = db.users().insertUser(newUserDto("without-permission-login", "without-permission-name", "without-permission-email"));
UserDto anotherUser = db.users().insertUser(newUserDto("another-user", "another-user", "another-user"));
- loginAsAdminOnDefaultOrganization();
- String result = newRequest().setParam(PARAM_PROJECT_ID, project.uuid()).setParam(TEXT_QUERY, "name").execute().getInput();
+ loginAsAdmin(db.getDefaultOrganization());
+ String result = newRequest()
+ .setParam(PARAM_PROJECT_ID, project.uuid())
+ .setParam(TEXT_QUERY, "with")
+ .execute()
+ .getInput();
assertThat(result).contains(user.getLogin(), withoutPermission.getLogin()).doesNotContain(anotherUser.getLogin());
}
UserDto withoutPermission = db.users().insertUser(newUserDto("without-permission-login", "without-permission-name", "without-permission-email"));
UserDto anotherUser = db.users().insertUser(newUserDto("another-user", "another-user", "another-user"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest().setParam(PARAM_PROJECT_ID, project.uuid()).setParam(TEXT_QUERY, "email").execute().getInput();
assertThat(result).contains(user.getLogin(), withoutPermission.getLogin()).doesNotContain(anotherUser.getLogin());
UserDto withoutPermission = db.users().insertUser(newUserDto("without-permission-login", "without-permission-name", "without-permission-email"));
UserDto anotherUser = db.users().insertUser(newUserDto("another-user", "another-user", "another-user"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest().setParam(PARAM_PROJECT_ID, project.uuid()).setParam(TEXT_QUERY, "login").execute().getInput();
assertThat(result).contains(user.getLogin(), withoutPermission.getLogin()).doesNotContain(anotherUser.getLogin());
public void search_for_users_with_query_as_a_parameter() throws Exception {
insertUsersHavingGlobalPermissions();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.setParam("permission", "scan")
.setParam(TEXT_QUERY, "ame-1")
public void search_for_users_with_select_as_a_parameter() throws Exception {
insertUsersHavingGlobalPermissions();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest()
.execute()
.getInput();
@Test
public void fail_if_project_permission_without_project() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_project_uuid_and_project_key_are_provided() throws Exception {
db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key"));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Project id or project key can be provided, not both.");
@Test
public void fail_if_search_query_is_too_short() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The 'q' parameter must have at least 3 characters");
@Before
public void setUp() {
- template = insertTemplate();
+ template = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
group = db.users().insertGroup(db.getDefaultOrganization(), "group-name");
}
@Test
public void add_group_to_template() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(group.getName(), template.getUuid(), CODEVIEWER);
@Test
public void add_group_to_template_by_name() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
@Test
public void add_with_group_id() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_TEMPLATE_ID, template.getUuid())
@Test
public void does_not_add_a_group_twice() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(group.getName(), template.getUuid(), ISSUE_ADMIN);
newRequest(group.getName(), template.getUuid(), ISSUE_ADMIN);
@Test
public void add_anyone_group_to_template() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(ANYONE, template.getUuid(), CODEVIEWER);
@Test
public void fail_if_add_anyone_group_to_admin_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage(String.format("It is not possible to add the '%s' permission to the group 'Anyone'", UserRole.ADMIN));
@Test
public void fail_if_not_a_project_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_group_params_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_permission_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_template_uuid_and_name_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_group_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("No group with name 'unknown-group-name'");
@Test
public void fail_if_template_key_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
@Before
public void setUp() {
- template = insertTemplate();
+ template = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
when(system.now()).thenReturn(2_000_000_000L);
}
@Test
public void insert_row_when_no_template_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_PERMISSION, UserRole.ADMIN)
@Test
public void update_row_when_existing_template_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
PermissionTemplateCharacteristicDto characteristic = db.getDbClient().permissionTemplateCharacteristicDao().insert(db.getSession(),
new PermissionTemplateCharacteristicDto()
.setTemplateId(template.getId())
@Test
public void fail_when_template_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
@Test
public void fail_if_permission_is_not_a_project_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Before
public void setUp() {
user = db.users().insertUser("user-login");
- permissionTemplate = insertTemplate();
+ permissionTemplate = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
}
@Test
public void add_user_to_template() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), permissionTemplate.getUuid(), CODEVIEWER);
@Test
public void add_user_to_template_by_name() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
@Test
public void does_not_add_a_user_twice() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), permissionTemplate.getUuid(), ISSUE_ADMIN);
newRequest(user.getLogin(), permissionTemplate.getUuid(), ISSUE_ADMIN);
@Test
public void fail_if_not_a_project_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_user_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_permission_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_template_uuid_and_name_are_missing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_user_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("User with login 'unknown-login' is not found");
@Test
public void fail_if_template_key_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
group2 = db.users().insertGroup();
// template 1
- template1 = insertTemplate();
+ template1 = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
addUserToTemplate(user1, template1, UserRole.CODEVIEWER);
addUserToTemplate(user2, template1, UserRole.ISSUE_ADMIN);
addGroupToTemplate(group1, template1, UserRole.ADMIN);
addGroupToTemplate(group2, template1, UserRole.USER);
// template 2
- template2 = insertTemplate();
+ template2 = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
addUserToTemplate(user1, template2, UserRole.USER);
addUserToTemplate(user2, template2, UserRole.USER);
addGroupToTemplate(group1, template2, UserRole.USER);
@Test
public void apply_template_with_project_uuid() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(template1.getUuid(), project.uuid(), null);
@Test
public void apply_template_with_project_uuid_by_template_name() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_TEMPLATE_NAME, template1.getName().toUpperCase())
@Test
public void apply_template_with_project_key() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(template1.getUuid(), null, project.key());
@Test
public void fail_when_unknown_template() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Permission template with id 'unknown-template-uuid' is not found");
@Test
public void fail_when_unknown_project_uuid() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Project id 'unknown-project-uuid' not found");
@Test
public void fail_when_unknown_project_key() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Project key 'unknown-project-key' not found");
@Test
public void fail_when_template_is_not_provided() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_when_project_uuid_and_key_not_provided() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Project id or project key can be provided, not both.");
import static org.mockito.Mockito.mock;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
private UserDto user2;
private GroupDto group1;
private GroupDto group2;
+ private OrganizationDto organization;
private PermissionTemplateDto template1;
private PermissionTemplateDto template2;
private PermissionIndexer issuePermissionIndexer = mock(PermissionIndexer.class);
@Override
protected BulkApplyTemplateAction buildWsAction() {
PermissionTemplateService permissionTemplateService = new PermissionTemplateService(db.getDbClient(),
- issuePermissionIndexer, userSession, defaultTemplatesResolver);
+ issuePermissionIndexer, userSession, defaultTemplatesResolver);
return new BulkApplyTemplateAction(db.getDbClient(), userSession, permissionTemplateService, newPermissionWsSupport(), new I18nRule(), newRootResourceTypes());
}
@Before
public void setUp() {
+ organization = db.organizations().insert();
+
user1 = db.users().insertUser();
user2 = db.users().insertUser();
- group1 = db.users().insertGroup();
- group2 = db.users().insertGroup();
+ group1 = db.users().insertGroup(organization);
+ group2 = db.users().insertGroup(organization);
- // template 1
- template1 = insertTemplate();
+ // template 1 for org 1
+ template1 = db.permissionTemplates().insertTemplate(organization);
addUserToTemplate(user1, template1, UserRole.CODEVIEWER);
addUserToTemplate(user2, template1, UserRole.ISSUE_ADMIN);
addGroupToTemplate(group1, template1, UserRole.ADMIN);
addGroupToTemplate(group2, template1, UserRole.USER);
// template 2
- template2 = insertTemplate();
+ template2 = db.permissionTemplates().insertTemplate(organization);
addUserToTemplate(user1, template2, UserRole.USER);
addUserToTemplate(user2, template2, UserRole.USER);
addGroupToTemplate(group1, template2, UserRole.USER);
@Test
public void bulk_apply_template_by_template_uuid() throws Exception {
- ComponentDto project = db.components().insertProject();
- ComponentDto view = db.components().insertView();
- ComponentDto developer = db.components().insertDeveloper("developer-name");
- db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, developer);
- db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, developer);
- db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, developer);
- db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, developer);
- loginAsAdminOnDefaultOrganization();
+ // this project should not be applied the template
+ OrganizationDto otherOrganization = db.organizations().insert();
+ db.components().insertProject(otherOrganization);
+
+ ComponentDto project = db.components().insertProject(organization);
+ ComponentDto view = db.components().insertView(organization);
+ loginAsAdmin(organization);
newRequest().setParam(PARAM_TEMPLATE_ID, template1.getUuid()).execute();
assertTemplate1AppliedToProject(view);
}
+ @Test
+ public void request_throws_NotFoundException_if_template_with_specified_name_does_not_exist_in_specified_organization() throws Exception {
+ OrganizationDto otherOrganization = db.organizations().insert();
+ loginAsAdmin(otherOrganization);
+
+ expectedException.expect(NotFoundException.class);
+ expectedException.expectMessage("Permission template with name '" + template1.getName()
+ + "' is not found (case insensitive) in organization with key '" + otherOrganization.getKey() + "'");
+
+ newRequest()
+ .setParam(PARAM_ORGANIZATION_KEY, otherOrganization.getKey())
+ .setParam(PARAM_TEMPLATE_NAME, template1.getName())
+ .execute();
+ }
+
@Test
public void bulk_apply_template_by_template_name() throws Exception {
- ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()));
- loginAsAdminOnDefaultOrganization();
+ ComponentDto project = db.components().insertComponent(newProjectDto(organization));
+ loginAsAdmin(organization);
- newRequest().setParam(PARAM_TEMPLATE_NAME, template1.getName()).execute();
+ newRequest()
+ .setParam(PARAM_ORGANIZATION_KEY, organization.getKey())
+ .setParam(PARAM_TEMPLATE_NAME, template1.getName())
+ .execute();
assertTemplate1AppliedToProject(project);
}
@Test
public void apply_template_by_qualifier() throws Exception {
- OrganizationDto organization = db.getDefaultOrganization();
ComponentDto project = db.components().insertComponent(newProjectDto(organization));
ComponentDto view = db.components().insertComponent(newView(organization));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(organization);
newRequest()
.setParam(PARAM_TEMPLATE_ID, template1.getUuid())
@Test
public void apply_template_by_query_on_name_and_key() throws Exception {
- OrganizationDto organization = db.getDefaultOrganization();
ComponentDto projectFoundByKey = newProjectDto(organization).setKey("sonar");
db.components().insertProjectAndSnapshot(projectFoundByKey);
ComponentDto projectFoundByName = newProjectDto(organization).setName("name-sonar-name");
// match must be exact on key
ComponentDto projectUntouched = newProjectDto(organization).setKey("new-sonar").setName("project-name");
db.components().insertProjectAndSnapshot(projectUntouched);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(organization);
newRequest()
.setParam(PARAM_TEMPLATE_ID, template1.getUuid())
@Test
public void fail_if_no_template_parameter() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Template name or template id must be provided, not both.");
@Test
public void fail_if_template_name_is_incorrect() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Permission template with id 'unknown-template-uuid' is not found");
private List<String> selectProjectPermissionGroups(ComponentDto project, String permission) {
PermissionQuery query = PermissionQuery.builder().setPermission(permission).setComponentUuid(project.uuid()).build();
- return db.getDbClient().groupPermissionDao().selectGroupNamesByQuery(db.getSession(), db.getDefaultOrganization().getUuid(), query);
+ return db.getDbClient().groupPermissionDao().selectGroupNamesByQuery(db.getSession(), project.getOrganizationUuid(), query);
}
private List<Long> selectProjectPermissionUsers(ComponentDto project, String permission) {
PermissionQuery query = PermissionQuery.builder().setPermission(permission).setComponentUuid(project.uuid()).build();
- return db.getDbClient().userPermissionDao().selectUserIds(db.getSession(), db.getDefaultOrganization().getUuid(), query);
+ return db.getDbClient().userPermissionDao().selectUserIds(db.getSession(), project.getOrganizationUuid(), query);
}
}
@Test
public void create_full_permission_template() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
TestResponse result = newRequest("Finance", "Permissions for financially related projects", ".*\\.finance\\..*");
@Test
public void create_minimalist_permission_template() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest("Finance", null, null);
@Test
public void fail_if_name_not_provided() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_name_empty() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The template name must not be blank");
@Test
public void fail_if_regexp_if_not_valid() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The 'projectKeyPattern' parameter must be a valid Java regular expression. '[azerty' was passed");
@Test
public void fail_if_name_already_exists_in_database_case_insensitive() throws Exception {
- loginAsAdminOnDefaultOrganization();
- PermissionTemplateDto template = insertTemplate();
+ loginAsAdmin(db.getDefaultOrganization());
+ PermissionTemplateDto template = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("A template with the name '" + template.getName() + "' already exists (case insensitive).");
newRequestByName(underTest, null, template);
fail("NotFoundException should have been raised");
} catch (NotFoundException e) {
- assertThat(e).hasMessage("Permission template with name '" + template.getName() + "' is not found (case insensitive)");
+ assertThat(e).hasMessage("Permission template with name '" + template.getName() + "' is not found (case insensitive) in organization with key '" + db.getDefaultOrganization().getKey() + "'");
}
});
}
newRequestByName(underTest, otherOrganization, template);
fail("NotFoundException should have been raised");
} catch (NotFoundException e) {
- assertThat(e).hasMessage("Permission template with name '" + template.getName() + "' is not found (case insensitive)");
+ assertThat(e).hasMessage("Permission template with name '" + template.getName() + "' is not found (case insensitive) in organization with key '" + otherOrganization.getKey() + "'");
}
});
}
@Before
public void setUp() {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
group = db.users().insertGroup(db.getDefaultOrganization(), "group-name");
- template = insertTemplate();
+ template = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
addGroupToTemplate(template, group.getId(), PERMISSION);
}
@Before
public void setUp() {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
when(system.now()).thenReturn(2_000_000_000L);
- template = insertTemplate();
+ template = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
}
@Test
@Before
public void setUp() {
user = db.users().insertUser("user-login");
- template = insertTemplate();
+ template = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
addUserToTemplate(user, template, DEFAULT_PERMISSION);
}
@Test
public void remove_user_from_template() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), template.getUuid(), DEFAULT_PERMISSION);
assertThat(getLoginsInTemplateAndPermission(template.getId(), DEFAULT_PERMISSION)).isEmpty();
@Test
public void remove_user_from_template_by_name_case_insensitive() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, DEFAULT_PERMISSION)
@Test
public void remove_user_from_template_twice_without_failing() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), template.getUuid(), DEFAULT_PERMISSION);
newRequest(user.getLogin(), template.getUuid(), DEFAULT_PERMISSION);
public void keep_user_permission_not_removed() throws Exception {
addUserToTemplate(user, template, ISSUE_ADMIN);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), template.getUuid(), DEFAULT_PERMISSION);
assertThat(getLoginsInTemplateAndPermission(template.getId(), DEFAULT_PERMISSION)).isEmpty();
UserDto newUser = db.users().insertUser("new-login");
addUserToTemplate(newUser, template, DEFAULT_PERMISSION);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), template.getUuid(), DEFAULT_PERMISSION);
assertThat(getLoginsInTemplateAndPermission(template.getId(), DEFAULT_PERMISSION)).containsExactly("new-login");
public void fail_if_not_a_project_permission() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), template.getUuid(), GlobalPermissions.PROVISIONING);
}
public void fail_if_user_missing() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(null, template.getUuid(), DEFAULT_PERMISSION);
}
public void fail_if_permission_missing() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), template.getUuid(), null);
}
public void fail_if_template_missing() throws Exception {
expectedException.expect(BadRequestException.class);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), null, DEFAULT_PERMISSION);
}
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("User with login 'unknown-login' is not found");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest("unknown-login", template.getUuid(), DEFAULT_PERMISSION);
}
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest(user.getLogin(), "unknown-key", DEFAULT_PERMISSION);
}
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), null));
commit();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String response = newRequest()
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
OrganizationDto otherOrganization = db.organizations().insert();
db.users().insertGroup(otherOrganization, groupName);
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
newRequest()
.setMediaType(PROTOBUF)
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getId(), group3.getId()));
commit();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest()
.setMediaType(PROTOBUF)
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getId(), group3.getId()));
commit();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest()
.setMediaType(PROTOBUF)
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getId(), group1.getId()));
commit();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest()
.setMediaType(PROTOBUF)
GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group2.getId()));
commit();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest()
.setMediaType(PROTOBUF)
GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3");
commit();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest()
.setMediaType(PROTOBUF)
db.users().insertGroup(defaultOrg, "group-2-name");
db.users().insertGroup(defaultOrg, "group-3-name");
commit();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest()
.setMediaType(PROTOBUF)
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group.getId()));
commit();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest()
.setMediaType(PROTOBUF)
@Test
public void fail_if_template_uuid_and_name_provided() throws Exception {
PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_template_uuid_nor_name_provided() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_template_is_not_found() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
@Test
public void fail_if_not_a_project_permission() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
expectedException.expect(IllegalArgumentException.class);
addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user1));
addUserToTemplate(newPermissionTemplateUser(CODEVIEWER, template1, user2));
addUserToTemplate(newPermissionTemplateUser(ADMIN, template1, user2));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = newRequest(null, template1.getUuid()).execute().getInput();
assertJson(result).isSimilarTo(getClass().getResource("template_users-example.json"));
@Test
public void search_for_users_by_template_name() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
UserDto user1 = insertUser(newUserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
@Test
public void search_using_text_query() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
UserDto user1 = insertUser(newUserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream bytes = newRequest(USER, template.getUuid())
.setMediaType(PROTOBUF)
.execute().getInputStream();
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream bytes = newRequest(USER, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setParam(WebService.Param.SELECTED, "all")
addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream bytes = newRequest(null, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setMediaType(PROTOBUF)
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user));
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
InputStream bytes = newRequest(null, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setMediaType(PROTOBUF)
@Test
public void fail_if_not_a_project_permission() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_no_template_param() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_template_does_not_exist() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
@Test
public void fail_if_template_uuid_and_name_provided() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
@Test
public void update_all_permission_template_fields() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
String result = call(template.getUuid(), "Finance", "Permissions for financially related projects", ".*\\.finance\\..*");
@Test
public void update_with_the_same_values() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
call(template.getUuid(), template.getName(), template.getDescription(), template.getKeyPattern());
@Test
public void update_name_only() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
call(template.getUuid(), "Finance", null, null);
@Test
public void fail_if_key_is_not_found() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
@Test
public void fail_if_name_already_exists_in_another_template() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_key_is_not_provided() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
@Test
public void fail_if_name_empty() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The template name must not be blank");
@Test
public void fail_if_name_has_just_whitespaces() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The template name must not be blank");
@Test
public void fail_if_regexp_if_not_valid() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The 'projectKeyPattern' parameter must be a valid Java regular expression. '[azerty' was passed");
@Test
public void fail_if_name_already_exists_in_database_case_insensitive() throws Exception {
- loginAsAdminOnDefaultOrganization();
+ loginAsAdmin(db.getDefaultOrganization());
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
String nameCaseInsensitive = anotherTemplate.getName().toUpperCase();