use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method search_by_template_name.
@Test
public void search_by_template_name() throws Exception {
OrganizationDto defaultOrg = db.getDefaultOrganization();
GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3-name");
PermissionTemplateDto template = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getId(), group1.getId()));
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_NAME, template.getName()).execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name", "group-2-name");
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateUsersActionTest method empty_result_when_no_user_on_template.
@Test
public void empty_result_when_no_user_on_template() throws Exception {
UserDto user = insertUser(newUserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
PermissionTemplateDto template = addTemplateToDefaultOrganization();
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user));
loginAsAdmin(db.getDefaultOrganization());
InputStream bytes = newRequest(null, null).setParam(PARAM_TEMPLATE_NAME, template.getName()).setMediaType(PROTOBUF).execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).isEmpty();
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateUsersActionTest method fail_if_not_a_project_permission.
@Test
public void fail_if_not_a_project_permission() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
loginAsAdmin(db.getDefaultOrganization());
expectedException.expect(IllegalArgumentException.class);
newRequest(GlobalPermissions.PROVISIONING, template.getUuid()).execute();
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateUsersActionTest method search_for_users_by_template_name.
@Test
public void search_for_users_by_template_name() throws Exception {
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"));
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
PermissionTemplateDto template = addTemplateToDefaultOrganization();
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();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
InputStream bytes = newRequest(null, null).setParam(PARAM_TEMPLATE_NAME, template.getName()).setMediaType(PROTOBUF).execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).extracting("login").containsExactly("login-1", "login-2", "login-3");
assertThat(response.getUsers(0).getPermissionsList()).containsOnly("issueadmin", "user");
assertThat(response.getUsers(1).getPermissionsList()).containsOnly("user");
assertThat(response.getUsers(2).getPermissionsList()).containsOnly("issueadmin");
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateUsersActionTest method search_with_pagination.
@Test
public void search_with_pagination() throws Exception {
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"));
UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
PermissionTemplateDto template = addTemplateToDefaultOrganization();
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();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
loginAsAdmin(db.getDefaultOrganization());
InputStream bytes = newRequest(USER, null).setParam(PARAM_TEMPLATE_NAME, template.getName()).setParam(WebService.Param.SELECTED, "all").setParam(WebService.Param.PAGE, "2").setParam(WebService.Param.PAGE_SIZE, "1").setMediaType(PROTOBUF).execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).extracting("login").containsOnly("login-2");
}
Aggregations