import org.sonar.server.user.UserSession;
import static org.apache.commons.lang.StringUtils.defaultIfBlank;
+import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_ORGANIZATION_KEY;
public void define(NewController context) {
WebService.NewAction action = context.createAction("search")
.setDescription("Search for user groups.<br>" +
- "Requires to be logged in.")
+ "Requires the following permission:" +
+ "<ul>" +
+ "<li>'Administer System'</li>" +
+ "</ul>")
.setHandler(this)
.setResponseExample(getClass().getResource("example-search.json"))
.setSince("5.2")
@Override
public void handle(Request request, Response response) throws Exception {
- userSession.checkLoggedIn();
-
int page = request.mandatoryParamAsInt(Param.PAGE);
int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
SearchOptions options = new SearchOptions()
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = groupWsSupport.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY));
+ userSession.checkLoggedIn().checkOrganizationPermission(organization.getUuid(), SYSTEM_ADMIN);
int limit = dbClient.groupDao().countByQuery(dbSession, organization.getUuid(), query);
List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, organization.getUuid(), query, options.getOffset(), pageSize);
import static org.apache.commons.lang.StringUtils.capitalize;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.user.GroupTesting.newGroupDto;
public class SearchActionTest {
@Test
public void search_empty() throws Exception {
- loginAsSimpleUser();
+ loginAsDefaultOrgAdmin();
newRequest().execute().assertJson(getClass(), "empty.json");
}
insertGroup(db.getDefaultOrganization(), "customer2", 0);
insertGroup(db.getDefaultOrganization(), "customer3", 0);
- loginAsSimpleUser();
+ loginAsDefaultOrgAdmin();
newRequest().execute().assertJson(getClass(), "five_groups.json");
}
insertGroup(db.getDefaultOrganization(), "customer2", 4);
insertGroup(db.getDefaultOrganization(), "customer3", 0);
- loginAsSimpleUser();
+ loginAsDefaultOrgAdmin();
newRequest().execute().assertJson(getClass(), "with_members.json");
}
insertGroup(db.getDefaultOrganization(), "customer%_%/2", 0);
insertGroup(db.getDefaultOrganization(), "customer%_%/3", 0);
- loginAsSimpleUser();
+ loginAsDefaultOrgAdmin();
newRequest().setParam(Param.TEXT_QUERY, "tomer%_%/").execute().assertJson(getClass(), "customers.json");
}
insertGroup(db.getDefaultOrganization(), "customer2", 0);
insertGroup(db.getDefaultOrganization(), "customer3", 0);
- loginAsSimpleUser();
+ loginAsDefaultOrgAdmin();
newRequest()
.setParam(Param.PAGE_SIZE, "3").execute().assertJson(getClass(), "page_1.json");
newRequest()
public void search_with_fields() throws Exception {
insertGroup(db.getDefaultOrganization(), "sonar-users", 0);
- loginAsSimpleUser();
+ loginAsDefaultOrgAdmin();
assertThat(newRequest().execute().outputAsString())
.contains("id")
.contains("name")
GroupDto group = db.users().insertGroup(org, "users");
// the group in default org is not returned
db.users().insertGroup(db.getDefaultOrganization(), "users");
+ loginAsDefaultOrgAdmin();
+ userSession.addOrganizationPermission(org.getUuid(), SYSTEM_ADMIN);
- loginAsSimpleUser();
newRequest()
.setParam("organization", org.getKey())
.execute()
}
}
- private void loginAsSimpleUser() {
- userSession.login("user");
+ private void loginAsDefaultOrgAdmin() {
+ userSession.login("user").addOrganizationPermission(db.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
}
private GroupWsSupport newGroupWsSupport() {