Search in sources :

Example 1 with Invitation

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

the class BinderDAO method getBinderAccesRights.

public List<AccessRights> getBinderAccesRights(BinderRef binder, IdentityRef identity) {
    if (binder == null) {
        return Collections.emptyList();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select membership.role, ident, invitation from pfbinder as binder").append(" inner join binder.baseGroup as baseGroup").append(" inner join baseGroup.members as membership");
    if (identity != null) {
        sb.append(" on (membership.identity.key =:identityKey)");
    }
    sb.append(" inner join membership.identity as ident").append(" inner join fetch ident.user as identUser").append(" left join binvitation as invitation on (invitation.baseGroup.key=baseGroup.key and identUser.email=invitation.mail)").append(" where binder.key=:binderKey");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("binderKey", binder.getKey());
    if (identity != null) {
        query.setParameter("identityKey", identity.getKey());
    }
    List<Object[]> objects = query.getResultList();
    List<AccessRights> rightList = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        String role = (String) object[0];
        Identity member = (Identity) object[1];
        Invitation invitation = (Invitation) object[2];
        AccessRights rights = new AccessRights();
        rights.setRole(PortfolioRoles.valueOf(role));
        rights.setBinderKey(binder.getKey());
        rights.setIdentity(member);
        rights.setInvitation(invitation);
        rightList.add(rights);
    }
    return rightList;
}
Also used : AccessRights(org.olat.modules.portfolio.model.AccessRights) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) Identity(org.olat.core.id.Identity)

Example 2 with Invitation

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

the class BinderDAO method getSectionAccesRights.

public List<AccessRights> getSectionAccesRights(Page page) {
    if (page == null) {
        return Collections.emptyList();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select binder.key, section.key, page.key, membership.role, ident, invitation from pfpage as page").append(" inner join page.section as section").append(" inner join section.binder as binder").append(" inner join section.baseGroup as baseGroup").append(" inner join baseGroup.members as membership").append(" inner join membership.identity as ident").append(" inner join fetch ident.user as identUser").append(" left join binvitation as invitation on (invitation.baseGroup.key=binder.baseGroup.key and identUser.email=invitation.mail)").append(" where page.key=:pageKey");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("pageKey", page.getKey());
    List<Object[]> objects = query.getResultList();
    List<AccessRights> rightList = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        Long binderKey = (Long) object[0];
        Long sectionKey = (Long) object[1];
        Long pageKey = (Long) object[2];
        String role = (String) object[3];
        Identity member = (Identity) object[4];
        Invitation invitation = (Invitation) object[5];
        AccessRights rights = new AccessRights();
        rights.setRole(PortfolioRoles.valueOf(role));
        rights.setBinderKey(binderKey);
        rights.setSectionKey(sectionKey);
        rights.setPageKey(pageKey);
        rights.setIdentity(member);
        rights.setInvitation(invitation);
        rightList.add(rights);
    }
    return rightList;
}
Also used : AccessRights(org.olat.modules.portfolio.model.AccessRights) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) Identity(org.olat.core.id.Identity)

Example 3 with Invitation

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

the class BinderDAO method getPageAccesRights.

public List<AccessRights> getPageAccesRights(Page page) {
    if (page == null) {
        return Collections.emptyList();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select binder.key, section.key, page.key, membership.role, ident, invitation from pfpage as page").append(" inner join page.section as section").append(" inner join section.binder as binder").append(" inner join page.baseGroup as baseGroup").append(" inner join baseGroup.members as membership").append(" inner join membership.identity as ident").append(" inner join fetch ident.user as identUser").append(" left join binvitation as invitation on (invitation.baseGroup.key=binder.baseGroup.key and identUser.email=invitation.mail)").append(" where page.key=:pageKey");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("pageKey", page.getKey());
    List<Object[]> objects = query.getResultList();
    List<AccessRights> rightList = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        Long binderKey = (Long) object[0];
        Long sectionKey = (Long) object[1];
        Long pageKey = (Long) object[2];
        String role = (String) object[3];
        Identity member = (Identity) object[4];
        Invitation invitation = (Invitation) object[5];
        AccessRights rights = new AccessRights();
        rights.setRole(PortfolioRoles.valueOf(role));
        rights.setBinderKey(binderKey);
        rights.setSectionKey(sectionKey);
        rights.setPageKey(pageKey);
        rights.setIdentity(member);
        rights.setInvitation(invitation);
        rightList.add(rights);
    }
    return rightList;
}
Also used : AccessRights(org.olat.modules.portfolio.model.AccessRights) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) Identity(org.olat.core.id.Identity)

Example 4 with Invitation

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

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

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

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)

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