use of org.olat.basesecurity.Invitation in project openolat by klemens.
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);
}
use of org.olat.basesecurity.Invitation in project openolat by klemens.
the class InvitationDAOTest method createAndUpdateInvitation.
@Test
public void createAndUpdateInvitation() {
Invitation invitation = invitationDao.createAndPersistInvitation();
dbInstance.commit();
Invitation updatedInvitation = invitationDao.update(invitation, "Kanu", "Unchou", "kanu.unchou@frentix.com");
dbInstance.commit();
Assert.assertEquals("Kanu", updatedInvitation.getFirstName());
Assert.assertEquals("Unchou", updatedInvitation.getLastName());
Assert.assertEquals("kanu.unchou@frentix.com", updatedInvitation.getMail());
Invitation reloadedInvitation = invitationDao.findInvitation(invitation.getToken());
Assert.assertEquals("Kanu", reloadedInvitation.getFirstName());
Assert.assertEquals("Unchou", reloadedInvitation.getLastName());
Assert.assertEquals("kanu.unchou@frentix.com", reloadedInvitation.getMail());
}
use of org.olat.basesecurity.Invitation in project openolat by klemens.
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");
}
}
Aggregations