From c04b5f10b68c529b28a04ba5895f2c3a284707d5 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Mon, 23 Feb 2015 13:09:31 +0100 Subject: [PATCH] OO-1445: allow olat.(local.)properties settings for registration module --- .../olat/registration/RegistrationModule.java | 45 ++++++++++++------- .../org/olat/restapi/RegistrationTest.java | 17 ++----- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/olat/registration/RegistrationModule.java b/src/main/java/org/olat/registration/RegistrationModule.java index 2b8af386432..cf69988ea09 100644 --- a/src/main/java/org/olat/registration/RegistrationModule.java +++ b/src/main/java/org/olat/registration/RegistrationModule.java @@ -99,6 +99,7 @@ public class RegistrationModule extends AbstractOLATModule { } public void setSelfRegistrationEnabled(boolean enable) { + selfRegistrationEnabled = enable; String value = enable ? "true" : "false"; setStringProperty("registration.enabled", value, true); } @@ -111,42 +112,45 @@ public class RegistrationModule extends AbstractOLATModule { } public void setStaticPropertyMappingEnabled(boolean enable) { + staticPropertyMappingEnabled = enable; String value = enable ? "true" : "false"; setStringProperty("static.prop.mapping.enabled", value, true); } public String getStaticPropertyMappingName() { - return staticPropertyMappingName; + return staticPropertyMappingName; } public void setStaticPropertyMappingName(String value) { - value = StringHelper.containsNonWhitespace(value) ? value : ""; - setStringProperty("static.prop.mapping", value, true); + staticPropertyMappingName = StringHelper.containsNonWhitespace(value) ? value : ""; + setStringProperty("static.prop.mapping", staticPropertyMappingName, true); } public String getStaticPropertyMappingValue() { - return staticPropertyMappingValue; + return staticPropertyMappingValue; } public void setStaticPropertyMappingValue(String value) { - value = StringHelper.containsNonWhitespace(value) ? value : ""; - setStringProperty("static.prop.mapping.value", value, true); + staticPropertyMappingValue = StringHelper.containsNonWhitespace(value) ? value : ""; + setStringProperty("static.prop.mapping.value", staticPropertyMappingValue, true); } public boolean isSelfRegistrationLinkEnabled(){ - return selfRegistrationLinkEnabled; + return selfRegistrationLinkEnabled; } public void setSelfRegistrationLinkEnabled(boolean enable) { + selfRegistrationLinkEnabled = enable; String value = enable ? "true" : "false"; setStringProperty("registration.link.enabled", value, true); } public boolean isSelfRegistrationLoginEnabled(){ - return selfRegistrationLoginEnabled; + return selfRegistrationLoginEnabled; } public void setSelfRegistrationLoginEnabled(boolean enable) { + selfRegistrationLoginEnabled = enable; String value = enable ? "true" : "false"; setStringProperty("registration.login.enabled", value, true); } @@ -156,7 +160,8 @@ public class RegistrationModule extends AbstractOLATModule { } public void setDomainListRaw(String list) { - setStringProperty("registration.domains", normalizeDomainList(list), true); + domainList = normalizeDomainList(list); + setStringProperty("registration.domains", domainList, true); } private String normalizeDomainList(String list) { @@ -210,35 +215,43 @@ public class RegistrationModule extends AbstractOLATModule { public void init() { //registration enabled/disabled String enabledObj = getStringPropertyValue("registration.enabled", true); - selfRegistrationEnabled = "true".equals(enabledObj); + if(StringHelper.containsNonWhitespace(enabledObj)) { + selfRegistrationEnabled = "true".equals(enabledObj); + } //link registration enabled/disabled (rest) String linkEnabledObj = getStringPropertyValue("registration.link.enabled", true); - selfRegistrationLinkEnabled = "true".equals(linkEnabledObj); + if(StringHelper.containsNonWhitespace(linkEnabledObj)) { + selfRegistrationLinkEnabled = "true".equals(linkEnabledObj); + } //link on the login page for registration enabled/disabled String loginEnabledObj = getStringPropertyValue("registration.login.enabled", true); - selfRegistrationLoginEnabled = "true".equals(loginEnabledObj); + if(StringHelper.containsNonWhitespace(loginEnabledObj)) { + selfRegistrationLoginEnabled = "true".equals(loginEnabledObj); + } //white list of domains String domainObj = getStringPropertyValue("registration.domains", true); if(StringHelper.containsNonWhitespace(domainObj)) { domainList = domainObj; - } else { + } else {// allowed because to olat.properties for this domainList = null; // reset } //static property mapping enabled/disabled String enabledPropObj = getStringPropertyValue("static.prop.mapping.enabled", true); - staticPropertyMappingEnabled = "true".equals(enabledPropObj); + if(StringHelper.containsNonWhitespace(enabledPropObj)) { + staticPropertyMappingEnabled = "true".equals(enabledPropObj); + } - String propKeyObj = getStringPropertyValue("static.prop.mapping", true); + String propKeyObj = getStringPropertyValue("static.prop.mapping", false); if(StringHelper.containsNonWhitespace(propKeyObj)) { staticPropertyMappingName = propKeyObj; } else { staticPropertyMappingName = null; // reset } - String propValueObj = getStringPropertyValue("static.prop.mapping.value", true); + String propValueObj = getStringPropertyValue("static.prop.mapping.value", false); if(StringHelper.containsNonWhitespace(propValueObj)) { staticPropertyMappingValue = propValueObj; } else { diff --git a/src/test/java/org/olat/restapi/RegistrationTest.java b/src/test/java/org/olat/restapi/RegistrationTest.java index d16542c7c3e..2cd476c3629 100644 --- a/src/test/java/org/olat/restapi/RegistrationTest.java +++ b/src/test/java/org/olat/restapi/RegistrationTest.java @@ -32,11 +32,9 @@ import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPut; import org.apache.http.util.EntityUtils; -import org.junit.Before; import org.junit.Test; import org.olat.core.id.Identity; import org.olat.core.id.UserConstants; -import org.olat.restapi.RestConnection; import org.olat.test.JunitTestHelper; import org.olat.test.OlatJerseyTestCase; @@ -51,17 +49,6 @@ import org.olat.test.OlatJerseyTestCase; */ public class RegistrationTest extends OlatJerseyTestCase { - private static Identity owner1; - - @Before - @Override - public void setUp() throws Exception { - super.setUp(); - //create a course with learn group - - owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-one"); - } - @Test public void testRegistration() throws IOException, URISyntaxException { RestConnection conn = new RestConnection(); @@ -79,10 +66,12 @@ public class RegistrationTest extends OlatJerseyTestCase { @Test public void testRedirectRegistration() throws IOException, URISyntaxException { + Identity id = JunitTestHelper.createAndPersistIdentityAsUser("rest-reg"); + RestConnection conn = new RestConnection(); URI uri = conn.getContextURI().path("registration") - .queryParam("email", owner1.getUser().getProperty(UserConstants.EMAIL, null)).build(); + .queryParam("email", id.getUser().getProperty(UserConstants.EMAIL, null)).build(); HttpPut put = conn.createPut(uri, "*/*", "de", true); HttpResponse response = conn.execute(put); -- GitLab