aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-07-05 14:53:32 +0200
committerStas Vilchik <vilchiks@gmail.com>2016-07-12 10:16:53 +0200
commitfc558542c4d6bbeb0b5f98314f9697c48d35a9a4 (patch)
treee82d3922bc3d83f9f4497e872075bdc474cb2ce5 /server/sonar-server
parentcf507c746df0fe8ceb3a1db2f1f4d0a4718f0ceb (diff)
downloadsonarqube-fc558542c4d6bbeb0b5f98314f9697c48d35a9a4.tar.gz
sonarqube-fc558542c4d6bbeb0b5f98314f9697c48d35a9a4.zip
SONAR-7835 Select users by query
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java22
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/OldUsersAction.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionsWsParametersBuilder.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchGlobalPermissionsAction.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateGroupsAction.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateUsersAction.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java19
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/PermissionQueryTest.java57
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddUserToTemplateActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java4
17 files changed, 65 insertions, 119 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java
index 554e24a0d7d..15949413fab 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionFinder.java
@@ -36,7 +36,7 @@ import org.sonar.db.component.ResourceDto;
import org.sonar.db.component.ResourceQuery;
import org.sonar.db.permission.GroupWithPermissionDto;
import org.sonar.db.permission.PermissionDao;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.UserWithPermissionDto;
import org.sonar.server.exceptions.NotFoundException;
@@ -55,7 +55,7 @@ public class PermissionFinder {
this.permissionDao = dbClient.permissionDao();
}
- public List<UserWithPermissionDto> findUsersWithPermission(DbSession dbSession, PermissionQuery query) {
+ public List<UserWithPermissionDto> findUsersWithPermission(DbSession dbSession, OldPermissionQuery query) {
Long componentId = componentId(query.component());
int limit = query.pageSize();
return permissionDao.selectUsers(dbSession, query, componentId, offset(query), limit);
@@ -64,7 +64,7 @@ public class PermissionFinder {
/**
* Paging for groups search is done in Java in order to correctly handle the 'Anyone' group
*/
- public List<GroupWithPermissionDto> findGroupsWithPermission(DbSession dbSession, PermissionQuery query) {
+ public List<GroupWithPermissionDto> findGroupsWithPermission(DbSession dbSession, OldPermissionQuery query) {
Long componentId = componentId(query.component());
return toGroupQueryResult(permissionDao.selectGroups(dbSession, query, componentId), query);
}
@@ -82,7 +82,7 @@ public class PermissionFinder {
}
}
- private static List<GroupWithPermissionDto> toGroupQueryResult(List<GroupWithPermissionDto> dtos, PermissionQuery query) {
+ private static List<GroupWithPermissionDto> toGroupQueryResult(List<GroupWithPermissionDto> dtos, OldPermissionQuery query) {
addAnyoneGroup(dtos, query);
List<GroupWithPermissionDto> filteredDtos = filterMembership(dtos, query);
@@ -93,13 +93,13 @@ public class PermissionFinder {
return pagedGroups(filteredDtos, paging);
}
- private static int offset(PermissionQuery query) {
+ private static int offset(OldPermissionQuery query) {
int pageSize = query.pageSize();
int pageIndex = query.pageIndex();
return (pageIndex - 1) * pageSize;
}
- private static List<GroupWithPermissionDto> filterMembership(List<GroupWithPermissionDto> dtos, PermissionQuery query) {
+ private static List<GroupWithPermissionDto> filterMembership(List<GroupWithPermissionDto> dtos, OldPermissionQuery query) {
return newArrayList(Iterables.filter(dtos, new GroupWithPermissionMatchQuery(query)));
}
@@ -107,7 +107,7 @@ public class PermissionFinder {
* As the anyone group does not exists in db, it's not returned when it has not the permission.
* We have to manually add it at the begin of the list, if it matched the search text
*/
- private static void addAnyoneGroup(List<GroupWithPermissionDto> groups, PermissionQuery query) {
+ private static void addAnyoneGroup(List<GroupWithPermissionDto> groups, OldPermissionQuery query) {
boolean hasAnyoneGroup = Iterables.any(groups, IsAnyoneGroup.INSTANCE);
if (!hasAnyoneGroup
&& !GlobalPermissions.SYSTEM_ADMIN.equals(query.permission())
@@ -131,17 +131,17 @@ public class PermissionFinder {
}
private static class GroupWithPermissionMatchQuery implements Predicate<GroupWithPermissionDto> {
- private final PermissionQuery query;
+ private final OldPermissionQuery query;
- public GroupWithPermissionMatchQuery(PermissionQuery query) {
+ public GroupWithPermissionMatchQuery(OldPermissionQuery query) {
this.query = query;
}
@Override
public boolean apply(@Nonnull GroupWithPermissionDto dto) {
- if (PermissionQuery.IN.equals(query.membership())) {
+ if (OldPermissionQuery.IN.equals(query.membership())) {
return dto.getPermission() != null;
- } else if (PermissionQuery.OUT.equals(query.membership())) {
+ } else if (OldPermissionQuery.OUT.equals(query.membership())) {
return dto.getPermission() == null;
}
return true;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java
index bf11e1f9813..4346b4ae2bf 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java
@@ -31,7 +31,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.GroupWithPermissionDto;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.server.permission.PermissionFinder;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Common;
@@ -98,7 +98,7 @@ public class GroupsAction implements PermissionsWsAction {
Optional<ComponentDto> project = dependenciesFinder.searchProject(dbSession, newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey()));
checkProjectAdminUserByComponentDto(userSession, project);
- PermissionQuery permissionQuery = buildPermissionQuery(request, project);
+ OldPermissionQuery permissionQuery = buildPermissionQuery(request, project);
Long projectIdIfPresent = project.isPresent() ? project.get().getId() : null;
int total = dbClient.permissionDao().countGroups(dbSession, permissionQuery.permission(), projectIdIfPresent);
List<GroupWithPermissionDto> groupsWithPermission = permissionFinder.findGroupsWithPermission(dbSession, permissionQuery);
@@ -128,8 +128,8 @@ public class GroupsAction implements PermissionsWsAction {
.setSelected(request.mandatoryParam(Param.SELECTED));
}
- private static PermissionQuery buildPermissionQuery(GroupsWsRequest request, Optional<ComponentDto> project) {
- PermissionQuery.Builder permissionQuery = PermissionQuery.builder()
+ private static OldPermissionQuery buildPermissionQuery(GroupsWsRequest request, Optional<ComponentDto> project) {
+ OldPermissionQuery.Builder permissionQuery = OldPermissionQuery.builder()
.permission(request.getPermission())
.pageIndex(request.getPage())
.pageSize(request.getPageSize())
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/OldUsersAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/OldUsersAction.java
index 830964e8993..fbee4d1eb4d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/OldUsersAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/OldUsersAction.java
@@ -30,7 +30,7 @@ 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.OldPermissionQuery;
import org.sonar.db.permission.UserWithPermissionDto;
import org.sonar.server.permission.PermissionFinder;
import org.sonar.server.user.UserSession;
@@ -99,7 +99,7 @@ public class OldUsersAction implements PermissionsWsAction {
try {
Optional<ComponentDto> project = dependenciesFinder.searchProject(dbSession, wsProjectRef);
checkProjectAdminUserByComponentDto(userSession, project);
- PermissionQuery permissionQuery = buildPermissionQuery(request, project);
+ OldPermissionQuery 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);
@@ -143,8 +143,8 @@ public class OldUsersAction implements PermissionsWsAction {
return userResponse.build();
}
- private static PermissionQuery buildPermissionQuery(OldUsersWsRequest request, Optional<ComponentDto> project) {
- PermissionQuery.Builder permissionQuery = PermissionQuery.builder()
+ private static OldPermissionQuery buildPermissionQuery(OldUsersWsRequest request, Optional<ComponentDto> project) {
+ OldPermissionQuery.Builder permissionQuery = OldPermissionQuery.builder()
.permission(request.getPermission())
.pageIndex(request.getPage())
.pageSize(request.getPageSize())
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionsWsParametersBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionsWsParametersBuilder.java
index 4acfc3b4513..c616ae192fe 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionsWsParametersBuilder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionsWsParametersBuilder.java
@@ -58,8 +58,8 @@ public class PermissionsWsParametersBuilder {
// static methods only
}
- public static void createPermissionParameter(NewAction action) {
- action.createParam(PARAM_PERMISSION)
+ public static NewParam createPermissionParameter(NewAction action) {
+ return action.createParam(PARAM_PERMISSION)
.setDescription(PERMISSION_PARAM_DESCRIPTION)
.setRequired(true);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchGlobalPermissionsAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchGlobalPermissionsAction.java
index 14321bdb43e..1dc976c2768 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchGlobalPermissionsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchGlobalPermissionsAction.java
@@ -26,7 +26,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.user.GroupMembershipQuery;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsPermissions.Permission;
@@ -78,7 +78,7 @@ public class SearchGlobalPermissionsAction implements PermissionsWsAction {
Permission.Builder permission = newBuilder();
for (String permissionKey : GlobalPermissions.ALL) {
- PermissionQuery permissionQuery = permissionQuery(permissionKey);
+ OldPermissionQuery permissionQuery = permissionQuery(permissionKey);
response.addPermissions(
permission
@@ -106,12 +106,12 @@ public class SearchGlobalPermissionsAction implements PermissionsWsAction {
return dbClient.permissionDao().countGroups(dbSession, permissionKey, null);
}
- private int countUsers(DbSession dbSession, PermissionQuery permissionQuery) {
+ private int countUsers(DbSession dbSession, OldPermissionQuery permissionQuery) {
return dbClient.permissionDao().countUsers(dbSession, permissionQuery, null);
}
- private static PermissionQuery permissionQuery(String permissionKey) {
- return PermissionQuery.builder()
+ private static OldPermissionQuery permissionQuery(String permissionKey) {
+ return OldPermissionQuery.builder()
.permission(permissionKey)
.membership(GroupMembershipQuery.IN)
.build();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateGroupsAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateGroupsAction.java
index 94c3871665a..5e92540405f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateGroupsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateGroupsAction.java
@@ -28,7 +28,7 @@ import org.sonar.api.server.ws.WebService.SelectionMode;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.GroupWithPermissionDto;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsPermissions.Group;
@@ -81,7 +81,7 @@ public class TemplateGroupsAction implements PermissionsWsAction {
WsTemplateRef templateRef = WsTemplateRef.fromRequest(wsRequest);
PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, templateRef);
- PermissionQuery query = buildQuery(wsRequest, template);
+ OldPermissionQuery query = buildQuery(wsRequest, template);
WsGroupsResponse groupsResponse = buildResponse(dbSession, query, template);
writeProtobuf(groupsResponse, wsRequest, wsResponse);
@@ -90,7 +90,7 @@ public class TemplateGroupsAction implements PermissionsWsAction {
}
}
- private WsGroupsResponse buildResponse(DbSession dbSession, PermissionQuery query, PermissionTemplateDto template) {
+ private WsGroupsResponse buildResponse(DbSession dbSession, OldPermissionQuery query, PermissionTemplateDto template) {
int total = dbClient.permissionTemplateDao().countGroups(dbSession, query, template.getId());
List<GroupWithPermissionDto> groupsWithPermission = dbClient.permissionTemplateDao().selectGroups(dbSession, query, template.getId(), query.pageOffset(), query.pageSize());
@@ -109,10 +109,10 @@ public class TemplateGroupsAction implements PermissionsWsAction {
return groupsResponse.build();
}
- private static PermissionQuery buildQuery(Request request, PermissionTemplateDto template) {
+ private static OldPermissionQuery buildQuery(Request request, PermissionTemplateDto template) {
String permission = validateProjectPermission(request.mandatoryParam(PARAM_PERMISSION));
- PermissionQuery.Builder permissionQuery = PermissionQuery.builder()
+ OldPermissionQuery.Builder permissionQuery = OldPermissionQuery.builder()
.permission(permission)
.pageIndex(request.mandatoryParamAsInt(Param.PAGE))
.pageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE))
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateUsersAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateUsersAction.java
index bd63a924e07..b115ad453f0 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateUsersAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateUsersAction.java
@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.server.ws.WebService.SelectionMode;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.UserWithPermissionDto;
import org.sonar.server.user.UserSession;
@@ -85,7 +85,7 @@ public class TemplateUsersAction implements PermissionsWsAction {
WsTemplateRef templateRef = WsTemplateRef.fromRequest(wsRequest);
PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, templateRef);
- PermissionQuery query = buildQuery(wsRequest, template);
+ OldPermissionQuery query = buildQuery(wsRequest, template);
WsPermissions.OldUsersWsResponse templateUsersResponse = buildResponse(dbSession, query, template);
writeProtobuf(templateUsersResponse, wsRequest, wsResponse);
} finally {
@@ -93,10 +93,10 @@ public class TemplateUsersAction implements PermissionsWsAction {
}
}
- private static PermissionQuery buildQuery(Request wsRequest, PermissionTemplateDto template) {
+ private static OldPermissionQuery buildQuery(Request wsRequest, PermissionTemplateDto template) {
String permission = validateProjectPermission(wsRequest.mandatoryParam(PARAM_PERMISSION));
- return PermissionQuery.builder()
+ return OldPermissionQuery.builder()
.template(template.getUuid())
.permission(permission)
.membership(fromSelectionModeToMembership(wsRequest.mandatoryParam(Param.SELECTED)))
@@ -106,7 +106,7 @@ public class TemplateUsersAction implements PermissionsWsAction {
.build();
}
- private OldUsersWsResponse buildResponse(DbSession dbSession, PermissionQuery query, PermissionTemplateDto template) {
+ private OldUsersWsResponse buildResponse(DbSession dbSession, OldPermissionQuery 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());
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java
index 40f50538e05..2950f8733eb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java
@@ -29,6 +29,7 @@ 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.OldPermissionQuery;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.UserWithPermissionDto;
import org.sonar.server.permission.PermissionFinder;
@@ -39,6 +40,8 @@ import org.sonarqube.ws.client.permission.UsersWsRequest;
import static com.google.common.base.Strings.nullToEmpty;
import static org.sonar.api.utils.Paging.forPageIndex;
+import static org.sonar.db.permission.PermissionQuery.DEFAULT_PAGE_SIZE;
+import static org.sonar.db.permission.PermissionQuery.RESULTS_MAX_SIZE;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentDto;
import static org.sonar.server.permission.ws.PermissionRequestValidator.validatePermission;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
@@ -51,8 +54,6 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_P
public class UsersAction implements PermissionsWsAction {
- private static final int MAX_SIZE = 100;
-
private final DbClient dbClient;
private final UserSession userSession;
private final PermissionFinder permissionFinder;
@@ -73,13 +74,15 @@ public class UsersAction implements PermissionsWsAction {
"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")
+ .addPagingParams(DEFAULT_PAGE_SIZE, RESULTS_MAX_SIZE)
.setInternal(true)
.setResponseExample(getClass().getResource("users-example.json"))
.setHandler(this);
- createPermissionParameter(action);
+ action.createParam(Param.TEXT_QUERY)
+ .setDescription("Limit search to user names that contain the supplied string. Must have at least %d characters.", PermissionQuery.SEARCH_QUERY_MIN_LENGTH)
+ .setExampleValue("eri");
+ createPermissionParameter(action).setRequired(false);
createProjectParameters(action);
}
@@ -96,7 +99,7 @@ public class UsersAction implements PermissionsWsAction {
try {
Optional<ComponentDto> project = dependenciesFinder.searchProject(dbSession, wsProjectRef);
checkProjectAdminUserByComponentDto(userSession, project);
- PermissionQuery permissionQuery = buildPermissionQuery(request, project);
+ OldPermissionQuery 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);
@@ -139,8 +142,8 @@ public class UsersAction implements PermissionsWsAction {
return userResponse.build();
}
- private static PermissionQuery buildPermissionQuery(UsersWsRequest request, Optional<ComponentDto> project) {
- PermissionQuery.Builder permissionQuery = PermissionQuery.builder()
+ private static OldPermissionQuery buildPermissionQuery(UsersWsRequest request, Optional<ComponentDto> project) {
+ OldPermissionQuery.Builder permissionQuery = OldPermissionQuery.builder()
.permission(request.getPermission())
.pageIndex(request.getPage())
.pageSize(request.getPageSize())
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java
index 7415ff30426..ceddba001b5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java
@@ -25,7 +25,7 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.permission.ws.PermissionDependenciesFinder;
@@ -110,7 +110,7 @@ public class AddGroupToTemplateAction implements PermissionsWsAction {
private boolean groupAlreadyAdded(DbSession dbSession, long templateId, @Nullable GroupDto group, String permission) {
String groupName = group == null ? ANYONE : group.getName();
- PermissionQuery permissionQuery = PermissionQuery.builder().membership(IN).permission(permission).build();
+ OldPermissionQuery permissionQuery = OldPermissionQuery.builder().membership(IN).permission(permission).build();
return dbClient.permissionTemplateDao().hasGroup(dbSession, permissionQuery, templateId, groupName);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java
index a6d895e5169..c0da46c0911 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java
@@ -26,7 +26,7 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.UserWithPermissionDto;
import org.sonar.db.user.UserDto;
@@ -108,7 +108,7 @@ public class AddUserToTemplateAction implements PermissionsWsAction {
}
private boolean isUserAlreadyAdded(DbSession dbSession, long templateId, String userLogin, String permission) {
- PermissionQuery permissionQuery = PermissionQuery.builder().permission(permission).membership(IN).build();
+ OldPermissionQuery permissionQuery = OldPermissionQuery.builder().permission(permission).membership(IN).build();
List<UserWithPermissionDto> usersWithPermission = dbClient.permissionTemplateDao().selectUsers(dbSession, permissionQuery, templateId, 0, Integer.MAX_VALUE);
return from(usersWithPermission).anyMatch(new HasUserPredicate(userLogin));
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionQueryTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionQueryTest.java
deleted file mode 100644
index 06d1aa9560f..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionQueryTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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;
-
-import org.junit.Test;
-import org.sonar.db.permission.PermissionQuery;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-
-public class PermissionQueryTest {
-
- @Test
- public void fail_on_null_permission() {
- PermissionQuery.Builder builder = PermissionQuery.builder();
- builder.permission(null);
-
- try {
- builder.build();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(NullPointerException.class).hasMessage("Permission cannot be null.");
- }
- }
-
- @Test
- public void fail_on_invalid_membership() {
- PermissionQuery.Builder builder = PermissionQuery.builder();
- builder.permission("admin");
- builder.membership("unknwown");
-
- try {
- builder.build();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Membership is not valid (got unknwown). Availables values are [ANY, IN, OUT]");
- }
- }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java
index f94005ad729..4339c5421de 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java
@@ -36,7 +36,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.GroupWithPermissionDto;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.component.ComponentFinder;
@@ -238,7 +238,7 @@ public class AddGroupToTemplateActionTest {
}
private List<String> getGroupNamesInTemplateAndPermission(long templateId, String permission) {
- PermissionQuery permissionQuery = PermissionQuery.builder().permission(permission).membership(IN).build();
+ OldPermissionQuery permissionQuery = OldPermissionQuery.builder().permission(permission).membership(IN).build();
return from(dbClient.permissionTemplateDao()
.selectGroups(dbSession, permissionQuery, templateId))
.transform(GroupWithPermissionToGroupName.INSTANCE)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddUserToTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddUserToTemplateActionTest.java
index d82607564d3..5574cad4d15 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddUserToTemplateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddUserToTemplateActionTest.java
@@ -34,7 +34,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.UserWithPermissionDto;
import org.sonar.db.user.UserDto;
@@ -207,7 +207,7 @@ public class AddUserToTemplateActionTest {
}
private List<String> getLoginsInTemplateAndPermission(long templateId, String permission) {
- PermissionQuery permissionQuery = PermissionQuery.builder().permission(permission).membership(IN).build();
+ OldPermissionQuery permissionQuery = OldPermissionQuery.builder().permission(permission).membership(IN).build();
return from(dbClient.permissionTemplateDao()
.selectUsers(dbSession, permissionQuery, templateId, 0, Integer.MAX_VALUE))
.transform(UserWithPermissionToUserLogin.INSTANCE)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
index 973e760cdf8..add9707d364 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
@@ -38,7 +38,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.GroupWithPermissionDto;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionRepository;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.UserWithPermissionDto;
@@ -301,8 +301,8 @@ public class ApplyTemplateActionTest {
dbSession.commit();
}
- private static PermissionQuery query(String permission) {
- return PermissionQuery.builder().membership(IN).permission(permission).build();
+ private static OldPermissionQuery query(String permission) {
+ return OldPermissionQuery.builder().membership(IN).permission(permission).build();
}
private static class PermissionNotNull implements Predicate<GroupWithPermissionDto> {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
index 100e3843f93..753c03c5191 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
@@ -54,7 +54,7 @@ import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.GroupWithPermissionDto;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionRepository;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.UserWithPermissionDto;
@@ -272,8 +272,8 @@ public class BulkApplyTemplateActionTest {
dbSession.commit();
}
- private static PermissionQuery query(String permission) {
- return PermissionQuery.builder().membership(IN).permission(permission).build();
+ private static OldPermissionQuery query(String permission) {
+ return OldPermissionQuery.builder().membership(IN).permission(permission).build();
}
private static class PermissionNotNull implements Predicate<GroupWithPermissionDto> {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java
index ad649dd0a38..9df6be6c954 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java
@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.permission.GroupWithPermissionDto;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.component.ComponentFinder;
@@ -245,7 +245,7 @@ public class RemoveGroupFromTemplateActionTest {
}
private List<String> getGroupNamesInTemplateAndPermission(long templateId, String permission) {
- PermissionQuery permissionQuery = PermissionQuery.builder().permission(permission).membership(IN).build();
+ OldPermissionQuery permissionQuery = OldPermissionQuery.builder().permission(permission).membership(IN).build();
return from(dbClient.permissionTemplateDao()
.selectGroups(dbSession, permissionQuery, templateId))
.transform(GroupWithPermissionToGroupName.INSTANCE)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java
index 770d3b4f2d9..764d4ad7bea 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java
@@ -34,7 +34,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionQuery;
+import org.sonar.db.permission.OldPermissionQuery;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.permission.UserWithPermissionDto;
import org.sonar.db.user.UserDto;
@@ -231,7 +231,7 @@ public class RemoveUserFromTemplateActionTest {
}
private List<String> getLoginsInTemplateAndPermission(long templateId, String permission) {
- PermissionQuery permissionQuery = PermissionQuery.builder().permission(permission).membership(IN).build();
+ OldPermissionQuery permissionQuery = OldPermissionQuery.builder().permission(permission).membership(IN).build();
return from(dbClient.permissionTemplateDao()
.selectUsers(dbSession, permissionQuery, templateId, 0, Integer.MAX_VALUE))
.transform(UserWithPermissionToUserLogin.INSTANCE)