Search in sources :

Example 41 with Invitation

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

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

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

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)

Example 43 with Invitation

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

the class EPFrontendManagerTest method removePolicyWithInvitation.

@Test
public void removePolicyWithInvitation() {
    // create a map
    PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Remove 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>();
    // invitation
    Invitation invitation = invitationDao.createAndPersistInvitation();
    invitation.setFirstName("John");
    invitation.setLastName("Doe");
    invitation.setMail("john2@doe.ch");
    EPMapPolicy invitationPolicy = new EPMapPolicy();
    invitationPolicy.setType(Type.invitation);
    invitationPolicy.setInvitation(invitation);
    policies.add(invitationPolicy);
    map = epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();
    // remove the policy
    policies.clear();
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();
    // check if the policies and the invitation are deleted
    List<EPMapPolicy> deletedPolicies = epFrontendManager.getMapPolicies(map);
    assertNotNull(deletedPolicies);
    assertTrue(deletedPolicies.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)

Example 44 with Invitation

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

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)

Example 45 with Invitation

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

the class InvitationDAOTest method countInvitations.

@Test
public void countInvitations() {
    Invitation invitation = invitationDao.createAndPersistInvitation();
    dbInstance.commit();
    Assert.assertNotNull(invitation);
    long numOfInvitations = invitationDao.countInvitations();
    Assert.assertTrue(numOfInvitations > 0l);
}
Also used : 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