Search in sources :

Example 26 with Invitation

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

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 27 with Invitation

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

the class EPPolicyManager method applyPolicy.

private List<EPStructureElementToGroupRelation> applyPolicy(EPMapPolicy policy, PortfolioStructureMap map) {
    List<EPStructureElementToGroupRelation> savedPolicies = new ArrayList<EPStructureElementToGroupRelation>();
    switch(policy.getType()) {
        case user:
            savedPolicies.add(applyPolicyToUsers(policy, map));
            break;
        case group:
            for (BusinessGroup group : policy.getGroups()) {
                savedPolicies.add(applyPolicyToGroup(group.getBaseGroup(), policy, map));
            }
            break;
        case invitation:
            Invitation invitation = policy.getInvitation();
            EPStructureElementToGroupRelation invitationPolicy = applyPolicyToInvitation(invitation, policy, map);
            savedPolicies.add(invitationPolicy);
            break;
        case allusers:
            EPStructureElementToGroupRelation allUsersPolicy = applyPolicyToAllUsers(policy, map);
            savedPolicies.add(allUsersPolicy);
            break;
    }
    return savedPolicies;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)

Example 28 with Invitation

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

the class InvitationDAO method cleanUpInvitations.

/**
 * Clean up old invitation and set to deleted temporary users
 */
public void cleanUpInvitations() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    Date currentTime = cal.getTime();
    cal.add(Calendar.HOUR, -6);
    Date dateLimit = cal.getTime();
    StringBuilder sb = new StringBuilder(512);
    sb.append("select invitation from ").append(InvitationImpl.class.getName()).append(" as invitation ").append(" inner join invitation.baseGroup baseGroup ").append(// someone can create an invitation but not add it to a policy within millisecond
    " where invitation.creationDate<:dateLimit").append(" and not exists (").append("  select policy.group from structuretogroup as policy ").append("   where policy.group=baseGroup ").append("   and (policy.validFrom is null or policy.validFrom<=:currentDate)").append("   and (policy.validTo is null or policy.validTo>=:currentDate)").append(" )");
    List<Invitation> oldInvitations = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Invitation.class).setParameter("currentDate", currentTime).setParameter("dateLimit", dateLimit).getResultList();
    if (oldInvitations.isEmpty()) {
        return;
    }
    SecurityGroup olatUserSecGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
    for (Invitation invitation : oldInvitations) {
        List<Identity> identities = groupDao.getMembers(invitation.getBaseGroup(), GroupRoles.invitee.name());
        // normally only one identity
        for (Identity identity : identities) {
            if (identity.getStatus().compareTo(Identity.STATUS_VISIBLE_LIMIT) >= 0) {
            // already deleted
            } else if (securityManager.isIdentityInSecurityGroup(identity, olatUserSecGroup)) {
            // out of scope
            } else {
                // delete user
                UserDeletionManager.getInstance().deleteIdentity(identity);
            }
        }
        Invitation invitationRef = dbInstance.getCurrentEntityManager().getReference(InvitationImpl.class, invitation.getKey());
        dbInstance.getCurrentEntityManager().remove(invitationRef);
        dbInstance.commit();
    }
}
Also used : Calendar(java.util.Calendar) Invitation(org.olat.basesecurity.Invitation) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 29 with Invitation

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

the class InvitationDAO method deleteInvitation.

/**
 * Delete an invitation
 * @param invitation
 */
public void deleteInvitation(Invitation invitation) {
    if (invitation == null || invitation.getKey() == null)
        return;
    Invitation refInvitation = dbInstance.getCurrentEntityManager().getReference(InvitationImpl.class, invitation.getKey());
    dbInstance.getCurrentEntityManager().remove(refInvitation);
}
Also used : Invitation(org.olat.basesecurity.Invitation)

Example 30 with Invitation

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

the class EPFrontendManagerTest method allMapPolicies.

@Test
public void allMapPolicies() {
    // create a map
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description");
    PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();
    // save a list of policies
    List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    // user policy
    EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.user);
    userPolicy.getIdentities().add(ident2);
    userPolicy.getIdentities().add(ident3);
    policies.add(userPolicy);
    // invitation
    Invitation invitation = invitationDao.createAndPersistInvitation();
    invitation.setFirstName("John");
    invitation.setLastName("Doe");
    invitation.setMail("john@doe.ch");
    EPMapPolicy invitationPolicy = new EPMapPolicy();
    invitationPolicy.setType(Type.invitation);
    invitationPolicy.setInvitation(invitation);
    policies.add(invitationPolicy);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();
    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (is in policy)
    assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check visible (is in policy)
    assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));
    // retrieved policies
    List<EPMapPolicy> savedPolicies = epFrontendManager.getMapPolicies(map);
    assertTrue(!savedPolicies.isEmpty());
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) 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