void deleteQualityGateEditor(DbSession dbSession, AbstractEditorNewValue newValue);
+ void addQualityProfileEditor(DbSession dbSession, AbstractEditorNewValue newValue);
+
+ void deleteQualityProfileEditor(DbSession dbSession, AbstractEditorNewValue newValue);
+
void addCharacteristicToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
void updateCharacteristicInPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
// no op
}
+ @Override
+ public void addQualityProfileEditor(DbSession dbSession, AbstractEditorNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteQualityProfileEditor(DbSession dbSession, AbstractEditorNewValue newValue) {
+ // no op
+ }
+
@Override
public void addCharacteristicToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
// no op
protected String qualityGateUuid;
@Nullable
protected String qualityGateName;
+ @Nullable
+ protected String qualityProfileUuid;
+ @Nullable
+ protected String qualityProfileName;
@CheckForNull
public String getQualityGateUuid() {
public String getQualityGateName() {
return this.qualityGateName;
}
+
+ @CheckForNull
+ public String getQualityProfileUuid() {
+ return this.qualityProfileUuid;
+ }
+
+ @CheckForNull
+ public String getQualityProfileName() {
+ return this.qualityProfileName;
+ }
}
import javax.annotation.Nullable;
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.db.qualitygate.QualityGateGroupPermissionsDto;
+import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.qualityprofile.QProfileEditGroupsDto;
import org.sonar.db.user.GroupDto;
public class GroupEditorNewValue extends AbstractEditorNewValue {
this.groupName = groupDto.getName();
}
+ public GroupEditorNewValue(QProfileEditGroupsDto qProfileEditGroupsDto, String qualityProfileName, String groupName) {
+ this.qualityProfileUuid = qProfileEditGroupsDto.getQProfileUuid();
+ this.qualityProfileName = qualityProfileName;
+ this.groupUuid = qProfileEditGroupsDto.getGroupUuid();
+ this.groupName = groupName;
+ }
+
+ public GroupEditorNewValue(QProfileDto qualityProfileDto, GroupDto groupDto) {
+ this.qualityProfileUuid = qualityProfileDto.getKee();
+ this.qualityProfileName = qualityProfileDto.getName();
+ this.groupUuid = groupDto.getUuid();
+ this.groupName = groupDto.getName();
+ }
+
+ public GroupEditorNewValue(QProfileDto qualityProfileDto) {
+ this.qualityProfileUuid = qualityProfileDto.getKee();
+ this.qualityProfileName = qualityProfileDto.getName();
+ }
+
@CheckForNull
public String getGroupUuid() {
return this.groupUuid;
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"qualityGateUuid\": ", this.qualityGateUuid, true);
addField(sb, "\"qualityGateName\": ", this.qualityGateName, true);
+ addField(sb, "\"qualityProfileUuid\": ", this.qualityProfileUuid, true);
+ addField(sb, "\"qualityProfileName\": ", this.qualityProfileName, true);
addField(sb, "\"groupUuid\": ", this.groupUuid, true);
addField(sb, "\"groupName\": ", this.groupName, true);
endString(sb);
import javax.annotation.Nullable;
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.db.qualitygate.QualityGateUserPermissionsDto;
+import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.qualityprofile.QProfileEditUsersDto;
import org.sonar.db.user.UserDto;
public class UserEditorNewValue extends AbstractEditorNewValue {
this.userLogin = userLogin;
}
- public UserEditorNewValue(@Nullable QualityGateDto qualityGateDto, @Nullable UserDto userDto) {
- if (qualityGateDto != null) {
- this.qualityGateUuid = qualityGateDto.getUuid();
- this.qualityGateName = qualityGateDto.getName();
- }
+ public UserEditorNewValue(QualityGateDto qualityGateDto, UserDto userDto) {
+ this.qualityGateUuid = qualityGateDto.getUuid();
+ this.qualityGateName = qualityGateDto.getName();
+ this.userUuid = userDto.getUuid();
+ this.userLogin = userDto.getLogin();
+ }
+
+ public UserEditorNewValue(QualityGateDto qualityGateDto) {
+ this.qualityGateUuid = qualityGateDto.getUuid();
+ this.qualityGateName = qualityGateDto.getName();
+ }
+
+ public UserEditorNewValue(UserDto userDto) {
+ this.userUuid = userDto.getUuid();
+ this.userLogin = userDto.getLogin();
+ }
+
+ public UserEditorNewValue(QProfileEditUsersDto qProfileEditUsersDto, String qualityProfileName, String userLogin) {
+ this.qualityProfileUuid = qProfileEditUsersDto.getQProfileUuid();
+ this.qualityProfileName = qualityProfileName;
+ this.userUuid = qProfileEditUsersDto.getUserUuid();
+ this.userLogin = userLogin;
+ }
+
+ public UserEditorNewValue(QProfileDto qProfileDto, UserDto userDto) {
+ this.qualityProfileUuid = qProfileDto.getKee();
+ this.qualityProfileName = qProfileDto.getName();
+ this.userUuid = userDto.getUuid();
+ this.userLogin = userDto.getLogin();
+ }
- if (userDto != null) {
- this.userUuid = userDto.getUuid();
- this.userLogin = userDto.getLogin();
- }
+ public UserEditorNewValue(QProfileDto qProfileDto) {
+ this.qualityProfileUuid = qProfileDto.getKee();
+ this.qualityProfileName = qProfileDto.getName();
}
@CheckForNull
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"qualityGateUuid\": ", this.qualityGateUuid, true);
addField(sb, "\"qualityGateName\": ", this.qualityGateName, true);
+ addField(sb, "\"qualityProfileUuid\": ", this.qualityProfileUuid, true);
+ addField(sb, "\"qualityProfileName\": ", this.qualityProfileName, true);
addField(sb, "\"userUuid\": ", this.userUuid, true);
addField(sb, "\"userLogin\": ", this.userLogin, true);
endString(sb);
package org.sonar.db.qualityprofile;
import java.util.Date;
+import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.core.util.UtcDateUtils;
/**
* Represents the join of "org_qprofiles" and "rules_profiles"
*/
-public class QProfileDto {
+public class QProfileDto implements Comparable<QProfileDto> {
private String kee;
private String name;
private String language;
.setLastUsed(org.getLastUsed())
.setUserUpdatedAt(org.getUserUpdatedAt());
}
+
+ @Override
+ public int compareTo(QProfileDto o) {
+ return kee.compareTo(o.kee);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ QProfileDto that = (QProfileDto) o;
+ return kee.equals(that.kee);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(kee);
+ }
}
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
import org.sonar.db.Pagination;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.GroupEditorNewValue;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.SearchGroupMembershipDto;
public class QProfileEditGroupsDao implements Dao {
private final System2 system2;
+ private final AuditPersister auditPersister;
- public QProfileEditGroupsDao(System2 system2) {
+ public QProfileEditGroupsDao(System2 system2, AuditPersister auditPersister) {
this.system2 = system2;
+ this.auditPersister = auditPersister;
}
public boolean exists(DbSession dbSession, QProfileDto profile, GroupDto group) {
g -> mapper(dbSession).selectQProfileUuidsByGroups(g));
}
- public void insert(DbSession dbSession, QProfileEditGroupsDto dto) {
+ public void insert(DbSession dbSession, QProfileEditGroupsDto dto, String qualityProfileName, String groupName) {
mapper(dbSession).insert(dto, system2.now());
+ auditPersister.addQualityProfileEditor(dbSession, new GroupEditorNewValue(dto, qualityProfileName, groupName));
}
public void deleteByQProfileAndGroup(DbSession dbSession, QProfileDto profile, GroupDto group) {
- mapper(dbSession).delete(profile.getKee(), group.getUuid());
+ int deletedRows = mapper(dbSession).delete(profile.getKee(), group.getUuid());
+
+ if (deletedRows > 0) {
+ auditPersister.deleteQualityProfileEditor(dbSession, new GroupEditorNewValue(profile, group));
+ }
}
public void deleteByQProfiles(DbSession dbSession, List<QProfileDto> qProfiles) {
- executeLargeUpdates(qProfiles.stream().map(QProfileDto::getKee).collect(toList()), p -> mapper(dbSession).deleteByQProfiles(p));
+ executeLargeUpdates(qProfiles,
+ partitionedProfiles ->
+ {
+ int deletedRows = mapper(dbSession).deleteByQProfiles(partitionedProfiles
+ .stream()
+ .map(QProfileDto::getKee)
+ .collect(toList()));
+
+ if (deletedRows > 0) {
+ partitionedProfiles.forEach(p -> auditPersister.deleteQualityProfileEditor(dbSession, new GroupEditorNewValue(p)));
+ }
+ });
}
public void deleteByGroup(DbSession dbSession, GroupDto group) {
- mapper(dbSession).deleteByGroup(group.getUuid());
+ int deletedRows = mapper(dbSession).deleteByGroup(group.getUuid());
+
+ if (deletedRows > 0) {
+ auditPersister.deleteQualityProfileEditor(dbSession, new GroupEditorNewValue(group));
+ }
}
private static QProfileEditGroupsMapper mapper(DbSession dbSession) {
void insert(@Param("dto") QProfileEditGroupsDto dto, @Param("now") long now);
- void delete(@Param("qProfileUuid") String qProfileUuid, @Param("groupUuid") String groupUuid);
+ int delete(@Param("qProfileUuid") String qProfileUuid, @Param("groupUuid") String groupUuid);
- void deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids);
+ int deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids);
- void deleteByGroup(@Param("groupUuid") String groupUuid);
+ int deleteByGroup(@Param("groupUuid") String groupUuid);
}
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.Pagination;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.UserEditorNewValue;
import org.sonar.db.user.SearchUserMembershipDto;
import org.sonar.db.user.UserDto;
public class QProfileEditUsersDao implements Dao {
private final System2 system2;
+ private final AuditPersister auditPersister;
- public QProfileEditUsersDao(System2 system2) {
+ public QProfileEditUsersDao(System2 system2, AuditPersister auditPersister) {
this.system2 = system2;
+ this.auditPersister = auditPersister;
}
public boolean exists(DbSession dbSession, QProfileDto profile, UserDto user) {
return mapper(dbSession).selectQProfileUuidsByUser(userDto.getUuid());
}
- public void insert(DbSession dbSession, QProfileEditUsersDto dto) {
+ public void insert(DbSession dbSession, QProfileEditUsersDto dto, String qualityProfileName, String userLogin) {
mapper(dbSession).insert(dto, system2.now());
+ auditPersister.addQualityProfileEditor(dbSession, new UserEditorNewValue(dto, qualityProfileName, userLogin));
}
public void deleteByQProfileAndUser(DbSession dbSession, QProfileDto profile, UserDto user) {
- mapper(dbSession).delete(profile.getKee(), user.getUuid());
+ int deletedRows = mapper(dbSession).delete(profile.getKee(), user.getUuid());
+
+ if (deletedRows > 0) {
+ auditPersister.deleteQualityProfileEditor(dbSession, new UserEditorNewValue(profile, user));
+ }
}
public void deleteByQProfiles(DbSession dbSession, List<QProfileDto> qProfiles) {
- executeLargeUpdates(qProfiles.stream().map(QProfileDto::getKee).collect(toList()), p -> mapper(dbSession).deleteByQProfiles(p));
+ executeLargeUpdates(qProfiles,
+ partitionedProfiles ->
+ {
+ int deletedRows = mapper(dbSession).deleteByQProfiles(partitionedProfiles
+ .stream()
+ .map(QProfileDto::getKee)
+ .collect(toList()));
+
+ if (deletedRows > 0) {
+ partitionedProfiles.forEach(p -> auditPersister.deleteQualityProfileEditor(dbSession, new UserEditorNewValue(p)));
+ }
+ });
}
public void deleteByUser(DbSession dbSession, UserDto user) {
- mapper(dbSession).deleteByUser(user.getUuid());
+ int deletedRows = mapper(dbSession).deleteByUser(user.getUuid());
+
+ if (deletedRows > 0) {
+ auditPersister.deleteQualityProfileEditor(dbSession, new UserEditorNewValue(user));
+ }
}
private static QProfileEditUsersMapper mapper(DbSession dbSession) {
void insert(@Param("dto") QProfileEditUsersDto dto, @Param("now") long now);
- void delete(@Param("qProfileUuid") String qProfileUuid, @Param("userUuid") String userUuid);
+ int delete(@Param("qProfileUuid") String qProfileUuid, @Param("userUuid") String userUuid);
- void deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids);
+ int deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids);
- void deleteByUser(@Param("userUuid") String userUuid);
+ int deleteByUser(@Param("userUuid") String userUuid);
}
*/
package org.sonar.db.qualityprofile;
+import java.util.List;
import org.junit.Rule;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.Pagination;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.GroupEditorNewValue;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.SearchGroupMembershipDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.ANY;
import static org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.IN;
import static org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.OUT;
private static final long NOW = 10_000_000_000L;
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+ private final ArgumentCaptor<GroupEditorNewValue> newValueCaptor = ArgumentCaptor.forClass(GroupEditorNewValue.class);
+
private System2 system2 = new TestSystem2().setNow(NOW);
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, auditPersister);
private QProfileEditGroupsDao underTest = db.getDbClient().qProfileEditGroupsDao();
.containsExactlyInAnyOrder(profile1.getKee(), profile2.getKee());
assertThat(underTest.selectQProfileUuidsByGroups(db.getSession(), asList(group1, group2, group3)))
.containsExactlyInAnyOrder(profile1.getKee(), profile2.getKee());
- assertThat(underTest.selectQProfileUuidsByGroups(db.getSession(),emptyList())).isEmpty();
+ assertThat(underTest.selectQProfileUuidsByGroups(db.getSession(), emptyList())).isEmpty();
}
@Test
public void insert() {
+ String qualityProfileName = "QPROFILE_NAME";
+ String qualityProfileKee = "QPROFILE";
+ String groupUuid = "100";
+ String groupName = "GROUP_NAME";
underTest.insert(db.getSession(), new QProfileEditGroupsDto()
- .setUuid("ABCD")
- .setGroupUuid("100")
- .setQProfileUuid("QPROFILE")
+ .setUuid("ABCD")
+ .setGroupUuid(groupUuid)
+ .setQProfileUuid(qualityProfileKee),
+ qualityProfileName,
+ groupName
);
+ verify(auditPersister).addQualityProfileEditor(eq(db.getSession()), newValueCaptor.capture());
+
+ GroupEditorNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(GroupEditorNewValue::getQualityProfileName, GroupEditorNewValue::getQualityProfileUuid,
+ GroupEditorNewValue::getGroupName, GroupEditorNewValue::getGroupUuid)
+ .containsExactly(qualityProfileName, qualityProfileKee, groupName, groupUuid);
+ assertThat(newValue.toString()).contains("\"qualityProfileName\"").contains("\"groupName\"");
+
assertThat(db.selectFirst(db.getSession(),
"select uuid as \"uuid\", group_uuid as \"groupUuid\", qprofile_uuid as \"qProfileUuid\", created_at as \"createdAt\" from qprofile_edit_groups")).contains(
entry("uuid", "ABCD"),
- entry("groupUuid", "100"),
- entry("qProfileUuid", "QPROFILE"),
+ entry("groupUuid", groupUuid),
+ entry("qProfileUuid", qualityProfileKee),
entry("createdAt", NOW));
}
underTest.deleteByQProfileAndGroup(db.getSession(), profile, group);
+ verify(auditPersister).deleteQualityProfileEditor(eq(db.getSession()), newValueCaptor.capture());
+
+ GroupEditorNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(GroupEditorNewValue::getQualityProfileName, GroupEditorNewValue::getQualityProfileName,
+ GroupEditorNewValue::getGroupName, GroupEditorNewValue::getGroupUuid)
+ .containsExactly(profile.getName(), profile.getKee(), group.getName(), group.getUuid());
+ assertThat(newValue.toString()).contains("\"qualityProfileName\"").contains("\"groupName\"");
+
assertThat(underTest.exists(db.getSession(), profile, group)).isFalse();
}
underTest.deleteByQProfiles(db.getSession(), asList(profile1, profile2));
+ verify(auditPersister, times(2)).deleteQualityProfileEditor(eq(db.getSession()), newValueCaptor.capture());
+
+ List<GroupEditorNewValue> newValues = newValueCaptor.getAllValues();
+ assertThat(newValues.get(0))
+ .extracting(GroupEditorNewValue::getQualityProfileName, GroupEditorNewValue::getQualityProfileUuid,
+ GroupEditorNewValue::getGroupName, GroupEditorNewValue::getGroupUuid)
+ .containsExactly(profile1.getName(), profile1.getKee(), null, null);
+ assertThat(newValues.get(0).toString()).contains("\"qualityProfileName\"").doesNotContain("\"groupName\"");
+ assertThat(newValues.get(1))
+ .extracting(GroupEditorNewValue::getQualityProfileName, GroupEditorNewValue::getQualityProfileUuid,
+ GroupEditorNewValue::getGroupName, GroupEditorNewValue::getGroupUuid)
+ .containsExactly(profile2.getName(), profile2.getKee(), null, null);
+ assertThat(newValues.get(1).toString()).contains("\"qualityProfileName\"").doesNotContain("\"groupName\"");
+
assertThat(underTest.exists(db.getSession(), profile1, group1)).isFalse();
assertThat(underTest.exists(db.getSession(), profile2, group2)).isFalse();
assertThat(underTest.exists(db.getSession(), profile3, group1)).isTrue();
underTest.deleteByGroup(db.getSession(), group1);
+ verify(auditPersister).deleteQualityProfileEditor(eq(db.getSession()), newValueCaptor.capture());
+
+ GroupEditorNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(GroupEditorNewValue::getQualityProfileName, GroupEditorNewValue::getQualityProfileName,
+ GroupEditorNewValue::getGroupName, GroupEditorNewValue::getGroupUuid)
+ .containsExactly(null, null, group1.getName(), group1.getUuid());
+ assertThat(newValue.toString()).doesNotContain("\"qualityProfileName\"").contains("\"groupName\"");
+
assertThat(underTest.exists(db.getSession(), profile1, group1)).isFalse();
assertThat(underTest.exists(db.getSession(), profile2, group2)).isTrue();
assertThat(underTest.exists(db.getSession(), profile3, group1)).isFalse();
package org.sonar.db.qualityprofile;
import java.sql.SQLException;
+import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.Pagination;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.UserEditorNewValue;
import org.sonar.db.user.SearchUserMembershipDto;
import org.sonar.db.user.UserDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.ANY;
import static org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.IN;
import static org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.OUT;
private static final long NOW = 10_000_000_000L;
private final System2 system2 = new TestSystem2().setNow(NOW);
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
+ private final ArgumentCaptor<UserEditorNewValue> newValueCaptor = ArgumentCaptor.forClass(UserEditorNewValue.class);
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, auditPersister);
private final QProfileEditUsersDao underTest = db.getDbClient().qProfileEditUsersDao();
UserDto anotherUser = db.users().insertUser();
db.qualityProfiles().addUserPermission(profile, user);
+ verify(auditPersister).addQualityProfileEditor(eq(db.getSession()), newValueCaptor.capture());
+
+ UserEditorNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(UserEditorNewValue::getQualityProfileName, UserEditorNewValue::getQualityProfileUuid,
+ UserEditorNewValue::getUserLogin, UserEditorNewValue::getUserUuid)
+ .containsExactly(profile.getName(), profile.getKee(), user.getLogin(), user.getUuid());
+ assertThat(newValue.toString()).contains("\"qualityProfileName\"").contains("\"userLogin\"");
+
assertThat(underTest.exists(db.getSession(), profile, user)).isTrue();
assertThat(underTest.exists(db.getSession(), profile, anotherUser)).isFalse();
assertThat(underTest.exists(db.getSession(), anotherProfile, user)).isFalse();
assertThat(underTest.countByQuery(db.getSession(), builder()
.setProfile(profile)
.setMembership(ANY).build()))
- .isEqualTo(3);
+ .isEqualTo(3);
assertThat(underTest.countByQuery(db.getSession(), builder()
.setProfile(profile)
.setMembership(IN).build()))
- .isEqualTo(2);
+ .isEqualTo(2);
assertThat(underTest.countByQuery(db.getSession(), builder()
.setProfile(profile)
.setMembership(OUT).build()))
- .isEqualTo(1);
+ .isEqualTo(1);
}
@Test
.setProfile(profile)
.setMembership(ANY).build(), Pagination.all()))
.extracting(SearchUserMembershipDto::getUserUuid, SearchUserMembershipDto::isSelected)
- .containsExactlyInAnyOrder(
- tuple(user1.getUuid(), true),
- tuple(user2.getUuid(), true),
- tuple(user3.getUuid(), false));
+ .containsExactlyInAnyOrder(
+ tuple(user1.getUuid(), true),
+ tuple(user2.getUuid(), true),
+ tuple(user3.getUuid(), false));
assertThat(underTest.selectByQuery(db.getSession(), builder()
.setProfile(profile)
.setMembership(IN).build(),
Pagination.all()))
.extracting(SearchUserMembershipDto::getUserUuid, SearchUserMembershipDto::isSelected)
- .containsExactlyInAnyOrder(tuple(user1.getUuid(), true), tuple(user2.getUuid(), true));
+ .containsExactlyInAnyOrder(tuple(user1.getUuid(), true), tuple(user2.getUuid(), true));
assertThat(underTest.selectByQuery(db.getSession(), builder()
.setProfile(profile)
.setMembership(OUT).build(),
Pagination.all()))
.extracting(SearchUserMembershipDto::getUserUuid, SearchUserMembershipDto::isSelected)
- .containsExactlyInAnyOrder(tuple(user3.getUuid(), false));
+ .containsExactlyInAnyOrder(tuple(user3.getUuid(), false));
}
@Test
.setQuery("user2").build(),
Pagination.all()))
.extracting(SearchUserMembershipDto::getUserUuid)
- .containsExactlyInAnyOrder(user2.getUuid());
+ .containsExactlyInAnyOrder(user2.getUuid());
assertThat(underTest.selectByQuery(db.getSession(), builder()
.setProfile(profile)
.setQuery("joh").build(),
Pagination.all()))
.extracting(SearchUserMembershipDto::getUserUuid)
- .containsExactlyInAnyOrder(user1.getUuid(), user2.getUuid());
+ .containsExactlyInAnyOrder(user1.getUuid(), user2.getUuid());
assertThat(underTest.selectByQuery(db.getSession(), builder()
.setProfile(profile)
.setQuery("Doe").build(),
Pagination.all()))
.extracting(SearchUserMembershipDto::getUserUuid)
- .containsExactlyInAnyOrder(user1.getUuid(), user3.getUuid());
+ .containsExactlyInAnyOrder(user1.getUuid(), user3.getUuid());
}
@Test
.build(),
Pagination.forPage(1).andSize(1)))
.extracting(SearchUserMembershipDto::getUserUuid)
- .containsExactly(user1.getUuid());
+ .containsExactly(user1.getUuid());
assertThat(underTest.selectByQuery(db.getSession(), builder()
.setProfile(profile)
.build(),
Pagination.forPage(3).andSize(1)))
.extracting(SearchUserMembershipDto::getUserUuid)
- .containsExactly(user3.getUuid());
+ .containsExactly(user3.getUuid());
assertThat(underTest.selectByQuery(db.getSession(), builder()
.setProfile(profile)
.build(),
Pagination.forPage(1).andSize(10)))
.extracting(SearchUserMembershipDto::getUserUuid)
- .containsExactly(user1.getUuid(), user2.getUuid(), user3.getUuid());
+ .containsExactly(user1.getUuid(), user2.getUuid(), user3.getUuid());
}
@Test
@Test
public void insert() {
+ String qualityProfileUuid = "QPROFILE";
+ String qualityProfileName = "QPROFILE_NAME";
+ String userUuid = "100";
+ String userLogin = "USER_LOGIN";
underTest.insert(db.getSession(), new QProfileEditUsersDto()
- .setUuid("ABCD")
- .setUserUuid("100")
- .setQProfileUuid("QPROFILE"));
+ .setUuid("ABCD")
+ .setUserUuid(userUuid)
+ .setQProfileUuid(qualityProfileUuid),
+ qualityProfileName, userLogin);
assertThat(db.selectFirst(db.getSession(),
"select uuid as \"uuid\", user_uuid as \"userUuid\", qprofile_uuid as \"qProfileUuid\", created_at as \"createdAt\" from qprofile_edit_users")).contains(
- entry("uuid", "ABCD"),
- entry("userUuid", "100"),
- entry("qProfileUuid", "QPROFILE"),
- entry("createdAt", NOW));
+ entry("uuid", "ABCD"),
+ entry("userUuid", userUuid),
+ entry("qProfileUuid", qualityProfileUuid),
+ entry("createdAt", NOW));
}
@Test
public void fail_to_insert_same_row_twice() {
+ String qualityProfileUuid = "QPROFILE";
+ String qualityProfileName = "QPROFILE_NAME";
+ String userUuid = "100";
+ String userLogin = "USER_LOGIN";
underTest.insert(db.getSession(), new QProfileEditUsersDto()
- .setUuid("UUID-1")
- .setUserUuid("100")
- .setQProfileUuid("QPROFILE"));
+ .setUuid("UUID-1")
+ .setUserUuid(userUuid)
+ .setQProfileUuid(qualityProfileUuid),
+ qualityProfileName, userLogin);
expectedException.expectCause(hasType(SQLException.class));
underTest.insert(db.getSession(), new QProfileEditUsersDto()
- .setUuid("UUID-2")
- .setUserUuid("100")
- .setQProfileUuid("QPROFILE"));
+ .setUuid("UUID-2")
+ .setUserUuid(userUuid)
+ .setQProfileUuid(qualityProfileUuid),
+ qualityProfileName, userLogin);
}
@Test
underTest.deleteByQProfileAndUser(db.getSession(), profile, user);
+ verify(auditPersister).deleteQualityProfileEditor(eq(db.getSession()), newValueCaptor.capture());
+
+ UserEditorNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(UserEditorNewValue::getQualityProfileName, UserEditorNewValue::getQualityProfileUuid,
+ UserEditorNewValue::getUserLogin, UserEditorNewValue::getUserUuid)
+ .containsExactly(profile.getName(), profile.getKee(), user.getLogin(), user.getUuid());
+ assertThat(newValue.toString()).contains("\"qualityProfileName\"").contains("\"userLogin\"");
+
assertThat(underTest.exists(db.getSession(), profile, user)).isFalse();
}
underTest.deleteByQProfiles(db.getSession(), asList(profile1, profile2));
+ verify(auditPersister, times(2)).deleteQualityProfileEditor(eq(db.getSession()), newValueCaptor.capture());
+
+ List<UserEditorNewValue> newValues = newValueCaptor.getAllValues();
+ assertThat(newValues.get(0))
+ .extracting(UserEditorNewValue::getQualityProfileName, UserEditorNewValue::getQualityProfileUuid,
+ UserEditorNewValue::getUserLogin, UserEditorNewValue::getUserUuid)
+ .containsExactly(profile1.getName(), profile1.getKee(), null, null);
+ assertThat(newValues.get(0).toString()).contains("\"qualityProfileName\"").doesNotContain("\"groupName\"");
+ assertThat(newValues.get(1))
+ .extracting(UserEditorNewValue::getQualityProfileName, UserEditorNewValue::getQualityProfileUuid,
+ UserEditorNewValue::getUserLogin, UserEditorNewValue::getUserUuid)
+ .containsExactly(profile2.getName(), profile2.getKee(), null, null);
+ assertThat(newValues.get(1).toString()).contains("\"qualityProfileName\"").doesNotContain("\"groupName\"");
+
assertThat(underTest.exists(db.getSession(), profile1, user1)).isFalse();
assertThat(underTest.exists(db.getSession(), profile2, user2)).isFalse();
assertThat(underTest.exists(db.getSession(), profile3, user1)).isTrue();
underTest.deleteByUser(db.getSession(), user1);
+ verify(auditPersister).deleteQualityProfileEditor(eq(db.getSession()), newValueCaptor.capture());
+
+ UserEditorNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(UserEditorNewValue::getQualityProfileName, UserEditorNewValue::getQualityProfileUuid,
+ UserEditorNewValue::getUserLogin, UserEditorNewValue::getUserUuid)
+ .containsExactly(null, null, user1.getLogin(), user1.getUuid());
+ assertThat(newValue.toString()).doesNotContain("\"qualityProfileName\"").contains("\"userLogin\"");
+
assertThat(underTest.exists(db.getSession(), profile1, user1)).isFalse();
assertThat(underTest.exists(db.getSession(), profile3, user2)).isTrue();
}
public QualityProfileDbTester setAsDefault(QProfileDto profile, QProfileDto... others) {
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
for (QProfileDto other : others) {
- dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from( other));
+ dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(other));
}
dbSession.commit();
return this;
}
- public void addUserPermission(QProfileDto profile, UserDto user){
+ public void addUserPermission(QProfileDto profile, UserDto user) {
checkArgument(!profile.isBuiltIn(), "Built-In profile cannot be used");
dbClient.qProfileEditUsersDao().insert(dbSession, new QProfileEditUsersDto()
- .setUuid(Uuids.createFast())
- .setUserUuid(user.getUuid())
- .setQProfileUuid(profile.getKee())
+ .setUuid(Uuids.createFast())
+ .setUserUuid(user.getUuid())
+ .setQProfileUuid(profile.getKee()),
+ profile.getName(), user.getLogin()
);
dbSession.commit();
}
- public void addGroupPermission(QProfileDto profile, GroupDto group){
+ public void addGroupPermission(QProfileDto profile, GroupDto group) {
checkArgument(!profile.isBuiltIn(), "Built-In profile cannot be used");
dbClient.qProfileEditGroupsDao().insert(dbSession, new QProfileEditGroupsDto()
- .setUuid(Uuids.createFast())
- .setGroupUuid(group.getUuid())
- .setQProfileUuid(profile.getKee())
- );
+ .setUuid(Uuids.createFast())
+ .setGroupUuid(group.getUuid())
+ .setQProfileUuid(profile.getKee()),
+ profile.getName(), group.getName());
dbSession.commit();
}
}
new QProfileEditGroupsDto()
.setUuid(uuidFactory.create())
.setGroupUuid(group.getUuid())
- .setQProfileUuid(profile.getKee()));
+ .setQProfileUuid(profile.getKee()),
+ profile.getName(),
+ group.getName());
dbSession.commit();
}
}
new QProfileEditUsersDto()
.setUuid(uuidFactory.create())
.setUserUuid(user.getUuid())
- .setQProfileUuid(profile.getKee()));
+ .setQProfileUuid(profile.getKee()),
+ profile.getName(), user.getLogin());
dbSession.commit();
}