delete pac domains

This commit is contained in:
Peter Hormanns 2011-07-27 16:45:47 +00:00
parent 8ae17912b7
commit 8c7363cb14

View File

@ -119,6 +119,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
public void delete(AbstractEntity existingEntity) throws HSAdminException { public void delete(AbstractEntity existingEntity) throws HSAdminException {
EntityManager em = getTransaction().getEntityManager(); EntityManager em = getTransaction().getEntityManager();
Pac pac = (Pac) existingEntity; Pac pac = (Pac) existingEntity;
String pacName = pac.getName();
Date dateCancelled = pac.getCancelled(); Date dateCancelled = pac.getCancelled();
if (dateCancelled == null || dateCancelled.getTime() > System.currentTimeMillis()) { if (dateCancelled == null || dateCancelled.getTime() > System.currentTimeMillis()) {
throw new AuthorisationException(getLoginUser(), "delete", existingEntity); throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
@ -126,7 +127,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction()); GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
Query qDoms = em.createQuery("SELECT dom FROM Domains dom WHERE dom.user.pac.name = :pac"); Query qDoms = em.createQuery("SELECT dom FROM Domains dom WHERE dom.user.pac.name = :pac");
qDoms.setParameter("pac", pac.getName()); qDoms.setParameter("pac", pacName);
List<?> domsList = qDoms.getResultList(); List<?> domsList = qDoms.getResultList();
for (Object o : domsList) { for (Object o : domsList) {
if (o instanceof Domain) { if (o instanceof Domain) {
@ -134,9 +135,8 @@ public class PacModuleImpl extends AbstractModuleImpl {
} }
} }
UnixUser admin = pac.owningUser(em);
for (UnixUser user : pac.getUnixUser()) { for (UnixUser user : pac.getUnixUser()) {
if (admin.getId() != user.getId()) { if (!pacName.equals(user.getName())) {
helperModule.delete(user); helperModule.delete(user);
} }
} }