From 0cbc47585976e86e63753f74e285ef95b7e59657 Mon Sep 17 00:00:00 2001 From: Belen Pruvost Date: Tue, 17 Aug 2021 15:04:08 +0200 Subject: [PATCH] SONAR-15142 - Include template data on user/group permission inserts --- .../audit/model/GroupPermissionNewValue.java | 13 ++++--- .../db/audit/model/PermissionNewValue.java | 22 +++++++++++- .../audit/model/UserPermissionNewValue.java | 12 +++++-- .../db/permission/GroupPermissionDao.java | 6 ++-- .../db/permission/UserPermissionDao.java | 7 ++-- .../GroupPermissionDaoWithPersisterTest.java | 16 ++++----- .../db/permission/UserPermissionDaoTest.java | 4 +-- .../UserPermissionDaoWithPersisterTest.java | 34 +++++++++++++++---- .../java/org/sonar/db/user/UserDbTester.java | 12 +++---- .../index/PermissionIndexerDaoTest.java | 2 +- .../permission/GroupPermissionChanger.java | 2 +- .../permission/PermissionTemplateService.java | 26 +++++++------- .../permission/UserPermissionChanger.java | 2 +- .../project/ws/UpdateVisibilityAction.java | 5 +-- .../server/issue/ws/SearchActionTest.java | 2 +- .../GroupPermissionChangerTest.java | 2 +- .../permission/ws/RemoveGroupActionTest.java | 2 +- .../ws/UpdateVisibilityActionTest.java | 6 ++-- 18 files changed, 114 insertions(+), 61 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 bad70117882..4b6569f947d 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 @@ -21,6 +21,7 @@ package org.sonar.db.audit.model; import javax.annotation.Nullable; import org.sonar.db.permission.GroupPermissionDto; +import org.sonar.db.permission.template.PermissionTemplateDto; public class GroupPermissionNewValue extends PermissionNewValue { @@ -31,20 +32,20 @@ public class GroupPermissionNewValue extends PermissionNewValue { private String groupName; public GroupPermissionNewValue(String uuid, String rootComponentUuid, String componentName, String role, String groupUuid, - String groupName, String qualifier) { - super(uuid, rootComponentUuid, componentName, role, qualifier); + String groupName, String qualifier, @Nullable PermissionTemplateDto permissionTemplateDto) { + super(uuid, rootComponentUuid, componentName, role, qualifier, permissionTemplateDto); this.groupUuid = groupUuid; this.groupName = groupName; } public GroupPermissionNewValue(String rootComponentUuid, String componentName, String role, String groupUuid, String groupName, String qualifier) { - this(null, rootComponentUuid, componentName, role, groupUuid, groupName, qualifier); + this(null, rootComponentUuid, componentName, role, groupUuid, groupName, qualifier, null); } - public GroupPermissionNewValue(GroupPermissionDto dto, String qualifier) { + public GroupPermissionNewValue(GroupPermissionDto dto, String qualifier, @Nullable PermissionTemplateDto permissionTemplateDto) { this(dto.getUuid(), dto.getComponentUuid(), dto.getComponentName(), dto.getRole(), dto.getGroupUuid(), - dto.getGroupName(), qualifier); + dto.getGroupName(), qualifier, permissionTemplateDto); } @Nullable @@ -66,6 +67,8 @@ public class GroupPermissionNewValue extends PermissionNewValue { addField(sb, "\"groupName\": ", this.groupName, true); addField(sb, "\"componentUuid\": ", this.componentUuid, true); addField(sb, "\"componentName\": ", this.componentName, true); + addField(sb, "\"permissionTemplateUuid\": ", this.permissionTemplateId, true); + addField(sb, "\"permissionTemplateName\": ", this.permissionTemplateName, true); addField(sb, "\"qualifier\": ", this.qualifier, true); endString(sb); return sb.toString(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java index 8c1addd360a..fd3de2db3a5 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java @@ -21,6 +21,7 @@ package org.sonar.db.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.sonar.db.permission.template.PermissionTemplateDto; public abstract class PermissionNewValue extends NewValue { @Nullable @@ -38,13 +39,21 @@ public abstract class PermissionNewValue extends NewValue { @Nullable protected String qualifier; + @Nullable + protected String permissionTemplateId; + + @Nullable + protected String permissionTemplateName; + protected PermissionNewValue(@Nullable String permissionUuid, @Nullable String componentUuid, @Nullable String componentName, - @Nullable String permission, @Nullable String qualifier) { + @Nullable String permission, @Nullable String qualifier, @Nullable PermissionTemplateDto permissionTemplateDto) { this.permissionUuid = permissionUuid; this.componentUuid = componentUuid; this.componentName = componentName; this.qualifier = getQualifier(qualifier); this.permission = permission; + this.permissionTemplateId = permissionTemplateDto == null ? null : permissionTemplateDto.getUuid(); + this.permissionTemplateName = permissionTemplateDto == null ? null : permissionTemplateDto.getName(); } @CheckForNull @@ -71,4 +80,15 @@ public abstract class PermissionNewValue extends NewValue { public String getQualifier() { return this.qualifier; } + + @CheckForNull + public String getPermissionTemplateId() { + return this.permissionTemplateId; + } + + @CheckForNull + public String getPermissionTemplateName() { + return this.permissionTemplateName; + } + } 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 6a42acd4957..6e96398c983 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 @@ -21,17 +21,21 @@ package org.sonar.db.audit.model; import javax.annotation.Nullable; import org.sonar.db.permission.UserPermissionDto; +import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.db.user.UserId; public class UserPermissionNewValue extends PermissionNewValue { @Nullable private final String userUuid; + @Nullable private final String userLogin; - public UserPermissionNewValue(UserPermissionDto permissionDto, @Nullable String projectName, @Nullable UserId userId, String qualifier) { - super(permissionDto.getUuid(), permissionDto.getComponentUuid(), projectName, permissionDto.getPermission(), qualifier); + public UserPermissionNewValue(UserPermissionDto permissionDto, @Nullable String projectName, @Nullable UserId userId, + String qualifier, @Nullable PermissionTemplateDto templateDto) { + super(permissionDto.getUuid(), permissionDto.getComponentUuid(), projectName, permissionDto.getPermission(), + qualifier, templateDto); this.userUuid = userId != null ? userId.getUuid() : null; this.userLogin = userId != null ? userId.getLogin() : null; } @@ -41,7 +45,7 @@ public class UserPermissionNewValue extends PermissionNewValue { } public UserPermissionNewValue(String role, String projectUuid, String projectName, UserId userId, String qualifier) { - super(null, projectUuid, projectName, role, qualifier); + super(null, projectUuid, projectName, role, qualifier, null); this.userUuid = userId != null ? userId.getUuid() : null; this.userLogin = userId != null ? userId.getLogin() : null; } @@ -63,6 +67,8 @@ public class UserPermissionNewValue extends PermissionNewValue { addField(sb, "\"permission\": ", this.permission, true); addField(sb, "\"componentUuid\": ", this.componentUuid, true); addField(sb, "\"componentName\": ", this.componentName, true); + addField(sb, "\"permissionTemplateUuid\": ", this.permissionTemplateId, true); + addField(sb, "\"permissionTemplateName\": ", this.permissionTemplateName, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); addField(sb, "\"qualifier\": ", this.qualifier, true); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index 72a3a3a876e..a864531b9ff 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -32,6 +32,7 @@ import org.sonar.db.DbSession; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.GroupPermissionNewValue; import org.sonar.db.component.ComponentDto; +import org.sonar.db.permission.template.PermissionTemplateDto; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput; @@ -123,12 +124,13 @@ public class GroupPermissionDao implements Dao { return mapper(session).selectGroupUuidsWithPermissionOnProjectBut(projectUuid, permission); } - public void insert(DbSession dbSession, GroupPermissionDto groupPermissionDto, @Nullable ComponentDto componentDto) { + public void insert(DbSession dbSession, GroupPermissionDto groupPermissionDto, @Nullable ComponentDto componentDto, + @Nullable PermissionTemplateDto permissionTemplateDto) { mapper(dbSession).insert(groupPermissionDto); if (auditPersister != null) { String qualifier = (componentDto != null) ? componentDto.qualifier() : null; - auditPersister.addGroupPermission(dbSession, new GroupPermissionNewValue(groupPermissionDto, qualifier)); + auditPersister.addGroupPermission(dbSession, new GroupPermissionNewValue(groupPermissionDto, qualifier, permissionTemplateDto)); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java index aee263e73dc..f321b9d1ba9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java @@ -30,6 +30,7 @@ import org.sonar.db.DbSession; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.UserPermissionNewValue; import org.sonar.db.component.ComponentDto; +import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.db.user.UserId; import org.sonar.db.user.UserIdDto; @@ -115,13 +116,15 @@ public class UserPermissionDao implements Dao { return mapper(session).selectUserIdsWithPermissionOnProjectBut(projectUuid, permission); } - public void insert(DbSession dbSession, UserPermissionDto dto, @Nullable ComponentDto componentDto, @Nullable UserId userId) { + public void insert(DbSession dbSession, UserPermissionDto dto, @Nullable ComponentDto componentDto, + @Nullable UserId userId, @Nullable PermissionTemplateDto templateDto) { mapper(dbSession).insert(dto); if (auditPersister != null) { String componentName = (componentDto != null) ? componentDto.name() : null; String qualifier = (componentDto != null) ? componentDto.qualifier() : null; - auditPersister.addUserPermission(dbSession, new UserPermissionNewValue(dto, componentName, userId, qualifier)); + auditPersister.addUserPermission(dbSession, new UserPermissionNewValue(dto, componentName, userId, qualifier, + templateDto)); } } 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 63d0a755617..b2ae70f6c66 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 @@ -20,14 +20,11 @@ package org.sonar.db.permission; import javax.annotation.Nullable; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.sonar.api.utils.System2; import org.sonar.core.util.SequenceUuidFactory; -import org.sonar.core.util.Uuids; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.audit.AuditPersister; @@ -39,7 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -91,8 +87,8 @@ public class GroupPermissionDaoWithPersisterTest { verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture()); GroupPermissionNewValue newValue = newValueCaptor.getValue(); assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.name(), "project"); - assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"groupUuid\": \"guuid\", \"groupName\": \"gname\", \"componentUuid\": \"cuuid\", " - + "\"componentName\": \"cname\", \"qualifier\": \"project\" }"); + assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"groupUuid\": \"guuid\", \"groupName\": \"gname\"," + + " \"componentUuid\": \"cuuid\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); underTest.deleteByRootComponentUuid(dbSession, project); @@ -118,7 +114,7 @@ public class GroupPermissionDaoWithPersisterTest { verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture()); GroupPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), null, null, project.uuid(), dto.getRole(), project.name(), "project"); + assertNewValue(newValue, dto.getUuid(), null, null, project.uuid(), dto.getRole(), project.name(), "project"); assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"componentUuid\": \"cuuid\", " + "\"componentName\": \"cname\", \"qualifier\": \"project\" }"); @@ -180,19 +176,19 @@ public class GroupPermissionDaoWithPersisterTest { group = db.users().insertGroup(g -> g.setUuid("guuid").setName("gname")); project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname")); dto = getGroupPermission(group, project); - underTest.insert(dbSession, dto, project); + underTest.insert(dbSession, dto, project, null); } private void addGroupPermissionWithoutGroup() { project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname")); dto = getGroupPermission(project); - underTest.insert(dbSession, dto, project); + underTest.insert(dbSession, dto, project, null); } private void addGroupPermissionWithoutComponent() { group = db.users().insertGroup(g -> g.setUuid("guuid").setName("gname")); dto = getGroupPermission(group); - underTest.insert(dbSession, dto, null); + underTest.insert(dbSession, dto, null, null); } private GroupPermissionDto getGroupPermission(@Nullable GroupDto group, @Nullable ComponentDto project) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java index cd636401209..97b28dbf552 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java @@ -637,14 +637,14 @@ public class UserPermissionDaoTest { private UserPermissionDto addGlobalPermission(String permission, UserDto user) { UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), null); - underTest.insert(dbSession, dto, null, user); + underTest.insert(dbSession, dto, null, user, null); db.commit(); return dto; } private UserPermissionDto addProjectPermission(String permission, UserDto user, ComponentDto project) { UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), project.uuid()); - underTest.insert(dbSession, dto, project, user); + underTest.insert(dbSession, dto, project, user, null); db.commit(); return dto; } 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 7be718c1c12..f32a4905119 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 @@ -30,6 +30,7 @@ import org.sonar.db.DbTester; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.UserPermissionNewValue; import org.sonar.db.component.ComponentDto; +import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.db.user.UserDto; import static org.assertj.core.api.Assertions.assertThat; @@ -40,6 +41,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION; import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN; +import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto; public class UserPermissionDaoWithPersisterTest { private final AuditPersister auditPersister = mock(AuditPersister.class); @@ -55,7 +57,7 @@ public class UserPermissionDaoWithPersisterTest { public void userGlobalPermissionInsertAndDeleteArePersisted() { UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), null); - underTest.insert(dbSession, dto, null, user); + underTest.insert(dbSession, dto, null, user, null); verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); @@ -70,6 +72,26 @@ public class UserPermissionDaoWithPersisterTest { assertThat(newValue.toString()).doesNotContain("permissionUuid"); } + @Test + public void userGlobalPermissionInsertWithTemplateIsPersisted() { + PermissionTemplateDto templateDto = newPermissionTemplateDto(); + db.getDbClient().permissionTemplateDao().insert(db.getSession(), templateDto); + UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); + UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), null); + underTest.insert(dbSession, dto, null, user, templateDto); + + 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, + UserPermissionNewValue::getPermissionTemplateId, UserPermissionNewValue::getPermissionTemplateName) + .containsExactly(dto.getUuid(), user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null, + templateDto.getUuid(), templateDto.getName()); + assertThat(newValue.toString()).doesNotContain("projectUuid"); + } + @Test public void userGlobalPermissionDeleteWithoutAffectedRowsIsNotPersisted() { UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); @@ -85,7 +107,7 @@ public class UserPermissionDaoWithPersisterTest { UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); ComponentDto project = db.components().insertPrivateProject(); UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), project.uuid()); - underTest.insert(dbSession, dto, project, user); + underTest.insert(dbSession, dto, project, user, null); verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); @@ -117,7 +139,7 @@ public class UserPermissionDaoWithPersisterTest { UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); ComponentDto portfolio = db.components().insertPublicPortfolio(); UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), portfolio.uuid()); - underTest.insert(dbSession, dto, portfolio, user); + underTest.insert(dbSession, dto, portfolio, user, null); verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); @@ -130,7 +152,7 @@ public class UserPermissionDaoWithPersisterTest { UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); ComponentDto application = db.components().insertPublicApplication(); UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), application.uuid()); - underTest.insert(dbSession, dto, application, user); + underTest.insert(dbSession, dto, application, user, null); verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); @@ -143,7 +165,7 @@ public class UserPermissionDaoWithPersisterTest { UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); ComponentDto project = db.components().insertPrivateProject(); UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SCAN_EXECUTION, user.getUuid(), project.uuid()); - underTest.insert(dbSession, dto, project, user); + underTest.insert(dbSession, dto, project, user, null); underTest.deleteProjectPermissionOfAnyUser(dbSession, SCAN_EXECUTION, project); verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture()); @@ -167,7 +189,7 @@ public class UserPermissionDaoWithPersisterTest { UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com")); ComponentDto project = db.components().insertPrivateProject(); UserPermissionDto dto = new UserPermissionDto(Uuids.create(), SYSTEM_ADMIN, user.getUuid(), project.uuid()); - underTest.insert(dbSession, dto, project, user); + underTest.insert(dbSession, dto, project, user, null); underTest.deleteByUserUuid(dbSession, user); verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture()); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java index f23eb157bc4..b7dfa5aeff2 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java @@ -196,7 +196,7 @@ public class UserDbTester { .setUuid(Uuids.createFast()) .setGroupUuid(null) .setRole(permission); - db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, null); + db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, null, null); db.commit(); return dto; } @@ -210,7 +210,7 @@ public class UserDbTester { .setUuid(Uuids.createFast()) .setGroupUuid(group.getUuid()) .setRole(permission); - db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, null); + db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, null, null); db.commit(); return dto; } @@ -235,7 +235,7 @@ public class UserDbTester { .setRole(permission) .setComponentUuid(project.uuid()) .setComponentName(project.name()); - db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project); + db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project, null); db.commit(); return dto; } @@ -256,7 +256,7 @@ public class UserDbTester { .setRole(permission) .setComponentUuid(project.uuid()) .setComponentName(project.name()); - db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project); + db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project, null); db.commit(); return dto; } @@ -291,7 +291,7 @@ public class UserDbTester { @Deprecated public UserPermissionDto insertPermissionOnUser(UserDto user, String permission) { UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), null); - db.getDbClient().userPermissionDao().insert(db.getSession(), dto, null, user); + db.getDbClient().userPermissionDao().insert(db.getSession(), dto, null, user, null); db.commit(); return dto; } @@ -314,7 +314,7 @@ public class UserDbTester { "%s can't be granted on a public project", permission); checkArgument(project.getMainBranchProjectUuid() == null, "Permissions can't be granted on branches"); UserPermissionDto dto = new UserPermissionDto(Uuids.create(), permission, user.getUuid(), project.uuid()); - db.getDbClient().userPermissionDao().insert(db.getSession(), dto, project, user); + db.getDbClient().userPermissionDao().insert(db.getSession(), dto, project, user, null); db.commit(); return dto; } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java index e7aba7949a5..94f6be7a39e 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java @@ -173,7 +173,7 @@ public class PermissionIndexerDaoTest { .setRole(USER) .setComponentUuid(project.uuid()) .setComponentName(project.name()); - dbClient.groupPermissionDao().insert(dbSession, dto, project); + dbClient.groupPermissionDao().insert(dbSession, dto, project, null); } dbSession.commit(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java index 1b7b340e567..82c114b19c2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java @@ -131,7 +131,7 @@ public class GroupPermissionChanger { .map(GroupDto::getName) .ifPresent(addedDto::setGroupName); - dbClient.groupPermissionDao().insert(dbSession, addedDto, change.getProject()); + dbClient.groupPermissionDao().insert(dbSession, addedDto, change.getProject(), null); return true; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java index 1af4b4bf74e..316e68f7e0a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java @@ -19,6 +19,16 @@ */ package org.sonar.server.permission; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.resources.Qualifiers; import org.sonar.api.server.ServerSide; @@ -45,16 +55,6 @@ import static java.util.Collections.singletonList; import static org.sonar.api.security.DefaultGroups.isAnyone; import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS; import static org.sonar.db.permission.GlobalPermission.SCAN; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; @ServerSide public class PermissionTemplateService { @@ -136,7 +136,7 @@ public class PermissionTemplateService { .filter(up -> permissionValidForProject(project, up.getPermission())) .forEach(up -> { UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), up.getPermission(), up.getUserUuid(), project.uuid()); - dbClient.userPermissionDao().insert(dbSession, dto, project, userIdByUuid.get(up.getUserUuid())); + dbClient.userPermissionDao().insert(dbSession, dto, project, userIdByUuid.get(up.getUserUuid()), template); }); List groupsPermissions = dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateUuid(dbSession, template.getUuid()); @@ -154,7 +154,7 @@ public class PermissionTemplateService { .setRole(gp.getPermission()) .setComponentUuid(project.uuid()) .setComponentName(project.name()); - dbClient.groupPermissionDao().insert(dbSession, dto, null); + dbClient.groupPermissionDao().insert(dbSession, dto, null, template); }); List characteristics = dbClient.permissionTemplateCharacteristicDao().selectByTemplateUuids(dbSession, singletonList(template.getUuid())); @@ -171,7 +171,7 @@ public class PermissionTemplateService { .filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission())) .forEach(c -> { UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), c.getPermission(), userDto.getUuid(), project.uuid()); - dbClient.userPermissionDao().insert(dbSession, dto, project, userDto); + dbClient.userPermissionDao().insert(dbSession, dto, project, userDto, template); }); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java index daf58e2f9dc..cf4fdd089a1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/UserPermissionChanger.java @@ -98,7 +98,7 @@ public class UserPermissionChanger { } UserPermissionDto dto = new UserPermissionDto(uuidFactory.create(), change.getPermission(), change.getUserId().getUuid(), change.getProjectUuid()); - dbClient.userPermissionDao().insert(dbSession, dto, change.getProject(), change.getUserId()); + dbClient.userPermissionDao().insert(dbSession, dto, change.getProject(), change.getUserId(), null); return true; } 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 28cf5d62724..fd5010c682c 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 @@ -166,7 +166,8 @@ 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); + dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), permission, userId.getUuid(), component.uuid()), + component, userId, null); } private void insertProjectPermissionOnGroup(DbSession dbSession, ComponentDto component, String permission, String groupUuid) { @@ -177,7 +178,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction { .setGroupUuid(groupUuid) .setGroupName(groupName) .setRole(permission) - .setComponentName(component.name()), component); + .setComponentName(component.name()), component, null); } private void updatePermissionsToPublic(DbSession dbSession, ComponentDto component) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index 0c30faf1f31..3585dd99201 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -1399,7 +1399,7 @@ public class SearchActionTest { .setGroupUuid(null) .setComponentUuid(project.uuid()) .setComponentName(project.name()) - .setRole(permission), project); + .setRole(permission), project, null); session.commit(); userSession.logIn().addProjectPermission(permission, project); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java index 03435d3c93b..6f85ad3d499 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java @@ -434,7 +434,7 @@ public class GroupPermissionChangerTest { .setRole(perm) .setComponentUuid(privateProject.uuid()) .setComponentName(privateProject.name()); - db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, privateProject); + db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, privateProject, null); db.commit(); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index ecc8c918a5f..849ae91eb73 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -476,7 +476,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest