DomainOptions Impl

This commit is contained in:
Peter Hormanns 2012-07-18 12:26:08 +00:00
parent 9453174b83
commit 93a4c560ab
3 changed files with 39 additions and 20 deletions

View File

@ -139,26 +139,32 @@ public class DomainModuleImpl extends AbstractModuleImpl {
@Override @Override
public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException { public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
Domain dom = (Domain) existingEntity; Domain updatedDom = (Domain) existingEntity;
UnixUser loginUser = getTransaction().getLoginUser(); if (updatedDom.getName() == null || updatedDom.getName().length() == 0) {
if (dom.isPacDomain() && !loginUser.hasHostmasterRole()) {
throw new AuthorisationException(loginUser, "update", existingEntity);
}
if (dom.getName() == null || dom.getName().length() == 0) {
throw new HSAdminException("domain name required"); throw new HSAdminException("domain name required");
} }
UnixUser admin = dom.getUser(); UnixUser loginUser = getTransaction().getLoginUser();
EntityManager em = getTransaction().getEntityManager();
Domain oldDom = em.find(Domain.class, updatedDom.getId());
UnixUser admin = updatedDom.getUser();
if (admin == null || admin.getName() == null || admin.getName().length() == 0) { if (admin == null || admin.getName() == null || admin.getName().length() == 0) {
throw new HSAdminException("domain admin required"); throw new HSAdminException("domain admin required");
} }
if (admin.getPac() == null) { if (!admin.getName().equals(oldDom.getUser().getName())) {
EntityManager em = getTransaction().getEntityManager(); throw new AuthorisationException(loginUser, "update", existingEntity);
Query query = em.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :adminName"); }
query.setParameter("adminName", admin.getName()); Query q = em.createQuery("SELECT opt FROM " +
dom.setUser((UnixUser) query.getSingleResult()); DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
" opt WHERE opt.name=:optName");
for (DomainOption opt : updatedDom.getDomainOptions()) {
q.setParameter("optName", opt.getName());
List<?> list = q.getResultList();
if (list.size() != 1) {
throw new HSAdminException("invalid domain option: " + opt.getName());
}
} }
needsWriteAccessOn(existingEntity, "update"); needsWriteAccessOn(existingEntity, "update");
throw new AuthorisationException(loginUser, "update", existingEntity); return super.update(existingEntity);
} }
@Override @Override

View File

@ -2,11 +2,16 @@ package de.hsadmin.remote;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.dom.Domain; import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.dom.DomainOption;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
public class DomainRemote extends AbstractRemote { public class DomainRemote extends AbstractRemote {
@ -36,6 +41,11 @@ public class DomainRemote extends AbstractRemote {
String since = df.format(sDate); String since = df.format(sDate);
resultMap.put("since", since); resultMap.put("since", since);
} }
List<String> domainOptionsList = new ArrayList<String>();
resultMap.put("domainoptions", domainOptionsList);
for (DomainOption opt : dom.getDomainOptions()) {
domainOptionsList.add(opt.getName());
}
} }
@Override @Override
@ -51,6 +61,15 @@ public class DomainRemote extends AbstractRemote {
u.setName(user); u.setName(user);
dom.setUser(u); dom.setUser(u);
} }
Set<DomainOption> domainOptionsSet = new TreeSet<DomainOption>();
Object domOptsObj = setParams.get("domainoptions");
if (domOptsObj != null && domOptsObj instanceof List<?>) {
List<String> domOptions = (List<String>) domOptsObj;
for (String optString : domOptions) {
domOptions.add(optString);
}
}
dom.setDomainOptions(domainOptionsSet);
} }
@Override @Override

View File

@ -53,13 +53,7 @@ public class EMailAddressRemote extends AbstractRemote {
adr.setSubdomain(subdomain); adr.setSubdomain(subdomain);
} }
Object l = map.get("target"); Object l = map.get("target");
if (l instanceof String) { if (l != null && l instanceof List<?>) {
String target = (String) l;
if (assertNotNull(target)) {
adr.setTarget(target);
}
}
if (l instanceof List<?>) {
StringBuffer tBuff = new StringBuffer(); StringBuffer tBuff = new StringBuffer();
for (Object o : (List<?>) l) { for (Object o : (List<?>) l) {
if (o instanceof String) { if (o instanceof String) {