summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/SetDefaultProjectPermissions.java37
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java7
2 files changed, 28 insertions, 16 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/SetDefaultProjectPermissions.java b/sonar-server/src/main/java/org/sonar/server/startup/SetDefaultProjectPermissions.java
index 9aa5702ea21..dc4d24d4b8f 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/SetDefaultProjectPermissions.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/SetDefaultProjectPermissions.java
@@ -20,6 +20,7 @@
package org.sonar.server.startup;
import com.google.common.collect.Maps;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.sonar.server.platform.PersistentSettings;
@@ -39,22 +40,30 @@ public class SetDefaultProjectPermissions {
}
public void start() {
- if (persistentSettings.getSettings().getKeysStartingWith("sonar.role.").isEmpty()) {
- LoggerFactory.getLogger(SetDefaultProjectPermissions.class).info("Setting default project permissions");
- Map<String, String> props = Maps.newHashMap();
- props.put("sonar.role.admin.TRK.defaultGroups", SONAR_ADMINISTRATORS);
- props.put("sonar.role.user.TRK.defaultGroups", ANYONE_AND_USERS);
- props.put("sonar.role.codeviewer.TRK.defaultGroups", ANYONE_AND_USERS);
-
- // Support old versions of Views plugin
- props.put("sonar.role.admin.VW.defaultGroups", SONAR_ADMINISTRATORS);
- props.put("sonar.role.user.VW.defaultGroups", ANYONE_AND_USERS);
- props.put("sonar.role.codeviewer.VW.defaultGroups", ANYONE_AND_USERS);
- props.put("sonar.role.admin.SVW.defaultGroups", SONAR_ADMINISTRATORS);
- props.put("sonar.role.user.SVW.defaultGroups", ANYONE_AND_USERS);
- props.put("sonar.role.codeviewer.SVW.defaultGroups", ANYONE_AND_USERS);
+ Map<String, String> props = Maps.newHashMap();
+ props.putAll(missingProperties("TRK"));
+ // Support old versions of Views plugin
+ props.putAll(missingProperties("VW"));
+ props.putAll(missingProperties("SVW"));
+
+ if (!props.isEmpty()) {
+ LoggerFactory.getLogger(SetDefaultProjectPermissions.class).info("Set default project roles");
persistentSettings.saveProperties(props);
}
}
+
+ private Map<String, String> missingProperties(String qualifier) {
+ Map<String, String> props = Maps.newHashMap();
+ if (StringUtils.isBlank(persistentSettings.getSettings().getString("sonar.role.user." + qualifier + ".defaultGroups"))) {
+ completeDefaultRoles(qualifier, props);
+ }
+ return props;
+ }
+
+ private void completeDefaultRoles(String qualifier, Map<String, String> props) {
+ props.put("sonar.role.admin." + qualifier + ".defaultGroups", SONAR_ADMINISTRATORS);
+ props.put("sonar.role.user." + qualifier + ".defaultGroups", ANYONE_AND_USERS);
+ props.put("sonar.role.codeviewer." + qualifier + ".defaultGroups", ANYONE_AND_USERS);
+ }
}
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java
index 3b2cba14604..3139bb6b192 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/SetDefaultProjectPermissionsTest.java
@@ -46,7 +46,7 @@ public class SetDefaultProjectPermissionsTest {
@Override
public boolean matches(Object o) {
Map<String, String> map = (Map<String, String>) o;
- return map.size() == 9 && map.get("sonar.role.admin.TRK.defaultGroups").equals("sonar-administrators");
+ return map.size()>1 && map.get("sonar.role.admin.TRK.defaultGroups").equals("sonar-administrators");
}
}));
}
@@ -54,7 +54,10 @@ public class SetDefaultProjectPermissionsTest {
@Test
public void do_not_set_default_permissions_if_exist() {
PersistentSettings persistentSettings = mock(PersistentSettings.class);
- Settings settings = new Settings().setProperty("sonar.role.admin.TRK.defaultGroups", "custom-group");
+ Settings settings = new Settings()
+ .setProperty("sonar.role.user.TRK.defaultGroups", "custom-group")
+ .setProperty("sonar.role.user.VW.defaultGroups", "custom-group")
+ .setProperty("sonar.role.user.SVW.defaultGroups", "custom-group");
when(persistentSettings.getSettings()).thenReturn(settings);
new SetDefaultProjectPermissions(persistentSettings).start();