aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-08-17 14:35:44 -0500
committersonartech <sonartech@sonarsource.com>2021-08-26 20:04:29 +0000
commit79b13ac2a166eea535deceade405e8b99b098c64 (patch)
tree0e979a6eebb7119d74b780a38dc387af5325ffe3 /server/sonar-webserver-webapi/src
parent680aed78d5a58249ae56ca36b5f495bb579bce1a (diff)
downloadsonarqube-79b13ac2a166eea535deceade405e8b99b098c64.tar.gz
sonarqube-79b13ac2a166eea535deceade405e8b99b098c64.zip
SONAR-15142 Always add AuditPersister to container and use typed NewValue for each audit
Diffstat (limited to 'server/sonar-webserver-webapi/src')
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/GenerateSecretKeyAction.java16
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java2
5 files changed, 10 insertions, 20 deletions
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 12dad7b7e1a..7011f0ad668 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
@@ -26,8 +26,6 @@ import org.sonar.api.resources.Qualifiers;
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.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
import org.sonar.core.util.UuidFactory;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
@@ -135,8 +133,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
private void setPrivateForRootComponentUuid(DbSession dbSession, ComponentDto component, boolean isPrivate) {
String uuid = component.uuid();
- dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.getKey(),
- component.qualifier(), component.name(), true);
+ dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.getKey(), component.qualifier(), component.name());
if (component.qualifier().equals(Qualifiers.PROJECT) || component.qualifier().equals(Qualifiers.APP)) {
dbClient.projectDao().updateVisibility(dbSession, uuid, isPrivate);
@@ -165,7 +162,6 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
});
}
-
private void insertProjectPermissionOnUser(DbSession dbSession, ComponentDto component, String permission, UserId userId) {
dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), permission, userId.getUuid(), component.uuid()),
component, userId, null);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/GenerateSecretKeyAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/GenerateSecretKeyAction.java
index 9bd81ab4219..2b56d343548 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/GenerateSecretKeyAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/GenerateSecretKeyAction.java
@@ -35,13 +35,7 @@ public class GenerateSecretKeyAction implements SettingsWsAction {
private final DbClient dbClient;
private final Settings settings;
private final UserSession userSession;
- private AuditPersister auditPersister;
-
- public GenerateSecretKeyAction(DbClient dbClient, Settings settings, UserSession userSession) {
- this.dbClient = dbClient;
- this.settings = settings;
- this.userSession = userSession;
- }
+ private final AuditPersister auditPersister;
public GenerateSecretKeyAction(DbClient dbClient, Settings settings, UserSession userSession, AuditPersister auditPersister) {
this.dbClient = dbClient;
@@ -67,11 +61,9 @@ public class GenerateSecretKeyAction implements SettingsWsAction {
writeProtobuf(GenerateSecretKeyWsResponse.newBuilder().setSecretKey(settings.getEncryption().generateRandomSecretKey()).build(), request, response);
- if (auditPersister != null) {
- try (DbSession dbSession = dbClient.openSession(false)) {
- auditPersister.generateSecretKey(dbSession);
- dbSession.commit();
- }
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ auditPersister.generateSecretKey(dbSession);
+ dbSession.commit();
}
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java
index 4f41d85c399..fdcd9597c1a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java
@@ -33,6 +33,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsActionTester;
@@ -53,7 +54,7 @@ public class GenerateSecretKeyActionTest {
private DbClient dbClient = db.getDbClient();
private MapSettings settings = new MapSettings();
private Encryption encryption = settings.getEncryption();
- private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(dbClient, settings, userSession);
+ private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(dbClient, settings, userSession, new NoOpAuditPersister());
private WsActionTester ws = new WsActionTester(underTest);
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
index 09dc785b3f2..2cbec0cee39 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
@@ -28,6 +28,7 @@ import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDao;
@@ -62,7 +63,7 @@ public class LinesActionTest {
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private final ComponentDao componentDao = new ComponentDao();
+ private final ComponentDao componentDao = new ComponentDao(new NoOpAuditPersister());
private final SnapshotDao snapshotDao = new SnapshotDao();
private final HtmlSourceDecorator htmlSourceDecorator = mock(HtmlSourceDecorator.class);
private final SourceService sourceService = new SourceService(db.getDbClient(), htmlSourceDecorator);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java
index 861523e4e21..98da7f5ea21 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java
@@ -100,7 +100,7 @@ public class SearchActionTest {
UserDto user = db.users().insertUser();
UserTokenDto token1 = db.users().insertToken(user);
UserTokenDto token2 = db.users().insertToken(user);
- db.getDbClient().userTokenDao().update(db.getSession(), token1.setLastConnectionDate(10_000_000_000L), false, user.getLogin());
+ db.getDbClient().userTokenDao().updateWithoutAudit(db.getSession(), token1.setLastConnectionDate(10_000_000_000L));
db.commit();
logInAsSystemAdministrator();