]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7174 Reintroduce UserSession.hasGlobalPermission
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 13 Jan 2016 09:09:39 +0000 (10:09 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 13 Jan 2016 09:09:46 +0000 (10:09 +0100)
This method is used by Views and Dev Cockpit plugins

server/sonar-server/src/main/java/org/sonar/server/user/AbstractUserSession.java
server/sonar-server/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java
server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
server/sonar-server/src/test/java/org/sonar/server/tester/UserSessionRule.java
server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java

index 60a531c3055ad4a646bbc7ae1f25ce3cc0c48676..c1b089969d6e3fcde7abed85c26d039c66c5930b 100644 (file)
@@ -154,6 +154,11 @@ public abstract class AbstractUserSession<T extends AbstractUserSession> impleme
     return globalPermissions().contains(globalPermission);
   }
 
+  @Override
+  public boolean hasGlobalPermission(String globalPermission) {
+    return hasPermission(globalPermission);
+  }
+
   @Override
   public UserSession checkComponentPermission(String projectPermission, String componentKey) {
     if (!hasComponentPermission(projectPermission, componentKey)) {
index b871a8aa7698c91554b5b446c2fc3b33a9f1c9a5..a920967c088e45046cabab561e948494f7e22e03 100644 (file)
@@ -102,6 +102,11 @@ public class ThreadLocalUserSession implements UserSession {
     return get().hasPermission(globalPermission);
   }
 
+  @Override
+  public boolean hasGlobalPermission(String globalPermission) {
+    return get().hasGlobalPermission(globalPermission);
+  }
+
   @Override
   public List<String> globalPermissions() {
     return get().globalPermissions();
index a926ee1de9eca420d11acd5490008f8211ab0702..ff54a30824012cfe5a007424d5487c70732ae0c9 100644 (file)
@@ -62,6 +62,12 @@ public interface UserSession {
    */
   boolean hasPermission(String globalPermission);
 
+  /**
+   * @deprecated Only used by Views and the Developer Cockpit.
+   */
+  @Deprecated
+  boolean hasGlobalPermission(String globalPermission);
+
   List<String> globalPermissions();
 
   /**
index fd2b6c4482f6d4b5e035e75942dbf388e30d9efe..f651d0a14ba13c04c705785634bd7932c194bef9 100644 (file)
@@ -284,6 +284,11 @@ public class UserSessionRule implements TestRule, UserSession {
     return currentUserSession.hasPermission(globalPermission);
   }
 
+  @Override
+  public boolean hasGlobalPermission(String globalPermission) {
+    return currentUserSession.hasGlobalPermission(globalPermission);
+  }
+
   @Override
   public UserSession checkComponentPermission(String projectPermission, String componentKey) {
     return currentUserSession.checkComponentPermission(projectPermission, componentKey);
index 7b4492f288893e54e74a58b227b90ba2b6e52b99..e1c918ad1e7e08bbc1ed8013581e72ec7cb2e35d 100644 (file)
@@ -205,6 +205,17 @@ public class ServerUserSessionTest {
     session.checkComponentPermission(UserRole.USER, "another");
   }
 
+  @Test
+  public void deprecated_has_global_permission() throws Exception {
+    UserSession session = newServerUserSession().setLogin(LOGIN);
+
+    when(authorizationDao.selectGlobalPermissions(LOGIN)).thenReturn(Arrays.asList("profileadmin", "admin"));
+
+    assertThat(session.hasGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN)).isTrue();
+    assertThat(session.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN)).isTrue();
+    assertThat(session.hasGlobalPermission(GlobalPermissions.DASHBOARD_SHARING)).isFalse();
+  }
+
   private ServerUserSession newServerUserSession() {
     return new ServerUserSession(authorizationDao, resourceDao);
   }