HSAdmin Backend Domains, E-Mail, Datenbanken
Michael Hierweck
2017-09-12 5097cdd638445f6f39b0ceaf213a9c12287e9937
Prevent backupmxforexternalmx option collision with active email addresses.
2 files modified
15 ■■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java 7 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAddressModuleImpl.java 8 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -230,6 +230,13 @@
            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);
hsarback/src/de/hsadmin/mods/email/EMailAddressModuleImpl.java
@@ -12,6 +12,7 @@
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 @@
        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);
    }