diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2020-03-24 11:13:08 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-04-14 20:04:04 +0000 |
commit | d8081f847f92247a64166572605876e67e9a34ed (patch) | |
tree | 6d267df0fdb86df044c04c7436e465318cdf8afa /server/sonar-webserver-webapi | |
parent | d662d0c0269e1a12da0c3ecdb8f9d33b765ccdcc (diff) | |
download | sonarqube-d8081f847f92247a64166572605876e67e9a34ed.tar.gz sonarqube-d8081f847f92247a64166572605876e67e9a34ed.zip |
SONAR-13193 Stop using legacy project ID and use project UUID instead
Diffstat (limited to 'server/sonar-webserver-webapi')
51 files changed, 343 insertions, 429 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java index a6439abda8c..d2fd1fffea3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java @@ -99,7 +99,7 @@ public class ComponentViewerJsonWriter { List<PropertyDto> propertyDtos = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey("favourite") - .setComponentId(component.getId()) + .setComponentUuid(component.uuid()) .setUserId(userSession.getUserId()) .build(), session); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 846b2c3af3d..721071b1f8f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -281,11 +281,11 @@ public class SearchProjectsAction implements ComponentsWsAction { .build(), dbSession); - List<Long> favoriteDbIds = props.stream() - .map(PropertyDto::getResourceId) - .collect(toList(props.size())); + List<String> favoriteDbUuids = props.stream() + .map(PropertyDto::getComponentUuid) + .collect(MoreCollectors.toList(props.size())); - return dbClient.componentDao().selectByIds(dbSession, favoriteDbIds).stream() + return dbClient.componentDao().selectByUuids(dbSession, favoriteDbUuids).stream() .filter(ComponentDto::isEnabled) .filter(f -> f.qualifier().equals(Qualifiers.PROJECT)) .map(ComponentDto::uuid) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java index c599edcbf15..3f1b145fff5 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java @@ -56,9 +56,9 @@ public class FavoriteFinder { .setKey(PROP_FAVORITE_KEY) .setUserId(userSession.getUserId()) .build(); - Set<Long> componentIds = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getResourceId).collect(Collectors.toSet()); + Set<String> componentUuids = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getComponentUuid).collect(Collectors.toSet()); - return dbClient.componentDao().selectByIds(dbSession, componentIds).stream() + return dbClient.componentDao().selectByUuids(dbSession, componentUuids).stream() .sorted(Comparator.comparing(ComponentDto::name)) .collect(toList()); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java index da7fcc654eb..0f0a53b7724 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java @@ -52,9 +52,9 @@ import static java.util.Comparator.naturalOrder; import static java.util.Comparator.nullsFirst; import static java.util.Optional.ofNullable; import static org.sonar.core.util.stream.MoreCollectors.toOneElement; +import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.notification.ws.NotificationsWsParameters.ACTION_LIST; import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_LOGIN; -import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.ws.WsUtils.writeProtobuf; public class ListAction implements NotificationsWsAction { @@ -122,11 +122,11 @@ public class ListAction implements NotificationsWsAction { private UnaryOperator<ListResponse.Builder> addNotifications(DbSession dbSession, UserDto user) { return response -> { List<PropertyDto> properties = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession); - Map<Long, ComponentDto> componentsById = searchProjects(dbSession, properties); - Map<String, OrganizationDto> organizationsByUuid = getOrganizations(dbSession, componentsById.values()); + Map<String, ComponentDto> componentsByUuid = searchProjects(dbSession, properties); + Map<String, OrganizationDto> organizationsByUuid = getOrganizations(dbSession, componentsByUuid.values()); Predicate<PropertyDto> isNotification = prop -> prop.getKey().startsWith("notification."); - Predicate<PropertyDto> isComponentInDb = prop -> prop.getResourceId() == null || componentsById.containsKey(prop.getResourceId()); + Predicate<PropertyDto> isComponentInDb = prop -> prop.getComponentUuid() == null || componentsByUuid.containsKey(prop.getComponentUuid()); Notification.Builder notification = Notification.newBuilder(); @@ -134,7 +134,7 @@ public class ListAction implements NotificationsWsAction { .filter(isNotification) .filter(channelAndDispatcherAuthorized()) .filter(isComponentInDb) - .map(toWsNotification(notification, organizationsByUuid, componentsById)) + .map(toWsNotification(notification, organizationsByUuid, componentsByUuid)) .sorted(comparing(Notification::getProject, nullsFirst(naturalOrder())) .thenComparing(Notification::getChannel) .thenComparing(Notification::getType)) @@ -154,19 +154,19 @@ public class ListAction implements NotificationsWsAction { } private boolean isDispatcherAuthorized(PropertyDto prop, String dispatcher) { - return (prop.getResourceId() != null && dispatchers.getProjectDispatchers().contains(dispatcher)) || dispatchers.getGlobalDispatchers().contains(dispatcher); + return (prop.getComponentUuid() != null && dispatchers.getProjectDispatchers().contains(dispatcher)) || dispatchers.getGlobalDispatchers().contains(dispatcher); } - private Map<Long, ComponentDto> searchProjects(DbSession dbSession, List<PropertyDto> properties) { - Set<Long> componentIds = properties.stream() - .map(PropertyDto::getResourceId) + private Map<String, ComponentDto> searchProjects(DbSession dbSession, List<PropertyDto> properties) { + Set<String> componentUuids = properties.stream() + .map(PropertyDto::getComponentUuid) .filter(Objects::nonNull) .collect(MoreCollectors.toSet(properties.size())); - Set<Long> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectIds(dbSession, componentIds, userSession.getUserId(), UserRole.USER); - return dbClient.componentDao().selectByIds(dbSession, componentIds) + Set<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedProjectUuids(dbSession, componentUuids, userSession.getUserId(), UserRole.USER); + return dbClient.componentDao().selectByUuids(dbSession, componentUuids) .stream() - .filter(c -> authorizedProjectIds.contains(c.getId())) - .collect(MoreCollectors.uniqueIndex(ComponentDto::getId)); + .filter(c -> authorizedProjectUuids.contains(c.uuid())) + .collect(MoreCollectors.uniqueIndex(ComponentDto::uuid)); } private Map<String, OrganizationDto> getOrganizations(DbSession dbSession, Collection<ComponentDto> values) { @@ -179,21 +179,21 @@ public class ListAction implements NotificationsWsAction { } private static Function<PropertyDto, Notification> toWsNotification(Notification.Builder notification, - Map<String, OrganizationDto> organizationsByUuid, Map<Long, ComponentDto> projectsById) { + Map<String, OrganizationDto> organizationsByUuid, Map<String, ComponentDto> projectsByUuid) { return property -> { notification.clear(); List<String> propertyKey = Splitter.on(".").splitToList(property.getKey()); notification.setType(propertyKey.get(1)); notification.setChannel(propertyKey.get(2)); - ofNullable(property.getResourceId()).ifPresent(componentId -> populateProjectFields(notification, componentId, organizationsByUuid, projectsById)); + ofNullable(property.getComponentUuid()).ifPresent(componentUuid -> populateProjectFields(notification, componentUuid, organizationsByUuid, projectsByUuid)); return notification.build(); }; } - private static Notification.Builder populateProjectFields(Notification.Builder notification, Long componentId, - Map<String, OrganizationDto> organizationsByUuid, Map<Long, ComponentDto> projectsById) { - ComponentDto project = projectsById.get(componentId); + private static Notification.Builder populateProjectFields(Notification.Builder notification, String componentUuid, + Map<String, OrganizationDto> organizationsByUuid, Map<String, ComponentDto> projectsByUuid) { + ComponentDto project = projectsByUuid.get(componentUuid); String organizationUuid = project.getOrganizationUuid(); OrganizationDto organizationDto = organizationsByUuid.get(organizationUuid); checkArgument(organizationDto != null, "No organization for uuid '%s'", organizationUuid); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java index 1309236fcad..ce79c49be02 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java @@ -47,12 +47,12 @@ public class NotificationUpdater { */ public void add(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) { String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel); - Long projectId = project == null ? null : project.getId(); + String projectUuid = project == null ? null : project.uuid(); List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery( PropertyQuery.builder() .setKey(key) - .setComponentId(projectId) + .setComponentUuid(projectUuid) .setUserId(user.getId()) .build(), dbSession).stream() @@ -65,7 +65,7 @@ public class NotificationUpdater { .setKey(key) .setUserId(user.getId()) .setValue(PROP_NOTIFICATION_VALUE) - .setResourceId(projectId)); + .setComponentUuid(projectUuid)); } /** @@ -73,12 +73,12 @@ public class NotificationUpdater { */ public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) { String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel); - Long projectId = project == null ? null : project.getId(); + String projectUuid = project == null ? null : project.uuid(); List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery( PropertyQuery.builder() .setKey(key) - .setComponentId(projectId) + .setComponentUuid(projectUuid) .setUserId(user.getId()) .build(), dbSession).stream() @@ -90,10 +90,10 @@ public class NotificationUpdater { .setKey(key) .setUserId(user.getId()) .setValue(PROP_NOTIFICATION_VALUE) - .setResourceId(projectId)); + .setComponentUuid(projectUuid)); } private static Predicate<PropertyDto> notificationScope(@Nullable ComponentDto project) { - return prop -> project == null ? (prop.getResourceId() == null) : (prop.getResourceId() != null); + return prop -> project == null ? (prop.getComponentUuid() == null) : (prop.getComponentUuid() != null); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java index 207506a62ee..59baccc69ae 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChange.java @@ -25,9 +25,9 @@ public class GroupPermissionChange extends PermissionChange { private final GroupIdOrAnyone groupId; - public GroupPermissionChange(Operation operation, String permission, @Nullable ProjectId projectId, + public GroupPermissionChange(Operation operation, String permission, @Nullable ProjectUuid projectUuid, GroupIdOrAnyone groupId, PermissionService permissionService) { - super(operation, groupId.getOrganizationUuid(), permission, projectId, permissionService); + super(operation, groupId.getOrganizationUuid(), permission, projectUuid, permissionService); this.groupId = groupId; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java index 228b2d2a46a..e46ba28cc76 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java @@ -20,7 +20,6 @@ package org.sonar.server.permission; import java.util.List; -import java.util.Optional; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -57,48 +56,48 @@ public class GroupPermissionChanger { } private static boolean isImplicitlyAlreadyDone(GroupPermissionChange change) { - return change.getProjectId() - .map(projectId -> isImplicitlyAlreadyDone(projectId, change)) - .orElse(false); + if (change.getProject() != null) { + return isImplicitlyAlreadyDone(change.getProject(), change); + } + return false; } - private static boolean isImplicitlyAlreadyDone(ProjectId projectId, GroupPermissionChange change) { - return isAttemptToAddPublicPermissionToPublicComponent(change, projectId) - || isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(change, projectId); + private static boolean isImplicitlyAlreadyDone(ProjectUuid project, GroupPermissionChange change) { + return isAttemptToAddPublicPermissionToPublicComponent(change, project) + || isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(change, project); } - private static boolean isAttemptToAddPublicPermissionToPublicComponent(GroupPermissionChange change, ProjectId projectId) { - return !projectId.isPrivate() + private static boolean isAttemptToAddPublicPermissionToPublicComponent(GroupPermissionChange change, ProjectUuid project) { + return !project.isPrivate() && change.getOperation() == ADD && PUBLIC_PERMISSIONS.contains(change.getPermission()); } - private static boolean isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectId projectId) { - return projectId.isPrivate() + private static boolean isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectUuid project) { + return project.isPrivate() && change.getOperation() == REMOVE && change.getGroupIdOrAnyone().isAnyone(); } private static void ensureConsistencyWithVisibility(GroupPermissionChange change) { - change.getProjectId() - .ifPresent(projectId -> { - checkRequest( - !isAttemptToAddPermissionToAnyoneOnPrivateComponent(change, projectId), - "No permission can be granted to Anyone on a private component"); - checkRequest( - !isAttemptToRemovePublicPermissionFromPublicComponent(change, projectId), - "Permission %s can't be removed from a public component", change.getPermission()); - }); + if (change.getProject() != null) { + checkRequest( + !isAttemptToAddPermissionToAnyoneOnPrivateComponent(change, change.getProject()), + "No permission can be granted to Anyone on a private component"); + checkRequest( + !isAttemptToRemovePublicPermissionFromPublicComponent(change, change.getProject()), + "Permission %s can't be removed from a public component", change.getPermission()); + } } - private static boolean isAttemptToAddPermissionToAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectId projectId) { - return projectId.isPrivate() + private static boolean isAttemptToAddPermissionToAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectUuid project) { + return project.isPrivate() && change.getOperation() == ADD && change.getGroupIdOrAnyone().isAnyone(); } - private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(GroupPermissionChange change, ProjectId projectId) { - return !projectId.isPrivate() + private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(GroupPermissionChange change, ProjectUuid project) { + return !project.isPrivate() && change.getOperation() == REMOVE && PUBLIC_PERMISSIONS.contains(change.getPermission()); } @@ -113,7 +112,7 @@ public class GroupPermissionChanger { .setRole(change.getPermission()) .setOrganizationUuid(change.getOrganizationUuid()) .setGroupId(change.getGroupIdOrAnyone().getId()) - .setResourceId(change.getNullableProjectId()); + .setComponentUuid(change.getProjectUuid()); dbClient.groupPermissionDao().insert(dbSession, addedDto); return true; } @@ -132,17 +131,17 @@ public class GroupPermissionChanger { change.getPermission(), change.getOrganizationUuid(), change.getGroupIdOrAnyone().getId(), - change.getNullableProjectId()); + change.getProjectUuid()); return true; } private List<String> loadExistingPermissions(DbSession dbSession, GroupPermissionChange change) { - Optional<ProjectId> projectId = change.getProjectId(); - if (projectId.isPresent()) { + String projectUuid = change.getProjectUuid(); + if (projectUuid != null) { return dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, change.getOrganizationUuid(), change.getGroupIdOrAnyone().getId(), - projectId.get().getId()); + projectUuid); } return dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, change.getOrganizationUuid(), @@ -152,7 +151,7 @@ public class GroupPermissionChanger { private void checkIfRemainingGlobalAdministrators(DbSession dbSession, GroupPermissionChange change) { if (SYSTEM_ADMIN.equals(change.getPermission()) && !change.getGroupIdOrAnyone().isAnyone() && - !change.getProjectId().isPresent()) { + change.getProjectUuid() == null) { // removing global admin permission from group int remaining = dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingGroup(dbSession, change.getOrganizationUuid(), SYSTEM_ADMIN, change.getGroupIdOrAnyone().getId()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java index 0b12ba7a68f..bf082924d8d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionChange.java @@ -19,7 +19,6 @@ */ package org.sonar.server.permission; -import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.permission.OrganizationPermission; @@ -37,16 +36,16 @@ public abstract class PermissionChange { private final Operation operation; private final String organizationUuid; private final String permission; - private final ProjectId projectId; + private final ProjectUuid projectUuid; protected final PermissionService permissionService; - public PermissionChange(Operation operation, String organizationUuid, String permission, @Nullable ProjectId projectId, PermissionService permissionService) { + public PermissionChange(Operation operation, String organizationUuid, String permission, @Nullable ProjectUuid projectUuid, PermissionService permissionService) { this.operation = requireNonNull(operation); this.organizationUuid = requireNonNull(organizationUuid); this.permission = requireNonNull(permission); - this.projectId = projectId; + this.projectUuid = projectUuid; this.permissionService = permissionService; - if (projectId == null) { + if (projectUuid == null) { checkRequest(permissionService.getAllOrganizationPermissions().stream().anyMatch(p -> p.getKey().equals(permission)), "Invalid global permission '%s'. Valid values are %s", permission, permissionService.getAllOrganizationPermissions().stream().map(OrganizationPermission::getKey).collect(toList())); @@ -68,23 +67,13 @@ public abstract class PermissionChange { return permission; } - public Optional<ProjectId> getProjectId() { - return Optional.ofNullable(projectId); - } - - /** - * Shortcut based on {@link #getProjectId()} - */ @CheckForNull - public String getProjectUuid() { - return projectId == null ? null : projectId.getUuid(); + public ProjectUuid getProject() { + return projectUuid; } - /** - * Shortcut based on {@link #getProjectId()} - */ @CheckForNull - public Long getNullableProjectId() { - return projectId == null ? null : projectId.getId(); + public String getProjectUuid() { + return projectUuid == null ? null : projectUuid.getUuid(); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java index db471ffeb71..1a3fa00d1e3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionPrivilegeChecker.java @@ -42,15 +42,15 @@ public class PermissionPrivilegeChecker { * defined. * @throws org.sonar.server.exceptions.ForbiddenException if user is not administrator */ - public static void checkProjectAdmin(UserSession userSession, String organizationUuid, Optional<ProjectId> projectId) { + public static void checkProjectAdmin(UserSession userSession, String organizationUuid, Optional<ProjectUuid> projectUuid) { userSession.checkLoggedIn(); if (userSession.hasPermission(OrganizationPermission.ADMINISTER, organizationUuid)) { return; } - if (projectId.isPresent()) { - userSession.checkComponentUuidPermission(UserRole.ADMIN, projectId.get().getUuid()); + if (projectUuid.isPresent()) { + userSession.checkComponentUuidPermission(UserRole.ADMIN, projectUuid.get().getUuid()); } else { throw insufficientPrivilegesException(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java index 918fc0ba3ec..dca1f7e2e8d 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java @@ -120,8 +120,8 @@ public class PermissionTemplateService { } private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable Integer projectCreatorUserId) { - dbClient.groupPermissionDao().deleteByRootComponentId(dbSession, project.getId()); - dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.getId()); + dbClient.groupPermissionDao().deleteByRootComponentUuid(dbSession, project.uuid()); + dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.uuid()); List<PermissionTemplateUserDto> usersPermissions = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateId(dbSession, template.getId()); String organizationUuid = template.getOrganizationUuid(); @@ -129,7 +129,7 @@ public class PermissionTemplateService { .stream() .filter(up -> permissionValidForProject(project, up.getPermission())) .forEach(up -> { - UserPermissionDto dto = new UserPermissionDto(organizationUuid, up.getPermission(), up.getUserId(), project.getId()); + UserPermissionDto dto = new UserPermissionDto(organizationUuid, up.getPermission(), up.getUserId(), project.uuid()); dbClient.userPermissionDao().insert(dbSession, dto); }); @@ -143,7 +143,7 @@ public class PermissionTemplateService { .setOrganizationUuid(organizationUuid) .setGroupId(isAnyone(gp.getGroupName()) ? null : gp.getGroupId()) .setRole(gp.getPermission()) - .setResourceId(project.getId()); + .setComponentUuid(project.uuid()); dbClient.groupPermissionDao().insert(dbSession, dto); }); @@ -158,7 +158,7 @@ public class PermissionTemplateService { .filter(up -> permissionValidForProject(project, up.getPermission())) .filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission())) .forEach(c -> { - UserPermissionDto dto = new UserPermissionDto(organizationUuid, c.getPermission(), projectCreatorUserId, project.getId()); + UserPermissionDto dto = new UserPermissionDto(organizationUuid, c.getPermission(), projectCreatorUserId, project.uuid()); dbClient.userPermissionDao().insert(dbSession, dto); }); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java index 076d37f119e..633578eeb95 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java @@ -22,7 +22,6 @@ package org.sonar.server.permission; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Optional; import org.sonar.db.DbSession; import org.sonar.server.es.ProjectIndexer; import org.sonar.server.es.ProjectIndexers; @@ -49,9 +48,9 @@ public class PermissionUpdater { List<String> projectOrViewUuids = new ArrayList<>(); for (PermissionChange change : changes) { boolean changed = doApply(dbSession, change); - Optional<ProjectId> projectId = change.getProjectId(); - if (changed && projectId.isPresent()) { - projectOrViewUuids.add(projectId.get().getUuid()); + String projectUuid = change.getProjectUuid(); + if (changed && projectUuid != null) { + projectOrViewUuids.add(projectUuid); } } projectIndexers.commitAndIndexByProjectUuids(dbSession, projectOrViewUuids, ProjectIndexer.Cause.PERMISSION_CHANGE); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java index 69ec60a35c9..6ab895bec2c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChange.java @@ -27,9 +27,9 @@ public class UserPermissionChange extends PermissionChange { private final UserId userId; - public UserPermissionChange(Operation operation, String organizationUuid, String permission, @Nullable ProjectId projectId, + public UserPermissionChange(Operation operation, String organizationUuid, String permission, @Nullable ProjectUuid project, UserId userId, PermissionService permissionService) { - super(operation, organizationUuid, permission, projectId, permissionService); + super(operation, organizationUuid, permission, project, permissionService); this.userId = requireNonNull(userId); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java index fde70ff828e..747041ac653 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java @@ -20,16 +20,15 @@ package org.sonar.server.permission; import java.util.List; -import java.util.Optional; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.permission.UserPermissionDto; import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS; import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN; +import static org.sonar.server.exceptions.BadRequestException.checkRequest; import static org.sonar.server.permission.PermissionChange.Operation.ADD; import static org.sonar.server.permission.PermissionChange.Operation.REMOVE; -import static org.sonar.server.exceptions.BadRequestException.checkRequest; /** * Adds and removes user permissions. Both global and project scopes are supported. @@ -58,30 +57,31 @@ public class UserPermissionChanger { } private static boolean isImplicitlyAlreadyDone(UserPermissionChange change) { - return change.getProjectId() - .map(projectId -> isImplicitlyAlreadyDone(projectId, change)) - .orElse(false); + if (change.getProject() != null) { + return isImplicitlyAlreadyDone(change.getProject(), change); + } + return false; } - private static boolean isImplicitlyAlreadyDone(ProjectId projectId, UserPermissionChange change) { - return isAttemptToAddPublicPermissionToPublicComponent(change, projectId); + private static boolean isImplicitlyAlreadyDone(ProjectUuid project, UserPermissionChange change) { + return isAttemptToAddPublicPermissionToPublicComponent(change, project); } - private static boolean isAttemptToAddPublicPermissionToPublicComponent(UserPermissionChange change, ProjectId projectId) { - return !projectId.isPrivate() + private static boolean isAttemptToAddPublicPermissionToPublicComponent(UserPermissionChange change, ProjectUuid project) { + return !project.isPrivate() && change.getOperation() == ADD && PUBLIC_PERMISSIONS.contains(change.getPermission()); } private static void ensureConsistencyWithVisibility(UserPermissionChange change) { - change.getProjectId() - .ifPresent(projectId -> checkRequest( - !isAttemptToRemovePublicPermissionFromPublicComponent(change, projectId), - "Permission %s can't be removed from a public component", change.getPermission())); + if (change.getProject() != null) { + checkRequest(!isAttemptToRemovePublicPermissionFromPublicComponent(change, change.getProject()), + "Permission %s can't be removed from a public component", change.getPermission()); + } } - private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(UserPermissionChange change, ProjectId projectId) { - return !projectId.isPrivate() + private static boolean isAttemptToRemovePublicPermissionFromPublicComponent(UserPermissionChange change, ProjectUuid projectUuid) { + return !projectUuid.isPrivate() && change.getOperation() == REMOVE && PUBLIC_PERMISSIONS.contains(change.getPermission()); } @@ -90,7 +90,7 @@ public class UserPermissionChanger { if (loadExistingPermissions(dbSession, change).contains(change.getPermission())) { return false; } - UserPermissionDto dto = new UserPermissionDto(change.getOrganizationUuid(), change.getPermission(), change.getUserId().getId(), change.getNullableProjectId()); + UserPermissionDto dto = new UserPermissionDto(change.getOrganizationUuid(), change.getPermission(), change.getUserId().getId(), change.getProjectUuid()); dbClient.userPermissionDao().insert(dbSession, dto); return true; } @@ -100,9 +100,9 @@ public class UserPermissionChanger { return false; } checkOtherAdminsExist(dbSession, change); - Optional<ProjectId> projectId = change.getProjectId(); - if (projectId.isPresent()) { - dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getId(), change.getPermission(), projectId.get().getId()); + String projectUuid = change.getProjectUuid(); + if (projectUuid != null) { + dbClient.userPermissionDao().deleteProjectPermission(dbSession, change.getUserId().getId(), change.getPermission(), projectUuid); } else { dbClient.userPermissionDao().deleteGlobalPermission(dbSession, change.getUserId().getId(), change.getPermission(), change.getOrganizationUuid()); } @@ -110,11 +110,9 @@ public class UserPermissionChanger { } private List<String> loadExistingPermissions(DbSession dbSession, UserPermissionChange change) { - Optional<ProjectId> projectId = change.getProjectId(); - if (projectId.isPresent()) { - return dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, - change.getUserId().getId(), - projectId.get().getId()); + String projectUuid = change.getProjectUuid(); + if (projectUuid != null) { + return dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, change.getUserId().getId(), projectUuid); } return dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, change.getUserId().getId(), @@ -122,7 +120,7 @@ public class UserPermissionChanger { } private void checkOtherAdminsExist(DbSession dbSession, UserPermissionChange change) { - if (SYSTEM_ADMIN.equals(change.getPermission()) && !change.getProjectId().isPresent()) { + if (SYSTEM_ADMIN.equals(change.getPermission()) && change.getProjectUuid() == null) { int remaining = dbClient.authorizationDao().countUsersWithGlobalPermissionExcludingUserPermission(dbSession, change.getOrganizationUuid(), change.getPermission(), change.getUserId().getId()); checkRequest(remaining > 0, "Last user with permission '%s'. Permission cannot be removed.", SYSTEM_ADMIN); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java index f26a7cf4d0a..f2213faaa7a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java @@ -26,13 +26,13 @@ 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.server.permission.GroupIdOrAnyone; import org.sonar.server.permission.GroupPermissionChange; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionService; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.permission.ProjectId; +import org.sonar.server.permission.ProjectUuid; import org.sonar.server.user.UserSession; -import org.sonar.server.permission.GroupIdOrAnyone; import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin; import static org.sonar.server.permission.ws.WsParameters.createGroupIdParameter; @@ -88,14 +88,14 @@ public class AddGroupAction implements PermissionsWsAction { public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { GroupIdOrAnyone group = wsSupport.findGroup(dbSession, request); - Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request); + Optional<ProjectUuid> projectUuid = wsSupport.findProjectUuid(dbSession, request); - checkProjectAdmin(userSession, group.getOrganizationUuid(), projectId); + checkProjectAdmin(userSession, group.getOrganizationUuid(), projectUuid); PermissionChange change = new GroupPermissionChange( PermissionChange.Operation.ADD, request.mandatoryParam(PARAM_PERMISSION), - projectId.orElse(null), + projectUuid.orElse(null), group, permissionService); permissionUpdater.apply(dbSession, ImmutableList.of(change)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java index c2984e40c04..0e51f3af6d4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddUserAction.java @@ -32,7 +32,7 @@ import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionService; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.permission.ProjectId; +import org.sonar.server.permission.ProjectUuid; import org.sonar.server.permission.UserId; import org.sonar.server.permission.UserPermissionChange; import org.sonar.server.user.UserSession; @@ -104,14 +104,14 @@ public class AddUserAction implements PermissionsWsAction { checkArgument(organizationKey == null || org.getKey().equals(organizationKey), "Organization key is incorrect."); wsSupport.checkMembership(dbSession, org, user); - Optional<ProjectId> projectId = project.map(ProjectId::new); - checkProjectAdmin(userSession, org.getUuid(), projectId); + Optional<ProjectUuid> projectUuid = project.map(ProjectUuid::new); + checkProjectAdmin(userSession, org.getUuid(), projectUuid); PermissionChange change = new UserPermissionChange( PermissionChange.Operation.ADD, org.getUuid(), request.mandatoryParam(PARAM_PERMISSION), - projectId.orElse(null), + projectUuid.orElse(null), user, permissionService); permissionUpdater.apply(dbSession, singletonList(change)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java index de58e0440b6..b6b8eeff9dd 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java @@ -39,7 +39,7 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.permission.GroupPermissionDto; import org.sonar.db.permission.PermissionQuery; import org.sonar.db.user.GroupDto; -import org.sonar.server.permission.ProjectId; +import org.sonar.server.permission.ProjectUuid; import org.sonar.server.user.UserSession; import org.sonarqube.ws.Permissions.Group; import org.sonarqube.ws.Permissions.WsGroupsResponse; @@ -101,21 +101,21 @@ public class GroupsAction implements PermissionsWsAction { public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto org = wsSupport.findOrganization(dbSession, request.param(PARAM_ORGANIZATION)); - Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request); - checkProjectAdmin(userSession, org.getUuid(), projectId); + Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request); + checkProjectAdmin(userSession, org.getUuid(), project); - PermissionQuery query = buildPermissionQuery(request, org, projectId); + PermissionQuery query = buildPermissionQuery(request, org, project); // TODO validatePermission(groupsRequest.getPermission(), wsProjectRef); List<GroupDto> groups = findGroups(dbSession, org, query); int total = dbClient.groupPermissionDao().countGroupsByQuery(dbSession, query); - List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, org, groups, projectId); + List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, org, groups, project); Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total); WsGroupsResponse groupsResponse = buildResponse(groups, groupsWithPermission, paging); writeProtobuf(groupsResponse, request, response); } } - private static PermissionQuery buildPermissionQuery(Request request, OrganizationDto org, Optional<ProjectId> project) { + private static PermissionQuery buildPermissionQuery(Request request, OrganizationDto org, Optional<ProjectUuid> project) { String textQuery = request.param(Param.TEXT_QUERY); PermissionQuery.Builder permissionQuery = PermissionQuery.builder() .setOrganizationUuid(org.getUuid()) @@ -123,7 +123,7 @@ public class GroupsAction implements PermissionsWsAction { .setPageIndex(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)) .setSearchQuery(textQuery); - project.ifPresent(projectId -> permissionQuery.setComponent(projectId.getUuid(), projectId.getId())); + project.ifPresent(projectUuid -> permissionQuery.setComponent(projectUuid.getUuid())); return permissionQuery.build(); } @@ -159,11 +159,11 @@ public class GroupsAction implements PermissionsWsAction { return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); } - private List<GroupPermissionDto> findGroupPermissions(DbSession dbSession, OrganizationDto org, List<GroupDto> groups, Optional<ProjectId> project) { + private List<GroupPermissionDto> findGroupPermissions(DbSession dbSession, OrganizationDto org, List<GroupDto> groups, Optional<ProjectUuid> project) { if (groups.isEmpty()) { return emptyList(); } List<Integer> ids = groups.stream().map(GroupDto::getId).collect(MoreCollectors.toList(groups.size())); - return dbClient.groupPermissionDao().selectByGroupIds(dbSession, org.getUuid(), ids, project.isPresent() ? project.get().getId() : null); + return dbClient.groupPermissionDao().selectByGroupIds(dbSession, org.getUuid(), ids, project.map(ProjectUuid::getUuid).orElse(null)); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java index 7be93754d3d..721e4f9dc45 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java @@ -29,10 +29,10 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.ComponentFinder; -import org.sonar.server.permission.ProjectId; +import org.sonar.server.permission.GroupIdOrAnyone; +import org.sonar.server.permission.ProjectUuid; import org.sonar.server.permission.UserId; import org.sonar.server.permission.ws.template.WsTemplateRef; -import org.sonar.server.permission.GroupIdOrAnyone; import org.sonar.server.usergroups.ws.GroupWsRef; import org.sonar.server.usergroups.ws.GroupWsSupport; import org.sonarqube.ws.client.permission.PermissionsWsParameters; @@ -59,9 +59,9 @@ public class PermissionWsSupport { return groupWsSupport.findOrganizationByKey(dbSession, organizationKey); } - public Optional<ProjectId> findProjectId(DbSession dbSession, Request request) { + public Optional<ProjectUuid> findProjectUuid(DbSession dbSession, Request request) { return findProject(dbSession, request) - .map(ProjectId::new); + .map(ProjectUuid::new); } public Optional<ComponentDto> findProject(DbSession dbSession, Request request) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java index 0f9e1eae23f..abc7a494723 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java @@ -25,13 +25,13 @@ 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.server.permission.GroupIdOrAnyone; import org.sonar.server.permission.GroupPermissionChange; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionService; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.permission.ProjectId; +import org.sonar.server.permission.ProjectUuid; import org.sonar.server.user.UserSession; -import org.sonar.server.permission.GroupIdOrAnyone; import static java.util.Arrays.asList; import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin; @@ -88,14 +88,14 @@ public class RemoveGroupAction implements PermissionsWsAction { public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { GroupIdOrAnyone group = wsSupport.findGroup(dbSession, request); - Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request); + Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request); - checkProjectAdmin(userSession, group.getOrganizationUuid(), projectId); + checkProjectAdmin(userSession, group.getOrganizationUuid(), project); PermissionChange change = new GroupPermissionChange( PermissionChange.Operation.REMOVE, request.mandatoryParam(PARAM_PERMISSION), - projectId.orElse(null), + project.orElse(null), group, permissionService); permissionUpdater.apply(dbSession, asList(change)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java index bc0bffa6203..535444fc6d7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java @@ -29,7 +29,7 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionService; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.permission.ProjectId; +import org.sonar.server.permission.ProjectUuid; import org.sonar.server.permission.UserId; import org.sonar.server.permission.UserPermissionChange; import org.sonar.server.user.UserSession; @@ -88,16 +88,16 @@ public class RemoveUserAction implements PermissionsWsAction { public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { UserId user = wsSupport.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN)); - Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request); + Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request); OrganizationDto org = wsSupport.findOrganization(dbSession, request.param(PARAM_ORGANIZATION)); - checkProjectAdmin(userSession, org.getUuid(), projectId); + checkProjectAdmin(userSession, org.getUuid(), project); PermissionChange change = new UserPermissionChange( PermissionChange.Operation.REMOVE, org.getUuid(), request.mandatoryParam(PARAM_PERMISSION), - projectId.orElse(null), + project.orElse(null), user, permissionService); permissionUpdater.apply(dbSession, singletonList(change)); response.noContent(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java index f6c1e43bd8c..a6f992aec73 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java @@ -43,7 +43,7 @@ import org.sonar.db.component.ComponentQuery; import org.sonar.db.permission.CountPerProjectPermission; import org.sonar.server.permission.PermissionPrivilegeChecker; import org.sonar.server.permission.PermissionService; -import org.sonar.server.permission.ProjectId; +import org.sonar.server.permission.ProjectUuid; import org.sonar.server.permission.RequestValidator; import org.sonar.server.user.UserSession; import org.sonarqube.ws.Common; @@ -56,8 +56,8 @@ import static org.sonar.api.utils.Paging.forPageIndex; import static org.sonar.server.permission.ws.ProjectWsRef.newOptionalWsProjectRef; import static org.sonar.server.permission.ws.SearchProjectPermissionsData.newBuilder; import static org.sonar.server.permission.ws.WsParameters.createProjectParameters; -import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter; import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; +import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY; @@ -141,7 +141,7 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction { com.google.common.base.Optional<ProjectWsRef> projectRef = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey()); if (projectRef.isPresent()) { ComponentDto project = wsSupport.getRootComponentOrModule(dbSession, projectRef.get()); - PermissionPrivilegeChecker.checkProjectAdmin(userSession, project.getOrganizationUuid(), Optional.of(new ProjectId(project))); + PermissionPrivilegeChecker.checkProjectAdmin(userSession, project.getOrganizationUuid(), Optional.of(new ProjectUuid(project))); } else { userSession.checkLoggedIn().checkIsSystemAdministrator(); } @@ -159,13 +159,13 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction { .setKey(rootComponent.getDbKey()) .setQualifier(rootComponent.qualifier()) .setName(rootComponent.name()); - for (String permission : data.permissions(rootComponent.getId())) { + for (String permission : data.permissions(rootComponent.uuid())) { rootComponentBuilder.addPermissions( permissionResponse .clear() .setKey(permission) - .setUsersCount(data.userCount(rootComponent.getId(), permission)) - .setGroupsCount(data.groupCount(rootComponent.getId(), permission))); + .setUsersCount(data.userCount(rootComponent.uuid(), permission)) + .setGroupsCount(data.groupCount(rootComponent.uuid(), permission))); } response.addProjects(rootComponentBuilder); } @@ -201,12 +201,12 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction { SearchProjectPermissionsData.Builder data = newBuilder(); int countRootComponents = countRootComponents(dbSession, request); List<ComponentDto> rootComponents = searchRootComponents(dbSession, request, paging(request, countRootComponents)); - List<Long> rootComponentIds = Lists.transform(rootComponents, ComponentDto::getId); + List<String> rootComponentUuids = Lists.transform(rootComponents, ComponentDto::uuid); data.rootComponents(rootComponents) .paging(paging(request, countRootComponents)) - .userCountByProjectIdAndPermission(userCountByRootComponentIdAndPermission(dbSession, rootComponentIds)) - .groupCountByProjectIdAndPermission(groupCountByRootComponentIdAndPermission(dbSession, rootComponentIds)); + .userCountByProjectIdAndPermission(userCountByRootComponentUuidAndPermission(dbSession, rootComponentUuids)) + .groupCountByProjectIdAndPermission(groupCountByRootComponentIdAndPermission(dbSession, rootComponentUuids)); return data.build(); } @@ -244,24 +244,24 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction { : (new String[] {requestQualifier}); } - private Table<Long, String, Integer> userCountByRootComponentIdAndPermission(DbSession dbSession, List<Long> rootComponentIds) { - final Table<Long, String, Integer> userCountByRootComponentIdAndPermission = TreeBasedTable.create(); + private Table<String, String, Integer> userCountByRootComponentUuidAndPermission(DbSession dbSession, List<String> rootComponentUuids) { + final Table<String, String, Integer> userCountByRootComponentUuidAndPermission = TreeBasedTable.create(); - dbClient.userPermissionDao().countUsersByProjectPermission(dbSession, rootComponentIds).forEach( - row -> userCountByRootComponentIdAndPermission.put(row.getComponentId(), row.getPermission(), row.getCount())); + dbClient.userPermissionDao().countUsersByProjectPermission(dbSession, rootComponentUuids).forEach( + row -> userCountByRootComponentUuidAndPermission.put(row.getComponentUuid(), row.getPermission(), row.getCount())); - return userCountByRootComponentIdAndPermission; + return userCountByRootComponentUuidAndPermission; } - private Table<Long, String, Integer> groupCountByRootComponentIdAndPermission(DbSession dbSession, List<Long> rootComponentIds) { - final Table<Long, String, Integer> userCountByRootComponentIdAndPermission = TreeBasedTable.create(); + private Table<String, String, Integer> groupCountByRootComponentIdAndPermission(DbSession dbSession, List<String> rootComponentUuids) { + final Table<String, String, Integer> userCountByRootComponentUuidAndPermission = TreeBasedTable.create(); - dbClient.groupPermissionDao().groupsCountByComponentIdAndPermission(dbSession, rootComponentIds, context -> { + dbClient.groupPermissionDao().groupsCountByComponentUuidAndPermission(dbSession, rootComponentUuids, context -> { CountPerProjectPermission row = (CountPerProjectPermission) context.getResultObject(); - userCountByRootComponentIdAndPermission.put(row.getComponentId(), row.getPermission(), row.getCount()); + userCountByRootComponentUuidAndPermission.put(row.getComponentUuid(), row.getPermission(), row.getCount()); }); - return userCountByRootComponentIdAndPermission; + return userCountByRootComponentUuidAndPermission; } private static class SearchProjectPermissionsRequest { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java index c075269ef87..3451dafc463 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsData.java @@ -36,14 +36,14 @@ import static com.google.common.collect.ImmutableTable.copyOf; class SearchProjectPermissionsData { private final List<ComponentDto> rootComponents; private final Paging paging; - private final Table<Long, String, Integer> userCountByProjectIdAndPermission; - private final Table<Long, String, Integer> groupCountByProjectIdAndPermission; + private final Table<String, String, Integer> userCountByProjectUuidAndPermission; + private final Table<String, String, Integer> groupCountByProjectUuidAndPermission; private SearchProjectPermissionsData(Builder builder) { this.rootComponents = copyOf(builder.projects); this.paging = builder.paging; - this.userCountByProjectIdAndPermission = copyOf(builder.userCountByProjectIdAndPermission); - this.groupCountByProjectIdAndPermission = copyOf(builder.groupCountByProjectIdAndPermission); + this.userCountByProjectUuidAndPermission = copyOf(builder.userCountByProjectUuidAndPermission); + this.groupCountByProjectUuidAndPermission = copyOf(builder.groupCountByProjectUuidAndPermission); } static Builder newBuilder() { @@ -58,27 +58,27 @@ class SearchProjectPermissionsData { return paging; } - int userCount(long rootComponentId, String permission) { - return firstNonNull(userCountByProjectIdAndPermission.get(rootComponentId, permission), 0); + int userCount(String rootComponentUuid, String permission) { + return firstNonNull(userCountByProjectUuidAndPermission.get(rootComponentUuid, permission), 0); } - int groupCount(long rootComponentId, String permission) { - return firstNonNull(groupCountByProjectIdAndPermission.get(rootComponentId, permission), 0); + int groupCount(String rootComponentUuid, String permission) { + return firstNonNull(groupCountByProjectUuidAndPermission.get(rootComponentUuid, permission), 0); } - Set<String> permissions(long rootComponentId) { + Set<String> permissions(String rootComponentUuid) { return FluentIterable.from( Iterables.concat( - userCountByProjectIdAndPermission.row(rootComponentId).keySet(), - groupCountByProjectIdAndPermission.row(rootComponentId).keySet())) + userCountByProjectUuidAndPermission.row(rootComponentUuid).keySet(), + groupCountByProjectUuidAndPermission.row(rootComponentUuid).keySet())) .toSortedSet(Ordering.natural()); } static class Builder { private List<ComponentDto> projects; private Paging paging; - private Table<Long, String, Integer> userCountByProjectIdAndPermission; - private Table<Long, String, Integer> groupCountByProjectIdAndPermission; + private Table<String, String, Integer> userCountByProjectUuidAndPermission; + private Table<String, String, Integer> groupCountByProjectUuidAndPermission; private Builder() { // prevents instantiation outside main class @@ -86,8 +86,8 @@ class SearchProjectPermissionsData { SearchProjectPermissionsData build() { checkState(projects != null); - checkState(userCountByProjectIdAndPermission != null); - checkState(groupCountByProjectIdAndPermission != null); + checkState(userCountByProjectUuidAndPermission != null); + checkState(groupCountByProjectUuidAndPermission != null); return new SearchProjectPermissionsData(this); } @@ -102,13 +102,13 @@ class SearchProjectPermissionsData { return this; } - Builder userCountByProjectIdAndPermission(Table<Long, String, Integer> userCountByProjectIdAndPermission) { - this.userCountByProjectIdAndPermission = userCountByProjectIdAndPermission; + Builder userCountByProjectIdAndPermission(Table<String, String, Integer> userCountByProjectIdAndPermission) { + this.userCountByProjectUuidAndPermission = userCountByProjectIdAndPermission; return this; } - Builder groupCountByProjectIdAndPermission(Table<Long, String, Integer> groupCountByProjectIdAndPermission) { - this.groupCountByProjectIdAndPermission = groupCountByProjectIdAndPermission; + Builder groupCountByProjectIdAndPermission(Table<String, String, Integer> groupCountByProjectIdAndPermission) { + this.groupCountByProjectUuidAndPermission = groupCountByProjectIdAndPermission; return this; } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java index 44d8b9acd65..76450b7c3dc 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/UsersAction.java @@ -38,7 +38,7 @@ import org.sonar.db.permission.PermissionQuery; import org.sonar.db.permission.UserPermissionDto; import org.sonar.db.user.UserDto; import org.sonar.server.issue.AvatarResolver; -import org.sonar.server.permission.ProjectId; +import org.sonar.server.permission.ProjectUuid; import org.sonar.server.permission.RequestValidator; import org.sonar.server.user.UserSession; import org.sonarqube.ws.Permissions; @@ -110,20 +110,20 @@ public class UsersAction implements PermissionsWsAction { public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto org = wsSupport.findOrganization(dbSession, request.param(PARAM_ORGANIZATION)); - Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request); - checkProjectAdmin(userSession, org.getUuid(), projectId); + Optional<ProjectUuid> project = wsSupport.findProjectUuid(dbSession, request); + checkProjectAdmin(userSession, org.getUuid(), project); - PermissionQuery query = buildPermissionQuery(request, org, projectId); + PermissionQuery query = buildPermissionQuery(request, org, project); List<UserDto> users = findUsers(dbSession, query); int total = dbClient.userPermissionDao().countUsersByQuery(dbSession, query); - List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, projectId); + List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, project); Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total); UsersWsResponse usersWsResponse = buildResponse(users, userPermissions, paging); writeProtobuf(usersWsResponse, request, response); } } - private PermissionQuery buildPermissionQuery(Request request, OrganizationDto organization, Optional<ProjectId> project) { + private PermissionQuery buildPermissionQuery(Request request, OrganizationDto organization, Optional<ProjectUuid> project) { String textQuery = request.param(Param.TEXT_QUERY); String permission = request.param(PARAM_PERMISSION); PermissionQuery.Builder permissionQuery = PermissionQuery.builder() @@ -132,7 +132,7 @@ public class UsersAction implements PermissionsWsAction { .setPageIndex(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)) .setSearchQuery(textQuery); - project.ifPresent(projectId -> permissionQuery.setComponent(projectId.getUuid(), projectId.getId())); + project.ifPresent(projectId -> permissionQuery.setComponent(projectId.getUuid())); if (permission != null) { if (project.isPresent()) { requestValidator.validateProjectPermission(permission); @@ -172,7 +172,7 @@ public class UsersAction implements PermissionsWsAction { return Ordering.explicit(orderedIds).onResultOf(UserDto::getId).immutableSortedCopy(dbClient.userDao().selectByIds(dbSession, orderedIds)); } - private List<UserPermissionDto> findUserPermissions(DbSession dbSession, OrganizationDto org, List<UserDto> users, Optional<ProjectId> project) { + private List<UserPermissionDto> findUserPermissions(DbSession dbSession, OrganizationDto org, List<UserDto> users, Optional<ProjectUuid> project) { if (users.isEmpty()) { return emptyList(); } @@ -180,7 +180,7 @@ public class UsersAction implements PermissionsWsAction { PermissionQuery.Builder queryBuilder = PermissionQuery.builder() .setOrganizationUuid(org.getUuid()) .withAtLeastOnePermission(); - project.ifPresent(p -> queryBuilder.setComponent(p.getUuid(), p.getId())); + project.ifPresent(p -> queryBuilder.setComponent(p.getUuid())); return dbClient.userPermissionDao().selectUserPermissionsByQuery(dbSession, queryBuilder.build(), userIds); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java index 09ad3ee95ce..b39a1f4eda4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java @@ -190,10 +190,10 @@ public class SearchMyProjectsAction implements ProjectsWsAction { private ProjectsResult searchProjects(DbSession dbSession, SearchMyProjectsRequest request) { int userId = requireNonNull(userSession.getUserId(), "Current user must be authenticated"); - List<Long> componentIds = dbClient.roleDao().selectComponentIdsByPermissionAndUserId(dbSession, UserRole.ADMIN, userId); + List<String> componentUuids = dbClient.roleDao().selectComponentUuidsByPermissionAndUserId(dbSession, UserRole.ADMIN, userId); ComponentQuery dbQuery = ComponentQuery.builder() .setQualifiers(Qualifiers.PROJECT) - .setComponentIds(ImmutableSet.copyOf(componentIds.subList(0, Math.min(componentIds.size(), DatabaseUtils.PARTITION_SIZE_FOR_ORACLE)))) + .setComponentUuids(ImmutableSet.copyOf(componentUuids.subList(0, Math.min(componentUuids.size(), DatabaseUtils.PARTITION_SIZE_FOR_ORACLE)))) .build(); return new ProjectsResult( diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java index 9b8f7075808..d7047a6e379 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java @@ -137,24 +137,24 @@ public class UpdateVisibilityAction implements ProjectsWsAction { private void updatePermissionsToPrivate(DbSession dbSession, ComponentDto component) { // delete project permissions for group AnyOne - dbClient.groupPermissionDao().deleteByRootComponentIdAndGroupId(dbSession, component.getId(), null); + dbClient.groupPermissionDao().deleteByRootComponentUuidAndGroupId(dbSession, component.uuid(), null); // grant UserRole.CODEVIEWER and UserRole.USER to any group or user with at least one permission on project PUBLIC_PERMISSIONS.forEach(permission -> { - dbClient.groupPermissionDao().selectGroupIdsWithPermissionOnProjectBut(dbSession, component.getId(), permission) + dbClient.groupPermissionDao().selectGroupIdsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) .forEach(groupId -> insertProjectPermissionOnGroup(dbSession, component, permission, groupId)); - dbClient.userPermissionDao().selectUserIdsWithPermissionOnProjectBut(dbSession, component.getId(), permission) + dbClient.userPermissionDao().selectUserIdsWithPermissionOnProjectBut(dbSession, component.uuid(), permission) .forEach(userId -> insertProjectPermissionOnUser(dbSession, component, permission, userId)); }); } private void insertProjectPermissionOnUser(DbSession dbSession, ComponentDto component, String permission, Integer userId) { - dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(component.getOrganizationUuid(), permission, userId, component.getId())); + dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(component.getOrganizationUuid(), permission, userId, component.uuid())); } private void insertProjectPermissionOnGroup(DbSession dbSession, ComponentDto component, String permission, Integer groupId) { dbClient.groupPermissionDao().insert(dbSession, new GroupPermissionDto() .setOrganizationUuid(component.getOrganizationUuid()) - .setResourceId(component.getId()) + .setComponentUuid(component.uuid()) .setGroupId(groupId) .setRole(permission)); } @@ -162,9 +162,9 @@ public class UpdateVisibilityAction implements ProjectsWsAction { private void updatePermissionsToPublic(DbSession dbSession, ComponentDto component) { PUBLIC_PERMISSIONS.forEach(permission -> { // delete project group permission for UserRole.CODEVIEWER and UserRole.USER - dbClient.groupPermissionDao().deleteByRootComponentIdAndPermission(dbSession, component.getId(), permission); + dbClient.groupPermissionDao().deleteByRootComponentUuidAndPermission(dbSession, component.uuid(), permission); // delete project user permission for UserRole.CODEVIEWER and UserRole.USER - dbClient.userPermissionDao().deleteProjectPermissionOfAnyUser(dbSession, component.getId(), permission); + dbClient.userPermissionDao().deleteProjectPermissionOfAnyUser(dbSession, component.uuid(), permission); }); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java index 2285db6964e..0a878750e82 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java @@ -23,13 +23,11 @@ import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; -import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; -import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_ID; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; @@ -55,14 +53,11 @@ public class DeselectAction implements QualityGatesWsAction { .setPost(true) .setSince("4.3") .setHandler(this) - .setChangelog(new Change("6.6", "The parameter 'gateId' was removed")); - - action.createParam(PARAM_PROJECT_ID) - .setDescription("Project id") - .setDeprecatedSince("6.1") - .setExampleValue(Uuids.UUID_EXAMPLE_01); + .setChangelog(new Change("6.6", "The parameter 'gateId' was removed"), + new Change("8.3", "The parameter 'projectId' was removed")); action.createParam(PARAM_PROJECT_KEY) + .setRequired(true) .setDescription("Project key") .setExampleValue(KEY_PROJECT_EXAMPLE_001) .setSince("6.1"); @@ -74,7 +69,7 @@ public class DeselectAction implements QualityGatesWsAction { public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); - ProjectDto project = wsSupport.getProject(dbSession, organization, request.param(PARAM_PROJECT_KEY), request.param(PARAM_PROJECT_ID)); + ProjectDto project = wsSupport.getProject(dbSession, organization, request.mandatoryParam(PARAM_PROJECT_KEY)); dissociateProject(dbSession, organization, project); response.noContent(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java index 55fdd97c354..d1d867f5661 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java @@ -45,8 +45,6 @@ import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_ import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION; -import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_ID; -import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; public class QualityGatesWsSupport { @@ -124,31 +122,12 @@ public class QualityGatesWsSupport { throw insufficientPrivilegesException(); } - ProjectDto getProject(DbSession dbSession, OrganizationDto organization, @Nullable String projectKey, @Nullable String projectId) { - ProjectDto project; - if (projectId != null) { - project = getProjectById(dbSession, projectId); - } else if (projectKey != null) { - project = componentFinder.getProjectByKey(dbSession, projectKey); - } else { - throw new IllegalArgumentException(String.format("Must specify %s or %s", PARAM_PROJECT_KEY, PARAM_PROJECT_ID)); - } - + ProjectDto getProject(DbSession dbSession, OrganizationDto organization, String projectKey) { + ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey); checkProjectBelongsToOrganization(organization, project); return project; } - ProjectDto getProjectById(DbSession dbSession, String projectId) { - try { - long dbId = Long.parseLong(projectId); - return dbClient.componentDao().selectById(dbSession, dbId) - .flatMap(c -> dbClient.projectDao().selectByUuid(dbSession, c.uuid())) - .orElseThrow(() -> new NotFoundException(String.format("Project '%s' not found", projectId))); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Invalid id: " + projectId); - } - } - void checkProjectBelongsToOrganization(OrganizationDto organization, ProjectDto project) { if (project.getOrganizationUuid().equals(organization.getUuid())) { return; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java index 5fba0af7cd0..8316e65bf6b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java @@ -126,7 +126,6 @@ public class SearchAction implements QualityGatesWsAction { for (ProjectQgateAssociationDto project : paginatedProjects) { createResponse.addResultsBuilder() - .setId(project.getId()) .setName(project.getName()) .setKey(project.getKey()) .setSelected(project.getGateId() != null); @@ -147,8 +146,8 @@ public class SearchAction implements QualityGatesWsAction { // Meanwhile root is explicitly handled. return projects; } - List<Long> projectIds = projects.stream().map(ProjectQgateAssociationDto::getId).collect(MoreCollectors.toList()); - Collection<Long> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectIds(dbSession, projectIds, userSession.getUserId(), UserRole.USER); - return projects.stream().filter(project -> authorizedProjectIds.contains(project.getId())).collect(MoreCollectors.toList()); + List<String> projectUuids = projects.stream().map(ProjectQgateAssociationDto::getUuid).collect(MoreCollectors.toList()); + Collection<String> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectUuids(dbSession, projectUuids, userSession.getUserId(), UserRole.USER); + return projects.stream().filter(project -> authorizedProjectIds.contains(project.getUuid())).collect(MoreCollectors.toList()); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java index b1ed5c3b8a2..6d96aa4e49f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java @@ -19,10 +19,10 @@ */ package org.sonar.server.qualitygate.ws; +import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; -import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.organization.OrganizationDto; @@ -32,7 +32,6 @@ import org.sonar.db.qualitygate.QualityGateDto; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.ACTION_SELECT; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GATE_ID; -import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_ID; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; @@ -49,29 +48,23 @@ public class SelectAction implements QualityGatesWsAction { public void define(WebService.NewController controller) { WebService.NewAction action = controller.createAction(ACTION_SELECT) .setDescription("Associate a project to a quality gate.<br>" + - "The '%s' or '%s' must be provided.<br>" + - "Project id as a numeric value is deprecated since 6.1. Please use the id similar to '%s'.<br>" + - "Requires one of the following permissions:" + - "<ul>" + - " <li>'Administer Quality Gates'</li>" + - " <li>'Administer' right on the specified project</li>" + - "</ul>", - PARAM_PROJECT_ID, PARAM_PROJECT_KEY, - Uuids.UUID_EXAMPLE_02) + "Requires one of the following permissions:" + + "<ul>" + + " <li>'Administer Quality Gates'</li>" + + " <li>'Administer' right on the specified project</li>" + + "</ul>") .setPost(true) .setSince("4.3") - .setHandler(this); + .setHandler(this) + .setChangelog(new Change("8.3", "The parameter 'projectId' was removed")); action.createParam(PARAM_GATE_ID) .setDescription("Quality gate id") .setRequired(true) .setExampleValue("1"); - action.createParam(PARAM_PROJECT_ID) - .setDescription("Project id. Project id as an numeric value is deprecated since 6.1") - .setExampleValue(Uuids.UUID_EXAMPLE_01); - action.createParam(PARAM_PROJECT_KEY) + .setRequired(true) .setDescription("Project key") .setExampleValue(KEY_PROJECT_EXAMPLE_001) .setSince("6.1"); @@ -82,13 +75,12 @@ public class SelectAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { long gateId = request.mandatoryParamAsLong(PARAM_GATE_ID); - String projectKey = request.param(PARAM_PROJECT_KEY); - String projectId = request.param(PARAM_PROJECT_ID); + String projectKey = request.mandatoryParam(PARAM_PROJECT_KEY); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, gateId); - ProjectDto project = wsSupport.getProject(dbSession, organization, projectKey, projectId); + ProjectDto project = wsSupport.getProject(dbSession, organization, projectKey); wsSupport.checkCanAdminProject(organization, project); QualityGateDto currentQualityGate = dbClient.qualityGateDao().selectByProjectUuid(dbSession, project.getUuid()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java index f3ce6aa089a..fbc75675971 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java @@ -175,16 +175,16 @@ public class SetAction implements SettingsWsAction { int[] fieldIds = IntStream.rangeClosed(1, request.getFieldValues().size()).toArray(); String inlinedFieldKeys = IntStream.of(fieldIds).mapToObj(String::valueOf).collect(COMMA_JOINER); String key = persistedKey(request); - Long componentId = component.isPresent() ? component.get().getId() : null; + String componentUuid = component.isPresent() ? component.get().uuid() : null; deleteSettings(dbSession, component, key); - dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setResourceId(componentId)); + dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setComponentUuid(componentUuid)); List<String> fieldValues = request.getFieldValues(); IntStream.of(fieldIds).boxed() .flatMap(i -> readOneFieldValues(fieldValues.get(i - 1), request.getKey()).entrySet().stream() .map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue()))) - .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentId))); + .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentUuid))); return inlinedFieldKeys; } @@ -321,14 +321,14 @@ public class SetAction implements SettingsWsAction { .setValue(value); if (component.isPresent()) { - property.setResourceId(component.get().getId()); + property.setComponentUuid(component.get().uuid()); } return property; } - private static PropertyDto toFieldProperty(KeyValue keyValue, @Nullable Long componentId) { - return new PropertyDto().setKey(keyValue.key).setValue(keyValue.value).setResourceId(componentId); + private static PropertyDto toFieldProperty(KeyValue keyValue, @Nullable String componentUuid) { + return new PropertyDto().setKey(keyValue.key).setValue(keyValue.value).setComponentUuid(componentUuid); } private static class KeyValue { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java index 777c9cdaaa4..3341172148e 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java @@ -35,7 +35,7 @@ public class Setting { private static final Splitter DOT_SPLITTER = Splitter.on(".").omitEmptyStrings(); private final String key; - private final Long componentId; + private final String componentUuid; private final String value; private final PropertyDefinition definition; private final List<Map<String, String>> propertySets; @@ -44,7 +44,7 @@ public class Setting { private Setting(PropertyDto propertyDto, List<PropertyDto> propertyDtoSetValues, @Nullable PropertyDefinition definition) { this.key = propertyDto.getKey(); this.value = propertyDto.getValue(); - this.componentId = propertyDto.getResourceId(); + this.componentUuid = propertyDto.getComponentUuid(); this.definition = definition; this.propertySets = buildPropertySetValuesAsMap(key, propertyDtoSetValues); this.isDefault = false; @@ -53,7 +53,7 @@ public class Setting { private Setting(PropertyDefinition definition) { this.key = definition.key(); this.value = definition.defaultValue(); - this.componentId = null; + this.componentUuid = null; this.definition = definition; this.propertySets = Collections.emptyList(); this.isDefault = true; @@ -72,8 +72,8 @@ public class Setting { } @CheckForNull - public Long getComponentId() { - return componentId; + public String getComponentUuid() { + return componentUuid; } @CheckForNull diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java index 3b9ebef289e..7ee450d8007 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java @@ -75,7 +75,7 @@ public class SettingsUpdater { private void deleteSetting(DbSession dbSession, String settingKey, Optional<ComponentDto> componentDto) { if (componentDto.isPresent()) { - dbClient.propertiesDao().deleteProjectProperty(settingKey, componentDto.get().getId(), dbSession); + dbClient.propertiesDao().deleteProjectProperty(settingKey, componentDto.get().uuid(), dbSession); } else { dbClient.propertiesDao().deleteGlobalProperty(settingKey, dbSession); } @@ -96,7 +96,7 @@ public class SettingsUpdater { private Optional<PropertyDto> selectPropertyDto(DbSession dbSession, String settingKey, Optional<ComponentDto> componentDto) { if (componentDto.isPresent()) { - return Optional.ofNullable(dbClient.propertiesDao().selectProjectProperty(dbSession, componentDto.get().getId(), settingKey)); + return Optional.ofNullable(dbClient.propertiesDao().selectProjectProperty(dbSession, componentDto.get().uuid(), settingKey)); } else { return Optional.ofNullable(dbClient.propertiesDao().selectGlobalProperty(dbSession, settingKey)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java index 491f1378b1d..b67461aad13 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java @@ -85,7 +85,7 @@ public class ValuesAction implements SettingsWsAction { private final boolean isSonarCloud; public ValuesAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions, - SettingsWsSupport settingsWsSupport, Configuration configuration) { + SettingsWsSupport settingsWsSupport, Configuration configuration) { this.dbClient = dbClient; this.componentFinder = componentFinder; this.userSession = userSession; @@ -215,19 +215,15 @@ public class ValuesAction implements SettingsWsAction { */ private Multimap<String, Setting> loadComponentSettings(DbSession dbSession, Set<String> keys, ComponentDto component) { List<String> componentUuids = DOT_SPLITTER.splitToList(component.moduleUuidPath()); - List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, componentUuids); - Set<Long> componentIds = componentDtos.stream().map(ComponentDto::getId).collect(Collectors.toSet()); - Map<Long, String> uuidsById = componentDtos.stream().collect(Collectors.toMap(ComponentDto::getId, ComponentDto::uuid)); - List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession, keys, componentIds); - List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession, getPropertySetKeys(properties), componentIds); + List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, keys, componentUuids); + List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, getPropertySetKeys(properties), componentUuids); Multimap<String, Setting> settingsByUuid = TreeMultimap.create(Ordering.explicit(componentUuids), Ordering.arbitrary()); for (PropertyDto propertyDto : properties) { - Long componentId = propertyDto.getResourceId(); - String componentUuid = uuidsById.get(componentId); + String componentUuid = propertyDto.getComponentUuid(); String propertyKey = propertyDto.getKey(); settingsByUuid.put(componentUuid, - Setting.createFromDto(propertyDto, getPropertySets(propertyKey, propertySets, componentId), propertyDefinitions.get(propertyKey))); + Setting.createFromDto(propertyDto, getPropertySets(propertyKey, propertySets, componentUuid), propertyDefinitions.get(propertyKey))); } return settingsByUuid; } @@ -240,9 +236,9 @@ public class ValuesAction implements SettingsWsAction { .collect(Collectors.toSet()); } - private static List<PropertyDto> getPropertySets(String propertyKey, List<PropertyDto> propertySets, @Nullable Long componentId) { + private static List<PropertyDto> getPropertySets(String propertyKey, List<PropertyDto> propertySets, @Nullable String componentUuid) { return propertySets.stream() - .filter(propertyDto -> Objects.equals(propertyDto.getResourceId(), componentId)) + .filter(propertyDto -> Objects.equals(propertyDto.getComponentUuid(), componentUuid)) .filter(propertyDto -> propertyDto.getKey().startsWith(propertyKey + ".")) .collect(Collectors.toList()); } @@ -284,7 +280,7 @@ public class ValuesAction implements SettingsWsAction { private void setInherited(Setting setting, Settings.Setting.Builder valueBuilder) { boolean isDefault = setting.isDefault(); boolean isGlobal = !requestedComponent.isPresent(); - boolean isOnComponent = requestedComponent.isPresent() && Objects.equals(setting.getComponentId(), requestedComponent.get().getId()); + boolean isOnComponent = requestedComponent.isPresent() && Objects.equals(setting.getComponentUuid(), requestedComponent.get().uuid()); boolean isSet = isGlobal || isOnComponent; valueBuilder.setInherited(isDefault || !isSet); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java index 933847203ef..83011027ea9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java @@ -245,7 +245,7 @@ public class ComponentAction implements NavigationWsAction { PropertyQuery propertyQuery = PropertyQuery.builder() .setUserId(userSession.getUserId()) .setKey("favourite") - .setComponentId(component.getId()) + .setComponentUuid(component.uuid()) .build(); List<PropertyDto> componentFavourites = dbClient.propertiesDao().selectByQuery(propertyQuery, session); return componentFavourites.size() == 1; diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json index 97332a0480b..97637865c4e 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/search-example.json @@ -6,13 +6,11 @@ }, "results": [ { - "id": 1, "name": "Simple Java project analyzed with the SonarQube Runner", "key": "somple-java", "selected": true }, { - "id": 4, "name": "My Project", "key": "my-project", "selected": false diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index 642565c60c1..ec39c563d4e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -1180,7 +1180,7 @@ public class SearchProjectsActionTest { } private void addFavourite(ComponentDto project) { - dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(userSession.getUserId())); + dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(userSession.getUserId())); dbSession.commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java index 67729fcf944..8f1238b4d5d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java @@ -399,7 +399,7 @@ public class SuggestionsActionTest { componentIndexer.indexOnStartup(null); authorizationIndexerTester.allowOnlyAnyone(project); - db.getDbClient().componentDao().delete(db.getSession(), project.getId()); + db.getDbClient().componentDao().delete(db.getSession(), project.uuid()); db.commit(); SuggestionsWsResponse response = ws.newRequest() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java index fe01076c628..57c97bb768a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java @@ -84,8 +84,8 @@ public class AddActionTest { assertThat(favorites).hasSize(1); PropertyDto favorite = favorites.get(0); assertThat(favorite) - .extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey) - .containsOnly(project.getId(), user.getId(), "favourite"); + .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getKey) + .containsOnly(project.uuid(), user.getId(), "favourite"); } @Test @@ -104,8 +104,8 @@ public class AddActionTest { assertThat(favorites).hasSize(1); PropertyDto favorite = favorites.get(0); assertThat(favorite) - .extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey) - .containsOnly(file.getId(), user.getId(), "favourite"); + .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserId, PropertyDto::getKey) + .containsOnly(file.uuid(), user.getId(), "favourite"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java index 7b1b0a68cc4..818684e3b97 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java @@ -70,9 +70,9 @@ public class WebIssueStorageTest { ComponentDto project = db.components().insertPrivateProject(organizationDto); ComponentDto file = db.components().insertComponent(newFileDto(project)); - long componentId = underTest.component(db.getSession(), new DefaultIssue().setComponentUuid(file.uuid())).getId(); + String componentUuid = underTest.component(db.getSession(), new DefaultIssue().setComponentUuid(file.uuid())).uuid(); - assertThat(componentId).isEqualTo(file.getId()); + assertThat(componentUuid).isEqualTo(file.uuid()); } @Test @@ -81,9 +81,9 @@ public class WebIssueStorageTest { ComponentDto project = db.components().insertPrivateProject(organizationDto); ComponentDto file = db.components().insertComponent(newFileDto(project)); - long projectId = underTest.project(db.getSession(), new DefaultIssue().setProjectUuid(project.uuid())).getId(); + String projectUuid = underTest.project(db.getSession(), new DefaultIssue().setProjectUuid(project.uuid())).uuid(); - assertThat(projectId).isEqualTo(project.getId()); + assertThat(projectUuid).isEqualTo(project.uuid()); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index 396b09db19b..68ba8cc8037 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -1023,7 +1023,7 @@ public class SearchActionTest { new GroupPermissionDto() .setOrganizationUuid(project.getOrganizationUuid()) .setGroupId(null) - .setResourceId(project.getId()) + .setComponentUuid(project.uuid()) .setRole(permission)); session.commit(); userSession.logIn().addProjectPermission(permission, project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java index 81f2368c762..a6cd4be7af0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java @@ -92,7 +92,7 @@ public class GroupPermissionChangerTest { permissionService.getAllProjectPermissions() .forEach(perm -> { try { - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectId(privateProject), anyOneGroupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(privateProject), anyOneGroupId, permissionService)); fail("a BadRequestException should have been thrown"); } catch (BadRequestException e) { assertThat(e).hasMessage("No permission can be granted to Anyone on a private component"); @@ -108,7 +108,7 @@ public class GroupPermissionChangerTest { GroupIdOrAnyone anyOneGroupId = GroupIdOrAnyone.forAnyone(org.getUuid()); permissionService.getAllProjectPermissions() .forEach(perm -> { - apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, perm, new ProjectId(privateProject), anyOneGroupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, perm, new ProjectUuid(privateProject), anyOneGroupId, permissionService)); assertThat(db.users().selectAnyonePermissions(org, privateProject)).contains(perm); }); @@ -142,7 +142,7 @@ public class GroupPermissionChangerTest { private void applyAddsPermissionToGroupOnPrivateProject(String permission) { GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectId(privateProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupId, permissionService)); assertThat(db.users().selectGroupPermissions(group, null)).isEmpty(); assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(permission); @@ -177,7 +177,7 @@ public class GroupPermissionChangerTest { GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); db.users().insertProjectPermissionOnGroup(group, permission, privateProject); - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectId(privateProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectUuid(privateProject), groupId, permissionService)); assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(permission); } @@ -186,7 +186,7 @@ public class GroupPermissionChangerTest { public void apply_has_no_effect_when_adding_USER_permission_to_group_AnyOne_on_a_public_project() { GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService)); assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty(); } @@ -195,7 +195,7 @@ public class GroupPermissionChangerTest { public void apply_has_no_effect_when_adding_CODEVIEWER_permission_to_group_AnyOne_on_a_public_project() { GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.CODEVIEWER, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService)); assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty(); } @@ -207,14 +207,14 @@ public class GroupPermissionChangerTest { expectedException.expect(BadRequestException.class); expectedException.expectMessage("It is not possible to add the 'admin' permission to group 'Anyone'"); - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ADMIN, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ADMIN, new ProjectUuid(publicProject), groupId, permissionService)); } @Test public void apply_adds_permission_ISSUE_ADMIN_to_group_AnyOne_on_a_public_project() { GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ISSUE_ADMIN, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.ISSUE_ADMIN, new ProjectUuid(publicProject), groupId, permissionService)); assertThat(db.users().selectAnyonePermissions(org, publicProject)).containsOnly(UserRole.ISSUE_ADMIN); } @@ -223,7 +223,7 @@ public class GroupPermissionChangerTest { public void apply_adds_permission_SCAN_EXECUTION_to_group_AnyOne_on_a_public_project() { GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.SCAN_EXECUTION, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.SCAN_EXECUTION, new ProjectUuid(publicProject), groupId, permissionService)); assertThat(db.users().selectAnyonePermissions(org, publicProject)).containsOnly(GlobalPermissions.SCAN_EXECUTION); } @@ -235,7 +235,7 @@ public class GroupPermissionChangerTest { expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission user can't be removed from a public component"); - apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService)); } @Test @@ -245,7 +245,7 @@ public class GroupPermissionChangerTest { expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission codeviewer can't be removed from a public component"); - apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService)); } @Test @@ -267,7 +267,7 @@ public class GroupPermissionChangerTest { GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); db.users().insertProjectPermissionOnAnyone(permission, publicProject); - apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, permission, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, permission, new ProjectUuid(publicProject), groupId, permissionService)); assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty(); } @@ -279,7 +279,7 @@ public class GroupPermissionChangerTest { expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission user can't be removed from a public component"); - apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.USER, new ProjectUuid(publicProject), groupId, permissionService)); } @Test @@ -289,7 +289,7 @@ public class GroupPermissionChangerTest { expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission codeviewer can't be removed from a public component"); - apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.CODEVIEWER, new ProjectUuid(publicProject), groupId, permissionService)); } @Test @@ -322,7 +322,7 @@ public class GroupPermissionChangerTest { .filter(perm -> !UserRole.ADMIN.equals(perm) && !GlobalPermissions.SCAN_EXECUTION.equals(perm)) .forEach(perm -> { try { - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectId(privateProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(privateProject), groupId, permissionService)); fail("a BadRequestException should have been thrown for permission " + perm); } catch (BadRequestException e) { assertThat(e).hasMessage("Invalid project permission '" + perm + @@ -340,7 +340,7 @@ public class GroupPermissionChangerTest { .filter(perm -> !UserRole.ADMIN.equals(perm) && !GlobalPermissions.SCAN_EXECUTION.equals(perm)) .forEach(perm -> { try { - apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectId(publicProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.ADD, perm, new ProjectUuid(publicProject), groupId, permissionService)); fail("a BadRequestException should have been thrown for permission " + perm); } catch (BadRequestException e) { assertThat(e).hasMessage("Invalid project permission '" + perm + @@ -384,7 +384,7 @@ public class GroupPermissionChangerTest { db.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, privateProject); db.users().insertProjectPermissionOnGroup(group, UserRole.CODEVIEWER, privateProject); - apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectId(privateProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupId, permissionService)); assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(ADMINISTER_QUALITY_GATES.getKey()); assertThat(db.users().selectGroupPermissions(group, privateProject)).containsOnly(UserRole.CODEVIEWER); @@ -394,7 +394,7 @@ public class GroupPermissionChangerTest { public void do_not_fail_if_removing_a_permission_that_does_not_exist() { GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); - apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectId(privateProject), groupId, permissionService)); + apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectUuid(privateProject), groupId, permissionService)); assertThat(db.users().selectGroupPermissions(group, null)).isEmpty(); assertThat(db.users().selectGroupPermissions(group, privateProject)).isEmpty(); @@ -433,7 +433,7 @@ public class GroupPermissionChangerTest { .setOrganizationUuid(privateProject.getOrganizationUuid()) .setGroupId(null) .setRole(perm) - .setResourceId(privateProject.getId()); + .setComponentUuid(privateProject.uuid()); db.getDbClient().groupPermissionDao().insert(db.getSession(), dto); db.commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java index ebab1802102..47b4464b759 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java @@ -435,12 +435,12 @@ public class PermissionTemplateServiceTest { private List<String> selectProjectPermissionsOfGroup(OrganizationDto organizationDto, @Nullable GroupDto groupDto, ComponentDto project) { return dbTester.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(session, - organizationDto.getUuid(), groupDto != null ? groupDto.getId() : null, project.getId()); + organizationDto.getUuid(), groupDto != null ? groupDto.getId() : null, project.uuid()); } private List<String> selectProjectPermissionsOfUser(UserDto userDto, ComponentDto project) { return dbTester.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(session, - userDto.getId(), project.getId()); + userDto.getId(), project.uuid()); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java index 7b25434bf9d..debbf6a23e3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java @@ -110,7 +110,7 @@ public class UserPermissionChangerTest { @Test public void apply_has_no_effect_when_adding_permission_USER_on_a_public_project() { - UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), USER, new ProjectId(publicProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), USER, new ProjectUuid(publicProject), UserId.from(user1), permissionService); apply(change); @@ -119,7 +119,7 @@ public class UserPermissionChangerTest { @Test public void apply_has_no_effect_when_adding_permission_CODEVIEWER_on_a_public_project() { - UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), CODEVIEWER, new ProjectId(publicProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), CODEVIEWER, new ProjectUuid(publicProject), UserId.from(user1), permissionService); apply(change); @@ -142,7 +142,7 @@ public class UserPermissionChangerTest { } private void applyAddsPermissionOnAPublicProject(String permission) { - UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), permission, new ProjectId(publicProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), permission, new ProjectUuid(publicProject), UserId.from(user1), permissionService); apply(change); @@ -151,7 +151,7 @@ public class UserPermissionChangerTest { @Test public void apply_fails_with_BadRequestException_when_removing_permission_USER_from_a_public_project() { - UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), USER, new ProjectId(publicProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), USER, new ProjectUuid(publicProject), UserId.from(user1), permissionService); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission user can't be removed from a public component"); @@ -161,7 +161,7 @@ public class UserPermissionChangerTest { @Test public void apply_fails_with_BadRequestException_when_removing_permission_CODEVIEWER_from_a_public_project() { - UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), CODEVIEWER, new ProjectId(publicProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), CODEVIEWER, new ProjectUuid(publicProject), UserId.from(user1), permissionService); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Permission codeviewer can't be removed from a public component"); @@ -186,7 +186,7 @@ public class UserPermissionChangerTest { private void applyRemovesPermissionFromPublicProject(String permission) { db.users().insertProjectPermissionOnUser(user1, permission, publicProject); - UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectId(publicProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectUuid(publicProject), UserId.from(user1), permissionService); apply(change); @@ -197,7 +197,7 @@ public class UserPermissionChangerTest { public void apply_adds_any_permission_to_a_private_project() { permissionService.getAllProjectPermissions() .forEach(permission -> { - UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), permission, new ProjectId(privateProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), permission, new ProjectUuid(privateProject), UserId.from(user1), permissionService); apply(change); @@ -212,7 +212,7 @@ public class UserPermissionChangerTest { permissionService.getAllProjectPermissions() .forEach(permission -> { - UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectId(privateProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), permission, new ProjectUuid(privateProject), UserId.from(user1), permissionService); apply(change); @@ -235,7 +235,7 @@ public class UserPermissionChangerTest { @Test public void add_project_permission_to_user() { - UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), ISSUE_ADMIN, new ProjectId(privateProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), ISSUE_ADMIN, new ProjectUuid(privateProject), UserId.from(user1), permissionService); apply(change); assertThat(db.users().selectPermissionsOfUser(user1, org1)).isEmpty(); @@ -259,7 +259,7 @@ public class UserPermissionChangerTest { expectedException.expect(BadRequestException.class); expectedException.expectMessage("Invalid project permission 'gateadmin'. Valid values are [" + StringUtils.join(permissionService.getAllProjectPermissions(), ", ") + "]"); - UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), QUALITY_GATE_ADMIN, new ProjectId(privateProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(ADD, org1.getUuid(), QUALITY_GATE_ADMIN, new ProjectUuid(privateProject), UserId.from(user1), permissionService); apply(change); } @@ -298,7 +298,7 @@ public class UserPermissionChangerTest { db.users().insertProjectPermissionOnUser(user2, ISSUE_ADMIN, privateProject); db.users().insertProjectPermissionOnUser(user1, ISSUE_ADMIN, project2); - UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ISSUE_ADMIN, new ProjectId(privateProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ISSUE_ADMIN, new ProjectUuid(privateProject), UserId.from(user1), permissionService); apply(change); assertThat(db.users().selectProjectPermissionsOfUser(user1, privateProject)).containsOnly(USER); @@ -316,7 +316,7 @@ public class UserPermissionChangerTest { @Test public void do_not_fail_if_removing_a_project_permission_that_does_not_exist() { - UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ISSUE_ADMIN, new ProjectId(privateProject), UserId.from(user1), permissionService); + UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ISSUE_ADMIN, new ProjectUuid(privateProject), UserId.from(user1), permissionService); apply(change); assertThat(db.users().selectProjectPermissionsOfUser(user1, privateProject)).isEmpty(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index 3af904b1416..36a2b9e980e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -476,7 +476,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio .setOrganizationUuid(project.getOrganizationUuid()) .setGroupId(null) .setRole(perm) - .setResourceId(project.getId()); + .setComponentUuid(project.uuid()); db.getDbClient().groupPermissionDao().insert(db.getSession(), dto); db.commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java index 3eb08cff46b..36247e218b3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java @@ -468,11 +468,11 @@ public class UpdateVisibilityActionTest { .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user1.getId(), project.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user1.getId(), project.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p1", "p2"); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user2.getId(), project.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user2.getId(), project.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p2"); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user3.getId(), project.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user3.getId(), project.uuid())) .isEmpty(); } @@ -492,11 +492,11 @@ public class UpdateVisibilityActionTest { .setParam(PARAM_VISIBILITY, PRIVATE) .execute(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group1.getId(), project.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p1", "p2"); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group2.getId(), project.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, "p2"); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group3.getId(), project.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group3.getId(), project.uuid())) .isEmpty(); } @@ -515,9 +515,9 @@ public class UpdateVisibilityActionTest { .execute(); assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isTrue(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN); } @@ -540,9 +540,9 @@ public class UpdateVisibilityActionTest { .execute(); assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isFalse(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid())) .containsOnly(UserRole.ISSUE_ADMIN); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) .containsOnly(UserRole.ADMIN); } @@ -561,9 +561,9 @@ public class UpdateVisibilityActionTest { .execute(); assertThat(dbClient.componentDao().selectByUuid(dbSession, application.uuid()).get().isPrivate()).isTrue(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), application.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), application.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), application.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), application.uuid())) .containsOnly(UserRole.USER, UserRole.CODEVIEWER, UserRole.ADMIN); } @@ -586,9 +586,9 @@ public class UpdateVisibilityActionTest { .execute(); assertThat(dbClient.componentDao().selectByUuid(dbSession, portfolio.uuid()).get().isPrivate()).isFalse(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, organization.getUuid(), group.getId(), portfolio.uuid())) .containsOnly(UserRole.ISSUE_ADMIN); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), portfolio.uuid())) .containsOnly(UserRole.ADMIN); } @@ -658,7 +658,7 @@ public class UpdateVisibilityActionTest { .setOrganizationUuid(component.getOrganizationUuid()) .setGroupId(null) .setRole(permission) - .setResourceId(component.getId()); + .setComponentUuid(component.uuid()); dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto); dbTester.commit(); } @@ -668,13 +668,13 @@ public class UpdateVisibilityActionTest { .setOrganizationUuid(group.getOrganizationUuid()) .setGroupId(group.getId()) .setRole(permission) - .setResourceId(component.getId()); + .setComponentUuid(component.uuid()); dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto); dbTester.commit(); } private void unsafeInsertProjectPermissionOnUser(ComponentDto component, UserDto user, String permission) { - UserPermissionDto dto = new UserPermissionDto(component.getOrganizationUuid(), permission, user.getId(), component.getId()); + UserPermissionDto dto = new UserPermissionDto(component.getOrganizationUuid(), permission, user.getId(), component.uuid()); dbTester.getDbClient().userPermissionDao().insert(dbTester.getSession(), dto); dbTester.commit(); } @@ -686,11 +686,11 @@ public class UpdateVisibilityActionTest { .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid())) .isEmpty(); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); } @@ -701,15 +701,15 @@ public class UpdateVisibilityActionTest { .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid())) .doesNotContain(UserRole.USER) .doesNotContain(UserRole.CODEVIEWER) .containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid())) .doesNotContain(UserRole.USER) .doesNotContain(UserRole.CODEVIEWER) .containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid())) .doesNotContain(UserRole.USER) .doesNotContain(UserRole.CODEVIEWER) .containsAll(PROJECT_PERMISSIONS_BUT_USER_AND_CODEVIEWER); @@ -722,11 +722,11 @@ public class UpdateVisibilityActionTest { .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), component.getOrganizationUuid())) .containsAll(ORGANIZATION_PERMISSIONS_NAME_SET); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), null, component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); - assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.getId())) + assertThat(dbClient.groupPermissionDao().selectProjectPermissionsOfGroup(dbSession, component.getOrganizationUuid(), group.getId(), component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); - assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.getId())) + assertThat(dbClient.userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), component.uuid())) .containsAll(permissionService.getAllProjectPermissions()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java index a52af6442d3..a9c76ab314a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java @@ -42,7 +42,6 @@ import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsActionTester; import static java.lang.String.format; -import static java.lang.String.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES; @@ -147,19 +146,6 @@ public class DeselectActionTest { } @Test - public void fail_when_no_project_id() { - OrganizationDto organization = db.organizations().insert(); - userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); - - expectedException.expect(NotFoundException.class); - - ws.newRequest() - .setParam("projectId", valueOf((Long) 1L)) - .setParam("organization", organization.getKey()) - .execute(); - } - - @Test public void fail_when_no_project_key() { OrganizationDto organization = db.organizations().insert(); userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); @@ -232,22 +218,6 @@ public class DeselectActionTest { } @Test - public void fail_when_using_branch_id() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPublicProject(organization); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - expectedException.expect(NotFoundException.class); - expectedException.expectMessage(format("Project '%s' not found", branch.getId())); - - ws.newRequest() - .setParam("projectId", String.valueOf(branch.getId())) - .setParam("organization", organization.getKey()) - .execute(); - } - - @Test public void definition() { WebService.Action def = ws.getDef(); @@ -255,13 +225,13 @@ public class DeselectActionTest { assertThat(def.isPost()).isTrue(); assertThat(def.since()).isEqualTo("4.3"); assertThat(def.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactly( - tuple("6.6", "The parameter 'gateId' was removed")); + tuple("6.6", "The parameter 'gateId' was removed"), + tuple("8.3", "The parameter 'projectId' was removed")); assertThat(def.params()) .extracting(WebService.Param::key, WebService.Param::isRequired) .containsExactlyInAnyOrder( - tuple("projectKey", false), - tuple("projectId", false), + tuple("projectKey", true), tuple("organization", false)); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java index 7b718f573f0..b3a569d29f4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java @@ -84,8 +84,8 @@ public class SearchActionTest { .executeProtobuf(SearchResponse.class); assertThat(response.getResultsList()) - .extracting(Result::getId, Result::getKey, Result::getName) - .containsExactlyInAnyOrder(tuple(project.getId(), project.getKey(), project.name())); + .extracting(Result::getKey, Result::getName) + .containsExactlyInAnyOrder(tuple(project.getKey(), project.name())); } @Test @@ -100,8 +100,8 @@ public class SearchActionTest { .executeProtobuf(SearchResponse.class); assertThat(response.getResultsList()) - .extracting(Result::getId, Result::getName) - .containsExactlyInAnyOrder(tuple(project.getId(), project.name())); + .extracting(Result::getKey, Result::getName) + .containsExactlyInAnyOrder(tuple(project.getKey(), project.name())); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java index 6fc1b274231..30a51c956e5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java @@ -481,7 +481,7 @@ public class ResetActionTest { } private void assertProjectPropertyDoesNotExist(ComponentDto component, String key) { - assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(component.getId()).setKey(key).build(), dbSession)).isEmpty(); + assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(component.uuid()).setKey(key).build(), dbSession)).isEmpty(); } private void assertProjectPropertyDoesNotExist(String key) { @@ -489,7 +489,7 @@ public class ResetActionTest { } private void assertProjectPropertyExists(String key) { - assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isNotEmpty(); + assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).setKey(key).build(), dbSession)).isNotEmpty(); } private void assertUserPropertyExists(String key, UserDto user) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java index 734869d66f9..ac26830ad8c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java @@ -145,7 +145,7 @@ public class SetActionTest { callForProjectSettingByKey("my.key", "my project value", project.getDbKey()); assertGlobalSetting("my.key", "my global value"); - assertComponentSetting("my.key", "my project value", project.getId()); + assertComponentSetting("my.key", "my project value", project.uuid()); assertThat(settingsChangeNotifier.wasCalled).isFalse(); } @@ -156,7 +156,7 @@ public class SetActionTest { callForProjectSettingByKey("my.key", "my value", project.getDbKey()); - assertComponentSetting("my.key", "my value", project.getId()); + assertComponentSetting("my.key", "my value", project.uuid()); } @Test @@ -164,12 +164,12 @@ public class SetActionTest { propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value")); ComponentDto project = db.components().insertPrivateProject(); propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project)); - assertComponentSetting("my.key", "my project value", project.getId()); + assertComponentSetting("my.key", "my project value", project.uuid()); logInAsProjectAdministrator(project); callForProjectSettingByKey("my.key", "my new project value", project.getDbKey()); - assertComponentSetting("my.key", "my new project value", project.getId()); + assertComponentSetting("my.key", "my new project value", project.uuid()); } @Test @@ -313,12 +313,12 @@ public class SetActionTest { assertGlobalSetting("my.key", "1"); assertGlobalSetting("my.key.1.firstField", "oldFirstValue"); assertGlobalSetting("my.key.1.secondField", "oldSecondValue"); - Long projectId = project.getId(); - assertComponentSetting("my.key", "1,2", projectId); - assertComponentSetting("my.key.1.firstField", "firstValue", projectId); - assertComponentSetting("my.key.1.secondField", "secondValue", projectId); - assertComponentSetting("my.key.2.firstField", "anotherFirstValue", projectId); - assertComponentSetting("my.key.2.secondField", "anotherSecondValue", projectId); + String projectUuid = project.uuid(); + assertComponentSetting("my.key", "1,2", projectUuid); + assertComponentSetting("my.key.1.firstField", "firstValue", projectUuid); + assertComponentSetting("my.key.1.secondField", "secondValue", projectUuid); + assertComponentSetting("my.key.2.firstField", "anotherFirstValue", projectUuid); + assertComponentSetting("my.key.2.secondField", "anotherSecondValue", projectUuid); assertThat(settingsChangeNotifier.wasCalled).isFalse(); } @@ -643,7 +643,7 @@ public class SetActionTest { callForProjectSettingByKey("my.key", "My Value", module.getDbKey()); - assertComponentSetting("my.key", "My Value", module.getId()); + assertComponentSetting("my.key", "My Value", module.uuid()); } private void failForPropertyWithoutDefinitionOnUnsupportedComponent(ComponentDto root, ComponentDto component) { @@ -962,7 +962,7 @@ public class SetActionTest { PropertyDto result = dbClient.propertiesDao().selectGlobalProperty(key); assertThat(result) - .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getResourceId) + .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getComponentUuid) .containsExactly(key, value, null); } @@ -974,13 +974,13 @@ public class SetActionTest { .containsExactly(tuple(key, value, userId)); } - private void assertComponentSetting(String key, String value, long componentId) { - PropertyDto result = dbClient.propertiesDao().selectProjectProperty(componentId, key); + private void assertComponentSetting(String key, String value, String componentUuid) { + PropertyDto result = dbClient.propertiesDao().selectProjectProperty(componentUuid, key); assertThat(result) .isNotNull() - .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getResourceId) - .containsExactly(key, value, componentId); + .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getComponentUuid) + .containsExactly(key, value, componentUuid); } private void callForGlobalSetting(@Nullable String key, @Nullable String value) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java index f41c559f670..6c04d4f67f0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java @@ -206,11 +206,11 @@ public class SettingsUpdaterTest { } private void assertProjectPropertyDoesNotExist(String key) { - assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isEmpty(); + assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).setKey(key).build(), dbSession)).isEmpty(); } private void assertProjectPropertyExists(String key) { - assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isNotEmpty(); + assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentUuid(project.uuid()).setKey(key).build(), dbSession)).isNotEmpty(); } private void assertUserPropertyExists(String key, UserDto user) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index 0583bd29652..83d45a54bd5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -147,7 +147,7 @@ public class ComponentActionTest { public void return_component_info_with_favourite() { ComponentDto project = insertOrganizationAndProject(); UserDto user = db.users().insertUser("obiwan"); - propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId())); + propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId())); userSession.logIn(user).addProjectPermission(UserRole.USER, project); init(); @@ -159,7 +159,7 @@ public class ComponentActionTest { ComponentDto project = insertOrganizationAndProject(); ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz")); UserDto user = db.users().insertUser("obiwan"); - propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId())); + propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId())); userSession.logIn(user).addProjectPermission(UserRole.USER, project); init(); @@ -606,7 +606,7 @@ public class ComponentActionTest { componentDbTester.insertSnapshot(analysis); when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType()); UserDto user = db.users().insertUser("obiwan"); - propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId())); + propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserId(user.getId())); addQualityProfiles(project, createQProfile("qp1", "Sonar Way Java", "java"), createQProfile("qp2", "Sonar Way Xoo", "xoo")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index c2a5b06183a..d86d6bea0b3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -143,12 +143,12 @@ public class DeactivateActionTest { ComponentDto project = db.components().insertPrivateProject(); db.properties().insertProperty(newUserPropertyDto(user)); db.properties().insertProperty(newUserPropertyDto(user)); - db.properties().insertProperty(newUserPropertyDto(user).setResourceId(project.getId())); + db.properties().insertProperty(newUserPropertyDto(user).setComponentUuid(project.uuid())); deactivate(user.getLogin()); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession)).isEmpty(); - assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentId(project.getId()).build(), dbSession)).isEmpty(); + assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentUuid(project.uuid()).build(), dbSession)).isEmpty(); } @Test @@ -164,7 +164,7 @@ public class DeactivateActionTest { deactivate(user.getLogin()); assertThat(db.getDbClient().userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), db.getDefaultOrganization().getUuid())).isEmpty(); - assertThat(db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), project.getId())).isEmpty(); + assertThat(db.getDbClient().userPermissionDao().selectProjectPermissionsOfUser(dbSession, user.getId(), project.uuid())).isEmpty(); } @Test @@ -201,9 +201,9 @@ public class DeactivateActionTest { UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto anotherProject = db.components().insertPrivateProject(); - db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(project.getId())); - db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(anotherProject.getId())); - db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setResourceId(anotherProject.getId())); + db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setComponentUuid(project.uuid())); + db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setComponentUuid(anotherProject.uuid())); + db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setComponentUuid(anotherProject.uuid())); deactivate(user.getLogin()); |