]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4475 Revert check of last admin removal
authorJulien Lancelot <julien.lancelot@gmail.com>
Mon, 19 Aug 2013 10:34:30 +0000 (12:34 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Mon, 19 Aug 2013 10:34:30 +0000 (12:34 +0200)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-batch/src/test/java/org/sonar/batch/scan/JsonReportTest.java
sonar-core/src/main/java/org/sonar/core/user/RoleDao.java
sonar-core/src/main/java/org/sonar/core/user/RoleMapper.java
sonar-core/src/main/resources/org/sonar/core/user/RoleMapper.xml
sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java
sonar-core/src/test/resources/org/sonar/core/user/RoleDaoTest/should_count_user_with_permission.xml [deleted file]
sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java

index 01df59dce079ff87f871eac22350917d256178c3..eb291c817c1ae0c406441a9c04be65960017473d 100644 (file)
@@ -2233,7 +2233,6 @@ global_permissions.scan.desc=Ability to execute analyses, and to get all setting
 global_permissions.dryRunScan=Execute Local Analysis (Dry Run)
 global_permissions.dryRunScan.desc=Ability to execute local (dry run) analyses without pushing the results to the server, and to get all settings required to perform a local analysis. This permission does not include the ability to access secured settings such as the scm account password, the jira account password, and so on.<br/>\
 This permission is <em>required</em> to execute a local analysis in Eclipse or via the Issues Report plugin.
-global_permissions.error.need_at_lest_one_admin=At least one admin must be defined.
 
 #------------------------------------------------------------------------------
 #
index c40f3aa54cad290a26e2b1d30ae00e8f57097e89..ce265bcfce2a5ed7e9d1e91ba82d29b2a882cbc3 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.collect.Lists;
 import org.json.JSONException;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.skyscreamer.jsonassert.JSONAssert;
@@ -85,7 +84,6 @@ public class JsonReportTest {
   }
 
   @Test
-  @Ignore
   public void should_write_json() throws JSONException {
     DefaultIssue issue = new DefaultIssue()
         .setKey("200")
@@ -109,7 +107,7 @@ public class JsonReportTest {
     jsonReport.writeJson(writer);
 
     JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/JsonReportTest/report.json"),
-      writer.toString(), false);
+        writer.toString(), false);
   }
 
   @Test
index b936f0e33081d472408271216eafda729a3c6040..c8bc741db1b1c216b7677c9eb7bcced6042bc79f 100644 (file)
@@ -144,14 +144,4 @@ public class RoleDao implements TaskComponent, ServerComponent {
       MyBatis.closeQuietly(session);
     }
   }
