Search in sources :

Example 16 with MailPackage

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));
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) HttpDelete(org.apache.http.client.methods.HttpDelete) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 17 with MailPackage

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();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) UserVO(org.olat.user.restapi.UserVO) HttpGet(org.apache.http.client.methods.HttpGet) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 18 with MailPackage

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);
}
Also used : LeavingStatusList(org.olat.repository.LeavingStatusList) MailPackage(org.olat.core.util.mail.MailPackage) MailerResult(org.olat.core.util.mail.MailerResult)

Example 19 with MailPackage

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());
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailPackage(org.olat.core.util.mail.MailPackage) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailTemplate(org.olat.core.util.mail.MailTemplate) MailBundle(org.olat.core.util.mail.MailBundle) Property(org.olat.properties.Property)

Example 20 with MailPackage

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);
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Aggregations

MailPackage (org.olat.core.util.mail.MailPackage)84 Identity (org.olat.core.id.Identity)58 RepositoryEntry (org.olat.repository.RepositoryEntry)42 Path (javax.ws.rs.Path)26 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)26 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)22 PUT (javax.ws.rs.PUT)16 Test (org.junit.Test)16 UserRequest (org.olat.core.gui.UserRequest)16 BusinessGroup (org.olat.group.BusinessGroup)16 BusinessGroupMembershipChange (org.olat.group.model.BusinessGroupMembershipChange)16 RepositoryManager (org.olat.repository.RepositoryManager)16 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)16 BaseSecurity (org.olat.basesecurity.BaseSecurity)14 ArrayList (java.util.ArrayList)12 MailerResult (org.olat.core.util.mail.MailerResult)12 RepositoryEntryPermissionChangeEvent (org.olat.repository.model.RepositoryEntryPermissionChangeEvent)12 DELETE (javax.ws.rs.DELETE)10 Consumes (javax.ws.rs.Consumes)8 MailTemplate (org.olat.core.util.mail.MailTemplate)8