Search in sources :

Example 56 with MailPackage

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

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

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

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

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

the class EnrollmentManager method doEnroll.

public EnrollStatus doEnroll(Identity identity, Roles roles, BusinessGroup group, ENCourseNode enNode, CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans, List<Long> groupKeys, List<Long> areaKeys, CourseGroupManager cgm) {
    final EnrollStatus enrollStatus = new EnrollStatus();
    if (isLogDebugEnabled())
        logDebug("doEnroll");
    // check if the user is able to be enrolled
    int groupsEnrolledCount = getBusinessGroupsWhereEnrolled(identity, groupKeys, areaKeys, cgm.getCourseEntry()).size();
    int waitingListCount = getBusinessGroupsWhereInWaitingList(identity, groupKeys, areaKeys).size();
    int enrollCountConfig = enNode.getModuleConfiguration().getIntegerSafe(ENCourseNode.CONFIG_ALLOW_MULTIPLE_ENROLL_COUNT, 1);
    if ((groupsEnrolledCount + waitingListCount) < enrollCountConfig) {
        if (isLogDebugEnabled())
            logDebug("Identity is not enrolled identity=" + identity.getName() + "  group=" + group.getName());
        // 1. Check if group has max size defined. If so check if group is full
        // o_clusterREVIEW cg please review it - also where does the group.getMaxParticipants().equals("") come from??
        // and: why can't we just have a group here and a max participants count and an identity to enrol?
        // the group was chosen, so why do we need the groupNames and areaNames here???
        MailPackage doNotSendmailPackage = new MailPackage(false);
        EnrollState state = businessGroupService.enroll(identity, roles, identity, group, doNotSendmailPackage);
        if (state.isFailed()) {
            enrollStatus.setErrorMessage(trans.translate(state.getI18nErrorMessage()));
        } else {
            if (state.getEnrolled() == BGMembership.participant) {
                addUserToParticipantList(identity, group, enNode, coursePropertyManager, wControl, trans);
                enrollStatus.setIsEnrolled(true);
            } else if (state.getEnrolled() == BGMembership.waiting) {
                addUserToWaitingList(identity, group, enNode, coursePropertyManager, wControl, trans);
                enrollStatus.setIsInWaitingList(true);
            }
        }
    } else {
        enrollStatus.setErrorMessage(trans.translate("error.group.already.enrolled"));
    }
    if (isLogDebugEnabled())
        logDebug("doEnroll finished");
    return enrollStatus;
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) EnrollState(org.olat.group.model.EnrollState)

Example 59 with MailPackage

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

the class RepositoryEntriesTest method removeCoach.

@Test
public void removeCoach() throws IOException, URISyntaxException {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-4-" + UUID.randomUUID());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryManager.addTutors(coach, ADMIN_ROLES, new IdentitiesAddEvent(coach), 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("coaches").path(coach.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> coaches = repositoryService.getMembers(re, GroupRoles.coach.name());
    Assert.assertNotNull(coaches);
    Assert.assertTrue(coaches.isEmpty());
    Assert.assertFalse(coaches.contains(coach));
}
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 60 with MailPackage

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

the class GroupOverviewController method removeUserFromGroup.

/**
 * @param ureq
 * @param doSendMail
 */
private void removeUserFromGroup(UserRequest ureq, List<BusinessGroup> groupsToLeave, List<BusinessGroup> groupsToDelete, boolean doSendMail) {
    for (BusinessGroup group : groupsToLeave) {
        if (groupsToDelete.contains(group)) {
            // really delete the group as it has no more owners/participants
            if (doSendMail) {
                String businessPath = getWindowControl().getBusinessControl().getAsString();
                businessGroupService.deleteBusinessGroupWithMail(group, businessPath, getIdentity(), getLocale());
            } else {
                businessGroupService.deleteBusinessGroup(group);
            }
        } else {
            // 1) remove as owner
            if (businessGroupService.hasRoles(identity, group, GroupRoles.coach.name())) {
                businessGroupService.removeOwners(ureq.getIdentity(), Collections.singletonList(identity), group);
            }
            MailPackage mailing = new MailPackage(doSendMail);
            // 2) remove as participant
            businessGroupService.removeParticipants(getIdentity(), Collections.singletonList(identity), group, mailing);
            MailHelper.printErrorsAndWarnings(mailing.getResult(), getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), getLocale());
        }
    }
    updateModel();
    StringBuilder groupNames = new StringBuilder();
    for (BusinessGroup group : groupsToLeave) {
        if (groupNames.length() > 0)
            groupNames.append(", ");
        groupNames.append(group.getName());
    }
    showInfo("unsubscribe.successful", groupNames.toString());
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup)

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