use of cz.metacentrum.perun.registrar.model.ApplicationMail in project perun by CESNET.
the class MailManagerImpl method copyMailsFromVoToGroup.
@Override
public void copyMailsFromVoToGroup(PerunSession sess, Vo fromVo, Group toGroup, boolean reverse) throws PerunException {
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, fromVo)) {
throw new PrivilegeException(sess, "copyMailsFromVoToVo");
}
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, toGroup) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, toGroup)) {
throw new PrivilegeException(sess, "copyMailsFromVoToVo");
}
if (reverse) {
// copy notifications from Group to VO
ApplicationForm voForm = registrarManager.getFormForVo(fromVo);
ApplicationForm groupForm = registrarManager.getFormForGroup(toGroup);
List<ApplicationMail> mails = getApplicationMails(sess, groupForm);
for (ApplicationMail mail : mails) {
// to start transaction
try {
registrarManager.getMailManager().addMail(sess, voForm, mail);
} catch (DuplicateKeyException ex) {
log.info("[MAIL MANAGER] Mail notification of type {} skipped while copying (was already present).", mail.getMailType() + "/" + mail.getAppType());
}
}
} else {
// copy notifications from VO to Group
ApplicationForm voForm = registrarManager.getFormForVo(fromVo);
ApplicationForm groupForm = registrarManager.getFormForGroup(toGroup);
List<ApplicationMail> mails = getApplicationMails(sess, voForm);
for (ApplicationMail mail : mails) {
// to start transaction
try {
registrarManager.getMailManager().addMail(sess, groupForm, mail);
} catch (DuplicateKeyException ex) {
log.info("[MAIL MANAGER] Mail notification of type {} skipped while copying (was already present).", mail.getMailType() + "/" + mail.getAppType());
}
}
}
}
use of cz.metacentrum.perun.registrar.model.ApplicationMail in project perun by CESNET.
the class MailManagerImpl method deleteMailById.
@Override
public void deleteMailById(PerunSession sess, ApplicationForm form, Integer id) throws PerunException {
if (form.getGroup() != null) {
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, form.getGroup())) {
throw new PrivilegeException(sess, "deleteMail");
}
} else {
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo())) {
throw new PrivilegeException(sess, "deleteMail");
}
}
ApplicationMail mail = getMailById(sess, id);
int result = jdbc.update("delete from application_mails where id=?", id);
if (result == 0)
throw new InternalErrorException("Mail notification with id=" + id + " doesn't exists!");
if (result == 1)
log.info("[MAIL MANAGER] Mail notification with id={} deleted", id);
if (result > 1)
throw new ConsistencyErrorException("There is more than one mail notification with id=" + id);
if (form.getGroup() != null) {
perun.getAuditer().log(sess, "Mail ID: {} of Type: {} removed for Group ID: {}.", id, mail.getMailType() + "/" + mail.getAppType(), form.getGroup().getId());
} else {
perun.getAuditer().log(sess, "Mail ID: {} of Type: {} removed for VO ID: {}.", id, mail.getMailType() + "/" + mail.getAppType(), form.getVo().getId());
}
}
Aggregations