use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.
the class RepositoryEntriesTest method removeOwner.
@Test
public void removeOwner() throws IOException, URISyntaxException {
Identity owner = JunitTestHelper.createAndPersistIdentityAsAuthor("author-4-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryManager.addOwners(owner, new IdentitiesAddEvent(owner), re, new MailPackage(false));
dbInstance.commitAndCloseSession();
// remove the owner
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("owners").path(owner.getKey().toString()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
// check
List<Identity> owners = repositoryService.getMembers(re, GroupRoles.owner.name());
Assert.assertNotNull(owners);
Assert.assertEquals(0, owners.size());
Assert.assertFalse(owners.contains(owner));
}
use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.
the class RepositoryEntriesTest method getCoaches.
@Test
public void getCoaches() throws IOException, URISyntaxException {
Identity coach1 = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-1-" + UUID.randomUUID().toString());
Identity coach2 = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-2-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryManager.addTutors(coach1, ADMIN_ROLES, new IdentitiesAddEvent(coach1), re, new MailPackage(false));
repositoryManager.addTutors(coach1, ADMIN_ROLES, new IdentitiesAddEvent(coach2), re, new MailPackage(false));
dbInstance.commitAndCloseSession();
// get the coaches
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("coaches").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<UserVO> users = parseUserArray(response.getEntity());
Assert.assertNotNull(users);
// our 2
Assert.assertEquals(2, users.size());
int found = 0;
for (UserVO user : users) {
String login = user.getLogin();
Assert.assertNotNull(login);
if (coach1.getName().equals(login) || coach2.getName().equals(login)) {
found++;
}
}
Assert.assertEquals(2, found);
conn.shutdown();
}
use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.
the class CourseRuntimeController method doLeave.
private void doLeave(UserRequest ureq) {
if (roles.isGuestOnly())
return;
MailerResult result = new MailerResult();
MailPackage reMailing = new MailPackage(result, getWindowControl().getBusinessControl().getAsString(), true);
// leave course
LeavingStatusList status = new LeavingStatusList();
repositoryManager.leave(getIdentity(), getRepositoryEntry(), status, reMailing);
// leave groups
businessGroupService.leave(getIdentity(), getRepositoryEntry(), status, reMailing);
if (status.isWarningManagedGroup() || status.isWarningManagedCourse()) {
showWarning("sign.out.warning.managed");
} else if (status.isWarningGroupWithMultipleResources()) {
showWarning("sign.out.warning.mutiple.resources");
} else {
showInfo("sign.out.success", new String[] { getRepositoryEntry().getDisplayname() });
}
doClose(ureq);
}
use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.
the class EnrollmentManager method doCancelEnrollment.
public void doCancelEnrollment(final Identity identity, final BusinessGroup enrolledGroup, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
if (isLogDebugEnabled())
logDebug("doCancelEnrollment");
// 1. Remove group membership, fire events, do loggin etc.
// Remove participant. This will also check if a waiting-list with auto-close-ranks is configurated
// and move the users accordingly
MailPackage doNotSendmailPackage = new MailPackage(false);
businessGroupService.removeParticipants(identity, Collections.singletonList(identity), enrolledGroup, doNotSendmailPackage);
logInfo(" doCancelEnrollment in group " + enrolledGroup, identity.getName());
logInfo(" doCancelEnrollment in group " + enrolledGroup, identity.getName());
// 2. Remove enrollmentdate property
// only remove last time date, not firsttime
Property lastTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE);
if (lastTime != null) {
coursePropertyManager.deleteProperty(lastTime);
}
// 3. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createRemoveMyselfMailTemplate(enrolledGroup, identity);
// fxdiff VCRP-16: intern mail system
MailContext context = new MailContextImpl(wControl.getBusinessControl().getAsString());
MailerResult result = new MailerResult();
MailBundle bundle = mailManager.makeMailBundle(context, identity, mailTemplate, null, null, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
MailHelper.printErrorsAndWarnings(result, wControl, false, trans.getLocale());
}
use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.
the class BusinessGroupMembershipProcessorTest method testUnlinkMemberOfBusinessGroup.
@Test
public void testUnlinkMemberOfBusinessGroup() {
// create a group with members
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-1");
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-2");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRole(id1, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, businessGroup, GroupRoles.participant.name());
// create a publisher
SubscriptionContext context = new SubscriptionContext(businessGroup, "");
PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
Assert.assertNotNull(publisher);
dbInstance.commitAndCloseSession();
// subscribe
notificationManager.subscribe(coach, context, publisherData);
notificationManager.subscribe(id1, context, publisherData);
notificationManager.subscribe(id2, context, publisherData);
dbInstance.commitAndCloseSession();
// remove id1 and check subscription
MailPackage mailing = new MailPackage(false);
List<Identity> identitiesToRemove = Collections.singletonList(id1);
businessGroupService.removeParticipants(coach, identitiesToRemove, businessGroup, mailing);
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(id1, context, dbInstance, notificationManager), 5000);
// check that subscription of id1 was deleted but not the ones of id2 and coach
boolean subscribedId1 = notificationManager.isSubscribed(id1, context);
Assert.assertFalse(subscribedId1);
boolean subscribedId2 = notificationManager.isSubscribed(id2, context);
Assert.assertTrue(subscribedId2);
boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
Assert.assertTrue(subscribedCoach);
}
Aggregations