import org.sonarqube.ws.client.permission.RemoveProjectCreatorFromTemplateWsRequest;
import org.sonarqube.ws.client.permission.RemoveUserFromTemplateWsRequest;
import org.sonarqube.ws.client.permission.SearchTemplatesWsRequest;
-import org.sonarqube.ws.client.permission.UsersWsRequest;
+import org.sonarqube.ws.client.permission.OldUsersWsRequest;
import util.QaOnly;
import static org.assertj.core.api.Assertions.assertThat;
assertThat(searchGlobalPermissionsWsResponse.getPermissionsList().get(0).getGroupsCount()).isEqualTo(2);
WsPermissions.UsersWsResponse users = permissionsWsClient
- .users(new UsersWsRequest()
+ .users(new OldUsersWsRequest()
.setPermission("admin"));
assertThat(users.getUsersList()).extracting("login").contains(LOGIN);
--- /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.sonar.server.permission.ws;
+
+import com.google.common.base.Optional;
+import java.util.List;
+import org.sonar.api.server.ws.Request;
+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.db.component.ComponentDto;
+import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.UserWithPermissionDto;
+import org.sonar.server.permission.PermissionFinder;
+import org.sonar.server.user.UserSession;
+import org.sonarqube.ws.WsPermissions;
+import org.sonarqube.ws.WsPermissions.OldUsersWsResponse;
+import org.sonarqube.ws.client.permission.OldUsersWsRequest;
+
+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;
+import static org.sonar.server.permission.ws.WsProjectRef.newOptionalWsProjectRef;
+import static org.sonar.server.ws.WsUtils.writeProtobuf;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
+
+public class OldUsersAction implements PermissionsWsAction {
+
+ private final DbClient dbClient;
+ private final UserSession userSession;
+ private final PermissionFinder permissionFinder;
+ private final PermissionDependenciesFinder dependenciesFinder;
+
+ public OldUsersAction(DbClient dbClient, UserSession userSession, PermissionFinder permissionFinder, PermissionDependenciesFinder dependenciesFinder) {
+ this.dbClient = dbClient;
+ this.userSession = userSession;
+ this.permissionFinder = permissionFinder;
+ this.dependenciesFinder = dependenciesFinder;
+ }
+
+ @Override
+ public void define(WebService.NewController context) {
+ WebService.NewAction action = context.createAction("users")
+ .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)
+ .addSearchQuery("stas", "names")
+ .addSelectionModeParam()
+ .setInternal(true)
+ .setResponseExample(getClass().getResource("old-users-example.json"))
+ .setHandler(this);
+
+ createPermissionParameter(action);
+ createProjectParameters(action);
+ }
+
+ @Override
+ public void handle(Request wsRequest, Response wsResponse) throws Exception {
+ OldUsersWsResponse usersWsResponse = doHandle(toUsersWsRequest(wsRequest));
+ writeProtobuf(usersWsResponse, wsRequest, wsResponse);
+ }
+
+ private OldUsersWsResponse doHandle(OldUsersWsRequest request) {
+ Optional<WsProjectRef> wsProjectRef = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
+ validatePermission(request.getPermission(), wsProjectRef);
+ DbSession dbSession = dbClient.openSession(false);
+ try {
+ Optional<ComponentDto> project = dependenciesFinder.searchProject(dbSession, wsProjectRef);
+ checkProjectAdminUserByComponentDto(userSession, project);
+ PermissionQuery permissionQuery = buildPermissionQuery(request, project);
+ Long projectIdIfPresent = project.isPresent() ? project.get().getId() : null;
+ int total = dbClient.permissionDao().countUsers(dbSession, permissionQuery, projectIdIfPresent);
+ List<UserWithPermissionDto> usersWithPermission = permissionFinder.findUsersWithPermission(dbSession, permissionQuery);
+ return buildResponse(usersWithPermission, forPageIndex(request.getPage()).withPageSize(request.getPageSize()).andTotal(total));
+ } finally {
+ dbClient.closeSession(dbSession);
+ }
+ }
+
+ private static OldUsersWsRequest toUsersWsRequest(Request request) {
+ return new OldUsersWsRequest()
+ .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));
+ }
+
+ private static OldUsersWsResponse buildResponse(List<UserWithPermissionDto> usersWithPermission, Paging paging) {
+ OldUsersWsResponse.Builder userResponse = OldUsersWsResponse.newBuilder();
+ WsPermissions.OldUser.Builder user = WsPermissions.OldUser.newBuilder();
+ for (UserWithPermissionDto userWithPermission : usersWithPermission) {
+ userResponse.addUsers(
+ user
+ .clear()
+ .setLogin(userWithPermission.getLogin())
+ .setName(nullToEmpty(userWithPermission.getName()))
+ .setEmail(nullToEmpty(userWithPermission.getEmail()))
+ .setSelected(userWithPermission.getPermission() != null));
+ }
+
+ userResponse.getPagingBuilder()
+ .clear()
+ .setPageIndex(paging.pageIndex())
+ .setPageSize(paging.pageSize())
+ .setTotal(paging.total())
+ .build();
+
+ return userResponse.build();
+ }
+
+ private static PermissionQuery buildPermissionQuery(OldUsersWsRequest 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());
+ }
+
+ return permissionQuery.build();
+ }
+}
AddUserAction.class,
RemoveGroupAction.class,
RemoveUserAction.class,
- UsersAction.class,
+ OldUsersAction.class,
GroupsAction.class,
SearchGlobalPermissionsAction.class,
SearchProjectPermissionsAction.class,
import org.sonar.db.permission.UserWithPermissionDto;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsPermissions;
-import org.sonarqube.ws.WsPermissions.User;
-import org.sonarqube.ws.WsPermissions.UsersWsResponse;
+import org.sonarqube.ws.WsPermissions.OldUser;
+import org.sonarqube.ws.WsPermissions.OldUsersWsResponse;
import static java.lang.String.format;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
import static org.sonar.server.permission.ws.PermissionQueryParser.fromSelectionModeToMembership;
import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectPermissionParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
public class TemplateUsersAction implements PermissionsWsAction {
PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, templateRef);
PermissionQuery query = buildQuery(wsRequest, template);
- WsPermissions.UsersWsResponse templateUsersResponse = buildResponse(dbSession, query, template);
+ WsPermissions.OldUsersWsResponse templateUsersResponse = buildResponse(dbSession, query, template);
writeProtobuf(templateUsersResponse, wsRequest, wsResponse);
} finally {
dbClient.closeSession(dbSession);
.build();
}
- private WsPermissions.UsersWsResponse buildResponse(DbSession dbSession, PermissionQuery query, PermissionTemplateDto template) {
+ private OldUsersWsResponse buildResponse(DbSession dbSession, PermissionQuery query, PermissionTemplateDto template) {
List<UserWithPermissionDto> usersWithPermission = dbClient.permissionTemplateDao().selectUsers(dbSession, query, template.getId(), query.pageOffset(), query.pageSize());
int total = dbClient.permissionTemplateDao().countUsers(dbSession, query, template.getId());
- UsersWsResponse.Builder responseBuilder = UsersWsResponse.newBuilder();
+ OldUsersWsResponse.Builder responseBuilder = OldUsersWsResponse.newBuilder();
for (UserWithPermissionDto userWithPermission : usersWithPermission) {
responseBuilder.addUsers(userDtoToUserResponse(userWithPermission));
}
return responseBuilder.build();
}
- private static User userDtoToUserResponse(UserWithPermissionDto userWithPermission) {
- User.Builder userBuilder = User.newBuilder();
+ private static OldUser userDtoToUserResponse(UserWithPermissionDto userWithPermission) {
+ OldUser.Builder userBuilder = OldUser.newBuilder();
userBuilder.setLogin(userWithPermission.getLogin());
String email = userWithPermission.getEmail();
if (email != null) {
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsPermissions;
import org.sonarqube.ws.WsPermissions.UsersWsResponse;
-import org.sonarqube.ws.client.permission.UsersWsRequest;
+import org.sonarqube.ws.client.permission.OldUsersWsRequest;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Strings.nullToEmpty;
@Override
public void define(WebService.NewController context) {
- WebService.NewAction action = context.createAction("users")
+ 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 /> " +
writeProtobuf(usersWsResponse, wsRequest, wsResponse);
}
- private UsersWsResponse doHandle(UsersWsRequest request) {
+ private UsersWsResponse doHandle(OldUsersWsRequest request) {
Optional<WsProjectRef> wsProjectRef = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
validatePermission(request.getPermission(), wsProjectRef);
DbSession dbSession = dbClient.openSession(false);
}
}
- private static UsersWsRequest toUsersWsRequest(Request request) {
- return new UsersWsRequest()
+ private static OldUsersWsRequest toUsersWsRequest(Request request) {
+ return new OldUsersWsRequest()
.setPermission(request.mandatoryParam(PARAM_PERMISSION))
.setProjectId(request.param(PARAM_PROJECT_ID))
.setProjectKey(request.param(PARAM_PROJECT_KEY))
return userResponse.build();
}
- private static PermissionQuery buildPermissionQuery(UsersWsRequest request, Optional<ComponentDto> project) {
+ private static PermissionQuery buildPermissionQuery(OldUsersWsRequest request, Optional<ComponentDto> project) {
PermissionQuery.Builder permissionQuery = PermissionQuery.builder()
.permission(request.getPermission())
.pageIndex(request.getPage())
--- /dev/null
+{
+ "users": [
+ {
+ "login": "admin",
+ "name": "Administrator",
+ "email": "admin@admin.com",
+ "selected": true
+ },
+ {
+ "login": "george.orwell",
+ "name": "George Orwell",
+ "email": "george.orwell@1984.net",
+ "selected": true
+ }
+ ],
+ "paging": {
+ "pageSize": 100,
+ "total": 2,
+ "pageIndex": 1
+ }
+}
+
--- /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.sonar.server.permission.ws;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.server.ws.WebService.Param;
+import org.sonar.api.server.ws.WebService.SelectionMode;
+import org.sonar.api.utils.System2;
+import org.sonar.api.web.UserRole;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceTypesRule;
+import org.sonar.db.user.UserDto;
+import org.sonar.db.user.UserRoleDto;
+import org.sonar.server.component.ComponentFinder;
+import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.exceptions.UnauthorizedException;
+import org.sonar.server.permission.PermissionFinder;
+import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.usergroups.ws.UserGroupFinder;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
+import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
+import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
+import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.user.UserTesting.newUserDto;
+import static org.sonar.test.JsonAssert.assertJson;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
+
+public class OldUsersActionTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Rule
+ public UserSessionRule userSession = UserSessionRule.standalone();
+
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+ ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
+ DbClient dbClient = db.getDbClient();
+ DbSession dbSession = db.getSession();
+ WsActionTester ws;
+ OldUsersAction underTest;
+
+ @Before
+ public void setUp() {
+ PermissionFinder permissionFinder = new PermissionFinder(dbClient);
+ PermissionDependenciesFinder dependenciesFinder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient), new UserGroupFinder(dbClient), resourceTypes);
+ underTest = new OldUsersAction(dbClient, userSession, permissionFinder, dependenciesFinder);
+ ws = new WsActionTester(underTest);
+
+ userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
+ }
+
+ @Test
+ public void search_for_users_with_response_example() {
+ UserDto user1 = insertUser(new UserDto().setLogin("admin").setName("Administrator").setEmail("admin@admin.com"));
+ UserDto user2 = insertUser(new UserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net"));
+ insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
+ insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
+ dbSession.commit();
+
+ String result = ws.newRequest().setParam("permission", "scan").execute().getInput();
+
+ assertJson(result).isSimilarTo(getClass().getResource("users-example.json"));
+ }
+
+ @Test
+ public void search_for_users_with_one_permission() {
+ insertUsers();
+ String result = ws.newRequest().setParam("permission", "scan").execute().getInput();
+
+ assertJson(result).isSimilarTo(getClass().getResource("UsersActionTest/users.json"));
+ }
+
+ @Test
+ public void search_for_users_with_permission_on_project() {
+ dbClient.componentDao().insert(dbSession, newProjectDto("project-uuid").setKey("project-key"));
+ ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, "project-uuid");
+ UserDto user = insertUser(newUserDto().setLogin("project-user-login").setName("project-user-name"));
+ insertUserRole(new UserRoleDto().setRole(ISSUE_ADMIN).setUserId(user.getId()).setResourceId(project.getId()));
+ dbSession.commit();
+ userSession.login().addProjectUuidPermissions(SYSTEM_ADMIN, "project-uuid");
+
+ String result = ws.newRequest()
+ .setParam(PARAM_PERMISSION, ISSUE_ADMIN)
+ .setParam(PARAM_PROJECT_ID, "project-uuid")
+ .execute().getInput();
+
+ assertThat(result).contains("project-user-login")
+ .doesNotContain("login-1");
+ }
+
+ @Test
+ public void search_for_users_with_query_as_a_parameter() {
+ insertUsers();
+ String result = ws.newRequest()
+ .setParam("permission", "scan")
+ .setParam(Param.TEXT_QUERY, "ame-1")
+ .execute().getInput();
+
+ assertThat(result).contains("login-1")
+ .doesNotContain("login-2")
+ .doesNotContain("login-3");
+ }
+
+ @Test
+ public void search_for_users_with_select_as_a_parameter() {
+ insertUsers();
+ String result = ws.newRequest()
+ .setParam("permission", "scan")
+ .setParam(Param.SELECTED, SelectionMode.ALL.value())
+ .execute().getInput();
+
+ assertThat(result).contains("login-1", "login-2", "login-3");
+ }
+
+ @Test
+ public void fail_if_project_permission_without_project() {
+ expectedException.expect(BadRequestException.class);
+
+ ws.newRequest()
+ .setParam(PARAM_PERMISSION, UserRole.ISSUE_ADMIN)
+ .setParam(Param.SELECTED, SelectionMode.ALL.value())
+ .execute();
+ }
+
+ @Test
+ public void fail_if_permission_parameter_is_not_filled() {
+ expectedException.expect(IllegalArgumentException.class);
+
+ ws.newRequest().execute();
+ }
+
+ @Test
+ public void fail_if_insufficient_privileges() {
+ expectedException.expect(ForbiddenException.class);
+ userSession.login("login");
+
+ ws.newRequest()
+ .setParam("permission", SYSTEM_ADMIN)
+ .execute();
+ }
+
+ @Test
+ public void fail_if_not_logged_in() {
+ expectedException.expect(UnauthorizedException.class);
+ userSession.anonymous();
+
+ ws.newRequest()
+ .setParam("permission", SYSTEM_ADMIN)
+ .execute();
+ }
+
+ @Test
+ public void fail_if_project_uuid_and_project_key_are_provided() {
+ expectedException.expect(BadRequestException.class);
+ expectedException.expectMessage("Project id or project key can be provided, not both.");
+ dbClient.componentDao().insert(dbSession, newProjectDto("project-uuid").setKey("project-key"));
+ dbSession.commit();
+
+ ws.newRequest()
+ .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
+ .setParam(PARAM_PROJECT_ID, "project-uuid")
+ .setParam(PARAM_PROJECT_KEY, "project-key")
+ .execute();
+ }
+
+ private UserDto insertUser(UserDto userDto) {
+ UserDto user = dbClient.userDao().insert(dbSession, userDto.setActive(true));
+ dbSession.commit();
+ return user;
+ }
+
+ private void insertUserRole(UserRoleDto userRoleDto) {
+ dbClient.roleDao().insertUserRole(dbSession, userRoleDto);
+ dbSession.commit();
+ }
+
+ private void insertUsers() {
+ UserDto user1 = insertUser(new UserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
+ UserDto user2 = insertUser(new UserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
+ UserDto user3 = insertUser(new UserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
+ insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
+ insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
+ insertUserRole(new UserRoleDto().setRole(SYSTEM_ADMIN).setUserId(user3.getId()));
+ dbSession.commit();
+ }
+}
--- /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;
+
+import static java.util.Objects.requireNonNull;
+
+public class OldUsersWsRequest {
+ private String permission;
+ private String projectId;
+ private String projectKey;
+ private String selected;
+ private String query;
+ private Integer page;
+ private Integer pageSize;
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public OldUsersWsRequest setPermission(String permission) {
+ this.permission = requireNonNull(permission);
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public OldUsersWsRequest setProjectId(@Nullable String projectId) {
+ this.projectId = projectId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectKey() {
+ return projectKey;
+ }
+
+ public OldUsersWsRequest setProjectKey(@Nullable String projectKey) {
+ this.projectKey = projectKey;
+ return this;
+ }
+
+ @CheckForNull
+ public String getSelected() {
+ return selected;
+ }
+
+ public OldUsersWsRequest setSelected(@Nullable String selected) {
+ this.selected = selected;
+ return this;
+ }
+
+ @CheckForNull
+ public String getQuery() {
+ return query;
+ }
+
+ public OldUsersWsRequest setQuery(@Nullable String query) {
+ this.query = query;
+ return this;
+ }
+
+ @CheckForNull
+ public Integer getPage() {
+ return page;
+ }
+
+ public OldUsersWsRequest setPage(int page) {
+ this.page = page;
+ return this;
+ }
+
+ @CheckForNull
+ public Integer getPageSize() {
+ return pageSize;
+ }
+
+ public OldUsersWsRequest setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ return this;
+ }
+}
.setParam(PARAM_PROJECT_KEY_PATTERN, request.getProjectKeyPattern()), UpdateTemplateWsResponse.parser());
}
- public UsersWsResponse users(UsersWsRequest request) {
+ public UsersWsResponse users(OldUsersWsRequest request) {
return call(new GetRequest(path("users"))
.setParam(PARAM_PERMISSION, request.getPermission())
.setParam(PARAM_PROJECT_ID, request.getProjectId())
+++ /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;
-
-import static java.util.Objects.requireNonNull;
-
-public class UsersWsRequest {
- private String permission;
- private String projectId;
- private String projectKey;
- private String selected;
- private String query;
- private Integer page;
- private Integer pageSize;
-
- public String getPermission() {
- return permission;
- }
-
- public UsersWsRequest setPermission(String permission) {
- this.permission = requireNonNull(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 getSelected() {
- return selected;
- }
-
- public UsersWsRequest setSelected(@Nullable String selected) {
- this.selected = selected;
- 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;
- }
-}
option java_outer_classname = "WsPermissions";
option optimize_for = SPEED;
+// WS api/permissions/users for internal use only
+// and WS api/permissions/template_users for internal use only
+message OldUsersWsResponse {
+ optional sonarqube.ws.commons.Paging paging = 1;
+ repeated OldUser users = 2;
+}
+
// WS api/permissions/users for internal use only
// and WS api/permissions/template_users for internal use only
message UsersWsResponse {
repeated Permission permissions = 7;
}
+message OldUser {
+ optional string login = 1;
+ optional string name = 2;
+ optional string email = 3;
+ optional bool selected = 4;
+}
+
message User {
optional string login = 1;
optional string name = 2;
@Test
public void users_does_GET_on_Ws_users() {
- underTest.users(new UsersWsRequest()
+ underTest.users(new OldUsersWsRequest()
.setPermission(PERMISSION_VALUE)
.setProjectId(PROJECT_ID_VALUE)
.setProjectKey(PROJECT_KEY_VALUE)