From a0f04eee8c55fa04cfd4ca99216fe2d44bbdf589 Mon Sep 17 00:00:00 2001 From: srosse <stephane.rosse@frentix.com> Date: Mon, 30 Mar 2020 20:35:44 +0200 Subject: [PATCH] OO-4606: don't send email for trashed or deleted repository entries --- .../manager/LectureBlockReminderDAO.java | 2 + .../lecture/manager/LectureServiceImpl.java | 8 ++-- .../manager/LectureBlockReminderDAOTest.java | 39 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/olat/modules/lecture/manager/LectureBlockReminderDAO.java b/src/main/java/org/olat/modules/lecture/manager/LectureBlockReminderDAO.java index 7641f66a1cb..bdd4d778917 100644 --- a/src/main/java/org/olat/modules/lecture/manager/LectureBlockReminderDAO.java +++ b/src/main/java/org/olat/modules/lecture/manager/LectureBlockReminderDAO.java @@ -31,6 +31,7 @@ import org.olat.modules.lecture.LectureBlockStatus; import org.olat.modules.lecture.LectureRollCallStatus; import org.olat.modules.lecture.model.LectureBlockReminderImpl; import org.olat.modules.lecture.model.LectureBlockToTeacher; +import org.olat.repository.RepositoryEntryStatusEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -69,6 +70,7 @@ public class LectureBlockReminderDAO { .append(" select reminder.key from lecturereminder reminder") .append(" where block.key=reminder.lectureBlock.key and teacher.key=reminder.identity.key") .append(" ) and block.statusString<>'").append(LectureBlockStatus.cancelled.name()).append("'") + .append(" and re.status ").in(RepositoryEntryStatusEnum.preparationToClosed()) .append(" and block.rollCallStatusString not in ('").append(LectureRollCallStatus.closed.name()).append("','") .append(LectureRollCallStatus.autoclosed.name()).append("','").append(LectureRollCallStatus.reopen.name()).append("')"); diff --git a/src/main/java/org/olat/modules/lecture/manager/LectureServiceImpl.java b/src/main/java/org/olat/modules/lecture/manager/LectureServiceImpl.java index 8a0ded580cc..2de251907ae 100644 --- a/src/main/java/org/olat/modules/lecture/manager/LectureServiceImpl.java +++ b/src/main/java/org/olat/modules/lecture/manager/LectureServiceImpl.java @@ -1331,7 +1331,9 @@ public class LectureServiceImpl implements LectureService, UserDataDeletable, De private void sendAutoCloseNotifications(LectureBlock lectureBlock) { RepositoryEntry entry = lectureBlock.getEntry(); RepositoryEntryLectureConfiguration config = getRepositoryEntryLectureConfiguration(entry); - if(config.isLectureEnabled()) { + if(config.isLectureEnabled() + && entry.getEntryStatus() != RepositoryEntryStatusEnum.trash + && entry.getEntryStatus() != RepositoryEntryStatusEnum.deleted) { List<Identity> owners = repositoryEntryRelationDao .getMembers(entry, RepositoryEntryRelationType.all, GroupRoles.owner.name()); List<Identity> teachers = getTeachers(lectureBlock); @@ -1340,9 +1342,9 @@ public class LectureServiceImpl implements LectureService, UserDataDeletable, De MailerResult result = sendMail("lecture.autoclose.notification.subject", "lecture.autoclose.notification.body", owner, teachers, lectureBlock); if(result.getReturnCode() == MailerResult.OK) { - log.info(Tracing.M_AUDIT, "Notification of lecture auto-close: " + lectureBlock.getKey() + " in course: " + entry.getKey()); + log.info(Tracing.M_AUDIT, "Notification of lecture auto-close: {} in course: {}", lectureBlock.getKey(), entry.getKey()); } else { - log.error("Notification of lecture auto-close cannot be send: " + lectureBlock.getKey() + " in course: " + entry.getKey()); + log.error("Notification of lecture auto-close cannot be send: {} in course: {}", lectureBlock.getKey(), entry.getKey()); } } } diff --git a/src/test/java/org/olat/modules/lecture/manager/LectureBlockReminderDAOTest.java b/src/test/java/org/olat/modules/lecture/manager/LectureBlockReminderDAOTest.java index ca08b6444be..0a3844f65b1 100644 --- a/src/test/java/org/olat/modules/lecture/manager/LectureBlockReminderDAOTest.java +++ b/src/test/java/org/olat/modules/lecture/manager/LectureBlockReminderDAOTest.java @@ -35,6 +35,8 @@ import org.olat.modules.lecture.RepositoryEntryLectureConfiguration; import org.olat.modules.lecture.model.LectureBlockReminderImpl; import org.olat.modules.lecture.model.LectureBlockToTeacher; import org.olat.repository.RepositoryEntry; +import org.olat.repository.RepositoryEntryStatusEnum; +import org.olat.repository.RepositoryManager; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; import org.springframework.beans.factory.annotation.Autowired; @@ -54,6 +56,8 @@ public class LectureBlockReminderDAOTest extends OlatTestCase { @Autowired private LectureBlockDAO lectureBlockDao; @Autowired + private RepositoryManager repositoryManager; + @Autowired private LectureBlockReminderDAO lectureBlockReminderDao; @Test @@ -162,6 +166,41 @@ public class LectureBlockReminderDAOTest extends OlatTestCase { Assert.assertFalse(hasOtherBlock); } + @Test + public void loadLectureBlockToRemind_entryStatus() { + Identity teacher1 = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-10"); + Identity teacher2 = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-11"); + LectureBlock lectureBlock1 = createMinimalLectureBlock(5); + LectureBlock lectureBlock2 = createMinimalLectureBlock(5); + + RepositoryEntry entryBlock1 = lectureBlock1.getEntry(); + RepositoryEntry entryBlock2 = lectureBlock2.getEntry(); + repositoryManager.setAccess(entryBlock1, RepositoryEntryStatusEnum.trash, false, false); + repositoryManager.setAccess(entryBlock2, RepositoryEntryStatusEnum.published, false, false); + dbInstance.commitAndCloseSession(); + + lectureService.addTeacher(lectureBlock1, teacher1); + lectureService.addTeacher(lectureBlock2, teacher2); + dbInstance.commitAndCloseSession(); + + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DATE, -3); + List<LectureBlockToTeacher> toRemind = lectureBlockReminderDao.getLectureBlockTeachersToReminder(cal.getTime()); + + boolean hasBlock1 = false; + boolean hasBlock2 = false; + for(LectureBlockToTeacher remind:toRemind) { + if(remind.getLectureBlock().equals(lectureBlock1)) { + hasBlock1 = true; + } else if(remind.getLectureBlock().equals(lectureBlock2)) { + hasBlock2 = true; + } + } + + Assert.assertFalse(hasBlock1); + Assert.assertTrue(hasBlock2); + } + @Test public void deleteReminder() { //create a reminder -- GitLab