Browse Source

SONAR-19445 Review and improve the endpoints in WebAPI that rely on ComponentDto

tags/10.2.0.77647
Duarte Meneses 1 year ago
parent
commit
4473576ffa
34 changed files with 266 additions and 237 deletions
  1. 11
    2
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
  2. 9
    9
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
  3. 2
    12
      server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
  4. 6
    6
      server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java
  5. 2
    2
      server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java
  6. 3
    3
      server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java
  7. 4
    4
      server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserSession.java
  8. 8
    3
      server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/UserSessionRule.java
  9. 29
    17
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/AddActionIT.java
  10. 16
    14
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/ListActionIT.java
  11. 6
    5
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/RemoveActionIT.java
  12. 1
    6
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/ProjectBadgesSupport.java
  13. 13
    12
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java
  14. 10
    9
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityStatusAction.java
  15. 3
    4
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/CancelAction.java
  16. 23
    6
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java
  17. 4
    4
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/SearchAction.java
  18. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/AddCommentAction.java
  19. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/AssignAction.java
  20. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ChangeStatusAction.java
  21. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/DeleteCommentAction.java
  22. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/EditCommentAction.java
  23. 13
    9
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsSupport.java
  24. 15
    16
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java
  25. 11
    15
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/AddAction.java
  26. 14
    14
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java
  27. 26
    26
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java
  28. 10
    15
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/RemoveAction.java
  29. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java
  30. 1
    1
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java
  31. 3
    3
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectdump/ws/ProjectDumpWsSupport.java
  32. 9
    6
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/scannercache/ws/GetAction.java
  33. 4
    4
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java
  34. 4
    4
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java

+ 11
- 2
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java View File

@@ -275,8 +275,12 @@ public class ComponentDbTester {
}

public final ComponentDto insertSubportfolio(ComponentDto parentPortfolio) {
ComponentDto subPortfolioComponent = ComponentTesting.newSubPortfolio(parentPortfolio);
return insertComponentAndPortfolio(subPortfolioComponent, true, defaults(), sp -> sp.setParentUuid(sp.getRootUuid()));
return insertSubportfolio(parentPortfolio, defaults());
}

public final ComponentDto insertSubportfolio(ComponentDto parentPortfolio, Consumer<ComponentDto> consumer) {
ComponentDto subPortfolioComponent = ComponentTesting.newSubPortfolio(parentPortfolio).setPrivate(true);
return insertComponentAndPortfolio(subPortfolioComponent, true, consumer, sp -> sp.setParentUuid(sp.getRootUuid()));
}

public void addPortfolioReference(String portfolioUuid, String... referencerUuids) {
@@ -484,6 +488,11 @@ public class ComponentDbTester {
return insertSnapshot(snapshotDto);
}

public SnapshotDto insertSnapshot(PortfolioDto portfolio) {
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(portfolio.getUuid());
return insertSnapshot(snapshotDto);
}

public SnapshotDto insertSnapshot(BranchDto branchDto, Consumer<SnapshotDto> consumer) {
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(branchDto);
consumer.accept(snapshotDto);

+ 9
- 9
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java View File

@@ -25,7 +25,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;

@@ -42,22 +42,22 @@ public class NotificationDbTester {
this.dbSession = db.getSession();
}

public void assertExists(String channel, String dispatcher, String userUuid, @Nullable ComponentDto component) {
public void assertExists(String channel, String dispatcher, String userUuid, @Nullable ProjectDto project) {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
.setEntityUuid(component == null ? null : component.uuid())
.setUserUuid(userUuid)
.build(), dbSession).stream()
.filter(prop -> component == null ? prop.getEntityUuid() == null : prop.getEntityUuid() != null)
.setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
.setEntityUuid(project == null ? null : project.getUuid())
.setUserUuid(userUuid)
.build(), dbSession).stream()
.filter(prop -> project == null ? prop.getEntityUuid() == null : prop.getEntityUuid() != null)
.collect(MoreCollectors.toList());
assertThat(result).hasSize(1);
assertThat(result.get(0).getValue()).isEqualTo("true");
}

public void assertDoesNotExist(String channel, String dispatcher, String userUuid, @Nullable ComponentDto component) {
public void assertDoesNotExist(String channel, String dispatcher, String userUuid, @Nullable ProjectDto project) {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
.setEntityUuid(component == null ? null : component.uuid())
.setEntityUuid(project == null ? null : project.getUuid())
.setUserUuid(userUuid)
.build(), dbSession);
assertThat(result).isEmpty();

+ 2
- 12
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java View File

@@ -300,11 +300,6 @@ public class UserDbTester {
return dto;
}

public void deleteProjectPermissionFromAnyone(ComponentDto project, String permission) {
db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, null, null, project.uuid(), project);
db.commit();
}

public void deleteProjectPermissionFromAnyone(EntityDto project, String permission) {
db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, null, null, project.getUuid(), project);
db.commit();
@@ -389,11 +384,6 @@ public class UserDbTester {
db.commit();
}

public void deletePermissionFromUser(ComponentDto project, UserDto user, String permission) {
db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user, permission, project);
db.commit();
}

