Search in sources :

Example 46 with Invitation

use of org.olat.basesecurity.Invitation in project openolat by klemens.

the class InvitationDAOTest method cleanUpInvitation.

/**
 * Check the HQL code of the the method, and that it doesn't delete to much invitations
 */
@Test
public void cleanUpInvitation() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Policy-User-2-");
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(user, "Title", "Description");
    Invitation invitation = invitationDao.createAndPersistInvitation();
    dbInstance.commit();
    invitation.setFirstName("John");
    invitation.setLastName("Smith Portfolio");
    EPMapPolicy policy = new EPMapPolicy();
    policy.setType(EPMapPolicy.Type.invitation);
    policy.setInvitation(invitation);
    policyManager.updateMapPolicies(map, Collections.singletonList(policy));
    dbInstance.commitAndCloseSession();
    // convert invitation to identity
    Identity invitee = invitationDao.createIdentityFrom(invitation, Locale.ENGLISH);
    dbInstance.commitAndCloseSession();
    // and check
    boolean visible = epFrontendManager.isMapVisible(invitee, map.getOlatResource());
    Assert.assertTrue(visible);
    // clean the invitations
    invitationDao.cleanUpInvitations();
    dbInstance.commitAndCloseSession();
    // check that the invitation not was not deleted
    boolean afterVisible = epFrontendManager.isMapVisible(invitee, map.getOlatResource());
    Assert.assertTrue(afterVisible);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) Invitation(org.olat.basesecurity.Invitation) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 47 with Invitation

use of org.olat.basesecurity.Invitation in project openolat by klemens.

the class InvitationDAOTest method createAndUpdateInvitation.

@Test
public void createAndUpdateInvitation() {
    Invitation invitation = invitationDao.createAndPersistInvitation();
    dbInstance.commit();
    Invitation updatedInvitation = invitationDao.update(invitation, "Kanu", "Unchou", "kanu.unchou@frentix.com");
    dbInstance.commit();
    Assert.assertEquals("Kanu", updatedInvitation.getFirstName());
    Assert.assertEquals("Unchou", updatedInvitation.getLastName());
    Assert.assertEquals("kanu.unchou@frentix.com", updatedInvitation.getMail());
    Invitation reloadedInvitation = invitationDao.findInvitation(invitation.getToken());
    Assert.assertEquals("Kanu", reloadedInvitation.getFirstName());
    Assert.assertEquals("Unchou", reloadedInvitation.getLastName());
    Assert.assertEquals("kanu.unchou@frentix.com", reloadedInvitation.getMail());
}
Also used : Invitation(org.olat.basesecurity.Invitation) Test(org.junit.Test)

Example 48 with Invitation

use of org.olat.basesecurity.Invitation in project openolat by klemens.

the class EPShareListController method sendInvitation.

/**
 * sends a link to the map to permitted users by email
 *
 * @param ureq
 * @param wrapper
 */
private void sendInvitation(UserRequest ureq, EPSharePolicyWrapper wrapper) {
    EPMapPolicy.Type shareType = wrapper.getType();
    List<Identity> identitiesToMail = new ArrayList<Identity>();
    Invitation invitation = null;
    if (shareType.equals(EPMapPolicy.Type.allusers)) {
        return;
    } else if (shareType.equals(EPMapPolicy.Type.invitation)) {
        invitation = wrapper.getInvitation();
    } else if (shareType.equals(EPMapPolicy.Type.group)) {
        List<BusinessGroup> groups = wrapper.getGroups();
        List<Identity> members = businessGroupService.getMembers(groups, GroupRoles.coach.name(), GroupRoles.participant.name());
        identitiesToMail.addAll(members);
    } else if (shareType.equals(EPMapPolicy.Type.user)) {
        identitiesToMail = wrapper.getIdentities();
    }
    wrapper.setInvitationSend(true);
    ContactList contactList = null;
    if (identitiesToMail.size() == 1) {
        contactList = new ContactList(identitiesToMail.get(0).getUser().getProperty(UserConstants.EMAIL, ureq.getLocale()));
    } else {
        contactList = new ContactList(translate("map.share.invitation.mail.list"));
    }
    contactList.addAllIdentites(identitiesToMail);
    String busLink = "";
    if (invitation != null) {
        contactList.add(invitation.getMail());
        busLink = getInvitationLink(invitation, map);
    } else {
        BusinessControlFactory bCF = BusinessControlFactory.getInstance();
        ContextEntry mapCE = bCF.createContextEntry(map.getOlatResource());
        ArrayList<ContextEntry> cEList = new ArrayList<ContextEntry>();
        cEList.add(mapCE);
        busLink = bCF.getAsURIString(cEList, true);
    }
    boolean success = false;
    try {
        String first = getIdentity().getUser().getProperty(UserConstants.FIRSTNAME, null);
        String last = getIdentity().getUser().getProperty(UserConstants.LASTNAME, null);
        String sender = first + " " + last;
        String[] bodyArgs = new String[] { busLink, sender };
        MailContext context = new MailContextImpl(map.getOlatResource(), null, getWindowControl().getBusinessControl().getAsString());
        MailBundle bundle = new MailBundle();
        bundle.setContext(context);
        bundle.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
        bundle.setContactList(contactList);
        bundle.setContent(translate("map.share.invitation.mail.subject"), translate("map.share.invitation.mail.body", bodyArgs));
        MailerResult result = mailManager.sendMessage(bundle);
        success = result.isSuccessful();
    } catch (Exception e) {
        logError("Error on sending invitation mail to contactlist, invalid address.", e);
    }
    if (success) {
        showInfo("map.share.invitation.mail.success");
    } else {
        showError("map.share.invitation.mail.failure");
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) BusinessGroup(org.olat.group.BusinessGroup) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) ContactList(org.olat.core.util.mail.ContactList) ContextEntry(org.olat.core.id.context.ContextEntry) Type(org.olat.portfolio.manager.EPMapPolicy.Type) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Aggregations

Invitation (org.olat.basesecurity.Invitation)48 Identity (org.olat.core.id.Identity)26 ArrayList (java.util.ArrayList)24 Test (org.junit.Test)22 AccessRights (org.olat.modules.portfolio.model.AccessRights)14 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)8 BusinessGroup (org.olat.group.BusinessGroup)6 EPMapPolicy (org.olat.portfolio.manager.EPMapPolicy)6 Group (org.olat.basesecurity.Group)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 EPStructureElementToGroupRelation (org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)4 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)4 Calendar (java.util.Calendar)2 Date (java.util.Date)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)2 BusinessControlFactory (org.olat.core.id.context.BusinessControlFactory)2