Prevent backupmxforexternalmx option collision with active email addresses.

This commit is contained in:
Michael Hierweck 2017-09-12 20:40:32 +02:00
parent b29374939c
commit 5097cdd638
2 changed files with 14 additions and 1 deletions

View File

@ -230,6 +230,13 @@ public class DomainModuleImpl extends AbstractModuleImpl {
if ("letsencrypt".equals(opt.getName()) && updatedDom.getServeraliases().contains("*")) {
throw new HSAdminException("invalid domain option: " + opt.getName() + " for wildcard subdomain");
}
if ("backupmxforexternalmx".equals(opt.getName())) {
final Query query = em.createQuery("SELECT e FROM EMailAddress e WHERE e.domain = :domname");
query.setParameter("domname", updatedDom.getName());
if (!query.getResultList().isEmpty()) {
throw new HSAdminException("domain option backupmaxforexternalmx may not be activated when email addresses exist");
}
}
}
needsWriteAccessOn(oldDom, "update");
return super.update(existingEntity);

View File

@ -12,6 +12,7 @@ import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.hostsharing.BasePacType;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.dom.DomainOption;
import de.hsadmin.mods.user.UnixUser;
public class EMailAddressModuleImpl extends AbstractModuleImpl {
@ -66,7 +67,12 @@ public class EMailAddressModuleImpl extends AbstractModuleImpl {
qEmailAddresses.setParameter("pacId", dom.getUser().getPac().getId());
if (qEmailAliases.getResultList().size() + qEmailAddresses.getResultList().size() >= EMAIL_PER_MULTI_OPTION * dom.getUser().getPac().getQuantityByComponentName("MULTI")) {
throw new HSAdminException("included email addresses/aliases exceeded");
}
}
for (DomainOption opt : adr.getDomain().getDomainoptions()) {
if ("backupmxforexternalmx".equals(opt.getName())) {
throw new HSAdminException("email addresses may not be added when domain option backumxforexternalmx is active");
}
}
return super.add(newEntity);
}