Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-25 23:58:51 +02:00
parent ea616ed2a1
commit 7bf7866d38
3 changed files with 8 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.stock;
import static de.srsoftware.tools.Optionals.is0;
import static de.srsoftware.tools.Optionals.nullIfEmpty;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
@@ -252,6 +253,11 @@ public class StockModule extends BaseHandler implements StockService {
if (parentId.longValue() != 0L) {
var target = stockDb.loadLocation(parentId.longValue());
if (target.id() == location.id()) throw forbidden("Location must not be it`s own parent!");
var current = target;
while (current != null){
if (current.id() == locationId) throw forbidden("Location cannot be contained in itself!");
current = is0(current.parent()) ? null : stockDb.loadLocation(current.parent());
}
var targetOwner = target.owner().resolve();
if (!assigned(targetOwner, user)) throw forbidden("You are not allowed to edit \"{0}\"!", target.name());
if (!targetOwner.equals(owner)) throw unprocessable("You may not move locations from one owner ({0}) to another ({1})", owner, targetOwner);