Skip to content

Commit

Permalink
Refactor permission handling logic in GroupManager classes
Browse files Browse the repository at this point in the history
Update the `addPermission` method to delegate to `setPermission` for consistency. Modify `setPermission` to handle permission state checks and removal/addition of permissions correctly, ensuring accurate toggle behavior.
  • Loading branch information
NonSwag committed Aug 30, 2024
1 parent 68b1e55 commit 4087c1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ public TriState checkPermission(String permission) {

@Override
public boolean addPermission(String permission) {
if (!checkPermission(permission).equals(TriState.NOT_SET)) return false;
group().addPermission(permission);
return true;
return setPermission(permission, true);
}

@Override
Expand All @@ -98,8 +96,11 @@ public boolean removePermission(String permission) {

@Override
public boolean setPermission(String permission, boolean value) {
removePermission(!value ? "-" + permission : permission);
return value ? addPermission(permission) : addPermission("-" + permission);
var state = checkPermission(permission).toBoolean();
if (state != null && state.equals(value)) return false;
removePermission(value ? "-" + permission : permission);
group().addPermission(!value ? "-" + permission : permission);
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public TriState checkPermission(String permission) {

@Override
public boolean addPermission(String permission) {
if (!checkPermission(permission).equals(TriState.NOT_SET)) return false;
user().addPermission(permission);
return true;
return setPermission(permission, true);
}

@Override
Expand All @@ -46,7 +44,11 @@ public boolean removePermission(String permission) {

@Override
public boolean setPermission(String permission, boolean value) {
return false;
var state = checkPermission(permission).toBoolean();
if (state != null && state.equals(value)) return false;
removePermission(value ? "-" + permission : permission);
user().addPermission(!value ? "-" + permission : permission);
return true;
}

@Override
Expand Down

0 comments on commit 4087c1c

Please sign in to comment.