summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-09-04 11:30:24 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-09-04 11:47:30 +0200
commitb90f78348c9325d58c9f236e2cdedbf10548d1ea (patch)
tree58ef32c1ee8fda8f0634ddd522ea5cb3b087ef7d /server
parent4621782bc3b63738f67957b1e8ca8a94906d0455 (diff)
downloadsonarqube-b90f78348c9325d58c9f236e2cdedbf10548d1ea.tar.gz
sonarqube-b90f78348c9325d58c9f236e2cdedbf10548d1ea.zip
SONAR-6499 WS permission/set_default_template fix when views default template has never been set
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/SetDefaultTemplateAction.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java25
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/SetDefaultTemplateActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java2
4 files changed, 15 insertions, 18 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SetDefaultTemplateAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SetDefaultTemplateAction.java
index fc17933db81..78524945197 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SetDefaultTemplateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/SetDefaultTemplateAction.java
@@ -35,7 +35,6 @@ import org.sonar.server.user.UserSession;
import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Ordering.natural;
import static java.lang.String.format;
-import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
import static org.sonar.server.permission.ws.Parameters.PARAM_QUALIFIER;
@@ -126,8 +125,5 @@ public class SetDefaultTemplateAction implements PermissionsWsAction {
private void setDefaultTemplateUuid(String templateUuid, String qualifier) {
settings.saveProperty(defaultRootQualifierTemplateProperty(qualifier), templateUuid);
- if (Qualifiers.PROJECT.equals(qualifier)) {
- settings.saveProperty(DEFAULT_TEMPLATE_PROPERTY, templateUuid);
- }
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java b/server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java
index 688e3bf3c70..8da3049818c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java
@@ -50,17 +50,21 @@ public class RegisterPermissionTemplates {
public void start() {
Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Register permission templates");
+ boolean shouldRegister = shouldRegister();
- if (shouldRegister()) {
- if (hasExistingPermissionsConfig()) {
- String projectsPermissionsKey = settings.getString(defaultRootQualifierTemplateProperty(Qualifiers.PROJECT));
- setDefaultProperty(projectsPermissionsKey);
- } else {
- insertDefaultTemplate();
- setDefaultProperty(PermissionTemplateDto.DEFAULT.getKee());
- }
+ if (hasExistingPermissionsConfig()) {
+ // needs to be done at each startup in the case a plugin has just been installed. The default property must be the project one
+ String defaultProjectPermissionTemplateUuid = settings.getString(defaultRootQualifierTemplateProperty(Qualifiers.PROJECT));
+ setDefaultProperty(defaultProjectPermissionTemplateUuid);
+ } else if (shouldRegister) {
+ insertDefaultTemplate();
+ setDefaultProperty(PermissionTemplateDto.DEFAULT.getKee());
+ }
+
+ if (shouldRegister) {
registerInitialization();
}
+
profiler.stopDebug();
}
@@ -113,9 +117,6 @@ public class RegisterPermissionTemplates {
}
private void setDefaultProperty(String defaultTemplate) {
- if (settings.getString(DEFAULT_TEMPLATE_PROPERTY) == null) {
- LOG.info("Set default permission template: " + defaultTemplate);
- settings.saveProperty(DEFAULT_TEMPLATE_PROPERTY, defaultTemplate);
- }
+ settings.saveProperty(DEFAULT_TEMPLATE_PROPERTY, defaultTemplate);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SetDefaultTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SetDefaultTemplateActionTest.java
index a6d3274ebd1..f1e20799985 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SetDefaultTemplateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SetDefaultTemplateActionTest.java
@@ -106,7 +106,7 @@ public class SetDefaultTemplateActionTest {
String result = newRequest(template.getUuid(), null);
assertThat(result).isEmpty();
- assertThat(persistentSettings.getString(DEFAULT_TEMPLATE_PROPERTY)).isEqualTo(template.getUuid());
+ assertThat(persistentSettings.getString(DEFAULT_TEMPLATE_PROPERTY)).isEqualTo("any-template-uuid");
assertThat(persistentSettings.getString(defaultRootQualifierTemplateProperty(PROJECT))).isEqualTo(template.getUuid());
assertThat(persistentSettings.getString(defaultRootQualifierTemplateProperty(VIEW))).isEqualTo("any-view-template-uuid");
assertThat(persistentSettings.getString(defaultRootQualifierTemplateProperty("DEV"))).isEqualTo("any-dev-template-uuid");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java
index 750248d7dc9..3165bce1f09 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java
@@ -108,7 +108,7 @@ public class RegisterPermissionTemplatesTest {
RegisterPermissionTemplates initializer = new RegisterPermissionTemplates(dbClient, settings);
initializer.start();
- verifyZeroInteractions(permissionTemplateDao, settings);
+ verifyZeroInteractions(permissionTemplateDao);
verify(loadedTemplateDao, never()).insert(any(LoadedTemplateDto.class));
}