set domain admin before persisting domain

This commit is contained in:
Peter Hormanns 2012-09-21 16:37:13 +02:00
parent b44aab8d2d
commit a5527411d8

View File

@ -96,21 +96,6 @@ public class DomainModuleImpl extends AbstractModuleImpl {
domainOption.setName("greylisting"); domainOption.setName("greylisting");
domainOptions.add(domainOption); domainOptions.add(domainOption);
EntityManager em = getTransaction().getEntityManager(); EntityManager em = getTransaction().getEntityManager();
em.persist(dom);
Query q = em.createQuery("SELECT opt FROM " +
DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
" opt WHERE opt.name=:optName");
for (DomainOption opt : domainOptions) {
q.setParameter("optName", opt.getName());
List<?> list = q.getResultList();
if (list.size() != 1) {
throw new HSAdminException("invalid domain option: " + opt.getName());
} else {
opt.setId(((DomainOption) list.get(0)).getId());
}
}
dom.setDomainoptions(domainOptions);
UnixUser loginUser = getTransaction().getLoginUser(); UnixUser loginUser = getTransaction().getLoginUser();
if (!loginUser.hasHostmasterRole()) { if (!loginUser.hasHostmasterRole()) {
// search for domains superior to dom // search for domains superior to dom
@ -137,12 +122,24 @@ public class DomainModuleImpl extends AbstractModuleImpl {
} }
} }
} }
Query adminQuery = em.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :adminName"); Query adminQuery = em.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :adminName");
adminQuery.setParameter("adminName", admin.getName()); adminQuery.setParameter("adminName", admin.getName());
dom.setUser((UnixUser) adminQuery.getSingleResult()); dom.setUser((UnixUser) adminQuery.getSingleResult());
needsWriteAccessOn(newEntity, "add"); needsWriteAccessOn(newEntity, "add");
em.persist(dom); em.persist(dom);
Query q = em.createQuery("SELECT opt FROM " +
DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
" opt WHERE opt.name=:optName");
for (DomainOption opt : domainOptions) {
q.setParameter("optName", opt.getName());
List<?> list = q.getResultList();
if (list.size() != 1) {
throw new HSAdminException("invalid domain option: " + opt.getName());
} else {
opt.setId(((DomainOption) list.get(0)).getId());
}
}
dom.setDomainoptions(domainOptions);
if (dom.isPacDomain()) { if (dom.isPacDomain()) {
em.persist(new EMailAddress("owner", "", dom, dom.getUser().getPac().getCustomer().getName().substring(6) + "@hostsharing.net")); em.persist(new EMailAddress("owner", "", dom, dom.getUser().getPac().getCustomer().getName().substring(6) + "@hostsharing.net"));
em.persist(new EMailAddress("admin", "", dom, dom.getUser().getPac().getName() + "@hostsharing.net")); em.persist(new EMailAddress("admin", "", dom, dom.getUser().getPac().getName() + "@hostsharing.net"));