Remove missing permission nodes before adding new ones when saving users/groups with SQL storage

This commit is contained in:
Luck 2017-03-27 16:54:59 +01:00
parent 8e557d122b
commit 65147e1935
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -392,10 +392,10 @@ public class SQLBacking extends AbstractBacking {
Set<NodeDataHolder> toAdd = diff.getKey(); Set<NodeDataHolder> toAdd = diff.getKey();
Set<NodeDataHolder> toRemove = diff.getValue(); Set<NodeDataHolder> toRemove = diff.getValue();
if (!toAdd.isEmpty()) { if (!toRemove.isEmpty()) {
try (Connection c = provider.getConnection()) { try (Connection c = provider.getConnection()) {
try (PreparedStatement ps = c.prepareStatement(prefix.apply(USER_PERMISSIONS_INSERT))) { try (PreparedStatement ps = c.prepareStatement(prefix.apply(USER_PERMISSIONS_DELETE_SPECIFIC))) {
for (NodeDataHolder nd : toAdd) { for (NodeDataHolder nd : toRemove) {
ps.setString(1, user.getUuid().toString()); ps.setString(1, user.getUuid().toString());
ps.setString(2, nd.getPermission()); ps.setString(2, nd.getPermission());
ps.setBoolean(3, nd.isValue()); ps.setBoolean(3, nd.isValue());
@ -413,10 +413,10 @@ public class SQLBacking extends AbstractBacking {
} }
} }
if (!toRemove.isEmpty()) { if (!toAdd.isEmpty()) {
try (Connection c = provider.getConnection()) { try (Connection c = provider.getConnection()) {
try (PreparedStatement ps = c.prepareStatement(prefix.apply(USER_PERMISSIONS_DELETE_SPECIFIC))) { try (PreparedStatement ps = c.prepareStatement(prefix.apply(USER_PERMISSIONS_INSERT))) {
for (NodeDataHolder nd : toRemove) { for (NodeDataHolder nd : toAdd) {
ps.setString(1, user.getUuid().toString()); ps.setString(1, user.getUuid().toString());
ps.setString(2, nd.getPermission()); ps.setString(2, nd.getPermission());
ps.setBoolean(3, nd.isValue()); ps.setBoolean(3, nd.isValue());
@ -675,10 +675,10 @@ public class SQLBacking extends AbstractBacking {
Set<NodeDataHolder> toAdd = diff.getKey(); Set<NodeDataHolder> toAdd = diff.getKey();
Set<NodeDataHolder> toRemove = diff.getValue(); Set<NodeDataHolder> toRemove = diff.getValue();
if (!toAdd.isEmpty()) { if (!toRemove.isEmpty()) {
try (Connection c = provider.getConnection()) { try (Connection c = provider.getConnection()) {
try (PreparedStatement ps = c.prepareStatement(prefix.apply(GROUP_PERMISSIONS_INSERT))) { try (PreparedStatement ps = c.prepareStatement(prefix.apply(GROUP_PERMISSIONS_DELETE_SPECIFIC))) {
for (NodeDataHolder nd : toAdd) { for (NodeDataHolder nd : toRemove) {
ps.setString(1, group.getName()); ps.setString(1, group.getName());
ps.setString(2, nd.getPermission()); ps.setString(2, nd.getPermission());
ps.setBoolean(3, nd.isValue()); ps.setBoolean(3, nd.isValue());
@ -696,10 +696,10 @@ public class SQLBacking extends AbstractBacking {
} }
} }
if (!toRemove.isEmpty()) { if (!toAdd.isEmpty()) {
try (Connection c = provider.getConnection()) { try (Connection c = provider.getConnection()) {
try (PreparedStatement ps = c.prepareStatement(prefix.apply(GROUP_PERMISSIONS_DELETE_SPECIFIC))) { try (PreparedStatement ps = c.prepareStatement(prefix.apply(GROUP_PERMISSIONS_INSERT))) {
for (NodeDataHolder nd : toRemove) { for (NodeDataHolder nd : toAdd) {
ps.setString(1, group.getName()); ps.setString(1, group.getName());
ps.setString(2, nd.getPermission()); ps.setString(2, nd.getPermission());
ps.setBoolean(3, nd.isValue()); ps.setBoolean(3, nd.isValue());