Skip to content
Snippets Groups Projects
Commit c5a80d8f authored by srosse's avatar srosse
Browse files

OO-3873: use status of course to blocked resources notifications

Use the status of the course where the resources is linked to block the
notifications. Reverse the check if the notifications are allowed
between preview and life course environment
parent bd727da8
No related branches found
No related tags found
No related merge requests found
Showing
with 61 additions and 60 deletions
......@@ -49,7 +49,6 @@ import org.olat.course.CourseModule;
import org.olat.group.BusinessGroup;
import org.olat.group.manager.BusinessGroupDAO;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryStatusEnum;
import org.olat.repository.RepositoryManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -100,10 +99,9 @@ public class CalendarNotificationHandler implements NotificationsHandler {
String calType = null;
String title = null;
if (type.equals(CalendarController.ACTION_CALENDAR_COURSE)) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", id), false);
RepositoryEntryStatusEnum status = re.getEntryStatus();
if(status.decommissioned()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", id), false);
if(re == null || re.getEntryStatus().decommissioned()) {
return notificationsManager.getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
calType = CalendarManager.TYPE_COURSE;
......
......@@ -26,7 +26,6 @@ import java.util.Locale;
import org.olat.commons.info.InfoMessage;
import org.olat.commons.info.InfoMessageManager;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.services.notifications.NotificationHelper;
import org.olat.core.commons.services.notifications.NotificationsHandler;
import org.olat.core.commons.services.notifications.NotificationsManager;
......@@ -46,7 +45,6 @@ import org.olat.core.util.resource.OresHelper;
import org.olat.group.BusinessGroup;
import org.olat.group.BusinessGroupService;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryStatusEnum;
import org.olat.repository.RepositoryManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -67,8 +65,14 @@ public class InfoMessageNotificationHandler implements NotificationsHandler {
private static final String CSS_CLASS_ICON = "o_infomsg_icon";
@Autowired
private RepositoryManager repositoryManager;
@Autowired
private InfoMessageManager infoMessageManager;
@Autowired
private NotificationsManager notificationsManager;
@Autowired
private BusinessGroupService businessGroupService;
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
......@@ -89,16 +93,13 @@ public class InfoMessageNotificationHandler implements NotificationsHandler {
String displayName;
String notificationtitle;
if ("BusinessGroup".equals(resName)) {
BusinessGroupService groupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup group = groupService.loadBusinessGroup(resId);
BusinessGroup group = businessGroupService.loadBusinessGroup(resId);
displayName = group.getName();
notificationtitle = "notification.title.group";
} else {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(resName, resId), false);
if(re== null || re.getEntryStatus() == RepositoryEntryStatusEnum.closed
|| re.getEntryStatus() == RepositoryEntryStatusEnum.trash
|| re.getEntryStatus() == RepositoryEntryStatusEnum.deleted) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(resName, resId), false);
if(re== null || re.getEntryStatus().decommissioned()) {
return notificationsManager.getNoSubscriptionInfo();
}
displayName = re.getDisplayname();
notificationtitle = "notification.title";
......@@ -122,10 +123,10 @@ public class InfoMessageNotificationHandler implements NotificationsHandler {
}
} catch (Exception e) {
log.error("Unexpected exception", e);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
si = notificationsManager.getNoSubscriptionInfo();
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
......@@ -133,7 +134,7 @@ public class InfoMessageNotificationHandler implements NotificationsHandler {
@Override
public String createTitleInfo(Subscriber subscriber, Locale locale) {
Translator translator = Util.createPackageTranslator(this.getClass(), locale);
String displayName = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(subscriber.getPublisher().getResId());
String displayName = repositoryManager.lookupDisplayNameByOLATResourceableId(subscriber.getPublisher().getResId());
return translator.translate("notification.title", new String[]{displayName});
}
......
......@@ -128,7 +128,11 @@ public class PersistingCourseGroupManager implements CourseGroupManager {
@Override
public boolean isNotificationsAllowed() {
return false;
RepositoryEntry re = getCourseEntry();
if(re == null || re.getEntryStatus() == null) {
return false;
}
return !re.getEntryStatus().decommissioned();
}
public void updateRepositoryEntry(RepositoryEntry entry) {
......
......@@ -95,7 +95,6 @@ public class GTAMarkedNotificationsHandler implements NotificationsHandler {
}
} catch (Exception e) {
log.error("Cannot create gtask notifications for subscriber: " + subscriber.getKey(), e);
//checkPublisher(p);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
......
......@@ -71,7 +71,6 @@ import org.olat.modules.assessment.Role;
import org.olat.modules.assessment.manager.AssessmentEntryDAO;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryRelationType;
import org.olat.repository.RepositoryEntryStatusEnum;
import org.olat.repository.RepositoryService;
import org.olat.user.UserManager;
......@@ -145,14 +144,12 @@ class GTANotifications {
if(subIdentifier.startsWith("Marked::")) {
subIdentifier = subIdentifier.substring("Marked::".length(), subIdentifier.length());
}
CourseNode node = course.getRunStructure().getNode(subIdentifier);
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
if(entry == null || entry.getEntryStatus() == RepositoryEntryStatusEnum.closed
|| entry.getEntryStatus() == RepositoryEntryStatusEnum.trash
|| entry.getEntryStatus() == RepositoryEntryStatusEnum.deleted) {
if(!course.getCourseEnvironment().getCourseGroupManager().isNotificationsAllowed()) {
return Collections.emptyList();
}
CourseNode node = course.getRunStructure().getNode(subIdentifier);
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
if(node instanceof GTACourseNode) {
gtaNode = (GTACourseNode)node;
displayName = entry.getDisplayname();
......
......@@ -95,7 +95,6 @@ public class GTANotificationsHandler implements NotificationsHandler {
}
} catch (Exception e) {
log.error("Cannot create gtask notifications for subscriber: " + subscriber.getKey(), e);
//checkPublisher(p);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
......
......@@ -25,6 +25,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
......@@ -83,19 +84,23 @@ public class PFNotifications {
translator = Util.createPackageTranslator(PFRunController.class, locale);
}
public List<SubscriptionListItem> getItems() throws Exception {
public List<SubscriptionListItem> getItems() {
Publisher p = subscriber.getPublisher();
Identity identity = subscriber.getIdentity();
ICourse course = CourseFactory.loadCourse(p.getResId());
CourseEnvironment courseEnv = course.getCourseEnvironment();
CourseGroupManager groupManager = courseEnv.getCourseGroupManager();
if(!courseEnv.getCourseGroupManager().isNotificationsAllowed()) {
return Collections.emptyList();
}
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
Date latestNews = p.getLatestNewsDate();
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
this.displayname = entry.getDisplayname();
CourseGroupManager groupManager = courseEnv.getCourseGroupManager();
if (groupManager.isIdentityCourseCoach(identity) || groupManager.isIdentityCourseAdministrator(identity)) {
List<Identity> participants = pfManager.getParticipants(identity, courseEnv, groupManager.isIdentityCourseAdministrator(identity));
......
......@@ -42,7 +42,6 @@ import org.olat.core.commons.services.notifications.model.TitleItem;
import org.olat.core.gui.translator.Translator;
import org.olat.core.id.Identity;
import org.olat.core.id.context.BusinessControlFactory;
import org.olat.core.logging.LogDelegator;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper;
......@@ -52,7 +51,6 @@ import org.olat.group.BusinessGroup;
import org.olat.group.BusinessGroupService;
import org.olat.modules.fo.manager.ForumManager;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryStatusEnum;
import org.olat.repository.RepositoryManager;
/**
......@@ -60,7 +58,7 @@ import org.olat.repository.RepositoryManager;
*
* @author Felix Jost
*/
public class ForumNotificationsHandler extends LogDelegator implements NotificationsHandler {
public class ForumNotificationsHandler implements NotificationsHandler {
private static final OLog log = Tracing.createLoggerFor(ForumNotificationsHandler.class);
public ForumNotificationsHandler() {
......@@ -85,16 +83,14 @@ public class ForumNotificationsHandler extends LogDelegator implements Notificat
try {
forumKey = Long.parseLong(p.getData());
} catch (NumberFormatException e) {
logError("Could not parse forum key!", e);
log.error("Could not parse forum key!", e);
NotificationsManager.getInstance().deactivate(p);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
if("CourseModule".equals(p.getResName())) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if(re == null || re.getEntryStatus() == RepositoryEntryStatusEnum.closed
|| re.getEntryStatus() == RepositoryEntryStatusEnum.trash
|| re.getEntryStatus() == RepositoryEntryStatusEnum.deleted) {
if(re == null || re.getEntryStatus().decommissioned()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
......@@ -153,17 +149,17 @@ public class ForumNotificationsHandler extends LogDelegator implements Notificat
if("BusinessGroup".equals(p.getResName())) {
BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(p.getResId());
if(bg == null) {
logInfo("deactivating publisher with key; " + p.getKey(), null);
log.info("deactivating publisher with key; " + p.getKey(), null);
NotificationsManager.getInstance().deactivate(p);
}
} else if ("CourseModule".equals(p.getResName())) {
if(!NotificationsUpgradeHelper.checkCourse(p)) {
logInfo("deactivating publisher with key; " + p.getKey(), null);
log.info("deactivating publisher with key; " + p.getKey(), null);
NotificationsManager.getInstance().deactivate(p);
}
}
} catch (Exception e) {
logError("", e);
log.error("", e);
}
}
......
......@@ -49,7 +49,6 @@ import org.olat.modules.webFeed.Feed;
import org.olat.modules.webFeed.Item;
import org.olat.modules.webFeed.ui.FeedMainController;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryStatusEnum;
import org.olat.repository.RepositoryManager;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -85,29 +84,28 @@ public abstract class FeedNotificationsHandler implements NotificationsHandler {
try {
final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
RepositoryEntry re = repoManager.lookupRepositoryEntry(
OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getEntryStatus().decommissioned()) {
return notificationsManager.getNoSubscriptionInfo();
}
String title;
try {
RepositoryEntry re = repoManager.lookupRepositoryEntry(
OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
RepositoryEntryStatusEnum status = re.getEntryStatus();
if (status.decommissioned()) {
String displayName = re.getDisplayname();
if("CourseModule".equals(p.getResName())) {
ICourse course = CourseFactory.loadCourse(re);
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
if(node == null) {
notificationsManager.deactivate(p);
return notificationsManager.getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
if("CourseModule".equals(p.getResName())) {
ICourse course = CourseFactory.loadCourse(re);
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
if(node == null) {
notificationsManager.deactivate(p);
return notificationsManager.getNoSubscriptionInfo();
}
title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[]{displayName});
} else {
title = getHeader(translator, displayName);
if (!course.getCourseEnvironment().getCourseGroupManager().isNotificationsAllowed()) {
return notificationsManager.getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Unknown Exception", e);
return notificationsManager.getNoSubscriptionInfo();
title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[]{displayName});
} else {
title = getHeader(translator, displayName);
}
OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData()));
......@@ -138,6 +136,10 @@ public abstract class FeedNotificationsHandler implements NotificationsHandler {
String urlToSend = BusinessControlFactory.getInstance()
.getURLFromBusinessPathString(businessPath);
String iconCssClass = item.extraCSSClass();
if(!StringHelper.containsNonWhitespace(iconCssClass)) {
iconCssClass = getCssClassIcon();
}
Date publishDate = item.getPublishDate();
if(item.isPublished()) {
if(compareDate.before(publishDate)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment