LuckPerms

LuckPerms

41.4k Downloads

Permission change not saved(with the API)

sumsar1812 opened this issue ยท 3 comments

commented

Description

I have the following method to remove a negated permission

public CompletableFuture<Void> removeNegatedPermission(UUID uuid, String permission) {
    return this.loadUser(uuid).thenCompose((user) -> {
        Node node = Node.builder(permission).negated(true).build();
        DataMutateResult result = user.data().remove(node);
        System.out.println("removed permission(2): " + permission + " from " + uuid + " with result " + result.name());
        return this.luckPermsApi.getUserManager().saveUser(user);
    });
}

private CompletableFuture<User> loadUser(UUID uuid) {
    if (luckPermsApi.getUserManager().isLoaded(uuid))
        return CompletableFuture.completedFuture(luckPermsApi.getUserManager().getUser(uuid));
    return luckPermsApi.getUserManager().loadUser(uuid);
}

I then call it here

public void addVVPerms(IGuard guard) {
        removeNegatedPerm(guard, GuardRank.AVAGT, oldSettings.getVvAPermission());
        removeNegatedPerm(guard, GuardRank.BVAGT, oldSettings.getVvBPermission());
        removeNegatedPerm(guard, GuardRank.CVAGT, oldSettings.getVvCPermission());
}

private CompletableFuture<Void> removeNegatedPerm(IGuard guard, GuardRank required, String perm) {
    if (guard.getGuardRank().getValue() >= required.getValue()) {
        return LPUtils.removeNegatedPermission(guard.getUUID(), perm);
    }
    return CompletableFuture.completedFuture(null);
}

The permission do get remvoed in some cases but shortly after the permission is readded, sometimes first when the user changes server(EDIT: after a few more reports from players it seems to only happen on server switches). I tried chaining the calls with thenCompose but that didnt change anything.
The result print in the first method is always printed with SUCCESS

Reproduction Steps

  1. Have 3 servers syncing permissions
  2. Give a user a group that has 3 permissions in it
  3. Give the user the same 3 permissions but negated
  4. Use the API to remove the negated permission

Expected Behaviour

Excepted the 3 permissions to get removed

Server Details

paperspigot188, 3 servers syncing perms

LuckPerms Version

5.4.40

Logs and Configs

No response

Extra Details

As said the result could be different in some cases it would work, in other cases it would work for a few seconds/until a user changes server and rarely it doesn't do anything

commented

I tried changing it to execute lp commands from the console instead of using the API, with the same result

commented

I seem to have found out what is the reason for why it seemed like it didnt save the permission. Here is some better Reproduction Steps and a better description of what the problem is.
If two or more servers are synced up and both servers add a permission(negated or not) at the exact same time the permission node is added multiple times.

Reproduction Steps:

  1. Setup 2 or more servers syncing permissions between them
  2. Setup redis on both servers
  3. Publish a message containing a luckperms command, eg "lp user player1 perm set vv.a false"
  4. Have each server subscribe to that message
  5. When a server recieves the message execute the command on the server
  6. run "/lp user player1 perm unset vv.a"
  7. See that "/lp user player1 perm info" still shows the player having vv.a
  8. repeat step 6 and 7 until the permission is gone

Expected Behaviour
I expect that there has to be some check to see if the node is already there when syncing between servers?
I expected that after step 6 the permission is gone

commented

It's a possibility yes, if you need to remove multiple permissions at the same time, I suggest looping inside the loadUser block instead of outside

e.g. this

this.loadUser(uuid).thenCompose((user) -> {
    for (String permission : permisisons) {
      // todo add
    }
});

instead of this

for (String permission : permisisons) {
    this.loadUser(uuid).thenCompose((user) -> {
      // todo add
    });
}