use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method template_groups_of_json_example.
@Test
public void template_groups_of_json_example() throws Exception {
GroupDto adminGroup = insertGroupOnDefaultOrganization("sonar-administrators", "System administrators");
GroupDto userGroup = insertGroupOnDefaultOrganization("sonar-users", "Any new users created will automatically join this group");
PermissionTemplateDto template = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), adminGroup.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), userGroup.getId()));
// Anyone group
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), null));
commit();
loginAsAdmin(db.getDefaultOrganization());
String response = newRequest().setParam(PARAM_PERMISSION, ISSUE_ADMIN).setParam(PARAM_TEMPLATE_ID, template.getUuid()).execute().getInput();
assertJson(response).ignoreFields("id").withStrictArrayOrder().isSimilarTo(getClass().getResource("template_groups-example.json"));
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method search_with_text_query_return_all_groups_even_when_no_permission_set.
@Test
public void search_with_text_query_return_all_groups_even_when_no_permission_set() throws Exception {
OrganizationDto defaultOrg = db.getDefaultOrganization();
PermissionTemplateDto template = addTemplateToDefaultOrganization();
db.users().insertGroup(defaultOrg, "group-1-name");
db.users().insertGroup(defaultOrg, "group-2-name");
db.users().insertGroup(defaultOrg, "group-3-name");
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_ID, template.getUuid()).setParam(TEXT_QUERY, "-name").execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("group-1-name", "group-2-name", "group-3-name");
assertThat(response.getGroups(0).getPermissionsList()).isEmpty();
assertThat(response.getGroups(1).getPermissionsList()).isEmpty();
assertThat(response.getGroups(2).getPermissionsList()).isEmpty();
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method return_all_permissions_of_matching_groups.
@Test
public void return_all_permissions_of_matching_groups() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getId(), group1.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group1.getId()));
GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group-2-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group2.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization(), "group-3-name");
// Anyone
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), null));
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getId(), group3.getId()));
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_ID, template.getUuid()).execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name", "group-2-name");
assertThat(response.getGroups(0).getPermissionsList()).containsOnly("user", "issueadmin");
assertThat(response.getGroups(1).getPermissionsList()).containsOnly("codeviewer", "admin");
assertThat(response.getGroups(2).getPermissionsList()).containsOnly("user", "admin");
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateUsersActionTest method search_using_permission.
@Test
public void search_using_permission() 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, template.getUuid()).setMediaType(PROTOBUF).execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).extracting("login").containsExactly("login-1", "login-2");
assertThat(response.getUsers(0).getPermissionsList()).containsOnly("issueadmin", "user");
assertThat(response.getUsers(1).getPermissionsList()).containsOnly("user");
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateUsersActionTest method users_are_sorted_by_name.
@Test
public void users_are_sorted_by_name() throws Exception {
UserDto user1 = insertUser(newUserDto().setLogin("login-2").setName("name-2"));
UserDto user2 = insertUser(newUserDto().setLogin("login-3").setName("name-3"));
UserDto user3 = insertUser(newUserDto().setLogin("login-1").setName("name-1"));
PermissionTemplateDto template = addTemplateToDefaultOrganization();
addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
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()).extracting("login").containsExactly("login-1", "login-2", "login-3");
}
Aggregations