Search in sources :

Example 36 with MailPackage

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

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 37 with MailPackage

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

the class BusinessGroupServiceTest method testUpdateMembership.

@Test
public void testUpdateMembership() {
    // create a group with owner and participant
    Identity ureqIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mship-u-");
    Identity ownerIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mship-o-");
    Identity partIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mship-p-");
    BusinessGroup group = businessGroupService.createBusinessGroup(ureqIdentity, "Up-mship", "updateMembership", 0, 10, false, false, null);
    businessGroupRelationDao.addRole(ownerIdentity, group, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(partIdentity, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // update memberships
    MailPackage mailing = new MailPackage(false);
    List<BusinessGroup> groups = Collections.singletonList(group);
    MembershipModification membersMod = new MembershipModification();
    membersMod.getAddOwners().add(partIdentity);
    membersMod.getAddParticipants().add(ownerIdentity);
    businessGroupService.updateMembership(ureqIdentity, membersMod, groups, mailing);
    dbInstance.commitAndCloseSession();
    // check if the participant is owner too and the owner is participant too
    boolean partIsOwner = businessGroupService.hasRoles(partIdentity, group, GroupRoles.coach.name());
    Assert.assertTrue(partIsOwner);
    boolean partIsPart = businessGroupService.hasRoles(partIdentity, group, GroupRoles.participant.name());
    Assert.assertTrue(partIsPart);
    boolean ownerIsOwner = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.coach.name());
    Assert.assertTrue(ownerIsOwner);
    boolean ownerIsPart = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.participant.name());
    Assert.assertTrue(ownerIsPart);
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) MembershipModification(org.olat.group.model.MembershipModification) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 38 with MailPackage

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

the class BusinessGroupServiceTest method testUpdateMemberships.

@Test
public void testUpdateMemberships() {
    // create a group with owner and participant
    Identity ureqIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-u-");
    Identity ownerIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-o-");
    Identity partIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-p-");
    BusinessGroup group = businessGroupService.createBusinessGroup(ureqIdentity, "Up-mships", "updateMemberships", 0, 10, false, false, null);
    businessGroupRelationDao.addRole(ownerIdentity, group, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(partIdentity, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // invert the roles
    BusinessGroupMembershipChange change1 = new BusinessGroupMembershipChange(ownerIdentity, group.getKey());
    change1.setTutor(Boolean.FALSE);
    change1.setParticipant(Boolean.TRUE);
    BusinessGroupMembershipChange change2 = new BusinessGroupMembershipChange(partIdentity, group.getKey());
    change2.setTutor(Boolean.TRUE);
    change2.setParticipant(Boolean.FALSE);
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    changes.add(change1);
    changes.add(change2);
    businessGroupService.updateMemberships(ureqIdentity, changes, new MailPackage(false));
    dbInstance.commitAndCloseSession();
    // check the result
    boolean partIsOwner = businessGroupService.hasRoles(partIdentity, group, GroupRoles.coach.name());
    Assert.assertTrue(partIsOwner);
    boolean partIsPart = businessGroupService.hasRoles(partIdentity, group, GroupRoles.participant.name());
    Assert.assertFalse(partIsPart);
    boolean ownerIsPart = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.participant.name());
    Assert.assertTrue(ownerIsPart);
    boolean ownerIsOwner = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.coach.name());
    Assert.assertFalse(ownerIsOwner);
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 39 with MailPackage

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

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)

Example 40 with MailPackage

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

the class AbstractMemberListController method doChangePermission.

protected void doChangePermission(UserRequest ureq, MemberPermissionChangeEvent e, boolean sendMail) {
    MailPackage mailing = new MailPackage(sendMail);
    if (repoEntry != null) {
        List<RepositoryEntryPermissionChangeEvent> changes = Collections.singletonList((RepositoryEntryPermissionChangeEvent) e);
        repositoryManager.updateRepositoryEntryMemberships(getIdentity(), ureq.getUserSession().getRoles(), repoEntry, changes, mailing);
    }
    businessGroupService.updateMemberships(getIdentity(), e.getGroupChanges(), mailing);
    // make sure all is committed before loading the model again (I see issues without)
    DBFactory.getInstance().commitAndCloseSession();
    reloadModel();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) RepositoryEntryPermissionChangeEvent(org.olat.repository.model.RepositoryEntryPermissionChangeEvent)

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