import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
-import org.sonar.api.server.ws.WebService.SelectionMode;
import org.sonar.api.utils.Paging;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsPermissions;
import org.sonarqube.ws.WsPermissions.UsersWsResponse;
-import org.sonarqube.ws.client.permission.OldUsersWsRequest;
+import org.sonarqube.ws.client.permission.UsersWsRequest;
-import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Strings.nullToEmpty;
import static org.sonar.api.utils.Paging.forPageIndex;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentDto;
-import static org.sonar.server.permission.ws.PermissionQueryParser.fromSelectionModeToMembership;
import static org.sonar.server.permission.ws.PermissionRequestValidator.validatePermission;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters;
public class UsersAction implements PermissionsWsAction {
+ private static final int MAX_SIZE = 100;
+
private final DbClient dbClient;
private final UserSession userSession;
private final PermissionFinder permissionFinder;
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("users2")
.setSince("5.2")
- .setDescription(String.format("Lists the users that have been granted the specified permission as individual users rather than through group affiliation. <br />" +
- "This service defaults to global permissions, but can be limited to project permissions by providing project id or project key.<br /> " +
- "If the query parameter '%s' is specified, the '%s' parameter is forced to '%s'.<br />" +
- "It requires administration permissions to access.<br />",
- Param.TEXT_QUERY, Param.SELECTED, SelectionMode.ALL.value()))
- .addPagingParams(100)
+ .setDescription("Lists the users with their permissions as individual users rather than through group affiliation.<br>" +
+ "This service defaults to global permissions, but can be limited to project permissions by providing project id or project key.<br> " +
+ "This service defaults to all users, but can be limited to users with a specific permission by providing the desired permission.<br>" +
+ "It requires administration permissions to access.")
+ .addPagingParams(20, MAX_SIZE)
.addSearchQuery("stas", "names")
- .addSelectionModeParam()
.setInternal(true)
.setResponseExample(getClass().getResource("users-example.json"))
.setHandler(this);
writeProtobuf(usersWsResponse, wsRequest, wsResponse);
}
- private UsersWsResponse doHandle(OldUsersWsRequest request) {
+ private UsersWsResponse doHandle(UsersWsRequest request) {
Optional<WsProjectRef> wsProjectRef = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
validatePermission(request.getPermission(), wsProjectRef);
DbSession dbSession = dbClient.openSession(false);
}
}
- private static OldUsersWsRequest toUsersWsRequest(Request request) {
- return new OldUsersWsRequest()
+ private static UsersWsRequest toUsersWsRequest(Request request) {
+ return new UsersWsRequest()
.setPermission(request.mandatoryParam(PARAM_PERMISSION))
.setProjectId(request.param(PARAM_PROJECT_ID))
.setProjectKey(request.param(PARAM_PROJECT_KEY))
- .setSelected(request.param(Param.SELECTED))
.setQuery(request.param(Param.TEXT_QUERY))
.setPage(request.mandatoryParamAsInt(Param.PAGE))
.setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE));
return userResponse.build();
}
- private static PermissionQuery buildPermissionQuery(OldUsersWsRequest request, Optional<ComponentDto> project) {
+ private static PermissionQuery buildPermissionQuery(UsersWsRequest request, Optional<ComponentDto> project) {
PermissionQuery.Builder permissionQuery = PermissionQuery.builder()
.permission(request.getPermission())
.pageIndex(request.getPage())
.pageSize(request.getPageSize())
- .membership(fromSelectionModeToMembership(firstNonNull(request.getSelected(), SelectionMode.SELECTED.value())))
.search(request.getQuery());
if (project.isPresent()) {
permissionQuery.component(project.get().getKey());
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.sonarqube.ws.client.permission;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class UsersWsRequest {
+ private String permission;
+ private String projectId;
+ private String projectKey;
+ private String query;
+ private Integer page;
+ private Integer pageSize;
+
+ @CheckForNull
+ public String getPermission() {
+ return permission;
+ }
+
+ public UsersWsRequest setPermission(@Nullable String permission) {
+ this.permission = permission;
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public UsersWsRequest setProjectId(@Nullable String projectId) {
+ this.projectId = projectId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectKey() {
+ return projectKey;
+ }
+
+ public UsersWsRequest setProjectKey(@Nullable String projectKey) {
+ this.projectKey = projectKey;
+ return this;
+ }
+
+ @CheckForNull
+ public String getQuery() {
+ return query;
+ }
+
+ public UsersWsRequest setQuery(@Nullable String query) {
+ this.query = query;
+ return this;
+ }
+
+ @CheckForNull
+ public Integer getPage() {
+ return page;
+ }
+
+ public UsersWsRequest setPage(int page) {
+ this.page = page;
+ return this;
+ }
+
+ @CheckForNull
+ public Integer getPageSize() {
+ return pageSize;
+ }
+
+ public UsersWsRequest setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ return this;
+ }
+}