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

OO-4606: don't send email for trashed or deleted repository entries

parent f9e3e1c8
No related branches found
No related tags found
No related merge requests found
......@@ -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("')");
......
......@@ -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());
}
}
}
......
......@@ -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
......
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