Search in sources :

Example 31 with Invitation

use of org.olat.basesecurity.Invitation in project OpenOLAT by OpenOLAT.

the class EPShareListController method initPolicyUI.

/**
 * creates the custom formLayoutContainer and adds a form-component for every
 * EPSharePolicyWrapper, according to its type.
 */
protected void initPolicyUI() {
    String template = Util.getPackageVelocityRoot(this.getClass()) + "/sharePolicy.html";
    for (EPSharePolicyWrapper policyWrapper : policyWrappers) {
        String cmpName = policyWrapper.getComponentName();
        if (cmpName != null && flc.getFormComponent(cmpName) != null) {
            flc.remove(cmpName);
        }
        cmpName = Integer.toString(cmpSuffixGenerator.getAndIncrement());
        policyWrapper.setComponentName(cmpName);
        FormLayoutContainer container = FormLayoutContainer.createCustomFormLayout(cmpName, getTranslator(), template);
        container.contextPut("wrapper", policyWrapper);
        container.setRootForm(mainForm);
        if (policyWrapper.getType() != null) {
            String[] curatedTargetKeys;
            String[] curatedTargetValues;
            if (!Type.invitation.equals(policyWrapper.getType()) && !loginModule.isInvitationEnabled()) {
                curatedTargetKeys = new String[targetKeys.length - 1];
                curatedTargetValues = new String[targetKeys.length - 1];
                int pos = 0;
                for (int i = targetKeys.length; i-- > 0; ) {
                    if (!targetKeys[i].equals(Type.invitation.name())) {
                        curatedTargetKeys[pos] = targetKeys[i];
                        curatedTargetValues[pos++] = targetValues[i];
                    }
                }
            } else {
                curatedTargetKeys = targetKeys;
                curatedTargetValues = targetValues;
            }
            SingleSelection type = uifactory.addDropdownSingleselect("map.share.target." + cmpName, "map.share.target", container, curatedTargetKeys, curatedTargetValues, null);
            type.addActionListener(FormEvent.ONCHANGE);
            type.setUserObject(policyWrapper);
            type.select(policyWrapper.getType().name(), true);
            switch(policyWrapper.getType()) {
                case user:
                    createContainerForUser(policyWrapper, cmpName, container);
                    break;
                case group:
                    createContainerForGroup(policyWrapper, cmpName, container);
                    break;
                case invitation:
                    Invitation invitation = policyWrapper.getInvitation();
                    if (invitation == null) {
                        invitation = invitationDao.createAndPersistInvitation();
                        policyWrapper.setInvitation(invitation);
                    }
                    createContainerForInvitation(invitation, policyWrapper, cmpName, container);
                    break;
                case allusers:
                    String text = translate("map.share.with.allOlatUsers");
                    uifactory.addStaticTextElement("map.share.with." + cmpName, text, container);
                    break;
            }
        }
        if (policyWrapper instanceof TutorEPSharePolicyWrapper) {
            String text = translate("map.share.with.tutor");
            uifactory.addStaticTextElement("map.share.text." + cmpName, text, container);
        } else {
            DateChooser fromChooser = uifactory.addDateChooser("map.share.from." + cmpName, "map.share.from", null, container);
            fromChooser.setDate(policyWrapper.getFrom());
            fromChooser.setValidDateCheck("map.share.date.invalid");
            policyWrapper.setFromChooser(fromChooser);
            DateChooser toChooser = uifactory.addDateChooser("map.share.to." + cmpName, "map.share.to", null, container);
            toChooser.setDate(policyWrapper.getTo());
            toChooser.setValidDateCheck("map.share.date.invalid");
            policyWrapper.setToChooser(toChooser);
            FormLink addLink = uifactory.addFormLink("map.share.policy.add." + cmpName, "map.share.policy.add", null, container, Link.BUTTON);
            addLink.setIconLeftCSS("o_icon o_icon-fw o_icon_add");
            addLink.setUserObject(policyWrapper);
            FormLink removeLink = uifactory.addFormLink("map.share.policy.delete." + cmpName, "map.share.policy.delete", null, container, Link.BUTTON);
            removeLink.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
            removeLink.setUserObject(policyWrapper);
            if (!policyWrapper.getType().equals(EPMapPolicy.Type.allusers)) {
                FormLink inviteLink = uifactory.addFormLink("map.share.policy.invite." + cmpName, "map.share.policy.invite", null, container, Link.BUTTON);
                inviteLink.setIconLeftCSS("o_icon o_icon-fw o_icon_share");
                inviteLink.setUserObject(policyWrapper);
                inviteLink.setEnabled(!policyWrapper.isInvitationSend() && (loginModule.isInvitationEnabled() || !policyWrapper.getType().equals(Type.invitation)));
            }
            StaticTextElement genErrorPanel = uifactory.addStaticTextElement("errorpanel." + cmpName, "", container);
            genErrorPanel.setUserObject(policyWrapper);
            policyWrapper.setErrorEl(genErrorPanel);
        }
        policyWrapper.setComponentName(cmpName);
        flc.add(container);
        flc.contextPut("wrapper", policyWrapper);
    }
    flc.contextPut("wrappers", policyWrappers);
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) Invitation(org.olat.basesecurity.Invitation) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 32 with Invitation

