]> source.dussan.org Git - sonarqube.git/commitdiff
cleanup unused sonarcloud code
authorPierre Guillot <pierre.guillot@sonarsource.com>
Thu, 6 Feb 2020 13:17:31 +0000 (14:17 +0100)
committerSonarTech <sonartech@sonarsource.com>
Thu, 20 Feb 2020 19:46:16 +0000 (20:46 +0100)
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java

index f8b1b12be315587f9881463bf630b6f76d1ef1f3..6f93b86fade76a0b1e02ba41865b27a672453c85 100644 (file)
@@ -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());
   }
index d2a37a2b8172c68e00b6f0d1a02c6c19e8d5c62e..16e197b67ea7a7cfe9ed8bb64f705e795e6ce846 100644 (file)
@@ -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);
index d6c6c9b059f09c0a22c67ff95be50f9f7b21d70b..82fd6784cdace825b9eacfe4c205a8e058fc0235 100644 (file)
         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,
index 08eb943f58fa3d343b9874681856d01f17a7dfc1..4dd8cbd122c5a2a5b8d1a755b866f9c37d45cf38 100644 (file)
@@ -457,35 +457,6 @@ public class UserDaoTest {
     assertThat(underTest.selectUserById(session, otherUser.getId())).isNotNull();
   }
 
-  @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() {
 
index 2c0254899b141b60e919844fc9ec16f4419b807f..3a5bbf967d4bd2bab0b335e44a8d2d1b032d21e1 100644 (file)
@@ -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) {
index 04a29d08ae3fdd03fe8e03c880d8c13ee8ef4d19..c2a5b06183a8f2d81f3e786afbb15e73e137d22b 100644 (file)
@@ -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()))
@@ -261,31 +258,6 @@ public class DeactivateActionTest {
     assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(dbSession, anotherUser.getUuid(), almSettingDto)).isNotNull();
   }
 
-  @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();
@@ -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()));
-  }
 }