-
-  public int countUserWithPermission(String permission) {
-    SqlSession session = mybatis.openSession();
-    try {
-      RoleMapper mapper = session.getMapper(RoleMapper.class);
-      return mapper.countUserWithPermission(permission);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
 }
index 7bd9fb0315e255375ef7fc1eccad592374dba821..531991b1531d75f6e638821aeaad341a5066043d 100644 (file)
@@ -21,6 +21,8 @@ package org.sonar.core.user;
 
 import org.apache.ibatis.annotations.Param;
 
+import javax.annotation.Nullable;
+
 import java.util.List;
 
 /**
@@ -48,6 +50,5 @@ public interface RoleMapper {
 
   int countUserRoles(Long resourceId);
 
-  int countUserWithPermission(@Param("permission") String permission);
-
+  List<Long> countSystemAdministrators(@Nullable @Param("groupName") String groupName);
 }
index be4b7671b5d1a7dd377588c18c3ef372f2b82392..3dba348d55a23be25e0b89ecff4e5430f0c8d026 100644 (file)
     SELECT count(id)
     FROM group_roles WHERE resource_id=#{id}
   </select>
-
-  <select id="countUserWithPermission" parameterType="map" resultType="int">
-    SELECT COUNT(DISTINCT tmp.id)
-    FROM (
-    SELECT u.id as id
-    FROM users u
-    INNER JOIN user_roles ur ON ur.user_id = u.id
-    <where>
-      AND (ur.role=#{permission} AND ur.resource_id IS NULL)
-      AND u.active=${_true}
-    </where>
-    UNION
-    select u.id as id
-    FROM users u
-    INNER JOIN groups_users gu ON gu.user_id = u.id
-    INNER JOIN group_roles gr ON gr.group_id = gu.group_id
-    INNER JOIN groups g ON g.id = gu.group_id
-    <where>
-      AND (gr.role=#{permission} AND gr.resource_id IS NULL)
-      AND u.active=${_true}
-    </where>
-    ) tmp
-  </select>
-
 </mapper>
index 427c2aee456f3b5ef4c7ad244a581ba592fcd34f..6d0c9b0830e4d6e1e1d720a99bfe02247041df85 100644 (file)
@@ -76,19 +76,4 @@ public class RoleDaoTest extends AbstractDaoTestCase {
     checkTable("groupPermissions", "group_roles", "group_id", "role");
   }
 
-  @Test
-  public void should_count_user_with_permission() {
-    setupData("should_count_user_with_permission");
-
-    RoleDao dao = new RoleDao(getMyBatis());
-
-    // 1 user have role 'admin', 1 user owns to the 'admin' group
-    assertThat(dao.countUserWithPermission("admin")).isEqualTo(2);
-    // 1 user have role 'profileadmin'
-    assertThat(dao.countUserWithPermission("profileadmin")).isEqualTo(1);
-    // 1 user owns to the 'user' group
-    assertThat(dao.countUserWithPermission("user")).isEqualTo(1);
-    assertThat(dao.countUserWithPermission("unknown")).isEqualTo(0);
-  }
-
 }
diff --git a/sonar-core/src/test/resources/org/sonar/core/user/RoleDaoTest/should_count_user_with_permission.xml b/sonar-core/src/test/resources/org/sonar/core/user/RoleDaoTest/should_count_user_with_permission.xml
deleted file mode 100644 (file)
index 8fe58e3..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<dataset>
-
-  <!-- users having role -->
-
-  <users id="200" login="admin_user" name="admin_user" active="[true]"/>
-  <users id="201" login="profile_admin_user" name="profile_admin_user" active="[true]"/>
-
-  <user_roles id="1" user_id="200" role="admin"/>
-  <user_roles id="2" user_id="201" role="profileadmin"/>
-
-  <!-- users having group -->
-
-  <users id="202" login="admin_group" name="admin_group" active="[true]"/>
-  <users id="203" login="user_group" name="user_group" active="[true]"/>
-
-  <groups id="100" name="sonar-administrators"/>
-  <groups id="101" name="sonar-users"/>
-
-  <group_roles id="1" group_id="100" role="admin"/>
-  <group_roles id="2" group_id="101" role="user"/>
-
-  <groups_users user_id="202" group_id="100"/>
-  <groups_users user_id="203" group_id="101"/>
-
-</dataset>
index 409deb97f77fb1c3113d7ffb0e36394890b4e52e..3fdcc998ab841bdc9c5893517e2a813eda4309f3 100644 (file)
@@ -24,7 +24,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.utils.MessageException;
 import org.sonar.core.permission.ComponentPermissionFacade;
 import org.sonar.core.permission.Permission;
 import org.sonar.core.user.*;
@@ -72,12 +71,6 @@ public class InternalPermissionService implements ServerComponent {
     }
   }
 
-  public void checkAtLeastOneSysAdminExists(){
-    if (roleDao.countUserWithPermission(Permission.SYSTEM_ADMIN.key()) == 0){
-      throw MessageException.ofL10n("global_permissions.error.need_at_lest_one_admin", null);
-    }
-  }
-
   private void applyPermissionTemplate(String templateKey, String componentId) {
     permissionFacade.applyPermissionTemplate(templateKey, Long.parseLong(componentId));
   }
index 1105fa5292ba1cfc10d5512006474fd87eb07540..f2d5fd5d8785f3904aeacadc8dcee72bc1d87c44 100644 (file)
@@ -23,7 +23,7 @@ class GroupsController < ApplicationController
   before_filter :admin_required
 
   def index
-    @groups = Group.all(:order => 'name')
+    @groups = Group.find(:all, :order => 'name')
     if params[:id]
       @group = Group.find(params[:id])
     else
@@ -72,7 +72,7 @@ class GroupsController < ApplicationController
   end
 
   def to_index(errors, id)
-    unless errors.empty?
+    if !errors.empty?
       flash[:error] = errors.full_messages.join("<br/>\n")
     end
 
index cf9104cc5e4b2a89b5732946a5114f3f63f09c31..d109cf33c447cb7704762429597f96f3e323a0d9 100644 (file)
@@ -161,7 +161,7 @@ class UsersController < ApplicationController
   end
 
   def to_index(errors, id)
-    unless errors.empty?
+    if !errors.empty?
       flash[:error] = errors.full_messages.join("<br/>\n")
     end
 
index bcff818c1cdf846b42f3c4b3d6a4222f6a8b3f9c..6dd2f92fca610aa018147275e24a37ba5e344f37 100644 (file)
@@ -30,7 +30,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.utils.MessageException;
 import org.sonar.core.permission.ComponentPermissionFacade;
 import org.sonar.core.permission.Permission;
 import org.sonar.core.user.*;
@@ -41,8 +40,6 @@ import org.sonar.server.user.MockUserSession;
 
 import java.util.Map;
 
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Mockito.*;
@@ -194,22 +191,6 @@ public class InternalPermissionServiceTest {
     verify(permissionFacade).applyPermissionTemplate("my_template_key", 3L);
   }
 
-  @Test
-  public void should_check_at_least_one_sys_admin_exists() throws Exception {
-    // One admin exists -> all is ok
-    when(roleDao.countUserWithPermission(anyString())).thenReturn(1);
-    service.checkAtLeastOneSysAdminExists();
-
-    // No admin -> fail
-    try {
-      when(roleDao.countUserWithPermission(anyString())).thenReturn(0);
-      service.checkAtLeastOneSysAdminExists();
-      fail();
-    } catch (Exception e){
-      assertThat(e).isInstanceOf(MessageException.class);
-    }
-  }
-
   protected static class MatchesUserRole extends BaseMatcher<UserRoleDto> {
 
     private final UserRoleDto referenceDto;