diff --git a/forms/common-themes/src/main/resources/theme/base/admin/resources/js/controllers/groups.js b/forms/common-themes/src/main/resources/theme/base/admin/resources/js/controllers/groups.js index 0525470059..00c8e93772 100755 --- a/forms/common-themes/src/main/resources/theme/base/admin/resources/js/controllers/groups.js +++ b/forms/common-themes/src/main/resources/theme/base/admin/resources/js/controllers/groups.js @@ -24,6 +24,7 @@ module.controller('GroupListCtrl', function($scope, $route, realm, groups, Group $scope.paste = function(selected) { if (selected == null) return; if ($scope.cutNode == null) return; + if (selected.id == $scope.cutNode.id) return; if (selected.id == 'realm') { Groups.save({realm: realm.realm}, {id:$scope.cutNode.id}, function() { $route.reload(); diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/GroupAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/GroupAdapter.java index 0fb9c2f22e..8ef4dd20a6 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/GroupAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/GroupAdapter.java @@ -104,6 +104,9 @@ public class GroupAdapter implements GroupModel { @Override public void setParent(GroupModel parent) { if (parent == null) group.setParent(null); + else if (parent.getId().equals(getId())) { + return; + } else { GroupEntity parentEntity = toEntity(parent, em); group.setParent(parentEntity); @@ -112,11 +115,17 @@ public class GroupAdapter implements GroupModel { @Override public void addChild(GroupModel subGroup) { + if (subGroup.getId().equals(getId())) { + return; + } subGroup.setParent(this); } @Override public void removeChild(GroupModel subGroup) { + if (subGroup.getId().equals(getId())) { + return; + } subGroup.setParent(null); } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index 88deab55b1..acc5182f60 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -1994,6 +1994,9 @@ public class RealmAdapter implements RealmModel { @Override public void moveGroup(GroupModel group, GroupModel toParent) { + if (toParent != null && group.getId().equals(toParent.getId())) { + return; + } if (group.getParentId() != null) { group.getParent().removeChild(group); } diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/GroupAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/GroupAdapter.java index 180eb9d399..32be0be2e6 100755 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/GroupAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/GroupAdapter.java @@ -223,6 +223,9 @@ public class GroupAdapter extends AbstractMongoAdapter impleme @Override public void setParent(GroupModel parent) { if (parent == null) group.setParentId(null); + else if (parent.getId().equals(getId())) { + return; + } else { group.setParentId(parent.getId()); } @@ -232,6 +235,9 @@ public class GroupAdapter extends AbstractMongoAdapter impleme @Override public void addChild(GroupModel subGroup) { + if (subGroup.getId().equals(getId())) { + return; + } subGroup.setParent(this); updateGroup(); @@ -239,6 +245,9 @@ public class GroupAdapter extends AbstractMongoAdapter impleme @Override public void removeChild(GroupModel subGroup) { + if (subGroup.getId().equals(getId())) { + return; + } subGroup.setParent(null); updateGroup(); diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java index 8f8d43dd78..d31503cf40 100755 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java @@ -636,6 +636,9 @@ public class RealmAdapter extends AbstractMongoAdapter impleme @Override public void moveGroup(GroupModel group, GroupModel toParent) { + if (toParent != null && group.getId().equals(toParent.getId())) { + return; + } if (group.getParentId() != null) { group.getParent().removeChild(group); }