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();
}
}
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());
}
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());
}
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);
}
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);
}
Aggregations