}
public void delete(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
- getMapper(dbSession).deleteByUuid(almPatDto.getUuid());
- if (auditPersister != null) {
+ int deletedRows = getMapper(dbSession).deleteByUuid(almPatDto.getUuid());
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
}
}
public void deleteByUser(DbSession dbSession, UserDto user) {
- getMapper(dbSession).deleteByUser(user.getUuid());
- if (auditPersister != null) {
+ int deletedRows = getMapper(dbSession).deleteByUser(user.getUuid());
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(user));
}
}
public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
- getMapper(dbSession).deleteByAlmSetting(almSetting.getUuid());
- if (auditPersister != null) {
+ int deletedRows = getMapper(dbSession).deleteByAlmSetting(almSetting.getUuid());
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almSetting));
}
}
void update(@Param("dto") AlmPatDto almPatDto);
- void deleteByUuid(@Param("uuid") String uuid);
+ int deleteByUuid(@Param("uuid") String uuid);
- void deleteByUser(@Param("userUuid") String userUuid);
+ int deleteByUser(@Param("userUuid") String userUuid);
- void deleteByAlmSetting(@Param("almSettingUuid") String almSettingUuid);
+ int deleteByAlmSetting(@Param("almSettingUuid") String almSettingUuid);
}
}
public void delete(DbSession dbSession, AlmSettingDto almSettingDto) {
- getMapper(dbSession).deleteByKey(almSettingDto.getKey());
+ int deletedRows = getMapper(dbSession).deleteByKey(almSettingDto.getKey());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(), almSettingDto.getKey()));
}
}
void update(@Param("dto") AlmSettingDto almSettingDto);
- void deleteByKey(@Param("key") String key);
+ int deleteByKey(@Param("key") String key);
}
}
public void deleteByProject(DbSession dbSession, ProjectDto project) {
- getMapper(dbSession).deleteByProjectUuid(project.getUuid());
+ int deletedRows = getMapper(dbSession).deleteByProjectUuid(project.getUuid());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(project));
}
}
int update(@Param("dto") ProjectAlmSettingDto projectAlmSettingDto, @Param("now") long now);
- void deleteByProjectUuid(@Param("projectUuid") String projectUuid);
+ int deleteByProjectUuid(@Param("projectUuid") String projectUuid);
void deleteByAlmSettingUuid(@Param("almSettingUuid") String almSettingUuid);
List<ProjectAlmSettingDto> selectByAlmSettingAndSlugs(@Param("almSettingUuid") String almSettingUuid, @Param("slugs") List<String> slugs);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.audit.model;
-
-import org.apache.commons.lang.ObjectUtils;
-
-public class ProjectNewValue extends NewValue{
-
- private final String uuid;
- private String name;
- private String description;
- private Boolean isPrivate;
-
- public ProjectNewValue(String uuid, boolean isPrivate, String name, String description) {
- this.uuid = uuid;
- this.isPrivate = isPrivate;
- this.name = name;
- this.description = description;
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public String getDescription() {
- return description;
- }
-
- public boolean isPrivate() {
- return isPrivate;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("{");
- addField(sb, "\"projectUuid\": ", this.uuid, true);
- addField(sb, "\"description\": ", this.description, true);
- addField(sb, "\"name\": ", this.name, true);
- addField(sb, "\"isPrivate\": ", ObjectUtils.toString(this.isPrivate), false);
- endString(sb);
- return sb.toString();
- }
-}
* Delete all the permissions associated to a root component (project)
*/
public void deleteByRootComponentUuid(DbSession dbSession, ComponentDto component) {
- mapper(dbSession).deleteByRootComponentUuid(component.uuid());
+ int deletedRecords = mapper(dbSession).deleteByRootComponentUuid(component.uuid());
- if (auditPersister != null) {
+ if (deletedRecords > 0 && auditPersister != null) {
auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(null, null, null, component.uuid(), component.name(),
component.qualifier(), null));
}
public int deleteByRootComponentUuidAndGroupUuid(DbSession dbSession, @Nullable String groupUuid, ComponentDto component) {
int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(component.uuid(), groupUuid);
- if (auditPersister != null) {
+ if (deletedRecords > 0 && auditPersister != null) {
auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(null, groupUuid, "", component.uuid(), component.name(),
component.qualifier(), null));
}
public int deleteByRootComponentUuidForAnyOne(DbSession dbSession, ComponentDto component) {
int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(component.uuid(), null);
- if (auditPersister != null) {
+ if (deletedRecords > 0 && auditPersister != null) {
auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(null, null, null, component.uuid(),
component.name(), component.qualifier(), null));
}
public int deleteByRootComponentUuidAndPermission(DbSession dbSession, String permission, ComponentDto component) {
int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndPermission(component.uuid(), permission);
- if (auditPersister != null) {
+ if (deletedRecords > 0 && auditPersister != null) {
auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(permission, null, null, component.uuid(),
component.name(), component.qualifier(), null));
}
public void delete(DbSession dbSession, String permission,
@Nullable String groupUuid, @Nullable String groupName, @Nullable String rootComponentUuid, @Nullable ComponentDto componentDto) {
- mapper(dbSession).delete(permission, groupUuid, rootComponentUuid);
+ int deletedRecords = mapper(dbSession).delete(permission, groupUuid, rootComponentUuid);
- if (auditPersister != null) {
+ if (deletedRecords > 0 && auditPersister != null) {
String projectName = (componentDto != null) ? componentDto.name() : null;
String qualifier = (componentDto != null) ? componentDto.qualifier() : null;
auditPersister.deleteGroupPermission(dbSession, new PermissionNewValue(permission, groupUuid, groupName, rootComponentUuid,
void insert(GroupPermissionDto dto);
- void delete(@Param("permission") String permission, @Nullable @Param("groupUuid") String groupUuid, @Nullable @Param("rootComponentUuid") String rootComponentUuid);
+ int delete(@Param("permission") String permission, @Nullable @Param("groupUuid") String groupUuid, @Nullable @Param("rootComponentUuid") String rootComponentUuid);
List<String> selectGlobalPermissionsOfGroup(@Nullable @Param("groupUuid") String groupUuid);
*/
Set<String> selectGroupUuidsWithPermissionOnProjectBut(@Param("projectUuid") String projectUuid, @Param("role") String permission);
- void deleteByRootComponentUuid(@Param("rootComponentUuid") String rootComponentUuid);
+ int deleteByRootComponentUuid(@Param("rootComponentUuid") String rootComponentUuid);
int deleteByRootComponentUuidAndGroupUuid(@Param("rootComponentUuid") String rootComponentUuid, @Nullable @Param("groupUuid") String groupUuid);
* Removes a single global permission from user
*/
public void deleteGlobalPermission(DbSession dbSession, String userUuid, String permission) {
- mapper(dbSession).deleteGlobalPermission(userUuid, permission);
+ int deletedRows = mapper(dbSession).deleteGlobalPermission(userUuid, permission);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, null,
null, null, null, userUuid));
}
* Removes a single project permission from user
*/
public void deleteProjectPermission(DbSession dbSession, String userUuid, String permission, ComponentDto component) {
- mapper(dbSession).deleteProjectPermission(userUuid, permission, component.uuid());
+ int deletedRows = mapper(dbSession).deleteProjectPermission(userUuid, permission, component.uuid());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, null, component.uuid(),
component.name(), component.qualifier(), userUuid));
}
* Deletes all the permissions defined on a project
*/
public void deleteProjectPermissions(DbSession dbSession, ComponentDto component) {
- mapper(dbSession).deleteProjectPermissions(component.uuid());
+ int deletedRows = mapper(dbSession).deleteProjectPermissions(component.uuid());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(null, null, null, component.uuid(), component.name(),
component.qualifier(), null));
}
public int deleteProjectPermissionOfAnyUser(DbSession dbSession, String permission, ComponentDto project) {
int deletedRows = mapper(dbSession).deleteProjectPermissionOfAnyUser(project.uuid(), permission);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(permission, null, null, project.uuid(), project.name(),
project.qualifier(), null));
}
}
public void deleteByUserUuid(DbSession dbSession, String userUuid) {
- mapper(dbSession).deleteByUserUuid(userUuid);
+ int deletedRows = mapper(dbSession).deleteByUserUuid(userUuid);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserPermission(dbSession, new PermissionNewValue(null, null, null, null,
null, null, userUuid));
}
void insert(@Param("dto")UserPermissionDto dto);
- void deleteGlobalPermission(@Param("userUuid") String userUuid, @Param("permission") String permission);
+ int deleteGlobalPermission(@Param("userUuid") String userUuid, @Param("permission") String permission);
- void deleteProjectPermission(@Param("userUuid") String userUuid, @Param("permission") String permission,
+ int deleteProjectPermission(@Param("userUuid") String userUuid, @Param("permission") String permission,
@Param("projectUuid") String projectUuid);
- void deleteProjectPermissions(@Param("projectUuid") String projectUuid);
+ int deleteProjectPermissions(@Param("projectUuid") String projectUuid);
int deleteProjectPermissionOfAnyUser(@Param("projectUuid") String projectUuid, @Param("permission") String permission);
List<String> selectProjectPermissionsOfUser(@Param("userUuid") String userUuid, @Param("projectUuid") String projectUuid);
- void deleteByUserUuid(@Param("userUuid") String userUuid);
+ int deleteByUserUuid(@Param("userUuid") String userUuid);
}
mapper.deleteUserPermissionsByTemplateUuid(templateUuid);
mapper.deleteGroupPermissionsByTemplateUuid(templateUuid);
session.getMapper(PermissionTemplateCharacteristicMapper.class).deleteByTemplateUuid(templateUuid);
- mapper.deleteByUuid(templateUuid);
+ int deletedRows = mapper.deleteByUuid(templateUuid);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deletePermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName));
}
}
.setTemplateUuid(templateUuid)
.setPermission(permission)
.setUserUuid(userUuid);
- mapper(session).deleteUserPermission(permissionTemplateUser);
+ int deletedRows = mapper(session).deleteUserPermission(permissionTemplateUser);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserFromPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
permission, userUuid, userLogin, null, null));
}
}
public void deleteUserPermissionsByUserUuid(DbSession dbSession, String userUuid, String userLogin) {
- mapper(dbSession).deleteUserPermissionsByUserUuid(userUuid);
+ int deletedRows = mapper(dbSession).deleteUserPermissionsByUserUuid(userUuid);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserFromPermissionTemplate(dbSession, new PermissionTemplateNewValue(null, null,
null, userUuid, userLogin, null, null));
}
.setTemplateUuid(templateUuid)
.setPermission(permission)
.setGroupUuid(groupUuid);
- mapper(session).deleteGroupPermission(permissionTemplateGroup);
+ int deletedRows = mapper(session).deleteGroupPermission(permissionTemplateGroup);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplateGroup.getTemplateUuid(), templateName,
permissionTemplateGroup.getPermission(), null, null, permissionTemplateGroup.getGroupUuid(), groupName));
}
* Remove a group from all templates (used when removing a group)
*/
public void deleteByGroup(DbSession session, String groupUuid, String groupName) {
- session.getMapper(PermissionTemplateMapper.class).deleteByGroupUuid(groupUuid);
+ int deletedRows = session.getMapper(PermissionTemplateMapper.class).deleteByGroupUuid(groupUuid);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(null, null,
null, null, null, groupUuid, groupName));
}
void update(PermissionTemplateDto permissionTemplate);
- void deleteByUuid(String templateUuid);
+ int deleteByUuid(String templateUuid);
void deleteByUuids(@Param("templateUuids") List<String> templateUuids);
void deleteUserPermissionsByTemplateUuids(@Param("templateUuids") List<String> templateUuids);
- void deleteUserPermissionsByUserUuid(@Param("userUuid") String userUuid);
+ int deleteUserPermissionsByUserUuid(@Param("userUuid") String userUuid);
- void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser);
+ int deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser);
void deleteGroupPermissionsByTemplateUuid(String templateUuid);
void deleteGroupPermissionsByTemplateUuids(@Param("templateUuids") List<String> templateUuids);
- void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
+ int deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
PermissionTemplateDto selectByUuid(String templateUuid);
void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
- void deleteByGroupUuid(String groupUuid);
+ int deleteByGroupUuid(String groupUuid);
PermissionTemplateDto selectByName(@Param("name") String name);
return mapper(session).selectByUuids(uuids);
}
- public void updateVisibility(DbSession session, String uuid, boolean isPrivate, String qualifier, String name) {
+ public void updateVisibility(DbSession session, String uuid, boolean isPrivate) {
mapper(session).updateVisibility(uuid, isPrivate, system2.now());
}
public int deleteByQuery(DbSession dbSession, PropertyQuery query) {
int deletedRows = getMapper(dbSession).deleteByQuery(query);
- if (auditPersister != null && query.key() != null && auditPersister.isTrackedProperty(query.key())) {
+ if (deletedRows > 0 && auditPersister != null && query.key() != null && auditPersister.isTrackedProperty(query.key())) {
auditPersister.deleteProperty(dbSession, new PropertyNewValue(query.key(), query.componentUuid(),
null, null, query.userUuid()), false);
}
public int delete(DbSession dbSession, PropertyDto dto, @Nullable String userLogin, @Nullable String projectName, @Nullable String qualifier) {
int deletedRows = getMapper(dbSession).delete(dto.getKey(), dto.getUserUuid(), dto.getComponentUuid());
- if (auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) {
+ if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) {
auditPersister.deleteProperty(dbSession, new PropertyNewValue(dto, userLogin, projectName, qualifier), false);
}
return deletedRows;
}
public void deleteProjectProperty(DbSession session, String key, String projectUuid, String projectName, String qualifier) {
- getMapper(session).deleteProjectProperty(key, projectUuid);
+ int deletedRows = getMapper(session).deleteProjectProperty(key, projectUuid);
- if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) {
auditPersister.deleteProperty(session, new PropertyNewValue(key, projectUuid, projectName, qualifier,
null), false);
}
}
public void deleteProjectProperties(String key, String value, DbSession session) {
- getMapper(session).deleteProjectProperties(key, value);
+ int deletedRows = getMapper(session).deleteProjectProperties(key, value);
- if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) {
auditPersister.deleteProperty(session, new PropertyNewValue(key, value), false);
}
}
}
public void deleteGlobalProperty(String key, DbSession session) {
- getMapper(session).deleteGlobalProperty(key);
+ int deletedRows = getMapper(session).deleteGlobalProperty(key);
- if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) {
auditPersister.deleteProperty(session, new PropertyNewValue(key), false);
}
}
}
public void deleteByKeyAndValue(DbSession dbSession, String key, String value) {
- getMapper(dbSession).deleteByKeyAndValue(key, value);
+ int deletedRows = getMapper(dbSession).deleteByKeyAndValue(key, value);
- if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) {
auditPersister.deleteProperty(dbSession, new PropertyNewValue(key, value), false);
}
}
}
private void persistDeletedProperties(DbSession dbSession, @Nullable String userUuid, String userLogin, List<String> uuids) {
- if (auditPersister != null) {
+ if (!uuids.isEmpty() && auditPersister != null) {
List<PropertyDto> properties = executeLargeInputs(uuids, subList -> getMapper(dbSession).selectByUuids(subList));
properties
void deleteByUuids(@Param("uuids") List<String> uuids);
- void deleteByKeyAndValue(@Param("key") String key, @Param("value") String value);
+ int deleteByKeyAndValue(@Param("key") String key, @Param("value") String value);
List<PropertyDto> selectByUuids(@Param("uuids") List<String> uuids);
}
public void deleteByUuid(DbSession dbSession, String groupUuid, String groupName) {
- mapper(dbSession).deleteByUuid(groupUuid);
+ int deletedRows = mapper(dbSession).deleteByUuid(groupUuid);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserGroup(dbSession, new UserGroupNewValue(groupUuid, groupName));
}
}
int countByQuery(@Nullable @Param("query") String query);
- void deleteByUuid(String groupUuid);
+ int deleteByUuid(String groupUuid);
@CheckForNull
GroupDto selectByName(@Param("name") String name);
}
public void delete(DbSession session, GroupDto group, UserDto user) {
- mapper(session).delete(group.getUuid(), user.getUuid());
+ int deletedRows = mapper(session).delete(group.getUuid(), user.getUuid());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserFromGroup(session, new UserGroupNewValue(group, user));
}
}
public void deleteByGroupUuid(DbSession session, String groupUuid, String groupName) {
- mapper(session).deleteByGroupUuid(groupUuid);
+ int deletedRows = mapper(session).deleteByGroupUuid(groupUuid);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserFromGroup(session, new UserGroupNewValue(groupUuid, groupName));
}
}
public void deleteByUserUuid(DbSession dbSession, UserDto userDto) {
- mapper(dbSession).deleteByUserUuid(userDto.getUuid());
+ int deletedRows = mapper(dbSession).deleteByUserUuid(userDto.getUuid());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserFromGroup(dbSession, new UserGroupNewValue(userDto));
}
}
Set<String> selectUserUuidsInGroup(@Param("groupUuid") String groupUuid);
- void delete(@Param("groupUuid") String groupUuid, @Param("userUuid") String userUuid);
+ int delete(@Param("groupUuid") String groupUuid, @Param("userUuid") String userUuid);
- void deleteByGroupUuid(@Param("groupUuid") String groupUuid);
+ int deleteByGroupUuid(@Param("groupUuid") String groupUuid);
- void deleteByUserUuid(@Param("userUuid") String userUuid);
+ int deleteByUserUuid(@Param("userUuid") String userUuid);
}
public void deleteByUser(DbSession session, UserDto user) {
List<UserPropertyDto> userProperties = selectByUser(session, user);
- mapper(session).deleteByUserUuid(user.getUuid());
+ int deletedRows = mapper(session).deleteByUserUuid(user.getUuid());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
userProperties.stream()
.filter(p -> auditPersister.isTrackedProperty(p.getKey()))
.forEach(p -> auditPersister.deleteProperty(session, new PropertyNewValue(p, user.getLogin()), true));
int update(@Param("userProperty") UserPropertyDto userPropertyDto, @Param("now") long now);
- void deleteByUserUuid(@Param("userUuid") String userUuid);
+ int deleteByUserUuid(@Param("userUuid") String userUuid);
}
}
public void deleteByUser(DbSession dbSession, UserDto user) {
- mapper(dbSession).deleteByUserUuid(user.getUuid());
+ int deletedRows = mapper(dbSession).deleteByUserUuid(user.getUuid());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserToken(dbSession, new UserTokenNewValue(user));
}
}
public void deleteByUserAndName(DbSession dbSession, UserDto user, String name) {
- mapper(dbSession).deleteByUserUuidAndName(user.getUuid(), name);
+ int deletedRows = mapper(dbSession).deleteByUserUuidAndName(user.getUuid(), name);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteUserToken(dbSession, new UserTokenNewValue(user, name));
}
}
List<UserTokenDto> selectByUserUuid(String userUuid);
- void deleteByUserUuid(String userUuid);
+ int deleteByUserUuid(String userUuid);
- void deleteByUserUuidAndName(@Param("userUuid") String userUuid, @Param("name") String name);
+ int deleteByUserUuidAndName(@Param("userUuid") String userUuid, @Param("name") String name);
List<UserTokenCount> countTokensByUserUuids(@Param("userUuids") List<String> userUuids);
}
}
public void delete(DbSession dbSession, String uuid, String webhookName) {
- mapper(dbSession).delete(uuid);
+ int deletedRows = mapper(dbSession).delete(uuid);
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteWebhook(dbSession, new WebhookNewValue(uuid, webhookName));
}
}
public void deleteByProject(DbSession dbSession, ProjectDto projectDto) {
- mapper(dbSession).deleteForProjectUuid(projectDto.getUuid());
+ int deletedRows = mapper(dbSession).deleteForProjectUuid(projectDto.getUuid());
- if (auditPersister != null) {
+ if (deletedRows > 0 && auditPersister != null) {
auditPersister.deleteWebhook(dbSession, new WebhookNewValue(projectDto));
}
}
void update(WebhookDto dto);
- void delete(@Param("uuid") String uuid);
+ int delete(@Param("uuid") String uuid);
- void deleteForProjectUuid(@Param("projectUuid") String projectUuid);
+ int deleteForProjectUuid(@Param("projectUuid") String projectUuid);
}
import org.sonar.db.user.UserDto;
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.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto;
assertThat(newValue.toString()).doesNotContain("userLogin");
}
+ @Test
+ public void deleteWithoutAffectedRowsIsNotPersisted() {
+ AlmPatDto almPat = newAlmPatDto();
+
+ underTest.delete(dbSession, almPat, null, null);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteByUserIsPersisted() {
when(uuidFactory.create()).thenReturn(A_UUID);
assertThat(newValue.toString()).doesNotContain("patUuid");
}
+ @Test
+ public void deleteByUserWithoutAffectedRowsIsNotPersisted() {
+ UserDto userDto = db.users().insertUser();
+
+ underTest.deleteByUser(dbSession, userDto);
+
+ verify(auditPersister).addUser(any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
@Test
public void deleteByAlmSettingIsPersisted() {
when(uuidFactory.create()).thenReturn(A_UUID);
assertThat(newValue.toString()).doesNotContain("userUuid");
}
+ @Test
+ public void deleteByAlmSettingWithoutAffectedRowsIsNotPersisted() {
+ AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
+
+ underTest.deleteByAlmSetting(dbSession, almSettingDto);
+
+ verifyNoInteractions(auditPersister);
+ }
+
}
import org.sonar.db.project.ProjectDto;
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.verify;
import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubProjectAlmSettingDto;
}
@Test
- public void deleteByProject() {
+ public void deleteByProjectIsPersisted() {
when(uuidFactory.create()).thenReturn(A_UUID);
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
ProjectDto project = db.components().insertPrivateProjectDto();
}
@Test
- public void deleteByAlmSettingNotTracked() {
+ public void deleteByWithoutAffectedRowsProjectIsNotPersisted() {
+ ProjectDto project = db.components().insertPrivateProjectDto();
+
+ underTest.deleteByProject(dbSession, project);
+
+ verify(auditPersister).addComponent(any(), any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ @Test
+ public void deleteByAlmSettingNotTrackedIsNotPersisted() {
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
underTest.deleteByAlmSetting(dbSession, githubAlmSetting);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.audit.model;
-
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ProjectNewValueTest {
-
- @Test
- public void toString_generatesValidJson() throws ParseException {
- ProjectNewValue newValue = new ProjectNewValue("uuid", true, "name", "description");
-
- JSONObject jsonObject = (JSONObject) new JSONParser().parse(newValue.toString());
-
- assertThat(jsonObject.size()).isEqualTo(4);
- }
-
-}
import org.sonar.db.user.GroupDto;
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.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.sonar.api.web.UserRole.ADMIN;
public class GroupPermissionDaoWithPersisterTest {
assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
+ @Test
+ public void groupGlobalPermissionDeleteWithoutAffectedRowsIsNotPersisted() {
+ underTest.delete(dbSession, ADMIN, "group-uuid", "group-name", null, null);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void groupProjectPermissionDeleteByComponentIsPersisted() {
GroupDto group = db.users().insertGroup();
assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
+ @Test
+ public void groupProjectPermissionDeleteByComponentWithoutAffectedRowsIsNotPersisted() {
+ ComponentDto project = db.components().insertPrivateProject();
+
+ underTest.deleteByRootComponentUuid(dbSession, project);
+
+ verify(auditPersister).addComponent(any(), any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
@Test
public void groupProjectPermissionDeleteByComponentAndGroupIsPersisted() {
GroupDto group = db.users().insertGroup();
ComponentDto project = db.components().insertPrivateProject();
- GroupPermissionDto dto = getGroupPermission(group, project);
+ GroupPermissionDto dto = getGroupPermission(project);
underTest.insert(dbSession, dto, project);
verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
.extracting(PermissionNewValue::getPermissionUuid, PermissionNewValue::getGroupUuid,
PermissionNewValue::getGroupName, PermissionNewValue::getComponentUuid,
PermissionNewValue::getRole, PermissionNewValue::getComponentName, PermissionNewValue::getQualifier)
- .containsExactly(dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.name(), "project");
+ .containsExactly(dto.getUuid(), null, null, project.uuid(), dto.getRole(), project.name(), "project");
assertThat(newValue.toString()).contains("componentUuid");
underTest.deleteByRootComponentUuidForAnyOne(dbSession, project);
assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
+ @Test
+ public void groupProjectPermissionDeleteByComponentAndGroupWithoutAffectedRowsIsNotPersisted() {
+ ComponentDto project = db.components().insertPrivateProject();
+
+ underTest.deleteByRootComponentUuidForAnyOne(dbSession, project);
+
+ verify(auditPersister).addComponent(any(), any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
@Test
public void groupProjectPermissionDeleteByComponentAndPermissionIsPersisted() {
GroupDto group = db.users().insertGroup();
assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
+ @Test
+ public void groupProjectPermissionDeleteByComponentAndPermissionWithoutAffectedRowsIsNotPersisted() {
+ GroupDto group = db.users().insertGroup();
+ ComponentDto project = db.components().insertPrivateProject();
+ GroupPermissionDto dto = getGroupPermission(group, project);
+
+ underTest.deleteByRootComponentUuidAndPermission(dbSession, dto.getRole(), project);
+
+ verify(auditPersister).addComponent(any(), any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
private GroupPermissionDto getGroupPermission(GroupDto group, ComponentDto project) {
return new GroupPermissionDto()
.setUuid(Uuids.createFast())
.setComponentUuid(project.uuid())
.setComponentName(project.name());
}
+
+ private GroupPermissionDto getGroupPermission(ComponentDto project) {
+ return new GroupPermissionDto()
+ .setUuid(Uuids.createFast())
+ .setRole(ADMIN)
+ .setComponentUuid(project.uuid())
+ .setComponentName(project.name());
+ }
}
import org.sonar.db.user.UserDto;
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.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;
assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
+ @Test
+ public void userGlobalPermissionDeleteWithoutAffectedRowsIsNotPersisted() {
+ UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+
+ underTest.deleteGlobalPermission(dbSession, user.getUuid(), SYSTEM_ADMIN);
+
+ verify(auditPersister).addUser(any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
@Test
public void userProjectPermissionInsertAndDeleteArePersisted() {
UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
.doesNotContain("permissionUuid");
}
+ @Test
+ public void userProjectPermissionDeleteWithoutAffectedRowsIsNotPersisted() {
+ UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+ ComponentDto project = db.components().insertPrivateProject();
+
+ underTest.deleteProjectPermission(dbSession, user.getUuid(), SYSTEM_ADMIN, project);
+
+ verify(auditPersister).addUser(any(), any());
+ verify(auditPersister).addComponent(any(), any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
@Test
public void userPortfolioPermissionIsPersisted() {
UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
assertThat(newValue.toString()).doesNotContain("userUuid");
}
+ @Test
+ public void deleteUserPermissionOfAnyUserWithoutAffectedRowsIsNotPersisted() {
+ ComponentDto project = db.components().insertPrivateProject();
+
+ underTest.deleteProjectPermissionOfAnyUser(dbSession, SCAN_EXECUTION, project);
+
+ verify(auditPersister).addComponent(any(), any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
@Test
public void deleteUserPermissionByUserUuidIsPersisted() {
UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
assertThat(newValue.toString()).contains("userUuid");
}
+ @Test
+ public void deleteUserPermissionByUserUuidWithoutAffectedRowsIsNotPersisted() {
+ UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
+
+ underTest.deleteByUserUuid(dbSession, user.getUuid());
+
+ verify(auditPersister).addUser(any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
private UserDto insertUser(Consumer<UserDto> populateUserDto) {
UserDto user = db.users().insertUser(populateUserDto);
return user;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
import static org.sonar.db.user.GroupTesting.newGroupDto;
assertThat(newValue.toString()).doesNotContain("keyPattern");
}
+ @Test
+ public void deletePermissionTemplateWithoutAffectedRowsIsPersisted() {
+ underTest.deleteByUuid(session, "template-uuid", "template-name");
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void insertAndDeleteUserPermissionToTemplateIsPersisted() {
PermissionTemplateDto dto = insertPermissionTemplate();
assertThat(newValue.toString()).doesNotContain("groupUuid");
}
+ @Test
+ public void deleteUserPermissionToTemplateWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteUserPermission(session, "template-uuid", "user-uuid", ADMIN,
+ "template-name", "user-login");
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void insertAndDeleteUserPermissionByUserUuidToTemplateIsPersisted() {
PermissionTemplateDto dto = insertPermissionTemplate();
assertThat(newValue.toString()).doesNotContain("groupUuid");
}
+ @Test
+ public void deleteUserPermissionByUserUuidToTemplateWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteUserPermissionsByUserUuid(session, "user-uuid", "user-login");
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void insertAndDeleteGroupPermissionToTemplateIsPersisted() {
PermissionTemplateDto dto = insertPermissionTemplate();
assertThat(newValue.toString()).contains("groupUuid");
}
+ @Test
+ public void deleteGroupPermissionToTemplateWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteGroupPermission(session, "template-uuid", "group-uuid", ADMIN,
+ "template-name", "group-name");
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void insertAndDeleteGroupPermissionByGroupUuidToTemplateIsPersisted() {
PermissionTemplateDto templateDto = insertPermissionTemplate();
PermissionTemplateGroupDto templateGroupDto = new PermissionTemplateGroupDto()
.setUuid(Uuids.createFast())
.setGroupName("group")
+ .setGroupUuid("group-id")
.setPermission(ADMIN)
.setTemplateUuid(templateDto.getUuid())
.setCreatedAt(new Date())
assertThat(newValue.toString()).doesNotContain("userUuid");
}
+ @Test
+ public void deleteGroupPermissionByGroupUuidToTemplateWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteByGroup(session, "group-uid", "group-name");
+
+ verifyNoInteractions(auditPersister);
+ }
+
private PermissionTemplateDto insertPermissionTemplate() {
return underTest.insert(session, newPermissionTemplateDto()
.setUuid("ABCD")
*/
package org.sonar.db.project;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.ArgumentMatchers.any;
-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.mockito.Mockito.verifyNoInteractions;
-import javax.annotation.Nullable;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
public class ProjectDaoTest {
assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", true);
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false);
- projectDao.updateVisibility(db.getSession(), dto1.getUuid(), false, Qualifiers.PROJECT, dto1.getName());
- projectDao.updateVisibility(db.getSession(), dto2.getUuid(), true, Qualifiers.PROJECT, dto2.getName());
+ projectDao.updateVisibility(db.getSession(), dto1.getUuid(), false);
+ projectDao.updateVisibility(db.getSession(), dto2.getUuid(), true);
projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
assertThat(projectsByUuids).hasSize(2);
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public void saveProjectTrackedPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
- PropertyDto propertyDto = getPropertyDto(KEY);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
verify(auditPersister).isTrackedProperty(KEY);
public void saveApplicationTrackedPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
- PropertyDto propertyDto = getPropertyDto(KEY);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
underTest.saveProperty(session, propertyDto, USER_LOGIN, "app-name", Qualifiers.APP);
verify(auditPersister).isTrackedProperty(KEY);
public void savePortfolioTrackedPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
- PropertyDto propertyDto = getPropertyDto(KEY);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
underTest.saveProperty(session, propertyDto, USER_LOGIN, "portfolio-name", Qualifiers.VIEW);
verify(auditPersister).isTrackedProperty(KEY);
public void saveProjectTrackedAndSecuredPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true);
- PropertyDto propertyDto = getPropertyDto(SECURED_KEY);
+ PropertyDto propertyDto = getPropertyDto(SECURED_KEY, PROJECT_UUID, USER_UUID);
underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
verify(auditPersister).isTrackedProperty(SECURED_KEY);
@Test
public void deleteTrackedPropertyByQueryIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
-
PropertyQuery query = getPropertyQuery(KEY);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
+
underTest.deleteByQuery(session, query);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
assertThat(newValue.toString()).doesNotContain("userLogin");
}
+ @Test
+ public void deleteTrackedPropertyByQueryWithoutAffectedRowsIsNotPersisted() {
+ PropertyQuery query = getPropertyQuery(KEY);
+
+ underTest.deleteByQuery(session, query);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteNotTrackedPropertyByQueryIsNotPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
-
PropertyQuery query = getPropertyQuery(KEY);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
+
underTest.deleteByQuery(session, query);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verifyNoMoreInteractions(auditPersister);
}
@Test
public void deleteTrackedPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null);
- PropertyDto propertyDto = getPropertyDto(KEY);
underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
assertThat(newValue.toString()).contains("userLogin");
}
+ @Test
+ public void deleteTrackedPropertyWithoutAffectedRowsIsNotPersisted() {
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
+
+ underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteNotTrackedPropertyIsNotPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
- PropertyDto propertyDto = getPropertyDto(KEY);
underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verifyNoMoreInteractions(auditPersister);
}
@Test
public void deleteTrackedProjectPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, null);
+ underTest.saveProperty(propertyDto);
+
underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_NAME, Qualifiers.PROJECT);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
assertThat(newValue.toString()).doesNotContain("userLogin");
}
+ @Test
+ public void deleteTrackedProjectPropertyWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_NAME, Qualifiers.PROJECT);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteNotTrackedProjectPropertyIsNotPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
- PropertyDto propertyDto = getPropertyDto(KEY);
underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verifyNoMoreInteractions(auditPersister);
}
@Test
public void deleteTrackedProjectPropertiesIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, null);
+ underTest.saveProperty(propertyDto);
underTest.deleteProjectProperties(KEY, VALUE);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
assertThat(newValue.toString()).doesNotContain("projectUuid");
}
+ @Test
+ public void deleteTrackedProjectPropertiesWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteProjectProperties(KEY, VALUE);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteNotTrackedProjectPropertiesIsNotPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+ PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, null);
+ underTest.saveProperty(propertyDto);
underTest.deleteProjectProperties(KEY, VALUE);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verifyNoMoreInteractions(auditPersister);
}
@Test
public void deleteTrackedGlobalPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+ PropertyDto propertyDto = getPropertyDto(KEY, null, null);
+ underTest.saveProperty(session, propertyDto, null, null, null);
underTest.deleteGlobalProperty(KEY, session);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
assertThat(newValue.toString()).doesNotContain("projectUuid");
}
+ @Test
+ public void deleteTrackedGlobalPropertyWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteGlobalProperty(KEY, session);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteNotTrackedGlobalPropertyIsNotPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+ PropertyDto propertyDto = getPropertyDto(KEY, null, null);
+ underTest.saveProperty(session, propertyDto, null, null, null);
underTest.deleteGlobalProperty(KEY, session);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verifyNoMoreInteractions(auditPersister);
}
assertThat(newValues.get(1).toString()).doesNotContain("value");
}
+ @Test
+ public void deletePropertyByUserWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteByUser(session, USER_UUID, USER_LOGIN);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deletePropertyByUserLoginIsPersisted() {
UserDto user = setUserProperties(null);
assertThat(newValues.get(1).toString()).doesNotContain("value");
}
+ @Test
+ public void deletePropertyByUserLoginWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteByMatchingLogin(session, USER_LOGIN, newArrayList(KEY, ANOTHER_KEY, SECURED_KEY));
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteTrackedPropertyByKeyAndValueIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
+ PropertyDto propertyDto = getPropertyDto(KEY, null, USER_UUID);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null);
underTest.deleteByKeyAndValue(session, KEY, VALUE);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
assertThat(newValue.toString()).doesNotContain("projectUuid");
}
+ @Test
+ public void deleteTrackedPropertyByKeyAndValueWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteByKeyAndValue(session, KEY, VALUE);
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteNotTrackedPropertyByKeyAndValueIsNotPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
+ PropertyDto propertyDto = getPropertyDto(KEY, null, USER_UUID);
+ underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null);
underTest.deleteByKeyAndValue(session, KEY, VALUE);
- verify(auditPersister).isTrackedProperty(KEY);
+ verify(auditPersister, times(2)).isTrackedProperty(KEY);
verifyNoMoreInteractions(auditPersister);
}
- private PropertyDto getPropertyDto(String key) {
+ private PropertyDto getPropertyDto(String key, @Nullable String projectUuid, @Nullable String userUuid) {
return new PropertyDto()
.setKey(key)
.setValue(VALUE)
- .setUserUuid(USER_UUID)
- .setComponentUuid(PROJECT_UUID);
+ .setUserUuid(userUuid)
+ .setComponentUuid(projectUuid);
}
private PropertyQuery getPropertyQuery(String key) {
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
public class GroupDaoWithPersisterTest {
.extracting(UserGroupNewValue::getGroupUuid, UserGroupNewValue::getName)
.containsExactly(aGroup.getUuid(), aGroup.getName());
}
+
+ @Test
+ public void deleteGroupWithoutAffectedRowsIsNotPersisted() {
+ underTest.deleteByUuid(db.getSession(), aGroup.getUuid(), aGroup.getName());
+
+ verifyNoInteractions(auditPersister);
+ }
}
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
public class UserGroupDaoWithPersisterTest {
private final AuditPersister auditPersister = mock(AuditPersister.class);
.containsExactly(group1.getUuid(), group1.getName());
}
+ @Test
+ public void deleteUserGroupByGroupWithoutAffectedRowsIsNotPersisted() {
+ GroupDto group1 = db.users().insertGroup();
+ underTest.deleteByGroupUuid(db.getSession(), group1.getUuid(), group1.getName());
+ db.getSession().commit();
+
+ verifyNoInteractions(auditPersister);
+ }
+
@Test
public void deleteUserGroupByUserIsPersisted() {
UserDto user1 = db.users().insertUser();
.containsExactly(user1.getUuid(), user1.getLogin());
}
+ @Test
+ public void deleteUserGroupByUserWithoutAffectedRowsIsNotPersisted() {
+ UserDto user1 = db.users().insertUser();
+ underTest.deleteByUserUuid(db.getSession(), user1);
+ db.getSession().commit();
+
+ verify(auditPersister).addUser(any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
@Test
public void delete_by_user_and_group() {
UserDto user1 = db.users().insertUser();
.extracting(UserGroupNewValue::getGroupUuid, UserGroupNewValue::getName, UserGroupNewValue::getUserUuid, UserGroupNewValue::getUserLogin)
.containsExactly(group1.getUuid(), group1.getName(), user1.getUuid(), user1.getLogin());
}
+
+ @Test
+ public void deletByUserAndGroupWithoutAffectedRowsIsNotPersisted() {
+ UserDto user1 = db.users().insertUser();
+ GroupDto group1 = db.users().insertGroup();
+ underTest.delete(db.getSession(), group1, user1);
+ db.getSession().commit();
+
+ verify(auditPersister).addUser(any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
}
PropertyNewValue::getUserLogin)
.containsExactly(userSetting.getKey(), userSetting.getValue(), user.getUuid(), user.getLogin());
}
+
+ @Test
+ public void deleteTrackedUserPropertyWithoutAffectedRowsIsNotPersisted() {
+ UserDto user = db.users().insertUser();
+
+ underTest.deleteByUser(db.getSession(), user);
+
+ verify(auditPersister).addUser(eq(db.getSession()), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
}
import org.sonar.db.audit.model.UserTokenNewValue;
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.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.sonar.db.user.UserTokenTesting.newUserToken;
public class UserTokenDaoWithPersisterTest {
private final UserTokenDao underTest = dbClient.userTokenDao();
@Test
- public void insert_token() {
+ public void insert_token_is_persisted() {
UserTokenDto userToken = newUserToken();
underTest.insert(db.getSession(), userToken, "login");
}
@Test
- public void update_token() {
+ public void update_token_is_persisted() {
UserDto user1 = db.users().insertUser();
UserTokenDto userToken1 = db.users().insertToken(user1);
}
@Test
- public void delete_tokens_by_user() {
+ public void delete_tokens_by_user_is_persisted() {
UserDto user1 = db.users().insertUser();
UserDto user2 = db.users().insertUser();
db.users().insertToken(user1);
}
@Test
- public void delete_token_by_user_and_name() {
+ public void delete_tokens_by_user_without_affected_rows_is_not_persisted() {
+ UserDto user1 = db.users().insertUser();
+
+ underTest.deleteByUser(dbSession, user1);
+
+ verify(auditPersister).addUser(any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
+ @Test
+ public void delete_token_by_user_and_name_is_persisted() {
UserDto user1 = db.users().insertUser();
UserDto user2 = db.users().insertUser();
db.users().insertToken(user1, t -> t.setName("name"));
.extracting(UserTokenNewValue::getUserUuid, UserTokenNewValue::getUserLogin, UserTokenNewValue::getTokenName)
.containsExactly(user1.getUuid(), user1.getLogin(), "name");
}
+
+ @Test
+ public void delete_token_by_user_and_name_without_affected_rows_is_persisted() {
+ UserDto user1 = db.users().insertUser();
+
+ underTest.deleteByUserAndName(dbSession, user1, "name");
+
+ verify(auditPersister).addUser(any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
}
import org.sonar.db.project.ProjectDto;
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.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
public class WebhookDaoWithPersisterTest {
private final AuditPersister auditPersister = mock(AuditPersister.class);
assertThat(newValue).hasToString("{\"projectUuid\": \"puuid\", \"projectName\": \"pname\" }");
}
+ @Test
+ public void deleteProjectWebhooksWithoutAffectedRowsIsNotPersisted() {
+ ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(p -> p.setUuid("puuid").setName("pname"));
+
+ underTest.deleteByProject(dbSession, projectDto);
+
+ verify(auditPersister).addComponent(any(), any(), any());
+ verifyNoMoreInteractions(auditPersister);
+ }
+
@Test
public void deleteWebhookIsPersisted() {
WebhookDto dto = webhookDbTester.insertGlobalWebhook();
.containsExactly(dto.getUuid(), dto.getName());
assertThat(newValue).hasToString("{\"webhookUuid\": \"" + dto.getUuid() + "\", \"name\": \"" + dto.getName() + "\" }");
}
+
+ @Test
+ public void deleteWebhookWithoutAffectedRowsIsNotPersisted() {
+ underTest.delete(dbSession, "webhook-uuid", "webhook-name");
+
+ verifyNoMoreInteractions(auditPersister);
+ }
}
package org.sonar.server.project.ws;
import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import org.sonar.api.config.Configuration;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.Request;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_VISIBILITY;
-import java.util.Set;
public class UpdateVisibilityAction implements ProjectsWsAction {
private static final Set<String> AUTHORIZED_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.APP);
dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.qualifier(), component.name());
if (component.qualifier().equals(Qualifiers.PROJECT) || component.qualifier().equals(Qualifiers.APP)) {
- dbClient.projectDao().updateVisibility(dbSession, uuid, isPrivate, component.qualifier(), component.name());
+ dbClient.projectDao().updateVisibility(dbSession, uuid, isPrivate);
}
ComponentMapper mapper = dbSession.getMapper(ComponentMapper.class);