Browse Source

SONAR-8957 Move deletion of user properties from UserDao to DeactivateAction

tags/6.4-RC1
Julien Lancelot 7 years ago
parent
commit
314e8b5af8

+ 0
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java View File

@@ -119,7 +119,6 @@ public class UserDao implements Dao {
return false;
}

mapper.deleteUserProperties(dto.getId());
mapper.deleteUserRoles(dto.getId());
mapper.deletePropertiesMatchingLogin(singletonList(DEFAULT_ISSUE_ASSIGNEE), dto.getLogin());
mapper.deleteOrganisationMembership(dto.getId());

+ 0
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java View File

@@ -64,8 +64,6 @@ public interface UserMapper {

void setRoot(@Param("login") String login, @Param("root") boolean root, @Param("now") long now);

void deleteUserProperties(int userId);

void deleteUserRoles(int userId);

void deletePropertiesMatchingLogin(@Param("propertyKeys") List<String> propertyKeys, @Param("login") String login);

+ 4
- 4
server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml View File

@@ -170,10 +170,10 @@
properties p
<where>
<if test="query.key() != null">
and p.prop_key=#{query.key}
and p.prop_key=#{query.key,jdbcType=VARCHAR}
</if>
<if test="query.componentId() != null">
and p.resource_id=#{query.componentId}
and p.resource_id=#{query.componentId,jdbcType=BIGINT}
</if>
<if test="query.userId() != null">
and p.user_id=#{query.userId,jdbcType=INTEGER}
@@ -332,10 +332,10 @@
delete from properties
<where>
<if test="query.key() != null">
and prop_key=#{query.key}
and prop_key=#{query.key,jdbcType=VARCHAR}
</if>
<if test="query.componentId() != null">
and resource_id=#{query.componentId}
and resource_id=#{query.componentId,jdbcType=BIGINT}
</if>
<if test="query.userId() != null">
and user_id=#{query.userId,jdbcType=INTEGER}

+ 0
- 4
server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml View File

@@ -119,10 +119,6 @@
DELETE FROM user_roles WHERE user_id=#{id,jdbcType=INTEGER}
</delete>

<delete id="deleteUserProperties" parameterType="int">
DELETE FROM properties WHERE user_id=#{id,jdbcType=BIGINT}
</delete>

<delete id="deletePropertiesMatchingLogin" parameterType="String">
DELETE FROM properties
<where>

+ 0
- 8
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java View File

@@ -391,7 +391,6 @@ public class UserDaoTest {
@Test
public void deactivate_user() throws Exception {
UserDto user = newActiveUser();
PropertyDto property = insertProperty(user);
db.users().insertPermissionOnUser(user, ADMINISTER);
insertUserGroup(user);

@@ -415,7 +414,6 @@ public class UserDaoTest {

assertThat(underTest.selectUserById(session, otherUser.getId())).isNotNull();

assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setKey(property.getKey()).build(), session)).isEmpty();
assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(session, user.getId(), db.getDefaultOrganization().getUuid())).isEmpty();
assertThat(dbClient.groupMembershipDao().countGroups(session, builder().organizationUuid(db.getDefaultOrganization().getUuid()).membership(IN).build(), user.getId())).isZero();
}
@@ -623,12 +621,6 @@ public class UserDaoTest {
return dto;
}

private PropertyDto insertProperty(UserDto user) {
PropertyDto dto = new PropertyDto().setKey(randomAlphanumeric(100)).setUserId(user.getId());
dbClient.propertiesDao().saveProperty(session, dto);
return dto;
}

private PropertyDto insertProperty(String key, String value, long componentId) {
PropertyDto dto = new PropertyDto().setKey(key).setValue(value).setResourceId(componentId);
dbClient.propertiesDao().saveProperty(session, dto);

+ 2
- 0
server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java View File

@@ -33,6 +33,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.property.PropertyQuery;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.organization.DefaultOrganizationProvider;
@@ -93,6 +94,7 @@ public class DeactivateAction implements UsersWsAction {

dbClient.userTokenDao().deleteByLogin(dbSession, login);
dbClient.userGroupDao().deleteByUserId(dbSession, user.getId());
dbClient.propertiesDao().deleteByQuery(dbSession, PropertyQuery.builder().setUserId(user.getId()).build());
dbClient.userDao().deactivateUserByLogin(dbSession, login);
dbSession.commit();
}

+ 4
- 0
server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java View File

@@ -29,6 +29,7 @@ import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
@@ -128,12 +129,15 @@ public class DeactivateActionTest {
public void deactivate_user_deletes_his_properties() {
logInAsSystemAdministrator();
UserDto user = insertUser(newUserDto());
ComponentDto project = db.components().insertProject();
db.properties().insertProperty(newUserPropertyDto(user));
db.properties().insertProperty(newUserPropertyDto(user));
db.properties().insertProperty(newUserPropertyDto(user).setResourceId(project.getId()));

deactivate(user.getLogin()).getInput();

assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession)).isEmpty();
assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentId(project.getId()).build(), dbSession)).isEmpty();
}

@Test

Loading…
Cancel
Save