aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-08-16 15:44:41 -0500
committersonartech <sonartech@sonarsource.com>2021-08-19 20:08:15 +0000
commitce94c8112cf4ae300ca17ca1efbc5b00202278fa (patch)
tree8b1e71ddad508b74a09bdc0a904c9cae3a77f401 /server/sonar-db-dao
parent458500e874b13093493165e6fbc736f46b2d7db5 (diff)
downloadsonarqube-ce94c8112cf4ae300ca17ca1efbc5b00202278fa.tar.gz
sonarqube-ce94c8112cf4ae300ca17ca1efbc5b00202278fa.zip
SONAR-15142 Set a permission template default for Projects / Applications / Portfolios is not tracked
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java59
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java6
6 files changed, 33 insertions, 52 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java
index ca0fec0c2dd..bad70117882 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java
@@ -61,7 +61,7 @@ public class GroupPermissionNewValue extends PermissionNewValue {
public String toString() {
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"permissionUuid\": ", this.permissionUuid, true);
- addField(sb, "\"role\": ", this.role, true);
+ addField(sb, "\"permission\": ", this.permission, true);
addField(sb, "\"groupUuid\": ", this.groupUuid, true);
addField(sb, "\"groupName\": ", this.groupName, true);
addField(sb, "\"componentUuid\": ", this.componentUuid, true);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java
index ff8f4dd95eb..62bd6e87bb1 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.java
@@ -26,7 +26,7 @@ import org.sonar.db.user.UserDto;
public class UserNewValue extends NewValue {
private String userUuid;
- private String login;
+ private String userLogin;
@Nullable
private String name;
@@ -63,12 +63,12 @@ public class UserNewValue extends NewValue {
public UserNewValue(String userUuid, String userLogin) {
this.userUuid = userUuid;
- this.login = userLogin;
+ this.userLogin = userLogin;
}
public UserNewValue(UserDto userDto) {
this.userUuid = userDto.getUuid();
- this.login = userDto.getLogin();
+ this.userLogin = userDto.getLogin();
this.name = userDto.getName();
this.email = userDto.getEmail();
this.isActive = userDto.isActive();
@@ -86,8 +86,8 @@ public class UserNewValue extends NewValue {
return this.userUuid;
}
- public String getLogin() {
- return this.login;
+ public String getUserLogin() {
+ return this.userLogin;
}
@CheckForNull
@@ -149,7 +149,7 @@ public class UserNewValue extends NewValue {
public String toString() {
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"userUuid\": ", this.userUuid, true);
- addField(sb, "\"userLogin\": ", this.login, true);
+ addField(sb, "\"userLogin\": ", this.userLogin, true);
addField(sb, "\"name\": ", this.name, true);
addField(sb, "\"email\": ", this.email, true);
addField(sb, "\"isActive\": ", ObjectUtils.toString(this.isActive), false);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java
index bcc93c41473..6a42acd4957 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java
@@ -60,7 +60,7 @@ public class UserPermissionNewValue extends PermissionNewValue {
public String toString() {
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"permissionUuid\": ", this.permissionUuid, true);
- addField(sb, "\"role\": ", this.role, true);
+ addField(sb, "\"permission\": ", this.permission, true);
addField(sb, "\"componentUuid\": ", this.componentUuid, true);
addField(sb, "\"componentName\": ", this.componentName, true);
addField(sb, "\"userUuid\": ", this.userUuid, true);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java
index a50e9b10b16..63d0a755617 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java
@@ -51,7 +51,7 @@ public class GroupPermissionDaoWithPersisterTest {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
- public final SequenceUuidFactory uuidFactory = new SequenceUuidFactory();
+ private final SequenceUuidFactory uuidFactory = new SequenceUuidFactory();
private final ArgumentCaptor<GroupPermissionNewValue> newValueCaptor = ArgumentCaptor.forClass(GroupPermissionNewValue.class);
private final DbSession dbSession = db.getSession();
private final GroupPermissionDao underTest = db.getDbClient().groupPermissionDao();
@@ -172,7 +172,7 @@ public class GroupPermissionDaoWithPersisterTest {
private void assertNewValue(GroupPermissionNewValue newValue, String uuid, String groupUuid, String groupName, String cUuid, String permission, String cName, String qualifier) {
assertThat(newValue)
- .extracting("permissionUuid", "groupUuid", "groupName", "componentUuid", "role", "componentName", "qualifier")
+ .extracting("permissionUuid", "groupUuid", "groupName", "componentUuid", "permission", "componentName", "qualifier")
.containsExactly(uuid, groupUuid, groupName, cUuid, permission, cName, qualifier);
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java
index b423bf01e2b..7be718c1c12 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java
@@ -59,20 +59,14 @@ public class UserPermissionDaoWithPersisterTest {
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin,
- UserPermissionNewValue::getComponentUuid, UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
- .containsExactly(dto.getUuid(), user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null);
+ assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null);
assertThat(newValue.toString()).doesNotContain("projectUuid");
underTest.deleteGlobalPermission(dbSession, user, SYSTEM_ADMIN);
verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName)
- .containsExactly(null, user.getUuid(), user.getLogin(), null, dto.getPermission(), null);
+ assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null);
assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
@@ -95,22 +89,15 @@ public class UserPermissionDaoWithPersisterTest {
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
- .containsExactly(dto.getUuid(), user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name(), "project");
+ assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name(), "project");
assertThat(newValue.toString()).contains("componentUuid");
underTest.deleteProjectPermission(dbSession, user, SYSTEM_ADMIN, project);
verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin,
- UserPermissionNewValue::getComponentUuid, UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName)
- .containsExactly(null, user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name());
- assertThat(newValue.toString())
- .doesNotContain("permissionUuid");
+ assertNewValue(newValue, null, user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name(), "project");
+ assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
@Test
@@ -134,12 +121,8 @@ public class UserPermissionDaoWithPersisterTest {
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
- .containsExactly(dto.getUuid(), user.getUuid(), portfolio.uuid(), dto.getPermission(), portfolio.name(), "portfolio");
- assertThat(newValue.toString())
- .contains("componentUuid");
+ assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), portfolio.uuid(), dto.getPermission(), portfolio.name(), "portfolio");
+ assertThat(newValue.toString()).contains("componentUuid");
}
@Test
@@ -151,12 +134,8 @@ public class UserPermissionDaoWithPersisterTest {
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
- .containsExactly(dto.getUuid(), user.getUuid(), application.uuid(), dto.getPermission(), application.name(), "application");
- assertThat(newValue.toString())
- .contains("componentUuid");
+ assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), application.uuid(), dto.getPermission(), application.name(), "application");
+ assertThat(newValue.toString()).contains("componentUuid");
}
@Test
@@ -169,10 +148,7 @@ public class UserPermissionDaoWithPersisterTest {
verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
- .containsExactly(null, null, null, project.uuid(), SCAN_EXECUTION, project.name(), "project");
+ assertNewValue(newValue, null, null, null, project.uuid(), dto.getPermission(), project.name(), "project");
assertThat(newValue.toString()).doesNotContain("userUuid");
}
@@ -196,10 +172,7 @@ public class UserPermissionDaoWithPersisterTest {
verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin, UserPermissionNewValue::getComponentUuid,
- UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
- .containsExactly(null, user.getUuid(), user.getLogin(), null, null, null, null);
+ assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, null, null, null);
assertThat(newValue.toString()).contains("userUuid");
}
@@ -213,7 +186,15 @@ public class UserPermissionDaoWithPersisterTest {
verifyNoMoreInteractions(auditPersister);
}
+ private void assertNewValue(UserPermissionNewValue newValue, String permissionUuid, String userUuid, String userLogin, String componentUuid, String permission,
+ String componentName, String qualifier) {
+ assertThat(newValue)
+ .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin,
+ UserPermissionNewValue::getComponentUuid, UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier)
+ .containsExactly(permissionUuid, userUuid, userLogin, componentUuid, permission, componentName, qualifier);
+ }
+
private UserDto insertUser(Consumer<UserDto> populateUserDto) {
- return db.users().insertUser(populateUserDto);
+ return db.users().insertUser(populateUserDto);
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java
index 695a3e49dad..c4db20ec07f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoWithPersisterTest.java
@@ -69,7 +69,7 @@ public class UserDaoWithPersisterTest {
verify(auditPersister).addUser(eq(db.getSession()), newValueCaptor.capture());
UserNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
- .extracting(UserNewValue::getUserUuid, UserNewValue::getLogin)
+ .extracting(UserNewValue::getUserUuid, UserNewValue::getUserLogin)
.containsExactly(user.getUuid(), user.getLogin());
assertThat(newValue.toString()).doesNotContain("name");
}
@@ -108,7 +108,7 @@ public class UserDaoWithPersisterTest {
verify(auditPersister).updateUser(eq(db.getSession()), newValueCaptor.capture());
UserNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
- .extracting(UserNewValue::getUserUuid, UserNewValue::getLogin, UserNewValue::getName, UserNewValue::getEmail, UserNewValue::isActive,
+ .extracting(UserNewValue::getUserUuid, UserNewValue::getUserLogin, UserNewValue::getName, UserNewValue::getEmail, UserNewValue::isActive,
UserNewValue::getScmAccounts, UserNewValue::getExternalId, UserNewValue::getExternalLogin, UserNewValue::getExternalIdentityProvider,
UserNewValue::isLocal, UserNewValue::isOnboarded, UserNewValue::isRoot, UserNewValue::getLastConnectionDate)
.containsExactly(updatedUser.getUuid(), updatedUser.getLogin(), updatedUser.getName(), updatedUser.getEmail(), updatedUser.isActive(),
@@ -148,7 +148,7 @@ public class UserDaoWithPersisterTest {
verify(auditPersister).deactivateUser(eq(db.getSession()), newValueCaptor.capture());
assertThat(newValueCaptor.getValue())
- .extracting(UserNewValue::getUserUuid, UserNewValue::getLogin)
+ .extracting(UserNewValue::getUserUuid, UserNewValue::getUserLogin)
.containsExactly(user.getUuid(), user.getLogin());
}