use of org.olat.basesecurity.Invitation in project OpenOLAT by OpenOLAT.

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)

Example 33 with Invitation

use of org.olat.basesecurity.Invitation in project OpenOLAT by OpenOLAT.

the class InvitationDAOTest method createAndPersistInvitation.

@Test
public void createAndPersistInvitation() {
    Invitation invitation = invitationDao.createAndPersistInvitation();
    Assert.assertNotNull(invitation);
    dbInstance.commit();
    Assert.assertNotNull(invitation);
    Assert.assertNotNull(invitation.getKey());
    Assert.assertNotNull(invitation.getBaseGroup());
    Assert.assertNotNull(invitation.getToken());
}
Also used : Invitation(org.olat.basesecurity.Invitation) Test(org.junit.Test)

Example 34 with Invitation

use of org.olat.basesecurity.Invitation in project OpenOLAT by OpenOLAT.

the class InvitationDAOTest method findInvitation_group.

@Test
public void findInvitation_group() {
    Invitation invitation = invitationDao.createAndPersistInvitation();
    Group baseGroup = invitation.getBaseGroup();
    Assert.assertNotNull(invitation);
    dbInstance.commitAndCloseSession();
    Invitation reloadedInvitation = invitationDao.findInvitation(baseGroup);
    Assert.assertNotNull(reloadedInvitation);
    Assert.assertNotNull(reloadedInvitation.getKey());
    Assert.assertEquals(baseGroup, reloadedInvitation.getBaseGroup());
    Assert.assertEquals(invitation, reloadedInvitation);
    Assert.assertEquals(invitation.getToken(), reloadedInvitation.getToken());
}
Also used : Group(org.olat.basesecurity.Group) Invitation(org.olat.basesecurity.Invitation) Test(org.junit.Test)

Example 35 with Invitation

use of org.olat.basesecurity.Invitation in project OpenOLAT by OpenOLAT.

the class EPPolicyManagerTest method createPolicy_invitation.

@Test
public void createPolicy_invitation() {
    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();
    // check that the policy is saved
    List<EPMapPolicy> policies = policyManager.getMapPolicies(map);
    Assert.assertNotNull(policies);
    Assert.assertEquals(1, policies.size());
    EPMapPolicy invitationPolicy = policies.get(0);
    Assert.assertEquals(EPMapPolicy.Type.invitation, invitationPolicy.getType());
    // convert invitation to identity
    Identity invitee = invitationDao.createIdentityFrom(invitation, Locale.ENGLISH);
    dbInstance.commitAndCloseSession();
    // check is shared
    boolean shared = policyManager.isMapShared(map.getOlatResource());
    Assert.assertTrue(shared);
    boolean visible = epFrontendManager.isMapVisible(invitee, map.getOlatResource());
    Assert.assertTrue(visible);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) Invitation(org.olat.basesecurity.Invitation) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

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