From 75a68d707a03360e7172e97ad83189a3ceba1149 Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@jalin.de>
Date: Mon, 21 Jan 2013 13:37:35 +0100
Subject: [PATCH] allow user.add with given userid, if it is free

---
 hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java b/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java
index 111c123..b677e54 100644
--- a/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java
+++ b/hsarback/src/de/hsadmin/mods/user/UnixUserModuleImpl.java
@@ -96,9 +96,6 @@
 		if (passWord.indexOf(':') >= 0) {
 			throw new AuthorisationException(loginUser, "add", newUnixUser, "userId");
 		}
-		if (newUnixUser.getPac() == null || newUnixUser.getPac().getNew()) {
-			
-		}
 		Query qPac = em.createQuery("SELECT obj FROM Pacs obj WHERE obj.name = :pacName");
 		qPac.setParameter("pacName", userName.substring(0, 5));
 		Object singleResult = qPac.getSingleResult();
@@ -117,11 +114,14 @@
 			newUnixUser.setUserId(nUID);
 		} else {
 			// given uid belongs to same pac?
-			Query q = em.createQuery("SELECT u.userId FROM UnixUsers u WHERE u.userId = :userId AND u.pac = :pac");
+			Query q = em.createQuery("SELECT u.userId FROM UnixUsers u WHERE u.userId = :userId");
+			q.setParameter("userId", newUnixUser.getUserId());
+			List<?> idExists = q.getResultList();
+			q = em.createQuery("SELECT u.userId FROM UnixUsers u WHERE u.userId = :userId AND u.pac = :pac");
 			q.setParameter("userId", newUnixUser.getUserId());
 			q.setParameter("pac", pac);
 			List<?> idOfSamePac = q.getResultList();
-			if (idOfSamePac.size() == 0) {
+			if (idOfSamePac.isEmpty() && !idExists.isEmpty()) {
 				throw new AuthorisationException(loginUser, "add", newUnixUser, "userId");
 			}
 		}

--
Gitblit v1.9.3