From d2a7a29d4eae5b320f9706815a386dca96ea4fd0 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Mon, 20 Oct 2014 11:38:06 +0200 Subject: [PATCH] OO-1264: disable mail tool with the mail module --- .../org/olat/core/util/mail/MailModule.java | 26 ---------- .../core/util/mail/MailToolExtension.java | 47 +++++++++++++++++++ .../core/util/mail/_spring/mailContext.xml | 3 +- 3 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 src/main/java/org/olat/core/util/mail/MailToolExtension.java diff --git a/src/main/java/org/olat/core/util/mail/MailModule.java b/src/main/java/org/olat/core/util/mail/MailModule.java index b105e143465..e2b7e93b2cc 100644 --- a/src/main/java/org/olat/core/util/mail/MailModule.java +++ b/src/main/java/org/olat/core/util/mail/MailModule.java @@ -21,16 +21,11 @@ package org.olat.core.util.mail; import java.io.File; -import org.olat.core.CoreSpringFactory; import org.olat.core.commons.modules.bc.FolderConfig; import org.olat.core.configuration.AbstractOLATModule; import org.olat.core.configuration.PersistedProperties; -import org.olat.core.extensions.action.GenericActionExtension; -import org.olat.core.gui.control.Event; import org.olat.core.util.StringHelper; import org.olat.core.util.WebappHelper; -import org.olat.core.util.event.FrameworkStartedEvent; -import org.olat.core.util.event.FrameworkStartupEventChannel; import org.olat.core.util.vfs.LocalFolderImpl; import org.olat.core.util.vfs.VFSContainer; @@ -59,7 +54,6 @@ public class MailModule extends AbstractOLATModule { public MailModule() { //make Spring happy - FrameworkStartupEventChannel.registerForStartupEvent(this); } /** @@ -116,29 +110,9 @@ public class MailModule extends AbstractOLATModule { */ public void setInterSystem(boolean internSystem) { String internSystemStr = internSystem ? "true" : "false"; - enableExtensions(internSystem); setStringProperty(INTERN_MAIL_SYSTEM, internSystemStr, true); } - private void enableExtensions(boolean enabled){ - try { - ((GenericActionExtension)CoreSpringFactory.getBean("mailAEparent")).setEnabled(enabled); - ((GenericActionExtension)CoreSpringFactory.getBean("mailAEinbox")).setEnabled(enabled); - ((GenericActionExtension)CoreSpringFactory.getBean("mailAEoutbox")).setEnabled(enabled); - } catch (Exception e) { - // do nothing when extension don't exist. - } - } - - @Override - public void event(Event event) { - if(event instanceof FrameworkStartedEvent) { - enableExtensions(isInternSystem()); - } else { - super.event(event); - } - } - /** * Users can receive real e-mail too. This setting is the default for * users. They can change it in Preferences Panel. diff --git a/src/main/java/org/olat/core/util/mail/MailToolExtension.java b/src/main/java/org/olat/core/util/mail/MailToolExtension.java new file mode 100644 index 00000000000..6d2277a7fd3 --- /dev/null +++ b/src/main/java/org/olat/core/util/mail/MailToolExtension.java @@ -0,0 +1,47 @@ +/** + * <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> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.core.util.mail; + +import org.olat.core.extensions.action.GenericActionExtension; + +/** + * + * Initial date: 20.10.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class MailToolExtension extends GenericActionExtension { + + private MailModule module; + + /** + * [used by Spring] + * @param module + */ + public void setMailModule(MailModule module) { + this.module = module; + } + + @Override + public boolean isEnabled() { + return module.isInternSystem() && super.isEnabled(); + } + +} diff --git a/src/main/java/org/olat/core/util/mail/_spring/mailContext.xml b/src/main/java/org/olat/core/util/mail/_spring/mailContext.xml index 1444bdfbd03..5c6451d6f8e 100644 --- a/src/main/java/org/olat/core/util/mail/_spring/mailContext.xml +++ b/src/main/java/org/olat/core/util/mail/_spring/mailContext.xml @@ -72,8 +72,9 @@ </bean> <!-- the email-parent-menu --> - <bean class="org.olat.core.extensions.action.GenericActionExtension" name="mailBox" init-method="initExtensionPoints" > + <bean class="org.olat.core.util.mail.MailToolExtension" name="mailBox" init-method="initExtensionPoints" > <property name="order" value="404" /> + <property name="mailModule" ref="mailModule" /> <property name="navigationKey" value="Mail" /> <property name="alternativeNavigationKeys" value="Inbox,Outbox" /> <property name="iconCssClass" value="o_icon o_icon-fw o_icon_mail" /> -- GitLab