diff options
6 files changed, 10 insertions, 103 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java index f8b1b12be31..6f93b86fade 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java @@ -136,10 +136,6 @@ public class UserDao implements Dao { mapper(dbSession).deactivateUser(user.getLogin(), system2.now()); } - public void deactivateSonarCloudUser(DbSession dbSession, UserDto user) { - mapper(dbSession).deactivateSonarCloudUser(user.getLogin(), system2.now()); - } - public void cleanHomepage(DbSession dbSession, OrganizationDto organization) { mapper(dbSession).clearHomepages("ORGANIZATION", organization.getUuid(), system2.now()); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java index d2a37a2b817..16e197b67ea 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java @@ -82,8 +82,6 @@ public interface UserMapper { void deactivateUser(@Param("login") String login, @Param("now") long now); - void deactivateSonarCloudUser(@Param("login") String login, @Param("now") long now); - void clearHomepages(@Param("homepageType") String type, @Param("homepageParameter") String value, @Param("now") long now); void clearHomepage(@Param("login") String login, @Param("now") long now); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml index d6c6c9b059f..82fd6784cda 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml @@ -189,14 +189,6 @@ login = #{login, jdbcType=VARCHAR} </update> - <update id="deactivateSonarCloudUser" parameterType="map"> - update users set - name = null, - <include refid="deactivateUserUpdatedFields"/> - where - login = #{login, jdbcType=VARCHAR} - </update> - <update id="clearHomepages" parameterType="map"> update users set homepage_type = null, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java index 08eb943f58f..4dd8cbd122c 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -458,35 +458,6 @@ public class UserDaoTest { } @Test - public void deactivate_sonarcloud_user() { - UserDto user = insertActiveUser(); - insertUserGroup(user); - UserDto otherUser = insertActiveUser(); - underTest.update(db.getSession(), user.setLastConnectionDate(10_000_000_000L)); - session.commit(); - - underTest.deactivateSonarCloudUser(session, user); - - UserDto userReloaded = underTest.selectUserById(session, user.getId()); - assertThat(userReloaded.isActive()).isFalse(); - assertThat(userReloaded.getName()).isNull(); - assertThat(userReloaded.getLogin()).isEqualTo(user.getLogin()); - assertThat(userReloaded.getExternalId()).isEqualTo(user.getExternalId()); - assertThat(userReloaded.getExternalLogin()).isEqualTo(user.getExternalLogin()); - assertThat(userReloaded.getExternalIdentityProvider()).isEqualTo(user.getExternalIdentityProvider()); - assertThat(userReloaded.getEmail()).isNull(); - assertThat(userReloaded.getScmAccounts()).isNull(); - assertThat(userReloaded.getSalt()).isNull(); - assertThat(userReloaded.getCryptedPassword()).isNull(); - assertThat(userReloaded.isRoot()).isFalse(); - assertThat(userReloaded.getUpdatedAt()).isEqualTo(NOW); - assertThat(userReloaded.getHomepageType()).isNull(); - assertThat(userReloaded.getHomepageParameter()).isNull(); - assertThat(userReloaded.getLastConnectionDate()).isNull(); - assertThat(underTest.selectUserById(session, otherUser.getId())).isNotNull(); - } - - @Test public void clean_users_homepage_when_deleting_organization() { UserDto userUnderTest = newUserDto().setHomepageType("ORGANIZATION").setHomepageParameter("dummy-organization-UUID"); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java index 2c0254899b1..3a5bbf967d4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java @@ -38,7 +38,6 @@ import org.sonar.db.organization.OrganizationHelper; import org.sonar.db.property.PropertyQuery; import org.sonar.db.user.UserDto; import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.user.UserSession; import org.sonar.server.user.index.UserIndexer; @@ -47,8 +46,8 @@ import static java.lang.String.format; import static java.util.Collections.singletonList; import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE; import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED; -import static org.sonar.server.exceptions.NotFoundException.checkFound; import static org.sonar.server.exceptions.BadRequestException.checkRequest; +import static org.sonar.server.exceptions.NotFoundException.checkFound; public class DeactivateAction implements UsersWsAction { @@ -61,16 +60,14 @@ public class DeactivateAction implements UsersWsAction { private final UserSession userSession; private final UserJsonWriter userWriter; private final DefaultOrganizationProvider defaultOrganizationProvider; - private final boolean isSonarCloud; public DeactivateAction(DbClient dbClient, UserIndexer userIndexer, UserSession userSession, UserJsonWriter userWriter, - DefaultOrganizationProvider defaultOrganizationProvider, Configuration configuration) { + DefaultOrganizationProvider defaultOrganizationProvider) { this.dbClient = dbClient; this.userIndexer = userIndexer; this.userSession = userSession; this.userWriter = userWriter; this.defaultOrganizationProvider = defaultOrganizationProvider; - this.isSonarCloud = configuration.getBoolean(SONARCLOUD_ENABLED.getKey()).orElse(false); } @Override @@ -92,16 +89,9 @@ public class DeactivateAction implements UsersWsAction { public void handle(Request request, Response response) throws Exception { String login; - if (isSonarCloud) { - login = request.mandatoryParam(PARAM_LOGIN); - if (!login.equals(userSession.getLogin()) && !userSession.checkLoggedIn().isSystemAdministrator()) { - throw new ForbiddenException("Insufficient privileges"); - } - } else { - userSession.checkLoggedIn().checkIsSystemAdministrator(); - login = request.mandatoryParam(PARAM_LOGIN); - checkRequest(!login.equals(userSession.getLogin()), "Self-deactivation is not possible"); - } + userSession.checkLoggedIn().checkIsSystemAdministrator(); + login = request.mandatoryParam(PARAM_LOGIN); + checkRequest(!login.equals(userSession.getLogin()), "Self-deactivation is not possible"); try (DbSession dbSession = dbClient.openSession(false)) { UserDto user = dbClient.userDao().selectByLogin(dbSession, login); @@ -130,11 +120,7 @@ public class DeactivateAction implements UsersWsAction { } private void deactivateUser(DbSession dbSession, UserDto user) { - if (isSonarCloud) { - dbClient.userDao().deactivateSonarCloudUser(dbSession, user); - } else { - dbClient.userDao().deactivateUser(dbSession, user); - } + dbClient.userDao().deactivateUser(dbSession, user); } private void writeResponse(Response response, String login) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index 04a29d08ae3..c2a5b06183a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -24,7 +24,6 @@ import javax.annotation.Nullable; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.config.internal.MapSettings; import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; import org.sonar.api.utils.System2; import org.sonar.db.DbClient; @@ -65,7 +64,6 @@ import static org.sonar.db.permission.OrganizationPermission.ADMINISTER; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; import static org.sonar.db.permission.OrganizationPermission.SCAN; import static org.sonar.db.property.PropertyTesting.newUserPropertyDto; -import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED; import static org.sonar.server.user.index.UserIndexDefinition.FIELD_ACTIVE; import static org.sonar.server.user.index.UserIndexDefinition.FIELD_UUID; import static org.sonar.test.JsonAssert.assertJson; @@ -90,9 +88,8 @@ public class DeactivateActionTest { private DbClient dbClient = db.getDbClient(); private UserIndexer userIndexer = new UserIndexer(dbClient, es.client()); private DbSession dbSession = db.getSession(); - private MapSettings settings = new MapSettings(); private WsActionTester ws = new WsActionTester(new DeactivateAction(dbClient, userIndexer, userSession, - new UserJsonWriter(userSession), defaultOrganizationProvider, settings.asConfig())); + new UserJsonWriter(userSession), defaultOrganizationProvider)); @Test public void deactivate_user_and_delete_his_related_data() { @@ -105,7 +102,7 @@ public class DeactivateActionTest { deactivate(user.getLogin()); - verifyThatUserIsDeactivated(user.getLogin(), false); + verifyThatUserIsDeactivated(user.getLogin()); assertThat(es.client().prepareSearch(UserIndexDefinition.TYPE_USER) .setQuery(boolQuery() .must(termQuery(FIELD_UUID, user.getUuid())) @@ -262,31 +259,6 @@ public class DeactivateActionTest { } @Test - public void user_can_deactivate_itself_on_sonarcloud() { - WsActionTester customWs = newSonarCloudWs(); - - UserDto user = db.users().insertUser(); - userSession.logIn(user.getLogin()); - - deactivate(customWs, user.getLogin()); - - verifyThatUserIsDeactivated(user.getLogin(), true); - } - - @Test - public void user_cannot_deactivate_another_user_on_sonarcloud() { - WsActionTester customWs = newSonarCloudWs(); - - UserDto user = db.users().insertUser(); - userSession.logIn(user.getLogin()); - - expectedException.expect(ForbiddenException.class); - expectedException.expectMessage("Insufficient privilege"); - - deactivate(customWs, "other user"); - } - - @Test public void user_cannot_deactivate_itself_on_sonarqube() { UserDto user = db.users().insertUser(); userSession.logIn(user.getLogin()).setSystemAdministrator(); @@ -391,7 +363,7 @@ public class DeactivateActionTest { deactivate(admin.getLogin()); - verifyThatUserIsDeactivated(admin.getLogin(), false); + verifyThatUserIsDeactivated(admin.getLogin()); verifyThatUserExists(anotherAdmin.getLogin()); } @@ -436,20 +408,12 @@ public class DeactivateActionTest { assertThat(db.users().selectUserByLogin(login)).isPresent(); } - private void verifyThatUserIsDeactivated(String login, boolean isSonarCloud) { + private void verifyThatUserIsDeactivated(String login) { Optional<UserDto> user = db.users().selectUserByLogin(login); assertThat(user).isPresent(); assertThat(user.get().isActive()).isFalse(); assertThat(user.get().getEmail()).isNull(); assertThat(user.get().getScmAccountsAsList()).isEmpty(); - if (isSonarCloud) { - assertThat(user.get().getName()).isNull(); - } } - private WsActionTester newSonarCloudWs() { - settings.setProperty(SONARCLOUD_ENABLED.getKey(), true); - return new WsActionTester(new DeactivateAction(dbClient, userIndexer, userSession, - new UserJsonWriter(userSession), defaultOrganizationProvider, settings.asConfig())); - } } |