Search in sources :

Example 21 with MailPackage

use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.

the class BusinessGroupServiceImpl method transferFirstIdentityFromWaitingToParticipant.

/**
 * Don't forget to lock the business group before calling this method.
 * @param ureqIdentity
 * @param group
 * @param mailing
 * @param syncIM
 */
private void transferFirstIdentityFromWaitingToParticipant(Identity ureqIdentity, BusinessGroup group, MailPackage mailing, List<BusinessGroupModifiedEvent.Deferred> events) {
    // Check if waiting-list is enabled and auto-rank-up
    if (group.getWaitingListEnabled() != null && group.getWaitingListEnabled().booleanValue() && group.getAutoCloseRanksEnabled() != null && group.getAutoCloseRanksEnabled().booleanValue()) {
        // Check if participant is not full
        Integer maxSize = group.getMaxParticipants();
        int reservations = reservationDao.countReservations(group.getResource());
        int partipiciantSize = businessGroupRelationDAO.countRoles(group, GroupRoles.participant.name());
        if (maxSize != null && (partipiciantSize + reservations) < maxSize.intValue()) {
            // ok it has free places => get first identities from waiting list
            List<Identity> identities = businessGroupRelationDAO.getMembersOrderByDate(group, GroupRoles.waiting.name());
            int counter = 0;
            int freeSlot = maxSize - (partipiciantSize + reservations);
            for (Identity firstWaitingListIdentity : identities) {
                if (counter >= freeSlot) {
                    break;
                }
                // Check if firstWaitingListIdentity is not allready in participant-group
                if (!businessGroupRelationDAO.hasRole(firstWaitingListIdentity, group, GroupRoles.participant.name())) {
                    // move the identity from the waitinglist to the participant group
                    ActionType formerStickyActionType = ThreadLocalUserActivityLogger.getStickyActionType();
                    try {
                        // OLAT-4955: force add-participant and remove-from-waitinglist logging actions
                        // that get triggered in the next two methods to be of ActionType admin
                        // This is needed to make sure the targetIdentity ends up in the o_loggingtable
                        ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin);
                        // Don't send mails for the sub-actions "adding to group" and "remove from waiting list", instead
                        // send a specific "graduate from waiting list" mailing a few lines below
                        MailPackage subMailing = new MailPackage(false);
                        addParticipant(ureqIdentity, null, firstWaitingListIdentity, group, subMailing, events);
                        removeFromWaitingList(ureqIdentity, firstWaitingListIdentity, group, subMailing, events);
                    } finally {
                        ThreadLocalUserActivityLogger.setStickyActionType(formerStickyActionType);
                    }
                    // Send mail to let user know he is now in group
                    if (mailing == null) {
                        mailing = new MailPackage(true);
                    }
                    BusinessGroupMailing.sendEmail(null, firstWaitingListIdentity, group, MailType.graduateFromWaitingListToParticpant, mailing);
                    counter++;
                }
            }
        }
    }
}
Also used : ActionType(org.olat.core.logging.activity.ActionType) MailPackage(org.olat.core.util.mail.MailPackage) Identity(org.olat.core.id.Identity)

Example 22 with MailPackage

use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.

the class AbstractBusinessGroupListController method finishUserManagement.

private void finishUserManagement(MembershipModification mod, List<BusinessGroup> groups, MailTemplate template, boolean sendMail) {
    MailPackage mailing = new MailPackage(template, getWindowControl().getBusinessControl().getAsString(), sendMail);
    businessGroupService.updateMembership(getIdentity(), mod, groups, mailing);
    MailHelper.printErrorsAndWarnings(mailing.getResult(), getWindowControl(), false, getLocale());
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage)

Example 23 with MailPackage

use of org.olat.core.util.mail.MailPackage in project OpenOLAT by OpenOLAT.

the class AbstractMemberListController method doChangePermission.

protected void doChangePermission(UserRequest ureq, MemberPermissionChangeEvent changes, List<Identity> members, boolean sendMail) {
    MailPackage mailing = new MailPackage(sendMail);
    if (repoEntry != null) {
        List<RepositoryEntryPermissionChangeEvent> repoChanges = changes.generateRepositoryChanges(members);
        repositoryManager.updateRepositoryEntryMemberships(getIdentity(), ureq.getUserSession().getRoles(), repoEntry, repoChanges, mailing);
    }
    // commit all changes to the group memberships
    List<BusinessGroupMembershipChange> allModifications = changes.generateBusinessGroupMembershipChange(members);
    businessGroupService.updateMemberships(getIdentity(), allModifications, mailing);
    reloadModel();
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) RepositoryEntryPermissionChangeEvent(org.olat.repository.model.RepositoryEntryPermissionChangeEvent)

Example 24 with MailPackage

use of org.olat.core.util.mail.MailPackage in project openolat by klemens.

the class RepositoryEntryMembershipProcessorTest method testRemoveParticipant.

@Test
public void testRemoveParticipant() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());
    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();
    // subscribe
    notificationManager.subscribe(owner, context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    notificationManager.subscribe(participant, context, publisherData);
    dbInstance.commitAndCloseSession();
    // remove member and participant as participant of the repo entry
    List<Identity> removeIdentities = new ArrayList<>(2);
    removeIdentities.add(member);
    removeIdentities.add(participant);
    MailPackage mailing = new MailPackage(false);
    repositoryManager.removeParticipants(owner, removeIdentities, re, mailing, false);
    // wait for the remove of subscription
    waitForCondition(new CheckUnsubscription(participant, context, dbInstance, notificationManager), 5000);
    sleep(1000);
    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedPart = notificationManager.isSubscribed(participant, context);
    Assert.assertFalse(subscribedPart);
    boolean subscribedMember = notificationManager.isSubscribed(member, context);
    Assert.assertTrue(subscribedMember);
    boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
    Assert.assertTrue(subscribedOwner);
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) 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)

Example 25 with MailPackage

use of org.olat.core.util.mail.MailPackage in project openolat by klemens.

the class RepositoryEntryMembershipProcessorTest method testRemoveCoach_withBusinessGroups.

@Test
public void testRemoveCoach_withBusinessGroups() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(businessGroup, re);
    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();
    // subscribe
    notificationManager.subscribe(owner, context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    notificationManager.subscribe(coach, context, publisherData);
    dbInstance.commitAndCloseSession();
    // remove member and coach as coach of the repo entry
    List<Identity> removeIdentities = new ArrayList<>(2);
    removeIdentities.add(member);
    removeIdentities.add(coach);
    repositoryManager.removeTutors(owner, removeIdentities, re, new MailPackage(false));
    // wait for the remove of subscription
    waitForCondition(new CheckUnsubscription(member, context, dbInstance, notificationManager), 5000);
    sleep(1000);
    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedMember = notificationManager.isSubscribed(member, context);
    Assert.assertFalse(subscribedMember);
    boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
    Assert.assertTrue(subscribedCoach);
    boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
    Assert.assertTrue(subscribedOwner);
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) 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