use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class RegistrarManagerImpl method tryToAutoApproveApplication.
/**
* Try to approve application if auto-approve is possible
*
* @param sess user who try to approves application
* @param app application to approve
* @throws InternalErrorException
*/
private void tryToAutoApproveApplication(PerunSession sess, Application app) throws PerunException {
ApplicationForm form;
if (app.getGroup() != null) {
// group application
form = getFormForGroup(app.getGroup());
} else {
// vo application
form = getFormForVo(app.getVo());
}
AppType type = app.getType();
if (AppType.INITIAL.equals(type) && !form.isAutomaticApproval())
return;
if (AppType.EXTENSION.equals(type) && !form.isAutomaticApprovalExtension())
return;
// do not auto-approve Group applications, if user is not member of VO
if (app.getGroup() != null && app.getVo() != null) {
try {
User u = null;
if (app.getUser() == null) {
u = usersManager.getUserByExtSourceNameAndExtLogin(registrarSession, app.getExtSourceName(), app.getCreatedBy());
if (u != null) {
membersManager.getMemberByUser(registrarSession, app.getVo(), u);
} else {
// user not found or null, hence can't be member of VO -> do not approve.
return;
}
} else {
// user known, but maybe not member of a vo
membersManager.getMemberByUser(registrarSession, app.getVo(), app.getUser());
}
} catch (MemberNotExistsException ex) {
return;
} catch (UserNotExistsException ex) {
return;
} catch (UserExtSourceNotExistsException ex) {
return;
} catch (ExtSourceNotExistsException ex) {
return;
}
}
try {
if (AppState.VERIFIED.equals(app.getState())) {
// with registrar session, since only VO admin can approve application
// check if can be approved (we normally call this manually from GUI before calling approve)
canBeApproved(registrarSession, app);
/*
FIXME - temporarily disabled checking
if (app.getUser() == null && !app.getExtSourceName().equalsIgnoreCase("LOCAL")) {
List<RichUser> list = checkForSimilarUsers(registrarSession, app.getId());
if (!list.isEmpty()) {
// found similar
throw new RegistrarException("Similar users are already registered in system. Automatic approval of application was canceled to prevent creation of duplicate user entry. Please check and approve application manually.");
} else {
// similar NOT found - continue
approveApplication(registrarSession, app.getId());
}
} else { }
*/
// other types of application doesn't create new user - continue
approveApplication(registrarSession, app.getId());
}
} catch (Exception ex) {
ArrayList<Exception> list = new ArrayList<Exception>();
list.add(ex);
getMailManager().sendMessage(app, MailType.APP_ERROR_VO_ADMIN, null, list);
throw ex;
}
}
use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class MailManagerImpl method copyMailsFromGroupToGroup.
@Override
public void copyMailsFromGroupToGroup(PerunSession sess, Group fromGroup, Group toGroup) throws PerunException {
perun.getGroupsManagerBl().checkGroupExists(sess, fromGroup);
perun.getGroupsManagerBl().checkGroupExists(sess, toGroup);
// Authorization
if (!AuthzResolver.authorizedInternal(sess, "copyMailsFromGroupToGroup_Group_Group_policy", fromGroup) || !AuthzResolver.authorizedInternal(sess, "copyMailsFromGroupToGroup_Group_Group_policy", toGroup)) {
throw new PrivilegeException(sess, "copyMailsFromGroupToGroup");
}
ApplicationForm formFrom = registrarManager.getFormForGroup(fromGroup);
ApplicationForm formTo = registrarManager.getFormForGroup(toGroup);
copyApplicationMails(sess, formFrom, formTo);
}
use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class MailManagerImpl method sendMessage.
@Override
public void sendMessage(PerunSession sess, Application app, MailType mailType, String reason) throws PerunException {
if (MailType.USER_INVITE.equals(mailType)) {
throw new RegistrarException("USER_INVITE notification can't be sent this way. Use sendInvitation() instead.");
}
// Authorization
if (app.getGroup() != null) {
if (!AuthzResolver.authorizedInternal(sess, "group-sendMessage_Application_MailType_String_policy", Arrays.asList(app.getGroup(), app.getVo())) && !AuthzResolver.selfAuthorizedForApplication(sess, app)) {
throw new PrivilegeException(sess, "sendMessage");
}
} else {
if (!AuthzResolver.authorizedInternal(sess, "vo-sendMessage_Application_MailType_String_policy", Collections.singletonList(app.getVo())) && !AuthzResolver.selfAuthorizedForApplication(sess, app)) {
throw new PrivilegeException(sess, "sendMessage");
}
}
ApplicationForm form = getForm(app);
ApplicationMail mail = getMailByParams(form.getId(), app.getType(), mailType);
if (mail == null)
throw new RegistrarException("Notification template for " + mailType + " is not defined.");
if (!mail.getSend())
throw new RegistrarException("Sending of notification " + mailType + " is disabled.");
if (!AuthzResolver.hasRole(sess.getPerunPrincipal(), Role.PERUNADMIN)) {
if (MailType.APP_ERROR_VO_ADMIN.equals(mailType)) {
throw new RegistrarException("APP_ERROR_VO_ADMIN notification can't be sent this way, since it's bound to each approval process. Try to approve application once again to receive this message.");
}
switch(mailType) {
case APP_CREATED_USER:
case APPROVABLE_GROUP_APP_USER:
case APP_CREATED_VO_ADMIN:
{
if (app.getState().equals(Application.AppState.NEW) || app.getState().equals(Application.AppState.VERIFIED)) {
sendMessage(app, mailType, null, null);
} else {
throw new RegistrarException("Application must be in state NEW or VERIFIED to allow sending of " + mailType + " notification.");
}
}
break;
case MAIL_VALIDATION:
{
if (app.getState().equals(Application.AppState.NEW)) {
sendMessage(app, mailType, null, null);
} else {
throw new RegistrarException("Application must be in state NEW to allow sending of " + mailType + " notification.");
}
}
break;
case APP_APPROVED_USER:
{
if (Application.AppState.APPROVED.equals(app.getState())) {
sendMessage(app, mailType, null, null);
} else {
throw new RegistrarException("Application must be in state APPROVED to allow sending of " + mailType + " notification.");
}
}
break;
case APP_REJECTED_USER:
{
if (Application.AppState.REJECTED.equals(app.getState())) {
sendMessage(app, mailType, reason, null);
} else {
throw new RegistrarException("Application must be in state REJECTED to allow sending of " + mailType + " notification.");
}
}
break;
}
} else {
// perun admin can always be sent any message with an exception to the USER_INVITE
sendMessage(app, mailType, reason, null);
}
perun.getAuditer().log(sess, new MailSentForApplication(mailType, app.getId()));
}
use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class MailManagerImpl method updateMailById.
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMailById(PerunSession sess, ApplicationMail mail) throws FormNotExistsException, ApplicationMailNotExistsException, PrivilegeException {
ApplicationForm form = registrarManager.getFormById(sess, mail.getFormId());
int numberOfExistences = jdbc.queryForInt("select count(1) from application_mails where id=?", mail.getId());
if (numberOfExistences < 1)
throw new ApplicationMailNotExistsException("Application mail does not exist.", mail);
if (numberOfExistences > 1)
throw new ConsistencyErrorException("There is more than one mail with id = " + mail.getId());
// update sending (enabled / disabled)
jdbc.update("update application_mails set send=? where id=?", mail.getSend(), mail.getId());
// update texts (easy way = delete and new insert)
jdbc.update("delete from application_mail_texts where mail_id=?", mail.getId());
for (Locale loc : mail.getMessage().keySet()) {
MailText text = mail.getMessage(loc);
jdbc.update("insert into application_mail_texts(mail_id,locale,subject,text) values (?,?,?,?)", mail.getId(), loc.toString(), text.getSubject(), text.getText());
}
if (form.getGroup() != null) {
perun.getAuditer().log(sess, new MailForGroupIdUpdated(mail, form.getGroup()));
} else {
perun.getAuditer().log(sess, new MailForVoIdUpdated(mail, form.getVo()));
}
}
use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class MailManagerImpl method sendMessage.
@Override
public void sendMessage(Application app, MailType mailType, String reason, List<Exception> exceptions) {
try {
// get form
ApplicationForm form = getForm(app);
// get mail definition
ApplicationMail mail = getMailByParams(form.getId(), app.getType(), mailType);
if (mail == null) {
log.error("[MAIL MANAGER] Mail not sent. Definition (or mail text) for: {} do not exists for " + "VO: {} and Group: {}", mailType.toString(), app.getVo(), app.getGroup());
// mail not found
return;
} else if (!mail.getSend()) {
log.info("[MAIL MANAGER] Mail not sent. Disabled by VO admin for: {} / appID: {} / {} / {}", mail.getMailType(), app.getId(), app.getVo(), app.getGroup());
// sending this mail has been disabled by VO admin
return;
}
// get app data
List<ApplicationFormItemData> data = registrarManager.getApplicationDataById(registrarSession, app.getId());
// different behavior based on mail type
switch(mail.getMailType()) {
case APP_CREATED_USER:
sendUserMessage(app, mail, data, reason, exceptions, MailType.APP_CREATED_USER);
break;
case APPROVABLE_GROUP_APP_USER:
sendUserMessage(app, mail, data, reason, exceptions, MailType.APPROVABLE_GROUP_APP_USER);
break;
case APP_CREATED_VO_ADMIN:
appCreatedVoAdmin(app, mail, data, reason, exceptions);
break;
case MAIL_VALIDATION:
mailValidation(app, mail, data, reason, exceptions);
break;
case APP_APPROVED_USER:
sendUserMessage(app, mail, data, reason, exceptions, MailType.APP_APPROVED_USER);
break;
case APP_REJECTED_USER:
sendUserMessage(app, mail, data, reason, exceptions, MailType.APP_REJECTED_USER);
break;
case APP_ERROR_VO_ADMIN:
appErrorVoAdmin(app, mail, data, reason, exceptions);
break;
default:
log.error("[MAIL MANAGER] Sending mail type: {} is not supported.", mail.getMailType());
break;
}
} catch (Exception ex) {
// catch all exceptions and log to: perun-registrar.log
log.error("[MAIL MANAGER] Exception thrown when sending email.", ex);
}
}
Aggregations