public void deletePermissionFromUser(EntityDto project, UserDto user, String permission) {
db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user, permission, project);
db.commit();
@@ -406,10 +396,10 @@ public class UserDbTester {
checkArgument(project.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
"%s can't be granted on a public project", permission);
EntityDto entityDto;
if (project.qualifier().equals(Qualifiers.VIEW) || project.qualifier().equals(Qualifiers.SUBVIEW)){
if (project.qualifier().equals(Qualifiers.VIEW) || project.qualifier().equals(Qualifiers.SUBVIEW)) {
entityDto = db.getDbClient().portfolioDao().selectByUuid(db.getSession(), project.uuid())
.orElseThrow();
}else{
} else {
BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.branchUuid())
.orElseThrow();
// I don't know if this check is worth it

+ 6
- 6
server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java View File

@@ -201,12 +201,12 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe
bulk.stop();
}

public static ComponentDoc toDocument(EntityDto component) {
public static ComponentDoc toDocument(EntityDto entity) {
return new ComponentDoc()
.setId(component.getUuid())
.setAuthUuid(component.getAuthUuid())
.setName(component.getName())
.setKey(component.getKey())
.setQualifier(component.getQualifier());
.setId(entity.getUuid())
.setAuthUuid(entity.getAuthUuid())
.setName(entity.getName())
.setKey(entity.getKey())
.setQualifier(entity.getQualifier());
}
}

+ 2
- 2
server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java View File

@@ -113,7 +113,7 @@ public abstract class AbstractUserSession implements UserSession {
}

@Override
public final boolean hasChildProjectsPermission(String permission, ProjectDto application) {
public final boolean hasChildProjectsPermission(String permission, EntityDto application) {
return hasChildProjectsPermission(permission, application.getUuid());
}

@@ -211,7 +211,7 @@ public abstract class AbstractUserSession implements UserSession {
}

@Override
public UserSession checkChildProjectsPermission(String projectPermission, ProjectDto application) {
public UserSession checkChildProjectsPermission(String projectPermission, EntityDto application) {
if (!APP.equals(application.getQualifier()) || hasChildProjectsPermission(projectPermission, application)) {
return this;
}

+ 3
- 3
server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java View File

@@ -142,7 +142,7 @@ public class ThreadLocalUserSession implements UserSession {
}

@Override
public UserSession checkChildProjectsPermission(String projectPermission, ProjectDto application) {
public UserSession checkChildProjectsPermission(String projectPermission, EntityDto application) {
get().checkChildProjectsPermission(projectPermission, application);
return this;
}
@@ -190,8 +190,8 @@ public class ThreadLocalUserSession implements UserSession {
}

@Override
public boolean hasChildProjectsPermission(String permission, ProjectDto project) {
return get().hasChildProjectsPermission(permission, project);
public boolean hasChildProjectsPermission(String permission, EntityDto application) {
return get().hasChildProjectsPermission(permission, application);
}

@Override

+ 4
- 4
server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserSession.java View File

@@ -153,7 +153,7 @@ public interface UserSession {

boolean hasChildProjectsPermission(String permission, ComponentDto component);

boolean hasChildProjectsPermission(String permission, ProjectDto component);
boolean hasChildProjectsPermission(String permission, EntityDto application);

boolean hasPortfolioChildProjectsPermission(String permission, ComponentDto component);

@@ -185,7 +185,7 @@ public interface UserSession {
UserSession checkComponentPermission(String projectPermission, ComponentDto component);

/**
* Ensures that {@link #hasEntityPermission(String, ProjectDto)} is {@code true},
* Ensures that {@link #hasEntityPermission(String, EntityDto)} is {@code true},
* otherwise throws a {@link org.sonar.server.exceptions.ForbiddenException}.
*/
UserSession checkEntityPermission(String projectPermission, EntityDto entity);
@@ -197,10 +197,10 @@ public interface UserSession {
UserSession checkChildProjectsPermission(String projectPermission, ComponentDto project);

/**
* Ensures that {@link #hasChildProjectsPermission(String, ProjectDto)} is {@code true}
* Ensures that {@link #hasChildProjectsPermission(String, EntityDto)} is {@code true}
* otherwise throws a {@link org.sonar.server.exceptions.ForbiddenException}.
*/
UserSession checkChildProjectsPermission(String projectPermission, ProjectDto application);
UserSession checkChildProjectsPermission(String projectPermission, EntityDto application);

/**
* Ensures that {@link #hasComponentUuidPermission(String, String)} is {@code true},

+ 8
- 3
server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/UserSessionRule.java View File

@@ -180,6 +180,11 @@ public class UserSessionRule implements TestRule, UserSession {
return this;
}

public UserSessionRule registerPortfolios(PortfolioDto... portfolioDtos) {
ensureAbstractMockUserSession().registerPortfolios(portfolioDtos);
return this;
}

public UserSessionRule registerProjects(ProjectDto... projectDtos) {
ensureAbstractMockUserSession().registerProjects(projectDtos);
return this;
@@ -274,8 +279,8 @@ public class UserSessionRule implements TestRule, UserSession {
}

@Override
public boolean hasChildProjectsPermission(String permission, ProjectDto component) {
return currentUserSession.hasChildProjectsPermission(permission, component);
public boolean hasChildProjectsPermission(String permission, EntityDto application) {
return currentUserSession.hasChildProjectsPermission(permission, application);
}

@Override
@@ -383,7 +388,7 @@ public class UserSessionRule implements TestRule, UserSession {
}

@Override
public UserSession checkChildProjectsPermission(String projectPermission, ProjectDto application) {
public UserSession checkChildProjectsPermission(String projectPermission, EntityDto application) {
currentUserSession.checkChildProjectsPermission(projectPermission, application);
return this;
}

+ 29
- 17
server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/AddActionIT.java View File

@@ -27,6 +27,7 @@ import org.sonar.api.notifications.NotificationChannel;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
@@ -62,18 +63,18 @@ public class AddActionIT {
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create();
public DbTester db = DbTester.create(true);

private DbClient dbClient = db.getDbClient();
private final DbClient dbClient = db.getDbClient();

private NotificationChannel emailChannel = new FakeNotificationChannel("EmailChannel");
private NotificationChannel twitterChannel = new FakeNotificationChannel("TwitterChannel");
private final NotificationChannel emailChannel = new FakeNotificationChannel("EmailChannel");
private final NotificationChannel twitterChannel = new FakeNotificationChannel("TwitterChannel");
// default channel, based on class simple name
private NotificationChannel defaultChannel = new FakeNotificationChannel("EmailNotificationChannel");
private final NotificationChannel defaultChannel = new FakeNotificationChannel("EmailNotificationChannel");

private Dispatchers dispatchers = mock(Dispatchers.class);
private final Dispatchers dispatchers = mock(Dispatchers.class);

private WsActionTester ws = new WsActionTester(new AddAction(new NotificationCenter(
private final WsActionTester ws = new WsActionTester(new AddAction(new NotificationCenter(
new NotificationDispatcherMetadata[] {},
new NotificationChannel[] {emailChannel, twitterChannel, defaultChannel}),
new NotificationUpdater(dbClient), dispatchers, dbClient, TestComponentFinder.from(db), userSession));
@@ -104,7 +105,7 @@ public class AddActionIT {
public void add_notification_on_private_with_USER_permission() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
userSession.addProjectPermission(USER, project);
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
@@ -118,8 +119,8 @@ public class AddActionIT {
public void add_notification_on_public_project() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
userSession.registerComponents(project);
ProjectDto project = db.components().insertPublicProject().getProjectDto();
userSession.registerProjects(project);
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));

@@ -134,7 +135,7 @@ public class AddActionIT {
userSession.logIn(user);
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES));
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
userSession.addProjectPermission(USER, project);
call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null);

@@ -150,7 +151,7 @@ public class AddActionIT {
userSession.logIn(user);
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
call(NOTIF_MY_NEW_ISSUES, null, null, null);

userSession.addProjectPermission(USER, project);
@@ -166,8 +167,8 @@ public class AddActionIT {
userSession.logIn(user);
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
userSession.registerComponents(project);
ProjectDto project = db.components().insertPublicProject().getProjectDto();
userSession.registerProjects(project);
call(NOTIF_MY_NEW_ISSUES, null, null, null);

call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null);
@@ -210,7 +211,7 @@ public class AddActionIT {
}

@Test
public void fail_if_login_provided_and_not_system_administrsator() {
public void fail_if_login_provided_and_not_system_administrator() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setNonSystemAdministrator();
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
@@ -219,6 +220,17 @@ public class AddActionIT {
.isInstanceOf(ForbiddenException.class);
}

@Test
public void fail_if_project_provided_and_not_project_user() {
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
UserDto user = db.users().insertUser();
userSession.logIn(user);
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));

assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null))
.isInstanceOf(ForbiddenException.class);
}

@Test
public void fail_when_notification_already_exists() {
UserDto user = db.users().insertUser();
@@ -299,8 +311,8 @@ public class AddActionIT {
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));

assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, "VIEW_1", null))
.isInstanceOf(BadRequestException.class)
.hasMessageContaining("Component 'VIEW_1' must be a project");
.isInstanceOf(NotFoundException.class)
.hasMessageContaining("Project 'VIEW_1' not found");
}

@Test

+ 16
- 14
server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/ListActionIT.java View File

@@ -26,7 +26,8 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
@@ -56,7 +57,7 @@ public class ListActionIT {
@Rule
public final UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public final DbTester db = DbTester.create();
public final DbTester db = DbTester.create(true);

private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
@@ -110,16 +111,16 @@ public class ListActionIT {
userSession.logIn(user);
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
db.users().insertProjectPermissionOnUser(user, USER, project);
ComponentDto anotherProject = db.components().insertPrivateProject().getMainBranchComponent();
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, project);
ProjectData project = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnUser(user, USER, project.getMainBranchComponent());
ProjectDto anotherProject = db.components().insertPrivateProject().getProjectDto();
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, project.getProjectDto());
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, anotherProject);
dbSession.commit();

ListResponse result = call();

assertThat(result.getNotificationsList()).extracting(Notification::getProject).containsOnly(project.getKey());
assertThat(result.getNotificationsList()).extracting(Notification::getProject).containsOnly(project.getProjectDto().getKey());
}

@Test
@@ -155,10 +156,10 @@ public class ListActionIT {
UserDto user = db.users().insertUser();
userSession.logIn(user);
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
db.users().insertProjectPermissionOnUser(user, USER, project);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, project);
notificationUpdater.add(dbSession, emailChannel.getKey(), "Unknown Notification", user, project);
ProjectData project = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnUser(user, USER, project.getMainBranchComponent());
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, project.getProjectDto());
notificationUpdater.add(dbSession, emailChannel.getKey(), "Unknown Notification", user, project.getProjectDto());
dbSession.commit();

ListResponse result = call();
@@ -174,7 +175,7 @@ public class ListActionIT {
userSession.logIn(user);
when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS));
when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS));
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
db.users().insertProjectPermissionOnUser(user, USER, project);
notificationUpdater.add(dbSession, twitterChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null);
@@ -241,8 +242,9 @@ public class ListActionIT {
userSession.logIn(user);
when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS));
when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS));
ComponentDto project = db.components().insertPrivateProject(p -> p.setKey(KEY_PROJECT_EXAMPLE_001).setName("My Project")).getMainBranchComponent();
db.users().insertProjectPermissionOnUser(user, USER, project);
ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey(KEY_PROJECT_EXAMPLE_001).setName("My Project"));
ProjectDto project = projectData.getProjectDto();
db.users().insertProjectPermissionOnUser(user, USER, projectData.getMainBranchComponent());
notificationUpdater.add(dbSession, twitterChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null);
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_NEW_ISSUES, user, null);

+ 6
- 5
server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/RemoveActionIT.java View File

@@ -27,6 +27,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
@@ -61,7 +62,7 @@ public class RemoveActionIT {
@Rule
public final UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public final DbTester db = DbTester.create();
public final DbTester db = DbTester.create(true);
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();

@@ -111,7 +112,7 @@ public class RemoveActionIT {
userSession.logIn(user);
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
notificationUpdater.add(dbSession, defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, project);
dbSession.commit();

@@ -126,7 +127,7 @@ public class RemoveActionIT {
userSession.logIn(user);
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
notificationUpdater.add(dbSession, defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, project);
dbSession.commit();

@@ -287,8 +288,8 @@ public class RemoveActionIT {

RemoveRequest request = this.request.setProject("VIEW_1");
assertThatThrownBy(() -> call(request))
.isInstanceOf(BadRequestException.class)
.hasMessage("Component 'VIEW_1' must be a project");
.isInstanceOf(NotFoundException.class)
.hasMessage("Project 'VIEW_1' not found");
}

@Test

+ 1
- 6
server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/ProjectBadgesSupport.java View File

@@ -76,12 +76,7 @@ public class ProjectBadgesSupport {
String branchName = request.param(PARAM_BRANCH);
ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);

BranchDto branch;
if (branchName == null) {
branch = componentFinder.getMainBranch(dbSession, project);
} else {
branch = componentFinder.getBranchOrPullRequest(dbSession, project, branchName, null);
}
BranchDto branch = componentFinder.getBranchOrPullRequest(dbSession, project, branchName, null);

if (!branch.getBranchType().equals(BRANCH)) {
throw generateInvalidProjectException();

+ 13
- 12
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityAction.java View File

@@ -47,6 +47,7 @@ import org.sonar.db.ce.CeTaskQuery;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentQuery;
import org.sonar.db.entity.EntityDto;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Ce;
import org.sonarqube.ws.Ce.ActivityResponse;
@@ -167,8 +168,8 @@ public class ActivityAction implements CeWsAction {
private ActivityResponse doHandle(Request request) {

try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = loadComponent(dbSession, request);
checkPermission(component);
EntityDto entity = loadEntity(dbSession, request);
checkPermission(entity);
// if a task searched by uuid is found all other parameters are ignored
Optional<Ce.Task> taskSearchedById = searchTaskByUuid(dbSession, request);
if (taskSearchedById.isPresent()) {
@@ -178,7 +179,7 @@ public class ActivityAction implements CeWsAction {
Paging.forPageIndex(1).withPageSize(1).andTotal(1), 0);
}

CeTaskQuery query = buildQuery(dbSession, request, component);
CeTaskQuery query = buildQuery(dbSession, request, entity);

return buildPaginatedResponse(dbSession, query, parseInt(request.getP()), parseInt(request.getPs()));
}
@@ -230,26 +231,26 @@ public class ActivityAction implements CeWsAction {
}

@CheckForNull
private ComponentDto loadComponent(DbSession dbSession, Request request) {
private EntityDto loadEntity(DbSession dbSession, Request request) {
String componentKey = request.getComponent();

if (componentKey != null) {
Optional<ComponentDto> foundComponent;
foundComponent = dbClient.componentDao().selectByKey(dbSession, componentKey);
Optional<EntityDto> foundComponent;
foundComponent = dbClient.entityDao().selectByKey(dbSession, componentKey);
return checkFoundWithOptional(foundComponent, "Component '%s' does not exist", componentKey);
} else {
return null;
}
}

private void checkPermission(@Nullable ComponentDto component) {
private void checkPermission(@Nullable EntityDto entity) {
// fail fast if not logged in
userSession.checkLoggedIn();

if (component == null) {
if (entity == null) {
userSession.checkIsSystemAdministrator();
} else {
userSession.checkComponentPermission(UserRole.ADMIN, component);
userSession.checkEntityPermission(UserRole.ADMIN, entity);
}
}

@@ -268,7 +269,7 @@ public class ActivityAction implements CeWsAction {
return activity.map(ceActivityDto -> formatter.formatActivity(dbSession, ceActivityDto, null));
}

private CeTaskQuery buildQuery(DbSession dbSession, Request request, @Nullable ComponentDto component) {
private CeTaskQuery buildQuery(DbSession dbSession, Request request, @Nullable EntityDto entity) {
CeTaskQuery query = new CeTaskQuery();
query.setType(request.getType());
query.setOnlyCurrents(parseBoolean(request.getOnlyCurrents()));
@@ -283,8 +284,8 @@ public class ActivityAction implements CeWsAction {
}

String componentQuery = request.getQ();
if (component != null) {
query.setMainComponentUuid(component.uuid());
if (entity != null) {
query.setMainComponentUuid(entity.getUuid());
} else if (componentQuery != null) {
query.setMainComponentUuids(loadComponents(dbSession, componentQuery).stream()
.map(ComponentDto::uuid)

+ 10
- 9
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/ActivityStatusAction.java View File

@@ -32,6 +32,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
import org.sonar.server.ws.KeyExamples;
@@ -83,8 +84,8 @@ public class ActivityStatusAction implements CeWsAction {

private ActivityStatusWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<ComponentDto> component = searchComponent(dbSession, request);
String componentUuid = component.map(ComponentDto::uuid).orElse(null);
Optional<EntityDto> component = searchComponent(dbSession, request);
String componentUuid = component.map(EntityDto::getUuid).orElse(null);
checkPermissions(component.orElse(null));
int pendingCount = dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, CeQueueDto.Status.PENDING, componentUuid);
int inProgressCount = dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, CeQueueDto.Status.IN_PROGRESS, componentUuid);
@@ -106,17 +107,17 @@ public class ActivityStatusAction implements CeWsAction {
}
}

private Optional<ComponentDto> searchComponent(DbSession dbSession, Request request) {
ComponentDto component = null;
private Optional<EntityDto> searchComponent(DbSession dbSession, Request request) {
EntityDto entity = null;
if (request.getComponentKey() != null) {
component = componentFinder.getByKey(dbSession, request.getComponentKey());
entity = componentFinder.getEntityByKey(dbSession, request.getComponentKey());
}
return Optional.ofNullable(component);
return Optional.ofNullable(entity);
}

private void checkPermissions(@Nullable ComponentDto component) {
if (component != null) {
userSession.checkComponentPermission(UserRole.ADMIN, component);
private void checkPermissions(@Nullable EntityDto entity) {
if (entity != null) {
userSession.checkEntityPermission(UserRole.ADMIN, entity);
} else {
userSession.checkIsSystemAdministrator();
}

+ 3
- 4
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/ws/CancelAction.java View File

@@ -19,10 +19,7 @@
*/
package org.sonar.server.ce.ws;

import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;

import java.util.Optional;

import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -35,12 +32,14 @@ import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.server.user.UserSession;

import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;

public class CancelAction implements CeWsAction {

public static final String PARAM_TASK_ID = "id";

private final UserSession userSession;
private DbClient dbClient;
private final DbClient dbClient;
private final CeQueue queue;

public CancelAction(UserSession userSession, DbClient dbClient, CeQueue queue) {

+ 23
- 6
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java View File

@@ -32,6 +32,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.exceptions.NotFoundException;

@@ -45,6 +46,7 @@ public class ComponentFinder {
private static final String LABEL_PROJECT = "Project";
private static final String LABEL_COMPONENT = "Component";
private static final String LABEL_PROJECT_NOT_FOUND = "Project '%s' not found";
private static final String LABEL_ENTITY_NOT_FOUND = "Component '%s' not found";

private final DbClient dbClient;
private final ResourceTypes resourceTypes;
@@ -64,6 +66,25 @@ public class ComponentFinder {
return getByKey(dbSession, checkParamNotEmpty(componentKey, parameterNames.getKeyParam()));
}

public EntityDto getEntityByUuidOrKey(DbSession dbSession, @Nullable String entityUuid, @Nullable String entityKey, ParamNames parameterNames) {
checkByUuidOrKey(entityUuid, entityKey, parameterNames);

if (entityUuid != null) {
return getEntityByUuid(dbSession, checkParamNotEmpty(entityUuid, parameterNames.getUuidParam()));
}
return getEntityByKey(dbSession, checkParamNotEmpty(entityKey, parameterNames.getKeyParam()));
}

public EntityDto getEntityByKey(DbSession dbSession, String entityKey) {
return dbClient.entityDao().selectByKey(dbSession, entityKey)
.orElseThrow(() -> new NotFoundException(String.format(LABEL_ENTITY_NOT_FOUND, entityKey)));
}

public EntityDto getEntityByUuid(DbSession dbSession, String entityUuid) {
return dbClient.entityDao().selectByUuid(dbSession, entityUuid)
.orElseThrow(() -> new NotFoundException(String.format(LABEL_ENTITY_NOT_FOUND, entityUuid)));
}

public ProjectDto getProjectByKey(DbSession dbSession, String projectKey) {
return dbClient.projectDao().selectProjectByKey(dbSession, projectKey)
.orElseThrow(() -> new NotFoundException(String.format(LABEL_PROJECT_NOT_FOUND, projectKey)));
@@ -105,12 +126,8 @@ public class ComponentFinder {
.orElseThrow(() -> new NotFoundException(String.format("Branch uuid '%s' not found", branchUuid)));
}

public BranchDto getBranchOrPullRequest(DbSession dbSession, ComponentDto project, @Nullable String branchKey, @Nullable String pullRequestKey) {
return getBranchOrPullRequest(dbSession, project.uuid(), project.getKey(), branchKey, pullRequestKey);
}

public BranchDto getBranchOrPullRequest(DbSession dbSession, ProjectDto project, @Nullable String branchKey, @Nullable String pullRequestKey) {
return getBranchOrPullRequest(dbSession, project.getUuid(), project.getKey(), branchKey, pullRequestKey);
public BranchDto getBranchOrPullRequest(DbSession dbSession, EntityDto entity, @Nullable String branchKey, @Nullable String pullRequestKey) {
return getBranchOrPullRequest(dbSession, entity.getUuid(), entity.getKey(), branchKey, pullRequestKey);
}

public ProjectAndBranch getAppOrProjectAndBranch(DbSession dbSession, String projectKey, @Nullable String branchKey, @Nullable String pullRequestKey) {

+ 4
- 4
server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/SearchAction.java View File

@@ -124,12 +124,12 @@ public class SearchAction implements FavoritesWsAction {
.forEach(builder::addFavorites);
}

private static Favorite toWsFavorite(Favorite.Builder builder, EntityDto componentDto) {
private static Favorite toWsFavorite(Favorite.Builder builder, EntityDto entity) {
builder
.clear()
.setKey(componentDto.getKey());
ofNullable(componentDto.getName()).ifPresent(builder::setName);
ofNullable(componentDto.getQualifier()).ifPresent(builder::setQualifier);
.setKey(entity.getKey());
ofNullable(entity.getName()).ifPresent(builder::setName);
ofNullable(entity.getQualifier()).ifPresent(builder::setQualifier);
return builder.build();
}


+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/AddCommentAction.java View File

@@ -80,7 +80,7 @@ public class AddCommentAction implements HotspotsWsAction {
String comment = request.mandatoryParam(PARAM_COMMENT);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto hotspot = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);
hotspotWsSupport.loadAndCheckProject(dbSession, hotspot, UserRole.USER);
hotspotWsSupport.loadAndCheckBranch(dbSession, hotspot, UserRole.USER);

DefaultIssue defaultIssue = hotspot.toDefaultIssue();
IssueChangeContext context = hotspotWsSupport.newIssueChangeContextWithoutMeasureRefresh();

+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/AssignAction.java View File

@@ -110,7 +110,7 @@ public class AssignAction implements HotspotsWsAction {
IssueDto hotspotDto = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);

checkHotspotStatusAndResolution(hotspotDto);
hotspotWsSupport.loadAndCheckProject(dbSession, hotspotDto, UserRole.USER);
hotspotWsSupport.loadAndCheckBranch(dbSession, hotspotDto, UserRole.USER);
UserDto assignee = isNullOrEmpty(login) ? null : getAssignee(dbSession, login);

IssueChangeContext context = hotspotWsSupport.newIssueChangeContextWithoutMeasureRefresh();

+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ChangeStatusAction.java View File

@@ -111,7 +111,7 @@ public class ChangeStatusAction implements HotspotsWsAction {
String newResolution = resolutionParam(request, newStatus);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto hotspot = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);
hotspotWsSupport.loadAndCheckProject(dbSession, hotspot, UserRole.SECURITYHOTSPOT_ADMIN);
hotspotWsSupport.loadAndCheckBranch(dbSession, hotspot, UserRole.SECURITYHOTSPOT_ADMIN);

if (needStatusUpdate(hotspot, newStatus, newResolution)) {
String transitionKey = toTransitionKey(newStatus, newResolution);

+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/DeleteCommentAction.java View File

@@ -83,7 +83,7 @@ public class DeleteCommentAction implements HotspotsWsAction {
}

private void validate(DbSession dbSession, IssueChangeDto issueChangeDto) {
hotspotWsSupport.loadAndCheckProject(dbSession, issueChangeDto.getIssueKey());
hotspotWsSupport.loadAndCheckBranch(dbSession, issueChangeDto.getIssueKey());
checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only delete your own comments");
}


+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/EditCommentAction.java View File

@@ -102,7 +102,7 @@ public class EditCommentAction implements HotspotsWsAction {
}

private void validate(DbSession dbSession, IssueChangeDto issueChangeDto) {
hotspotWsSupport.loadAndCheckProject(dbSession, issueChangeDto.getIssueKey());
hotspotWsSupport.loadAndCheckBranch(dbSession, issueChangeDto.getIssueKey());
checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only edit your own comments");
}


+ 13
- 9
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsSupport.java View File

@@ -27,8 +27,10 @@ import org.sonar.api.web.UserRole;
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;

@@ -51,9 +53,9 @@ public class HotspotWsSupport {
return userSession.checkLoggedIn().getUuid();
}

ComponentDto loadAndCheckProject(DbSession dbSession, String hotspotKey) {
BranchDto loadAndCheckBranch(DbSession dbSession, String hotspotKey) {
IssueDto hotspot = loadHotspot(dbSession, hotspotKey);
return loadAndCheckProject(dbSession, hotspot, UserRole.USER);
return loadAndCheckBranch(dbSession, hotspot, UserRole.USER);
}

IssueDto loadHotspot(DbSession dbSession, String hotspotKey) {
@@ -63,15 +65,17 @@ public class HotspotWsSupport {
.orElseThrow(() -> new NotFoundException(format("Hotspot '%s' does not exist", hotspotKey)));
}

ComponentDto loadAndCheckProject(DbSession dbSession, IssueDto hotspot, String userRole) {
String projectUuid = hotspot.getProjectUuid();
checkArgument(projectUuid != null, "Hotspot '%s' has no project", hotspot.getKee());
BranchDto loadAndCheckBranch(DbSession dbSession, IssueDto hotspot, String userRole) {
String branchUuid = hotspot.getProjectUuid();
checkArgument(branchUuid != null, "Hotspot '%s' has no branch", hotspot.getKee());

ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, projectUuid)
.orElseThrow(() -> new NotFoundException(format("Project with uuid '%s' does not exist", projectUuid)));
userSession.checkComponentPermission(userRole, project);
BranchDto branch = dbClient.branchDao().selectByUuid(dbSession, branchUuid)
.orElseThrow(() -> new NotFoundException(format("Branch with uuid '%s' does not exist", branchUuid)));
ProjectDto project = dbClient.projectDao().selectByUuid(dbSession, branch.getProjectUuid())
.orElseThrow(() -> new NotFoundException(format("Project with uuid '%s' does not exist", branch.getProjectUuid())));

return project;
userSession.checkEntityPermission(userRole, project);
return branch;
}

boolean canChangeStatus(ComponentDto project) {

+ 15
- 16
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java View File

@@ -177,9 +177,9 @@ public class ShowAction implements HotspotsWsAction {

private void formatComponents(Components components, ShowWsResponse.Builder responseBuilder) {
responseBuilder
.setProject(responseFormatter.formatComponent(Hotspots.Component.newBuilder(), components.getProject(), components.getBranch(), components.getPullRequest()))
.setProject(responseFormatter.formatComponent(Hotspots.Component.newBuilder(), components.getBranchComponent(), components.getBranch(), components.getPullRequest()))
.setComponent(responseFormatter.formatComponent(Hotspots.Component.newBuilder(), components.getComponent(), components.getBranch(), components.getPullRequest()));
responseBuilder.setCanChangeStatus(hotspotWsSupport.canChangeStatus(components.getProject()));
responseBuilder.setCanChangeStatus(hotspotWsSupport.canChangeStatus(components.getBranchComponent()));
}

private static void formatRule(ShowWsResponse.Builder responseBuilder, RuleDto ruleDto) {
@@ -266,7 +266,7 @@ public class ShowAction implements HotspotsWsAction {
.filter(Optional::isPresent)
.map(Optional::get)
.collect(toSet());
Set<ComponentDto> preloadedComponents = ImmutableSet.of(components.project, components.component);
Set<ComponentDto> preloadedComponents = ImmutableSet.of(components.branchComponent, components.component);
FormattingContext formattingContext = issueChangeSupport
.newFormattingContext(dbSession, singleton(hotspot), Load.ALL, preloadedUsers, preloadedComponents);

@@ -298,27 +298,26 @@ public class ShowAction implements HotspotsWsAction {

private Components loadComponents(DbSession dbSession, IssueDto hotspot) {
String componentUuid = hotspot.getComponentUuid();

ComponentDto project = hotspotWsSupport.loadAndCheckProject(dbSession, hotspot, UserRole.USER);
BranchDto branch = dbClient.branchDao().selectByUuid(dbSession, project.branchUuid()).orElseThrow(() -> new IllegalStateException("Can't find branch " + project.branchUuid()));

checkArgument(componentUuid != null, "Hotspot '%s' has no component", hotspot.getKee());
boolean hotspotOnProject = Objects.equals(project.uuid(), componentUuid);
ComponentDto component = hotspotOnProject ? project
: dbClient.componentDao().selectByUuid(dbSession, componentUuid)

BranchDto branch = hotspotWsSupport.loadAndCheckBranch(dbSession, hotspot, UserRole.USER);
ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, componentUuid)
.orElseThrow(() -> new NotFoundException(format("Component with uuid '%s' does not exist", componentUuid)));
boolean hotspotOnBranch = Objects.equals(branch.getUuid(), componentUuid);
ComponentDto branchComponent = hotspotOnBranch ? component : dbClient.componentDao().selectByUuid(dbSession, branch.getUuid())
.orElseThrow(() -> new NotFoundException(format("Component with uuid '%s' does not exist", componentUuid)));

return new Components(project, component, branch);
return new Components(branchComponent, component, branch);
}

private static final class Components {
private final ComponentDto project;
private final ComponentDto branchComponent;
private final ComponentDto component;
private final String branch;
private final String pullRequest;

private Components(ComponentDto project, ComponentDto component, BranchDto branch) {
this.project = project;
private Components(ComponentDto branchComponent, ComponentDto component, BranchDto branch) {
this.branchComponent = branchComponent;
this.component = component;
if (branch.isMain()) {
this.branch = null;
@@ -342,8 +341,8 @@ public class ShowAction implements HotspotsWsAction {
return pullRequest;
}

public ComponentDto getProject() {
return project;
public ComponentDto getBranchComponent() {
return branchComponent;
}

public ComponentDto getComponent() {

+ 11
- 15
server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/AddAction.java View File

@@ -22,15 +22,13 @@ package org.sonar.server.notification.ws;
import java.util.List;
import java.util.Optional;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.issue.notification.MyNewIssuesNotificationHandler;
@@ -40,13 +38,13 @@ import org.sonar.server.ws.KeyExamples;

import static java.util.Optional.empty;
import static java.util.Optional.ofNullable;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;
import static org.sonar.server.exceptions.NotFoundException.checkFound;
import static org.sonar.server.notification.ws.NotificationsWsParameters.ACTION_ADD;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_CHANNEL;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_LOGIN;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_PROJECT;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_TYPE;
import static org.sonar.server.exceptions.NotFoundException.checkFound;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;

public class AddAction implements NotificationsWsAction {
private final NotificationCenter notificationCenter;
@@ -91,10 +89,10 @@ public class AddAction implements NotificationsWsAction {

action.createParam(PARAM_TYPE)
.setDescription("Notification type. Possible values are for:" +
"<ul>" +
" <li>Global notifications: %s</li>" +
" <li>Per project notifications: %s</li>" +
"</ul>",
"<ul>" +
" <li>Global notifications: %s</li>" +
" <li>Per project notifications: %s</li>" +
"</ul>",
String.join(", ", dispatchers.getGlobalDispatchers()),
String.join(", ", dispatchers.getProjectDispatchers()))
.setRequired(true)
@@ -117,7 +115,7 @@ public class AddAction implements NotificationsWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
checkPermissions(request);
UserDto user = getUser(dbSession, request);
Optional<ComponentDto> project = searchProject(dbSession, request);
Optional<ProjectDto> project = searchProject(dbSession, request);
notificationUpdater.add(dbSession, request.getChannel(), request.getType(), user, project.orElse(null));
dbSession.commit();
}
@@ -128,11 +126,9 @@ public class AddAction implements NotificationsWsAction {
return checkFound(dbClient.userDao().selectByLogin(dbSession, login), "User '%s' not found", login);
}

private Optional<ComponentDto> searchProject(DbSession dbSession, AddRequest request) {
Optional<ComponentDto> project = request.getProject() == null ? empty() : Optional.of(componentFinder.getByKey(dbSession, request.getProject()));
project.ifPresent(p -> checkRequest(Qualifiers.PROJECT.equals(p.qualifier()) && Scopes.PROJECT.equals(p.scope()),
"Component '%s' must be a project", request.getProject()));
project.ifPresent(p -> userSession.checkComponentPermission(UserRole.USER, p));
private Optional<ProjectDto> searchProject(DbSession dbSession, AddRequest request) {
Optional<ProjectDto> project = request.getProject() == null ? empty() : Optional.of(componentFinder.getProjectByKey(dbSession, request.getProject()));
project.ifPresent(p -> userSession.checkEntityPermission(UserRole.USER, p));
return project;
}


+ 14
- 14
server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/ListAction.java View File

@@ -37,6 +37,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
import org.sonar.db.user.UserDto;
@@ -120,10 +121,10 @@ public class ListAction implements NotificationsWsAction {
private UnaryOperator<ListResponse.Builder> addNotifications(DbSession dbSession, UserDto user) {
return response -> {
List<PropertyDto> properties = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserUuid(user.getUuid()).build(), dbSession);
Map<String, ComponentDto> componentsByUuid = searchProjects(dbSession, properties);
Map<String, EntityDto> entitiesByUuid = searchProjects(dbSession, properties);

Predicate<PropertyDto> isNotification = prop -> prop.getKey().startsWith("notification.");
Predicate<PropertyDto> isComponentInDb = prop -> prop.getEntityUuid() == null || componentsByUuid.containsKey(prop.getEntityUuid());
Predicate<PropertyDto> isComponentInDb = prop -> prop.getEntityUuid() == null || entitiesByUuid.containsKey(prop.getEntityUuid());

Notification.Builder notification = Notification.newBuilder();

@@ -131,7 +132,7 @@ public class ListAction implements NotificationsWsAction {
.filter(isNotification)
.filter(channelAndDispatcherAuthorized())
.filter(isComponentInDb)
.map(toWsNotification(notification, componentsByUuid))
.map(toWsNotification(notification, entitiesByUuid))
.sorted(comparing(Notification::getProject, nullsFirst(naturalOrder()))
.thenComparing(Notification::getChannel)
.thenComparing(Notification::getType))
@@ -154,19 +155,19 @@ public class ListAction implements NotificationsWsAction {
return (prop.getEntityUuid() != null && dispatchers.getProjectDispatchers().contains(dispatcher)) || dispatchers.getGlobalDispatchers().contains(dispatcher);
}

private Map<String, ComponentDto> searchProjects(DbSession dbSession, List<PropertyDto> properties) {
Set<String> componentUuids = properties.stream()
private Map<String, EntityDto> searchProjects(DbSession dbSession, List<PropertyDto> properties) {
Set<String> entityUuids = properties.stream()
.map(PropertyDto::getEntityUuid)
.filter(Objects::nonNull)
.collect(MoreCollectors.toSet(properties.size()));
Set<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedEntityUuids(dbSession, componentUuids, userSession.getUuid(), UserRole.USER);
return dbClient.componentDao().selectByUuids(dbSession, componentUuids)
Set<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedEntityUuids(dbSession, entityUuids, userSession.getUuid(), UserRole.USER);
return dbClient.entityDao().selectByUuids(dbSession, entityUuids)
.stream()
.filter(c -> authorizedProjectUuids.contains(c.uuid()))
.collect(MoreCollectors.uniqueIndex(ComponentDto::uuid));
.filter(c -> authorizedProjectUuids.contains(c.getUuid()))
.collect(MoreCollectors.uniqueIndex(EntityDto::getUuid));
}

private static Function<PropertyDto, Notification> toWsNotification(Notification.Builder notification, Map<String, ComponentDto> projectsByUuid) {
private static Function<PropertyDto, Notification> toWsNotification(Notification.Builder notification, Map<String, EntityDto> projectsByUuid) {
return property -> {
notification.clear();
List<String> propertyKey = Splitter.on(".").splitToList(property.getKey());
@@ -178,12 +179,11 @@ public class ListAction implements NotificationsWsAction {
};
}

private static void populateProjectFields(Builder notification, String componentUuid,
Map<String, ComponentDto> projectsByUuid) {
ComponentDto project = projectsByUuid.get(componentUuid);
private static void populateProjectFields(Builder notification, String componentUuid, Map<String, EntityDto> projectsByUuid) {
EntityDto project = projectsByUuid.get(componentUuid);
notification
.setProject(project.getKey())
.setProjectName(project.name());
.setProjectName(project.getName());
}

private void checkPermissions(Request request) {

+ 26
- 26
server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java View File

@@ -25,7 +25,7 @@ import javax.annotation.Nullable;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
import org.sonar.db.user.UserDto;
@@ -45,50 +45,50 @@ public class NotificationUpdater {
/**
* Add a notification to a user.
*/
public void add(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) {
public void add(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable EntityDto project) {
String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel);
String projectUuid = project == null ? null : project.uuid();
String projectUuid = project == null ? null : project.getUuid();
String projectKey = project == null ? null : project.getKey();
String projectName = project == null ? null : project.name();
String qualifier = project == null ? null : project.qualifier();
String projectName = project == null ? null : project.getName();
String qualifier = project == null ? null : project.getQualifier();

List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery(
PropertyQuery.builder()
.setKey(key)
.setEntityUuid(projectUuid)
.setUserUuid(user.getUuid())
.build(),
dbSession).stream()
PropertyQuery.builder()
.setKey(key)
.setEntityUuid(projectUuid)
.setUserUuid(user.getUuid())
.build(),
dbSession).stream()
.filter(notificationScope(project))
.collect(MoreCollectors.toList());
checkArgument(existingNotification.isEmpty()
|| !PROP_NOTIFICATION_VALUE.equals(existingNotification.get(0).getValue()), "Notification already added");

dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
.setKey(key)
.setUserUuid(user.getUuid())
.setValue(PROP_NOTIFICATION_VALUE)
.setEntityUuid(projectUuid),
.setKey(key)
.setUserUuid(user.getUuid())
.setValue(PROP_NOTIFICATION_VALUE)
.setEntityUuid(projectUuid),
user.getLogin(), projectKey, projectName, qualifier);
}

/**
* Remove a notification from a user.
*/
public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) {
public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable EntityDto project) {
String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel);
String projectUuid = project == null ? null : project.uuid();
String projectUuid = project == null ? null : project.getUuid();
String projectKey = project == null ? null : project.getKey();
String projectName = project == null ? null : project.name();
String qualifier = project == null ? null : project.qualifier();
String projectName = project == null ? null : project.getName();
String qualifier = project == null ? null : project.getQualifier();

List<PropertyDto> existingNotification = dbClient.propertiesDao().selectByQuery(
PropertyQuery.builder()
.setKey(key)
.setEntityUuid(projectUuid)
.setUserUuid(user.getUuid())
.build(),
dbSession).stream()
PropertyQuery.builder()
.setKey(key)
.setEntityUuid(projectUuid)
.setUserUuid(user.getUuid())
.build(),
dbSession).stream()
.filter(notificationScope(project))
.collect(MoreCollectors.toList());
checkArgument(!existingNotification.isEmpty() && PROP_NOTIFICATION_VALUE.equals(existingNotification.get(0).getValue()), "Notification doesn't exist");
@@ -100,7 +100,7 @@ public class NotificationUpdater {
.setEntityUuid(projectUuid), user.getLogin(), projectKey, projectName, qualifier);
}

private static Predicate<PropertyDto> notificationScope(@Nullable ComponentDto project) {
private static Predicate<PropertyDto> notificationScope(@Nullable EntityDto project) {
return prop -> project == null ? (prop.getEntityUuid() == null) : (prop.getEntityUuid() != null);
}
}

+ 10
- 15
server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/RemoveAction.java View File

@@ -23,14 +23,12 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.issue.notification.MyNewIssuesNotificationHandler;
@@ -40,13 +38,13 @@ import org.sonar.server.ws.KeyExamples;

import static java.util.Optional.empty;
import static java.util.Optional.ofNullable;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;
import static org.sonar.server.exceptions.NotFoundException.checkFound;
import static org.sonar.server.notification.ws.NotificationsWsParameters.ACTION_REMOVE;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_CHANNEL;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_LOGIN;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_PROJECT;
import static org.sonar.server.notification.ws.NotificationsWsParameters.PARAM_TYPE;
import static org.sonar.server.exceptions.NotFoundException.checkFound;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;

public class RemoveAction implements NotificationsWsAction {
private final NotificationCenter notificationCenter;
@@ -91,10 +89,10 @@ public class RemoveAction implements NotificationsWsAction {

action.createParam(PARAM_TYPE)
.setDescription("Notification type. Possible values are for:" +
"<ul>" +
" <li>Global notifications: %s</li>" +
" <li>Per project notifications: %s</li>" +
"</ul>",
"<ul>" +
" <li>Global notifications: %s</li>" +
" <li>Per project notifications: %s</li>" +
"</ul>",
dispatchers.getGlobalDispatchers().stream().sorted().collect(Collectors.joining(", ")),
dispatchers.getProjectDispatchers().stream().sorted().collect(Collectors.joining(", ")))
.setRequired(true)
@@ -117,7 +115,7 @@ public class RemoveAction implements NotificationsWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
checkPermissions(request);
UserDto user = getUser(dbSession, request);
Optional<ComponentDto> project = searchProject(dbSession, request);
Optional<ProjectDto> project = searchProject(dbSession, request);
notificationUpdater.remove(dbSession, request.getChannel(), request.getType(), user, project.orElse(null));
dbSession.commit();
}
@@ -128,11 +126,8 @@ public class RemoveAction implements NotificationsWsAction {
return checkFound(dbClient.userDao().selectByLogin(dbSession, login), "User '%s' not found", login);
}

private Optional<ComponentDto> searchProject(DbSession dbSession, RemoveRequest request) {
Optional<ComponentDto> project = request.getProject() == null ? empty() : Optional.of(componentFinder.getByKey(dbSession, request.getProject()));
project.ifPresent(p -> checkRequest(Qualifiers.PROJECT.equals(p.qualifier()) && Scopes.PROJECT.equals(p.scope()),
"Component '%s' must be a project", request.getProject()));
return project;
private Optional<ProjectDto> searchProject(DbSession dbSession, RemoveRequest request) {
return request.getProject() == null ? empty() : Optional.of(componentFinder.getProjectByKey(dbSession, request.getProject()));
}

private void checkPermissions(RemoveRequest request) {

+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java View File

@@ -81,7 +81,7 @@ public class PermissionWsSupport {
return Optional.empty();
}

public ComponentDto getRootComponentOrModule(DbSession dbSession, ProjectWsRef projectRef) {
public ComponentDto getRootComponent(DbSession dbSession, ProjectWsRef projectRef) {
return componentFinder.getRootComponentByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key());
}


+ 1
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java View File

@@ -92,7 +92,7 @@ public class ApplyTemplateAction implements PermissionsWsAction {
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(
request.getTemplateId(), request.getTemplateName()));

ComponentDto project = wsSupport.getRootComponentOrModule(dbSession, newWsProjectRef(request.getProjectId(), request.getProjectKey()));
ComponentDto project = wsSupport.getRootComponent(dbSession, newWsProjectRef(request.getProjectId(), request.getProjectKey()));
checkGlobalAdmin(userSession);

permissionTemplateService.applyAndCommit(dbSession, template, Collections.singletonList(project));

+ 3
- 3
server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectdump/ws/ProjectDumpWsSupport.java View File

@@ -23,7 +23,7 @@ import org.sonar.api.server.ServerSide;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;

@@ -42,8 +42,8 @@ public class ProjectDumpWsSupport {

public void verifyAdminOfProjectByKey(String projectKey) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = componentFinder.getByKey(dbSession, projectKey);
userSession.checkComponentPermission(UserRole.ADMIN, project);
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
userSession.checkEntityPermission(UserRole.ADMIN, project);
}
}
}

+ 9
- 6
server/sonar-webserver-webapi/src/main/java/org/sonar/server/scannercache/ws/GetAction.java View File

@@ -32,7 +32,9 @@ import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbInputStream;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.scannercache.ScannerCache;
@@ -85,10 +87,11 @@ public class GetAction implements AnalysisCacheWsAction {
String branchKey = request.param(BRANCH);

try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, projectKey, branchKey, null);
checkPermission(component);
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
checkPermission(project);
BranchDto branchDto = componentFinder.getBranchOrPullRequest(dbSession, project, branchKey, null);

try (DbInputStream dbInputStream = cache.get(component.uuid())) {
try (DbInputStream dbInputStream = cache.get(branchDto.getUuid())) {
if (dbInputStream == null) {
throw new NotFoundException("No cache for given branch or pull request");
}
@@ -117,9 +120,9 @@ public class GetAction implements AnalysisCacheWsAction {
.orElse(false);
}

private void checkPermission(ComponentDto project) {
if (userSession.hasComponentPermission(UserRole.SCAN, project) ||
userSession.hasComponentPermission(UserRole.ADMIN, project) ||
private void checkPermission(ProjectDto project) {
if (userSession.hasEntityPermission(UserRole.SCAN, project) ||
userSession.hasEntityPermission(UserRole.ADMIN, project) ||
userSession.hasPermission(SCAN)) {
return;
}

+ 4
- 4
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java View File

@@ -88,14 +88,14 @@ public class SettingValidations {
}

private static boolean checkComponentQualifier(SettingData data, @Nullable PropertyDefinition definition) {
EntityDto component = data.entity;
if (component == null) {
EntityDto entity = data.entity;
if (entity == null) {
return true;
}
if (definition == null) {
return SUPPORTED_QUALIFIERS.contains(component.getQualifier());
return SUPPORTED_QUALIFIERS.contains(entity.getQualifier());
}
return definition.qualifiers().contains(component.getQualifier());
return definition.qualifiers().contains(entity.getQualifier());
}

public Consumer<SettingData> valueType() {

+ 4
- 4
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java View File

@@ -144,15 +144,15 @@ public class ValuesAction implements SettingsWsAction {
return Optional.empty();
}

EntityDto component = dbClient.entityDao().selectByKey(dbSession, componentKey)
EntityDto entity = dbClient.entityDao().selectByKey(dbSession, componentKey)
.orElseThrow(() -> new NotFoundException(format("Component key '%s' not found", componentKey)));

if (!userSession.hasEntityPermission(USER, component) &&
!userSession.hasEntityPermission(UserRole.SCAN, component) &&
if (!userSession.hasEntityPermission(USER, entity) &&
!userSession.hasEntityPermission(UserRole.SCAN, entity) &&
!userSession.hasPermission(GlobalPermission.SCAN)) {
throw insufficientPrivilegesException();
}
return Optional.of(component);
return Optional.of(entity);
}

private List<Setting> loadSettings(DbSession dbSession, Optional<EntityDto> component, Set<String> keys) {

Loading…
Cancel
Save