diff --git a/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java b/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java index 242a120017fedd704ec31ac55cfcfdfb4d47828a..8529a7c1c5db2dea10dc75d2668cbb06350bac3a 100644 --- a/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java +++ b/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java @@ -28,6 +28,7 @@ package org.olat.collaboration; import java.util.ArrayList; import org.olat.basesecurity.BaseSecurityModule; +import org.olat.commons.calendar.CalendarModule; import org.olat.core.CoreSpringFactory; import org.olat.core.id.OLATResourceable; import org.olat.core.logging.AssertException; @@ -82,7 +83,10 @@ public class CollaborationToolsFactory { ArrayList<String> toolArr = new ArrayList<String>(); toolArr.add(CollaborationTools.TOOL_NEWS); toolArr.add(CollaborationTools.TOOL_CONTACT); - toolArr.add(CollaborationTools.TOOL_CALENDAR); + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + if(calendarModule.isEnabled() && calendarModule.isEnableGroupCalendar()) { + toolArr.add(CollaborationTools.TOOL_CALENDAR); + } toolArr.add(CollaborationTools.TOOL_FOLDER); toolArr.add(CollaborationTools.TOOL_FORUM); if (CoreSpringFactory.getImpl(InstantMessagingModule.class).isEnabled()) { diff --git a/src/main/java/org/olat/collaboration/CollaborationToolsSettingsController.java b/src/main/java/org/olat/collaboration/CollaborationToolsSettingsController.java index 198df544e17a6b6bb48787a5acb338302677ffe4..417346ef41c91e156d1e624d843cc3450477abe7 100644 --- a/src/main/java/org/olat/collaboration/CollaborationToolsSettingsController.java +++ b/src/main/java/org/olat/collaboration/CollaborationToolsSettingsController.java @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.List; import org.olat.commons.calendar.CalendarManager; +import org.olat.commons.calendar.CalendarModule; import org.olat.commons.calendar.ui.events.KalendarModifiedEvent; import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; @@ -49,6 +50,7 @@ import org.olat.core.util.vfs.QuotaManager; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupManagedFlag; import org.olat.instantMessaging.InstantMessagingModule; +import org.springframework.beans.factory.annotation.Autowired; /** * Description: <BR> @@ -71,6 +73,9 @@ public class CollaborationToolsSettingsController extends BasicController { private final String[] availableTools; private final boolean managed; private final BusinessGroup businessGroup; + + @Autowired + private CalendarModule calendarModule; /** * @param ureq @@ -110,20 +115,22 @@ public class CollaborationToolsSettingsController extends BasicController { } // update calendar form: only show when enabled - if (collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR)) { - lastCalendarEnabledState = true; - vc_collabtools.contextPut("calendarToolEnabled", Boolean.TRUE); - int iCalendarAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS; - Long lCalendarAccess = collabTools.lookupCalendarAccess(); - if (lCalendarAccess != null) iCalendarAccess = lCalendarAccess.intValue(); - calendarForm = new CalendarToolSettingsController(ureq, getWindowControl(), iCalendarAccess); - calendarForm.setEnabled(!managed); - listenTo(calendarForm); - - vc_collabtools.put("calendarform", calendarForm.getInitialComponent()); - } else { - lastCalendarEnabledState = false; - vc_collabtools.contextPut("calendarToolEnabled", Boolean.FALSE); + if(calendarModule.isEnabled() && calendarModule.isEnableGroupCalendar()) { + if (collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR)) { + lastCalendarEnabledState = true; + vc_collabtools.contextPut("calendarToolEnabled", Boolean.TRUE); + int iCalendarAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS; + Long lCalendarAccess = collabTools.lookupCalendarAccess(); + if (lCalendarAccess != null) iCalendarAccess = lCalendarAccess.intValue(); + calendarForm = new CalendarToolSettingsController(ureq, getWindowControl(), iCalendarAccess); + calendarForm.setEnabled(!managed); + listenTo(calendarForm); + + vc_collabtools.put("calendarform", calendarForm.getInitialComponent()); + } else { + lastCalendarEnabledState = false; + vc_collabtools.contextPut("calendarToolEnabled", Boolean.FALSE); + } } // update quota form: only show when enabled diff --git a/src/main/java/org/olat/commons/calendar/CalendarModule.java b/src/main/java/org/olat/commons/calendar/CalendarModule.java index bd8c4200a10cf7e5b24dcb872b44941fe677d1d1..4da0476193c01406ccaf3d50ed51a99d927fd732 100644 --- a/src/main/java/org/olat/commons/calendar/CalendarModule.java +++ b/src/main/java/org/olat/commons/calendar/CalendarModule.java @@ -24,10 +24,14 @@ import net.fortuna.ical4j.model.TimeZoneRegistry; import net.fortuna.ical4j.model.TimeZoneRegistryFactory; import net.fortuna.ical4j.util.CompatibilityHints; -import org.olat.core.configuration.AbstractOLATModule; -import org.olat.core.configuration.PersistedProperties; +import org.olat.core.configuration.AbstractSpringModule; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; +import org.olat.core.util.StringHelper; +import org.olat.core.util.coordinate.CoordinatorManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; /** * @@ -38,13 +42,36 @@ import org.olat.core.logging.Tracing; * * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com */ -public class CalendarModule extends AbstractOLATModule { +@Service("calendarModule") +public class CalendarModule extends AbstractSpringModule { private static final OLog log = Tracing.createLoggerFor(CalendarModule.class); + private static final String CALENDAR_ENABLED = "calendar.enable"; + private static final String CALENDAR_PERSONAL_ENABLED = "calendar.personal.enabled"; + private static final String CALENDAR_GROUP_ENABLED = "calendar.group.enabled"; + private static final String CALENDAR_COURSE_TOOL_ENABLED = "calendar.course.tool.enabled"; + private static final String CALENDAR_COURSE_ELEMENT_ENABLED = "calendar.course.element.enabled"; + private TimeZone defaultTimeZone; private TimeZoneRegistry timeZoneRegistry; + @Value("${calendar.enabled:true}") + private boolean enabled; + @Value("${calendar.personal.enabled:true}") + private boolean enablePersonalCalendar; + @Value("${calendar.group.enabled:true}") + private boolean enableGroupCalendar; + @Value("${calendar.course.tool.enabled:true}") + private boolean enableCourseToolCalendar; + @Value("${calendar.course.element.enabled:true}") + private boolean enableCourseElementCalendar; + + @Autowired + public CalendarModule(CoordinatorManager coordinatorManager) { + super(coordinatorManager); + } + @Override public void init() { //some computers have no Internet access, the host can be down and we must get the default time zone @@ -58,24 +85,87 @@ public class CalendarModule extends AbstractOLATModule { if(defaultTimeZone == null) { log.error("Cannot match the JVM default time zone to an ical4j time zone: " + defaultTimeZoneID); } - } - - @Override - public void setPersistedProperties(PersistedProperties persistedProperties) { - this.moduleConfigProperties = persistedProperties; - } - - @Override - protected void initDefaultProperties() { - // + updateProperties(); } @Override protected void initFromChangedProperties() { - init(); + updateProperties(); + } + + private void updateProperties() { + String enabledObj = getStringPropertyValue(CALENDAR_ENABLED, true); + if(StringHelper.containsNonWhitespace(enabledObj)) { + enabled = "true".equals(enabledObj); + } + + String personalEnabledObj = getStringPropertyValue(CALENDAR_PERSONAL_ENABLED, true); + if(StringHelper.containsNonWhitespace(personalEnabledObj)) { + enablePersonalCalendar = "true".equals(personalEnabledObj); + } + + String groupEnabledObj = getStringPropertyValue(CALENDAR_GROUP_ENABLED, true); + if(StringHelper.containsNonWhitespace(groupEnabledObj)) { + enableGroupCalendar = "true".equals(groupEnabledObj); + } + + String courseToolEnabledObj = getStringPropertyValue(CALENDAR_COURSE_TOOL_ENABLED, true); + if(StringHelper.containsNonWhitespace(courseToolEnabledObj)) { + enableCourseToolCalendar = "true".equals(courseToolEnabledObj); + } + + String courseElementEnabledObj = getStringPropertyValue(CALENDAR_COURSE_ELEMENT_ENABLED, true); + if(StringHelper.containsNonWhitespace(courseElementEnabledObj)) { + enableCourseElementCalendar = "true".equals(courseElementEnabledObj); + } } public TimeZone getDefaultTimeZone() { return defaultTimeZone; } -} + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + setStringProperty(CALENDAR_ENABLED, Boolean.toString(enabled), true); + } + + public boolean isEnablePersonalCalendar() { + return enablePersonalCalendar; + } + + public void setEnablePersonalCalendar(boolean enablePersonalCalendar) { + this.enablePersonalCalendar = enablePersonalCalendar; + setStringProperty(CALENDAR_PERSONAL_ENABLED, Boolean.toString(enablePersonalCalendar), true); + } + + public boolean isEnableGroupCalendar() { + return enableGroupCalendar; + } + + public void setEnableGroupCalendar(boolean enableGroupCalendar) { + this.enableGroupCalendar = enableGroupCalendar; + setStringProperty(CALENDAR_GROUP_ENABLED, Boolean.toString(enableGroupCalendar), true); + } + + public boolean isEnableCourseToolCalendar() { + return enableCourseToolCalendar; + } + + public void setEnableCourseToolCalendar(boolean enableCourseToolCalendar) { + this.enableCourseToolCalendar = enableCourseToolCalendar; + setStringProperty(CALENDAR_COURSE_TOOL_ENABLED, Boolean.toString(enableCourseToolCalendar), true); + } + + public boolean isEnableCourseElementCalendar() { + return enableCourseElementCalendar; + } + + public void setEnableCourseElementCalendar(boolean enableCourseElementCalendar) { + this.enableCourseElementCalendar = enableCourseElementCalendar; + setStringProperty(CALENDAR_COURSE_ELEMENT_ENABLED, Boolean.toString(enableCourseElementCalendar), true); + } +} \ No newline at end of file diff --git a/src/main/java/org/olat/commons/calendar/ImportCalendarManager.java b/src/main/java/org/olat/commons/calendar/ImportCalendarManager.java index ae05c12a27549ee140726dd45865c9c86f2e3083..d56dce5fbd2acc56a9869df458539c2707032f1f 100644 --- a/src/main/java/org/olat/commons/calendar/ImportCalendarManager.java +++ b/src/main/java/org/olat/commons/calendar/ImportCalendarManager.java @@ -43,6 +43,7 @@ import org.olat.commons.calendar.model.Kalendar; import org.olat.commons.calendar.model.KalendarComparator; import org.olat.commons.calendar.model.KalendarConfig; import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; +import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.gui.UserRequest; import org.olat.core.id.Identity; @@ -217,29 +218,31 @@ public class ImportCalendarManager extends BasicManager { public static List<KalendarRenderWrapper> getImportedCalendarsForIdentity(UserRequest ureq) { // initialize the calendars list List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>(); - - // read all the entries from the database - PropertyManager pm = PropertyManager.getInstance(); - List<Property> properties = pm.listProperties(ureq.getIdentity(), null, null, PROP_CATEGORY, null); - - // return the list of calendar objects - Iterator<Property> propertyIter = properties.iterator(); - CalendarManager calManager = CalendarManagerFactory.getInstance().getCalendarManager(); - while (propertyIter.hasNext()) { - Property calendarProperty = propertyIter.next(); - String calendarName = calendarProperty.getName(); - KalendarRenderWrapper calendarWrapper = calManager.getImportedCalendar(ureq.getIdentity(), calendarName); - calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY); - calendarWrapper.setImported(true); - KalendarConfig importedKalendarConfig = calManager.findKalendarConfigForIdentity( - calendarWrapper.getKalendar(), ureq); - if (importedKalendarConfig != null) { - calendarWrapper.getKalendarConfig().setCss(importedKalendarConfig.getCss()); - calendarWrapper.getKalendarConfig().setVis(importedKalendarConfig.isVis()); + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + if(calendarModule.isEnabled() && calendarModule.isEnablePersonalCalendar()) { + // read all the entries from the database + PropertyManager pm = PropertyManager.getInstance(); + List<Property> properties = pm.listProperties(ureq.getIdentity(), null, null, PROP_CATEGORY, null); + + // return the list of calendar objects + Iterator<Property> propertyIter = properties.iterator(); + CalendarManager calManager = CalendarManagerFactory.getInstance().getCalendarManager(); + while (propertyIter.hasNext()) { + Property calendarProperty = propertyIter.next(); + String calendarName = calendarProperty.getName(); + KalendarRenderWrapper calendarWrapper = calManager.getImportedCalendar(ureq.getIdentity(), calendarName); + calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY); + calendarWrapper.setImported(true); + KalendarConfig importedKalendarConfig = calManager.findKalendarConfigForIdentity( + calendarWrapper.getKalendar(), ureq); + if (importedKalendarConfig != null) { + calendarWrapper.getKalendarConfig().setCss(importedKalendarConfig.getCss()); + calendarWrapper.getKalendarConfig().setVis(importedKalendarConfig.isVis()); + } + calendars.add(calendarWrapper); } - calendars.add(calendarWrapper); + Collections.sort(calendars, KalendarComparator.getInstance()); } - Collections.sort(calendars, KalendarComparator.getInstance()); return calendars; } diff --git a/src/main/java/org/olat/commons/calendar/_chelp/admin-calendar.html b/src/main/java/org/olat/commons/calendar/_chelp/admin-calendar.html new file mode 100644 index 0000000000000000000000000000000000000000..4410f95120ddbac8515a5cd71fed3048f38bb408 --- /dev/null +++ b/src/main/java/org/olat/commons/calendar/_chelp/admin-calendar.html @@ -0,0 +1 @@ +<p>[placeholder]</p> \ No newline at end of file diff --git a/src/main/java/org/olat/commons/calendar/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/commons/calendar/_i18n/LocalStrings_de.properties index b63c9575659f74f17ef4c1b4b5437c100ea35a4f..125cec0d340f634ba25d00b34b9a1b9f25325c22 100644 --- a/src/main/java/org/olat/commons/calendar/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/commons/calendar/_i18n/LocalStrings_de.properties @@ -135,6 +135,7 @@ chelp.group-calendar.title=Gruppenkalender chelp.personal-calendar-details.title=Persönlicher Kalender: Termine anlegen chelp.personal-calendar.title=Persönlicher Kalender chelp.personal-calendar-callist.title=Kalenderliste +chelp.admin-calendar.title=Kalender: Konfiguration day.short.di=$org.olat.core.gui.components.form.flexible.impl.elements\:day.short.di day.short.do=$org.olat.core.gui.components.form.flexible.impl.elements\:day.short.do @@ -167,6 +168,16 @@ month.short.mar=M\u00E4r month.short.nov=Nov month.short.oct=Okt month.short.sep=Sep +calendar.enable=Kalendar einschalten +calendar.admin=Kalendar konfiguration +calendar.admin.description=Hier k\u00F6nnen Sie den Kalender an oder abschalten. +calendar.enable.personal=Pers\u00F6nnliches Kalendar einschalten +calendar.enable.group=Gruppewerkzeug einschalten +calendar.enable.course.tool=Kurzswerkzeug einschalten +calendar.enable.course.element=Kursbaustein einschalten +menu.admin.calendar=Kalender +menu.admin.calendar.alt=Kalendar +help.hover.calendaradmin=Hilfe zur Kalendar konfigurieren error.goto.date=Falsche Datumseingabe (dd.mm.yyyy) help.hover.cal=Hilfe zum Kalender diff --git a/src/main/java/org/olat/commons/calendar/_spring/calendarContext.xml b/src/main/java/org/olat/commons/calendar/_spring/calendarContext.xml index 1de4b27eeea41b862f85593a9a8eb5848197bd83..0404bbc8be7d75dd9fc4737a3964a7573ae2201f 100644 --- a/src/main/java/org/olat/commons/calendar/_spring/calendarContext.xml +++ b/src/main/java/org/olat/commons/calendar/_spring/calendarContext.xml @@ -1,9 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" - http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd"> + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context.xsd"> + + <context:component-scan base-package="org.olat.commons.calendar" /> <bean id="calendarImportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="calendarImportJob" /> @@ -21,20 +26,9 @@ they will get notified. The shortest interval is set to two hours. --> <property name="cronExpression" value="0 22 */4 * * ?" /> - - <!-- OLAT-5093 start delay ensures there's no conflict with server startup and db not being ready yet --> + <!-- OLAT-5093 start delay ensures there's no conflict with server startup and db not being ready yet --> <property name="startDelay" value="40000" /> </bean> - - <bean id="calendarModule" class="org.olat.commons.calendar.CalendarModule" init-method="init"> - <property name="persistedProperties"> - <bean class="org.olat.core.configuration.PersistedProperties" scope="prototype" init-method="init" destroy-method="destroy" - depends-on="coordinatorManager,org.olat.core.util.WebappHelper"> - <constructor-arg index="0" ref="coordinatorManager"/> - <constructor-arg index="1" ref="calendarModule" /> - </bean> - </property> - </bean> <bean id="calendarImportJob" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="org.olat.commons.calendar.ImportCalendarJob" /> @@ -43,4 +37,23 @@ <bean id="calendarNotificationManager" class="org.olat.commons.calendar.notification.CalendarNotificationManagerImpl"/> <bean id="calendarUserDataDeleteManager" class="org.olat.commons.calendar.ICalFileCalendarUserDeleteManager"/> + <bean class="org.olat.core.extensions.action.GenericActionExtension" init-method="initExtensionPoints"> + <property name="order" value="7207" /> + <property name="navigationKey" value="usertools" /> + <property name="actionController"> + <bean class="org.olat.core.gui.control.creator.AutoCreator" scope="prototype"> + <property name="className" value="org.olat.commons.calendar.ui.CalendarAdminController"/> + </bean> + </property> + <property name="i18nActionKey" value="menu.admin.calendar"/> + <property name="i18nDescriptionKey" value="menu.admin.calendar.alt"/> + <property name="translationPackage" value="org.olat.commons.calendar"/> + <property name="extensionPoints"> + <list> + <value>org.olat.admin.SystemAdminMainController</value> + </list> + </property> + <property name="parentTreeNodeIdentifier" value="sysconfigParent" /> + </bean> + </beans> \ No newline at end of file diff --git a/src/main/java/org/olat/commons/calendar/restapi/UserCalendarWebService.java b/src/main/java/org/olat/commons/calendar/restapi/UserCalendarWebService.java index eda77926fd370d83b63eb4432cf0242c8d649e4b..fb581a5d872fcef9e440f5f8f1c56680c4a5193c 100644 --- a/src/main/java/org/olat/commons/calendar/restapi/UserCalendarWebService.java +++ b/src/main/java/org/olat/commons/calendar/restapi/UserCalendarWebService.java @@ -49,6 +49,7 @@ import org.olat.collaboration.CollaborationManager; import org.olat.collaboration.CollaborationTools; import org.olat.commons.calendar.CalendarManager; import org.olat.commons.calendar.CalendarManagerFactory; +import org.olat.commons.calendar.CalendarModule; import org.olat.commons.calendar.model.KalendarConfig; import org.olat.commons.calendar.model.KalendarEvent; import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; @@ -164,12 +165,18 @@ public class UserCalendarWebService { int typeIndex = calendarId.indexOf('_'); if(typeIndex <= 0 || (typeIndex + 1 >= calendarId.length())) { return null; - } + } + + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + if(!calendarModule.isEnabled()) { + return null; + } + String type = calendarId.substring(0, typeIndex); String id = calendarId.substring(typeIndex + 1); KalendarRenderWrapper wrapper = null; - if("group".equals(type)) { + if("group".equals(type) && calendarModule.isEnableGroupCalendar()) { Long groupId = Long.parseLong(id); BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); BusinessGroup group = bgs.loadBusinessGroup(groupId); @@ -177,11 +184,11 @@ public class UserCalendarWebService { CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class); wrapper = collaborationManager.getCalendar(group, ureq, false); } - } else if("course".equals(type)) { + } else if("course".equals(type) && (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar())) { Long courseId = Long.parseLong(id); ICourse course = CourseFactory.loadCourse(courseId); wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, course, null); - } else if("user".equals(type)) { + } else if("user".equals(type) && calendarModule.isEnablePersonalCalendar()) { List<String> identityName = Collections.singletonList(id); List<IdentityShort> shorts = BaseSecurityManager.getInstance().findShortIdentitiesByName(identityName); if(shorts.size() == 1 && shorts.get(0).getKey().equals(ureq.getIdentity().getKey())) { @@ -209,49 +216,59 @@ public class UserCalendarWebService { Roles roles = ureq.getUserSession().getRoles(); Identity retrievedUser = ureq.getIdentity(); - KalendarRenderWrapper personalWrapper = getPersonalCalendar(ureq); - calVisitor.visit(personalWrapper); - - RepositoryManager rm = RepositoryManager.getInstance(); - ACService acManager = CoreSpringFactory.getImpl(ACService.class); - SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule"); - repoParams.setOnlyExplicitMember(true); - repoParams.setIdentity(retrievedUser); - List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true); - for(RepositoryEntry entry:entries) { - AccessResult result = acManager.isAccessible(entry, retrievedUser, false); - if(result.isAccessible()) { - try { - final ICourse course = CourseFactory.loadCourse(entry.getOlatResource()); - CourseConfig config = course.getCourseEnvironment().getCourseConfig(); - if(config.isCalendarEnabled()) { - KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, entry.getOlatResource(), null); - calVisitor.visit(wrapper); - } else { - IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles); - CalCourseNodeVisitor visitor = new CalCourseNodeVisitor(); - new CourseTreeVisitor(course, ienv).visit(visitor); - if(visitor.isFound()) { - KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, entry.getOlatResource(), null); - calVisitor.visit(wrapper); + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + if(calendarModule.isEnabled()) { + + if(calendarModule.isEnablePersonalCalendar()) { + KalendarRenderWrapper personalWrapper = getPersonalCalendar(ureq); + calVisitor.visit(personalWrapper); + } + + if(calendarModule.isEnableCourseToolCalendar() || calendarModule.isEnableCourseElementCalendar()) { + RepositoryManager rm = RepositoryManager.getInstance(); + ACService acManager = CoreSpringFactory.getImpl(ACService.class); + SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule"); + repoParams.setOnlyExplicitMember(true); + repoParams.setIdentity(retrievedUser); + List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true); + for(RepositoryEntry entry:entries) { + AccessResult result = acManager.isAccessible(entry, retrievedUser, false); + if(result.isAccessible()) { + try { + final ICourse course = CourseFactory.loadCourse(entry.getOlatResource()); + CourseConfig config = course.getCourseEnvironment().getCourseConfig(); + if(config.isCalendarEnabled()) { + KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, entry.getOlatResource(), null); + calVisitor.visit(wrapper); + } else { + IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles); + CalCourseNodeVisitor visitor = new CalCourseNodeVisitor(); + new CourseTreeVisitor(course, ienv).visit(visitor); + if(visitor.isFound()) { + KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, entry.getOlatResource(), null); + calVisitor.visit(wrapper); + } + } + } catch (Exception e) { + log.error("", e); } } - } catch (Exception e) { - log.error("", e); } } - } - - CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class); - - //start found forums in groups - BusinessGroupService bgm = CoreSpringFactory.getImpl(BusinessGroupService.class); - SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true); - params.addTools(CollaborationTools.TOOL_CALENDAR); - List<BusinessGroup> groups = bgm.findBusinessGroups(params, null, 0, -1); - for(BusinessGroup group:groups) { - KalendarRenderWrapper wrapper = collaborationManager.getCalendar(group, ureq, false); - calVisitor.visit(wrapper); + + if(calendarModule.isEnableGroupCalendar()) { + CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class); + + //start found forums in groups + BusinessGroupService bgm = CoreSpringFactory.getImpl(BusinessGroupService.class); + SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true); + params.addTools(CollaborationTools.TOOL_CALENDAR); + List<BusinessGroup> groups = bgm.findBusinessGroups(params, null, 0, -1); + for(BusinessGroup group:groups) { + KalendarRenderWrapper wrapper = collaborationManager.getCalendar(group, ureq, false); + calVisitor.visit(wrapper); + } + } } } diff --git a/src/main/java/org/olat/commons/calendar/ui/CalendarAdminController.java b/src/main/java/org/olat/commons/calendar/ui/CalendarAdminController.java new file mode 100644 index 0000000000000000000000000000000000000000..74ab43d53aef2396ffd9de43afe76fc561a0b511 --- /dev/null +++ b/src/main/java/org/olat/commons/calendar/ui/CalendarAdminController.java @@ -0,0 +1,121 @@ +/** + * <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.commons.calendar.ui; + +import org.olat.collaboration.CollaborationToolsFactory; +import org.olat.commons.calendar.CalendarModule; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.form.flexible.FormItem; +import org.olat.core.gui.components.form.flexible.FormItemContainer; +import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement; +import org.olat.core.gui.components.form.flexible.impl.FormBasicController; +import org.olat.core.gui.components.form.flexible.impl.FormEvent; +import org.olat.core.gui.control.Controller; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.util.Util; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * + * Initial date: 02.10.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class CalendarAdminController extends FormBasicController { + + private MultipleSelectionElement enableEl, enablePersonalCalendarEl, + enableGroupCalendarEl, enableCourseToolEl, enableCourseElementEl; + + private static final String[] onKeys = new String[]{ "on" }; + private static final String[] onValues = new String[]{ "" }; + + @Autowired + private CalendarModule calendarModule; + + public CalendarAdminController(UserRequest ureq, WindowControl wControl) { + super(ureq, wControl, Util.createPackageTranslator(CalendarModule.class, ureq.getLocale())); + + initForm(ureq); + } + + @Override + protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { + setFormTitle("calendar.admin"); + setFormDescription("calendar.admin.description"); + setFormContextHelp("org.olat.commons.calendar", "admin-calendar.html", "help.hover.calendaradmin"); + + // + enableEl = uifactory.addCheckboxesHorizontal("enable", "calendar.enable", formLayout, onKeys, onValues); + enableEl.addActionListener(FormEvent.ONCHANGE); + enableEl.select("on", calendarModule.isEnabled()); + + enablePersonalCalendarEl = uifactory.addCheckboxesHorizontal("enable.personal", "calendar.enable.personal", formLayout, onKeys, onValues); + enablePersonalCalendarEl.addActionListener(FormEvent.ONCHANGE); + enablePersonalCalendarEl.select("on", calendarModule.isEnablePersonalCalendar()); + + enableGroupCalendarEl = uifactory.addCheckboxesHorizontal("enable.group", "calendar.enable.group", formLayout, onKeys, onValues); + enableGroupCalendarEl.addActionListener(FormEvent.ONCHANGE); + enableGroupCalendarEl.select("on", calendarModule.isEnableGroupCalendar()); + + enableCourseToolEl = uifactory.addCheckboxesHorizontal("enable.course.tool", "calendar.enable.course.tool", formLayout, onKeys, onValues); + enableCourseToolEl.addActionListener(FormEvent.ONCHANGE); + enableCourseToolEl.select("on", calendarModule.isEnableCourseToolCalendar()); + + enableCourseElementEl = uifactory.addCheckboxesHorizontal("enable.course.element", "calendar.enable.course.element", formLayout, onKeys, onValues); + enableCourseElementEl.addActionListener(FormEvent.ONCHANGE); + enableCourseElementEl.select("on", calendarModule.isEnableCourseElementCalendar()); + updateEnableElements(); + } + + @Override + protected void doDispose() { + // + } + + @Override + protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { + if(enableEl == source) { + calendarModule.setEnabled(enableEl.isAtLeastSelected(1)); + updateEnableElements(); + } else if(enablePersonalCalendarEl == source) { + calendarModule.setEnablePersonalCalendar(enablePersonalCalendarEl.isAtLeastSelected(1)); + } else if(enableGroupCalendarEl == source) { + calendarModule.setEnableGroupCalendar(enableGroupCalendarEl.isAtLeastSelected(1)); + CollaborationToolsFactory.getInstance().initAvailableTools(); + } else if(enableCourseToolEl == source) { + calendarModule.setEnableCourseToolCalendar(enableCourseToolEl.isAtLeastSelected(1)); + } else if(enableCourseElementEl == source) { + calendarModule.setEnableCourseElementCalendar(enableCourseElementEl.isAtLeastSelected(1)); + } + } + + @Override + protected void formOK(UserRequest ureq) { + // + } + + private void updateEnableElements() { + boolean enableOptions = enableEl.isAtLeastSelected(1); + enablePersonalCalendarEl.setEnabled(enableOptions); + enableGroupCalendarEl.setEnabled(enableOptions); + enableCourseToolEl.setEnabled(enableOptions); + enableCourseElementEl.setEnabled(enableOptions); + } +} diff --git a/src/main/java/org/olat/core/gui/control/generic/portal/PortalImpl.java b/src/main/java/org/olat/core/gui/control/generic/portal/PortalImpl.java index b3c8ff554b02799fd715337d27f7c5302af546fa..8acae679b226a69660c0b7e8030ad6f58fe0ed48 100644 --- a/src/main/java/org/olat/core/gui/control/generic/portal/PortalImpl.java +++ b/src/main/java/org/olat/core/gui/control/generic/portal/PortalImpl.java @@ -330,21 +330,23 @@ public class PortalImpl extends DefaultController implements Portal, ControllerE int rowcount = 0; while (rowIter.hasNext()) { String portletName = rowIter.next(); - PortletContainer pc = this.portletContainers.get(portletName); - // up command - if(rowcount == 0) pc.setCanMoveUp(false); - else pc.setCanMoveUp(true); - // down command - if (rowIter.hasNext()) pc.setCanMoveDown(true); - else pc.setCanMoveDown(false); - // left command - if(colcount == 0) pc.setCanMoveLeft(false); - else pc.setCanMoveLeft(true); - // right command - if (colIter.hasNext()) pc.setCanMoveRight(true); - else pc.setCanMoveRight(false); - - rowcount++; + PortletContainer pc = portletContainers.get(portletName); + if(pc != null) { + // up command + if(rowcount == 0) pc.setCanMoveUp(false); + else pc.setCanMoveUp(true); + // down command + if (rowIter.hasNext()) pc.setCanMoveDown(true); + else pc.setCanMoveDown(false); + // left command + if(colcount == 0) pc.setCanMoveLeft(false); + else pc.setCanMoveLeft(true); + // right command + if (colIter.hasNext()) pc.setCanMoveRight(true); + else pc.setCanMoveRight(false); + + rowcount++; + } } colcount++; } diff --git a/src/main/java/org/olat/course/config/ui/CourseOptionsController.java b/src/main/java/org/olat/course/config/ui/CourseOptionsController.java index 20ddc52befbb79b3baf0fcab46b7a197b1567de7..34b6e5ffcf2a0cb4390a94f87d61938c78a49397 100644 --- a/src/main/java/org/olat/course/config/ui/CourseOptionsController.java +++ b/src/main/java/org/olat/course/config/ui/CourseOptionsController.java @@ -22,6 +22,7 @@ package org.olat.course.config.ui; import java.util.List; import org.olat.commons.calendar.CalendarManager; +import org.olat.commons.calendar.CalendarModule; import org.olat.commons.calendar.ui.events.KalendarModifiedEvent; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; @@ -99,6 +100,8 @@ public class CourseOptionsController extends FormBasicController { private ReferencableEntriesSearchController glossarySearchCtr, folderSearchCtr; private DialogBoxController enableEfficiencyDC, disableEfficiencyDC; + @Autowired + private CalendarModule calendarModule; @Autowired private ReferenceManager referenceManager; @Autowired @@ -170,19 +173,21 @@ public class CourseOptionsController extends FormBasicController { efficencyEl.addActionListener(FormEvent.ONCHANGE); efficencyEl.select("xx", effEnabled); efficencyEl.setEnabled(editable && !managedEff); - - //calendar - FormLayoutContainer calCont = FormLayoutContainer.createDefaultFormLayout("cal", getTranslator()); - calCont.setRootForm(mainForm); - formLayout.add(calCont); - calCont.setFormContextHelp("org.olat.course.config.ui","course-calendar.html","help.hover.coursecal"); - - boolean calendarEnabled = courseConfig.isCalendarEnabled(); - boolean managedCal = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.calendar); - calendarEl = uifactory.addCheckboxesHorizontal("calIsOn", "chkbx.calendar.onoff", calCont, new String[] {"xx"}, new String[] {""}); - calendarEl.addActionListener(FormEvent.ONCHANGE); - calendarEl.select("xx", calendarEnabled); - calendarEl.setEnabled(editable && !managedCal); + + if(calendarModule.isEnabled() && calendarModule.isEnableCourseToolCalendar()) { + //calendar + FormLayoutContainer calCont = FormLayoutContainer.createDefaultFormLayout("cal", getTranslator()); + calCont.setRootForm(mainForm); + formLayout.add(calCont); + calCont.setFormContextHelp("org.olat.course.config.ui","course-calendar.html","help.hover.coursecal"); + + boolean calendarEnabled = courseConfig.isCalendarEnabled(); + boolean managedCal = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.calendar); + calendarEl = uifactory.addCheckboxesHorizontal("calIsOn", "chkbx.calendar.onoff", calCont, new String[] {"xx"}, new String[] {""}); + calendarEl.addActionListener(FormEvent.ONCHANGE); + calendarEl.select("xx", calendarEnabled); + calendarEl.setEnabled(editable && !managedCal); + } //chat FormLayoutContainer chatCont = FormLayoutContainer.createDefaultFormLayout("chat", getTranslator()); @@ -355,8 +360,8 @@ public class CourseOptionsController extends FormBasicController { boolean updateChat = courseConfig.isChatEnabled() != enableChat; courseConfig.setChatIsEnabled(enableChat); - boolean enableCalendar = calendarEl.isSelected(0); - boolean updateCalendar = courseConfig.isCalendarEnabled() != enableCalendar; + boolean enableCalendar = calendarEl == null ? false : calendarEl.isSelected(0); + boolean updateCalendar = courseConfig.isCalendarEnabled() != enableCalendar && calendarModule.isEnableCourseToolCalendar(); courseConfig.setCalendarEnabled(enableCalendar); String currentGlossarySoftKey = courseConfig.getGlossarySoftKey(); diff --git a/src/main/java/org/olat/course/nodes/cal/CalCourseNodeConfiguration.java b/src/main/java/org/olat/course/nodes/cal/CalCourseNodeConfiguration.java index 157464ea54dfb8c4094c9cc4f93b319f9fd37985..23f56a92a823b216dc5f6fc082e237cd81a0e832 100644 --- a/src/main/java/org/olat/course/nodes/cal/CalCourseNodeConfiguration.java +++ b/src/main/java/org/olat/course/nodes/cal/CalCourseNodeConfiguration.java @@ -22,6 +22,8 @@ package org.olat.course.nodes.cal; import java.util.Locale; +import org.olat.commons.calendar.CalendarModule; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.translator.Translator; import org.olat.core.util.Util; import org.olat.course.nodes.AbstractCourseNodeConfiguration; @@ -70,4 +72,10 @@ public class CalCourseNodeConfiguration extends AbstractCourseNodeConfiguration public String getGroup() { return CourseNodeGroup.management.name(); } -} + + @Override + public boolean isEnabled() { + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + return calendarModule.isEnabled() && calendarModule.isEnableCourseElementCalendar() && super.isEnabled(); + } +} \ No newline at end of file diff --git a/src/main/java/org/olat/course/run/CourseRuntimeController.java b/src/main/java/org/olat/course/run/CourseRuntimeController.java index 8b7175d6aeb16d09b23dd63d1ace964aafb5d2ca..537e66b2cd545714040637bbb1f15424aaafe327 100644 --- a/src/main/java/org/olat/course/run/CourseRuntimeController.java +++ b/src/main/java/org/olat/course/run/CourseRuntimeController.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import org.olat.NewControllerFactory; +import org.olat.commons.calendar.CalendarModule; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel; import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; @@ -161,6 +162,8 @@ public class CourseRuntimeController extends RepositoryEntryRuntimeController im private int currentUserCount; private Map<String, Boolean> courseRightsCache; + @Autowired + private CalendarModule calendarModule; @Autowired private RepositoryService repositoryService; @Autowired @@ -542,7 +545,7 @@ public class CourseRuntimeController extends RepositoryEntryRuntimeController im detailsLink = LinkFactory.createToolLink("courseconfig",translate("command.courseconfig"), this, "o_icon_details"); toolbarPanel.addTool(detailsLink); } - if (!isGuestOnly) { + if (!isGuestOnly && calendarModule.isEnabled() && calendarModule.isEnableCourseToolCalendar()) { calendarLink = LinkFactory.createToolLink("calendar",translate("command.calendar"), this, "o_icon_calendar"); calendarLink.setPopup(new LinkPopupSettings(950, 750, "cal")); calendarLink.setVisible(cc.isCalendarEnabled()); @@ -1151,7 +1154,7 @@ public class CourseRuntimeController extends RepositoryEntryRuntimeController im if(calendarLink != null) { ICourse course = CourseFactory.loadCourse(getOlatResourceable()); CourseConfig cc = course.getCourseEnvironment().getCourseConfig(); - calendarLink.setVisible(cc.isCalendarEnabled()); + calendarLink.setVisible(cc.isCalendarEnabled() && calendarModule.isEnabled() && calendarModule.isEnableCourseToolCalendar()); toolbarPanel.setDirty(true); } break; diff --git a/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java b/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java index 27f56c2529cb84e051ace67d872a5757ef1188ed..7856827eb64d0ca41ebc36d0d3097d955b0c6f0a 100644 --- a/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java +++ b/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java @@ -37,6 +37,7 @@ import org.olat.basesecurity.GroupRoles; import org.olat.basesecurity.ui.GroupController; import org.olat.collaboration.CollaborationTools; import org.olat.collaboration.CollaborationToolsFactory; +import org.olat.commons.calendar.CalendarModule; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; import org.olat.core.commons.services.notifications.SubscriptionContext; @@ -201,6 +202,8 @@ public class BusinessGroupMainRunController extends MainLayoutBasicController im @Autowired private BaseSecurity securityManager; @Autowired + private CalendarModule calendarModule; + @Autowired private BusinessGroupService businessGroupService; private EventBus singleUserEventBus; private String adminNodeId; // reference to admin menu item @@ -992,11 +995,10 @@ public class BusinessGroupMainRunController extends MainLayoutBasicController im gtnChild.setAltText(translate("menutree.news.alt")); gtnChild.setIconCssClass("o_icon_news"); root.addChild(gtnChild); - //fxdiff BAKS-7 Resume function nodeInformation = gtnChild; } - if (collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR)) { + if (calendarModule.isEnabled() && calendarModule.isEnableGroupCalendar() && collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR)) { gtnChild = new GenericTreeNode(); gtnChild.setTitle(translate("menutree.calendar")); gtnChild.setUserObject(ACTIVITY_MENUSELECT_CALENDAR); diff --git a/src/main/java/org/olat/home/HomeCalendarController.java b/src/main/java/org/olat/home/HomeCalendarController.java index 619fccdc04b38ae698b84c64e0a9379b3625000d..f189f467b6d4e09fa9e6fbd0d6f9fd2f818ec9e3 100644 --- a/src/main/java/org/olat/home/HomeCalendarController.java +++ b/src/main/java/org/olat/home/HomeCalendarController.java @@ -35,6 +35,7 @@ import org.olat.collaboration.CollaborationManager; import org.olat.collaboration.CollaborationTools; import org.olat.commons.calendar.CalendarManager; import org.olat.commons.calendar.CalendarManagerFactory; +import org.olat.commons.calendar.CalendarModule; import org.olat.commons.calendar.ImportCalendarManager; import org.olat.commons.calendar.model.KalendarConfig; import org.olat.commons.calendar.ui.CalendarController; @@ -78,6 +79,7 @@ public class HomeCalendarController extends BasicController implements Activatea private UserSession userSession; private CalendarController calendarController; + public HomeCalendarController(UserRequest ureq, WindowControl windowControl) { super(ureq, windowControl); @@ -104,92 +106,104 @@ public class HomeCalendarController extends BasicController implements Activatea public static List<KalendarRenderWrapper> getListOfCalendarWrappers(UserRequest ureq, WindowControl wControl) { List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>(); + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + if(!calendarModule.isEnabled()) { + return calendars; + } + // get the personal calendar CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager(); - KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(ureq.getIdentity()); - calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE); - KalendarConfig personalKalendarConfig = calendarManager.findKalendarConfigForIdentity( - calendarWrapper.getKalendar(), ureq); - if (personalKalendarConfig != null) { - calendarWrapper.getKalendarConfig().setCss(personalKalendarConfig.getCss()); - calendarWrapper.getKalendarConfig().setVis(personalKalendarConfig.isVis()); + if(calendarModule.isEnablePersonalCalendar()) { + KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(ureq.getIdentity()); + calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE); + KalendarConfig personalKalendarConfig = calendarManager.findKalendarConfigForIdentity( + calendarWrapper.getKalendar(), ureq); + if (personalKalendarConfig != null) { + calendarWrapper.getKalendarConfig().setCss(personalKalendarConfig.getCss()); + calendarWrapper.getKalendarConfig().setVis(personalKalendarConfig.isVis()); + } + calendars.add(calendarWrapper); } - calendars.add(calendarWrapper); // get group calendars - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - - SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams(ureq.getIdentity(), true, false); - groupParams.addTools(CollaborationTools.TOOL_CALENDAR); - List<BusinessGroup> ownerGroups = bgs.findBusinessGroups(groupParams, null, 0, -1); - addCalendars(ureq, ownerGroups, true, calendars); - - SearchBusinessGroupParams groupParams2 = new SearchBusinessGroupParams(ureq.getIdentity(), false, true); - groupParams2.addTools(CollaborationTools.TOOL_CALENDAR); - List<BusinessGroup> attendedGroups = bgs.findBusinessGroups(groupParams2, null, 0, -1); - for (Iterator<BusinessGroup> ownerGroupsIterator = ownerGroups.iterator(); ownerGroupsIterator.hasNext();) { - BusinessGroup ownerGroup = ownerGroupsIterator.next(); - if (attendedGroups.contains(ownerGroup)) { - attendedGroups.remove(ownerGroup); + if(calendarModule.isEnableGroupCalendar()) { + BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + + SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams(ureq.getIdentity(), true, false); + groupParams.addTools(CollaborationTools.TOOL_CALENDAR); + List<BusinessGroup> ownerGroups = bgs.findBusinessGroups(groupParams, null, 0, -1); + addCalendars(ureq, ownerGroups, true, calendars); + + SearchBusinessGroupParams groupParams2 = new SearchBusinessGroupParams(ureq.getIdentity(), false, true); + groupParams2.addTools(CollaborationTools.TOOL_CALENDAR); + List<BusinessGroup> attendedGroups = bgs.findBusinessGroups(groupParams2, null, 0, -1); + for (Iterator<BusinessGroup> ownerGroupsIterator = ownerGroups.iterator(); ownerGroupsIterator.hasNext();) { + BusinessGroup ownerGroup = ownerGroupsIterator.next(); + if (attendedGroups.contains(ownerGroup)) { + attendedGroups.remove(ownerGroup); + } } + addCalendars(ureq, attendedGroups, false, calendars); } - addCalendars(ureq, attendedGroups, false, calendars); - - // add course calendars - List<String> subscribedCourseCalendarIDs = CourseCalendarSubscription.getSubscribedCourseCalendarIDs( - ureq.getUserSession().getGuiPreferences()); - RepositoryManager repoManager = RepositoryManager.getInstance(); - List<String> calendarIDsToBeRemoved = new ArrayList<String>(); - for (Iterator<String> iter = subscribedCourseCalendarIDs.iterator(); iter.hasNext();) { - String courseCalendarID = iter.next(); - final long courseResourceableID = Long.parseLong(courseCalendarID); + if(calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar()) { + // add course calendars + List<String> subscribedCourseCalendarIDs = CourseCalendarSubscription.getSubscribedCourseCalendarIDs( + ureq.getUserSession().getGuiPreferences()); - RepositoryEntry repoEntry = repoManager.lookupRepositoryEntry(new OLATResourceable() { - - public Long getResourceableId() { return new Long(courseResourceableID); } - public String getResourceableTypeName() { return CourseModule.getCourseTypeName(); } - }, false); - if (repoEntry == null) { - // mark calendar ID for cleanup - calendarIDsToBeRemoved.add(courseCalendarID); - continue; - } - try { - ICourse course = CourseFactory.loadCourse(new Long(courseResourceableID)); - //calendar course aren't enabled per default but course node of type calendar are always possible - //REVIEW if (!course.getCourseEnvironment().getCourseConfig().isCalendarEnabled()) continue; - // add course calendar - KalendarRenderWrapper courseCalendarWrapper = calendarManager.getCourseCalendar(course); - CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager(); - boolean isPrivileged = cgm.isIdentityCourseAdministrator(ureq.getIdentity()) - || cgm.hasRight(ureq.getIdentity(), CourseRights.RIGHT_COURSEEDITOR); - if (isPrivileged) { - courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE); - } else { - courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY); + RepositoryManager repoManager = RepositoryManager.getInstance(); + List<String> calendarIDsToBeRemoved = new ArrayList<String>(); + for (Iterator<String> iter = subscribedCourseCalendarIDs.iterator(); iter.hasNext();) { + String courseCalendarID = iter.next(); + final long courseResourceableID = Long.parseLong(courseCalendarID); + + RepositoryEntry repoEntry = repoManager.lookupRepositoryEntry(new OLATResourceable() { + + public Long getResourceableId() { return new Long(courseResourceableID); } + public String getResourceableTypeName() { return CourseModule.getCourseTypeName(); } + }, false); + if (repoEntry == null) { + // mark calendar ID for cleanup + calendarIDsToBeRemoved.add(courseCalendarID); + continue; } - KalendarConfig courseKalendarConfig = calendarManager.findKalendarConfigForIdentity(courseCalendarWrapper.getKalendar(), ureq); - if (courseKalendarConfig != null) { - courseCalendarWrapper.getKalendarConfig().setCss(courseKalendarConfig.getCss()); - courseCalendarWrapper.getKalendarConfig().setVis(courseKalendarConfig.isVis()); + try { + ICourse course = CourseFactory.loadCourse(new Long(courseResourceableID)); + //calendar course aren't enabled per default but course node of type calendar are always possible + //REVIEW if (!course.getCourseEnvironment().getCourseConfig().isCalendarEnabled()) continue; + // add course calendar + KalendarRenderWrapper courseCalendarWrapper = calendarManager.getCourseCalendar(course); + CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager(); + boolean isPrivileged = cgm.isIdentityCourseAdministrator(ureq.getIdentity()) + || cgm.hasRight(ureq.getIdentity(), CourseRights.RIGHT_COURSEEDITOR); + if (isPrivileged) { + courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE); + } else { + courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY); + } + KalendarConfig courseKalendarConfig = calendarManager.findKalendarConfigForIdentity(courseCalendarWrapper.getKalendar(), ureq); + if (courseKalendarConfig != null) { + courseCalendarWrapper.getKalendarConfig().setCss(courseKalendarConfig.getCss()); + courseCalendarWrapper.getKalendarConfig().setVis(courseKalendarConfig.isVis()); + } + courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl)); + calendars.add(courseCalendarWrapper); + } catch (CorruptedCourseException e) { + log.error("Corrupted course: " + courseResourceableID, null); } - courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl)); - calendars.add(courseCalendarWrapper); - } catch (CorruptedCourseException e) { - log.error("Corrupted course: " + courseResourceableID, null); } - } - - // do calendar ID cleanup - if (!calendarIDsToBeRemoved.isEmpty()) { - subscribedCourseCalendarIDs = CourseCalendarSubscription.getSubscribedCourseCalendarIDs( - ureq.getUserSession().getGuiPreferences()); - for (Iterator<String> iter = calendarIDsToBeRemoved.iterator(); iter.hasNext();) { - subscribedCourseCalendarIDs.remove(iter.next()); + + // do calendar ID cleanup + if (!calendarIDsToBeRemoved.isEmpty()) { + subscribedCourseCalendarIDs = CourseCalendarSubscription.getSubscribedCourseCalendarIDs( + ureq.getUserSession().getGuiPreferences()); + for (Iterator<String> iter = calendarIDsToBeRemoved.iterator(); iter.hasNext();) { + subscribedCourseCalendarIDs.remove(iter.next()); + } + CourseCalendarSubscription.persistSubscribedCalendarIDs(subscribedCourseCalendarIDs, ureq.getUserSession().getGuiPreferences()); } - CourseCalendarSubscription.persistSubscribedCalendarIDs(subscribedCourseCalendarIDs, ureq.getUserSession().getGuiPreferences()); } + return calendars; } diff --git a/src/main/java/org/olat/home/HomeCalendarExtension.java b/src/main/java/org/olat/home/HomeCalendarExtension.java new file mode 100644 index 0000000000000000000000000000000000000000..75d5442851c57066889694ed788980776530b0e0 --- /dev/null +++ b/src/main/java/org/olat/home/HomeCalendarExtension.java @@ -0,0 +1,39 @@ +/** + * <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.home; + +import org.olat.commons.calendar.CalendarModule; +import org.olat.core.CoreSpringFactory; +import org.olat.core.extensions.action.GenericActionExtension; + +/** + * + * Initial date: 03.10.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class HomeCalendarExtension extends GenericActionExtension { + + @Override + public boolean isEnabled() { + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + return calendarModule.isEnabled() && calendarModule.isEnablePersonalCalendar() && super.isEnabled(); + } +} diff --git a/src/main/java/org/olat/home/_spring/homeContext.xml b/src/main/java/org/olat/home/_spring/homeContext.xml index 34fc054995ff213feaf23b0458a6e716e7931fe6..70bf9b2ea9401ad08b716b45e0de1334aa0d99a7 100644 --- a/src/main/java/org/olat/home/_spring/homeContext.xml +++ b/src/main/java/org/olat/home/_spring/homeContext.xml @@ -8,7 +8,7 @@ <bean class="org.olat.home.HomeModule" init-method="init"/> <!-- the weekly calendar --> - <bean class="org.olat.core.extensions.action.GenericActionExtension" init-method="initExtensionPoints"> + <bean class="org.olat.home.HomeCalendarExtension" init-method="initExtensionPoints"> <property name="order" value="102" /> <property name="enabled" value="${minimalhome.ext.calendar}"></property> <property name="navigationKey" value="calendar" /> diff --git a/src/main/java/org/olat/portal/calendar/CalendarPortlet.java b/src/main/java/org/olat/portal/calendar/CalendarPortlet.java index 543672647f55eb701d00d14b56bcee9556034494..edb56193ae51a0a5b5f129654eb6595e69b5b7be 100644 --- a/src/main/java/org/olat/portal/calendar/CalendarPortlet.java +++ b/src/main/java/org/olat/portal/calendar/CalendarPortlet.java @@ -31,6 +31,8 @@ import java.util.Date; import java.util.Locale; import java.util.Map; +import org.olat.commons.calendar.CalendarModule; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.control.Controller; @@ -63,6 +65,16 @@ public class CalendarPortlet extends AbstractPortlet { p.setLocale(ureq.getLocale()); return p; } + + + + @Override + public boolean isEnabled() { + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + return calendarModule.isEnabled() && super.isEnabled(); + } + + /** * @see org.olat.gui.control.generic.portal.Portlet#getTitle() diff --git a/src/main/java/org/olat/portal/calendar/CalendarPortletRunController.java b/src/main/java/org/olat/portal/calendar/CalendarPortletRunController.java index 00062eb1cf7d735e2a99cdde3cfaf924694aef1b..730302146ab07ea9e25528c1abbd95fe73bd24d1 100644 --- a/src/main/java/org/olat/portal/calendar/CalendarPortletRunController.java +++ b/src/main/java/org/olat/portal/calendar/CalendarPortletRunController.java @@ -156,6 +156,7 @@ public class CalendarPortletRunController extends BasicController { * org.olat.core.gui.components.Component, * org.olat.core.gui.control.Event) */ + @Override public void event(UserRequest ureq, Component source, Event event) { if (source == showAllLink) { // activate homes tab in top navigation and active calendar menu item @@ -173,6 +174,7 @@ public class CalendarPortletRunController extends BasicController { * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, * org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event) */ + @Override public void event(UserRequest ureq, Controller source, Event event) { if (source == tableController) { if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) { @@ -192,14 +194,10 @@ public class CalendarPortletRunController extends BasicController { } } + @Override protected void doDispose() { // } - - public void event(Event event) { - dirty = true; - } - } class EventsModel extends DefaultTableDataModel<KalendarEvent> { @@ -211,10 +209,12 @@ class EventsModel extends DefaultTableDataModel<KalendarEvent> { super(events); } + @Override public int getColumnCount() { return COLUMNS; } + @Override public Object getValueAt(int row, int col) { KalendarEvent event = getObject(row); switch (col) { diff --git a/src/main/java/org/olat/restapi/repository/course/CourseWebService.java b/src/main/java/org/olat/restapi/repository/course/CourseWebService.java index 66303d7321b8c821cd6d3652b2a0dc84e384cff3..f93ab74f3a0d98a8661d50c3050f23d85faf8e78 100644 --- a/src/main/java/org/olat/restapi/repository/course/CourseWebService.java +++ b/src/main/java/org/olat/restapi/repository/course/CourseWebService.java @@ -54,6 +54,7 @@ import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.Constants; import org.olat.basesecurity.GroupRoles; import org.olat.basesecurity.SecurityGroup; +import org.olat.commons.calendar.CalendarModule; import org.olat.commons.calendar.restapi.CalWebService; import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; import org.olat.core.CoreSpringFactory; @@ -142,7 +143,10 @@ public class CourseWebService { @Path("calendar") public CalWebService getCourseCalendarWebService(@Context HttpServletRequest request) { - if(course.getCourseConfig().isCalendarEnabled()) { + CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class); + if(calendarModule.isEnabled() + && (calendarModule.isEnableCourseToolCalendar() || calendarModule.isEnableCourseElementCalendar()) + && course.getCourseConfig().isCalendarEnabled()) { UserRequest ureq = getUserRequest(request); KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, courseOres, null); return new CalWebService(wrapper); diff --git a/src/main/resources/serviceconfig/olat.properties b/src/main/resources/serviceconfig/olat.properties index 32ad97e9e50f6c364205f2575b911b6ad784a6c3..1f85442867fb7c0159c001bdcc3bd07a762d934b 100644 --- a/src/main/resources/serviceconfig/olat.properties +++ b/src/main/resources/serviceconfig/olat.properties @@ -559,6 +559,26 @@ instantMessaging.enable=true #whether to display current course participant count in the course toolbox course.display.participants.count=true +######################################################################## +# Calendar +######################################################################## + +# Enable or not the calendar feature in OpenOLAT +calendar.enabled=true +calendar.enabled.values=true,false +# Enable personal calendar (if calendar is enabled) +calendar.personal.enabled=true +calendar.personal.enabled.values=true,false +# Enable group calendar (if calendar is enabled) +calendar.group.enabled=true +calendar.group.enabled.values=true,false +# Enable the calendar tool in course (if calendar is enabled) +calendar.course.tool.enabled=true +calendar.course.tool.enabled.values=true,false +# Enable the calendar course element in course (if calendar is enabled) +calendar.course.element.enabled=true +calendar.course.element.enabled.values=true,false + ######################################################################## # Social sharing options ########################################################################