From 190e9792b80dde490550c77dd16f140dc8e87153 Mon Sep 17 00:00:00 2001 From: gnaegi <none@none> Date: Mon, 27 Aug 2012 17:31:45 +0200 Subject: [PATCH] OO-335 controller creator that checks if user has a missing mandatory field --- ...itIfMissingMandatoryControllerCreator.java | 98 +++++++++++++++++++ .../org/olat/user/_spring/userContext.xml | 29 ++++-- 2 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/olat/user/ProfileAndHomePageEditIfMissingMandatoryControllerCreator.java diff --git a/src/main/java/org/olat/user/ProfileAndHomePageEditIfMissingMandatoryControllerCreator.java b/src/main/java/org/olat/user/ProfileAndHomePageEditIfMissingMandatoryControllerCreator.java new file mode 100644 index 00000000000..2f2b5f7321a --- /dev/null +++ b/src/main/java/org/olat/user/ProfileAndHomePageEditIfMissingMandatoryControllerCreator.java @@ -0,0 +1,98 @@ +/** + * <a href=“http://www.openolat.org“> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * 28. August 2012 by frentix GmbH, http://www.frentix.com + * <p> + **/ + +package org.olat.user; + +import java.util.List; + +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.creator.AutoCreator; +import org.olat.core.util.StringHelper; +import org.olat.user.propertyhandlers.UserPropertyHandler; + +/** + * <h3>Description:</h3> This interceptor checks if the user has filled all + * mandatory fields of the profile form. If yes, the controller creator method + * creates the profile form controller, if no it returns null + * <p> + * Note that the controller does not actually validate each field, it only + * checks if any mandatory field is empty. + * <p> + * <h3>Events thrown by this controller:</h3> + * <p> + * none + * <p> + * Initial Date: 27.08.2012 <br> + * + * @author Florian Gnaegi, frentix GmbH, http://www.frentix.com + */ + +public class ProfileAndHomePageEditIfMissingMandatoryControllerCreator + extends AutoCreator { + + /* + * (non-Javadoc) + * + * @see + * org.olat.core.gui.control.creator.ControllerCreator#createController( + * org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl) + */ + @Override + public ProfileAndHomePageEditController createController(UserRequest lureq, + WindowControl lwControl) { + + // get all userproperties from the profile form + UserManager um = UserManager.getInstance(); + String usageIdentifier = ProfileFormController.class.getCanonicalName(); + List<UserPropertyHandler> userPropertyHandlers = um + .getUserPropertyHandlersFor(usageIdentifier, false); + // check if all mandatory properties are set + boolean foundMissingMandatory = false; // think positive! + for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) { + if (um.isMandatoryUserProperty(usageIdentifier, userPropertyHandler)) { + String curValue = userPropertyHandler.getUserProperty(lureq + .getIdentity().getUser(), lureq.getLocale()); + if (!StringHelper.containsNonWhitespace(curValue)) { + foundMissingMandatory = true; + break; + } + } + } + // only create profile controller when profile contains empty mandatory + // fields + if (foundMissingMandatory) { + return new ProfileAndHomePageEditController(lureq, lwControl); + } else { + return null; + } + } + + /* + * (non-Javadoc) + * @see org.olat.core.gui.control.creator.AutoCreator#getClassName() + */ + @Override + public String getClassName() { + return ProfileAndHomePageEditController.class.getName(); + } + + +} diff --git a/src/main/java/org/olat/user/_spring/userContext.xml b/src/main/java/org/olat/user/_spring/userContext.xml index b036db71c2b..973ba1f2471 100644 --- a/src/main/java/org/olat/user/_spring/userContext.xml +++ b/src/main/java/org/olat/user/_spring/userContext.xml @@ -178,6 +178,8 @@ <!-- <bean id="org.olat.user.AfterLoginConfig" class="org.olat.login.AfterLoginConfig" scope="prototype"> <property name="afterLoginControllerList"> <list> + --> + <!-- Configuration to force users to regularly check and update the user profile, redoTimeout sets the interval (seconds) <map> <entry key="controller"> <bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype"> @@ -187,8 +189,21 @@ <entry key="forceUser"><value>true</value></entry> <entry key="redoTimeout"><value>10</value></entry> <entry key="i18nIntro"><value>org.olat.user:runonce.profile.intro</value></entry> - </map> --> - <!-- <map> + </map> + --> + <!-- Alternative configuration to force users to fill out profile if a mandatory user property is missing (no syntax checks done, only checks if property exists) + <map> + <entry key="controller"> + <bean class="org.olat.user.ProfileAndHomePageEditIfMissingMandatoryControllerCreator" scope="prototype" /> + </entry> + <entry key="forceUser"><value>true</value></entry> + <entry key="redoTimeout"><value>31536000</value></entry> + <entry key="i18nIntro"><value>org.olat.user:runonce.profile.intro</value></entry> + <entry key="size"><value>800x600</value></entry> + </map> + --> + <!-- Configuration to force users to change their password after the configured redoTimeout (seconds) + <map> <entry key="controller"> <bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype"> <property name="className" value="org.olat.user.ChangePasswordController"/> @@ -198,9 +213,10 @@ ## equals 30d in seconds ## <entry key="redoTimeout"><value>2592000</value></entry> <entry key="i18nIntro"><value>org.olat.user:runonce.changepw.intro</value></entry> - </map> --> - - <!-- example config: <map> + </map> + --> + <!-- Documented example of the change password dialog + <map> ## specify a controller to start with default args (ureq, wControl) <entry key="controller"> <bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype"> @@ -215,7 +231,8 @@ ## optional i18nKey to present an intro-text for this controller ## specify in the form of "package:i18nKey" <entry key="i18nIntro"><value>org.olat.user:runonce.intro</value></entry> - </map> --> + </map> + --> <!-- </list> </property> </bean> --> -- GitLab