LiteCommands icon indicating copy to clipboard operation
LiteCommands copied to clipboard

Support "OR" behavior for permissions.

Open CarmJos opened this issue 1 year ago • 7 comments

I expect that one instruction supports multiple different permissions, and the user only needs to have one set of permissions to execute the corresponding instruction.

It seems like

return p.hasPermission("xxx.admin") || p.hasPermission("xxx.command.reload");

And I saw the @Permission is "Repeatable" annotation, but I just tested with 2 seperated @Permission for different permissions, also need to have all of them. It's that a mistake?

CarmJos avatar Sep 14 '24 08:09 CarmJos

You must need all required permissions.

Rollczi avatar Sep 14 '24 10:09 Rollczi

Is there any way to achieve this requirement?

CarmJos avatar Sep 14 '24 10:09 CarmJos

No, but you can implement validator on your own.

Rollczi avatar Sep 14 '24 10:09 Rollczi

I think this feature is quite common, and since this annotation is "Repeatable", it should support "or" judgment.

Otherwise, just write all permissions in a single annotation and it's over.

CarmJos avatar Sep 14 '24 13:09 CarmJos

I think this feature is quite common, and since this annotation is "Repeatable", it should support "or" judgment.

Otherwise, just write all permissions in a single annotation and it's over.

This change in the behavior of the @Permission annotation may affect the security of other projects.

Rollczi avatar Sep 15 '24 21:09 Rollczi

I think it would be to just let the user implement a OrPermission annotation if they require this functionality.

kermandev avatar Sep 16 '24 21:09 kermandev

I think it would be to just let the user implement a OrPermission annotation if they require this functionality.

This is what I am thinking about, too. But since @Permission has been marked as "Repeatable", why not directly mark different permission sets with different @Permission to determine whether the user meets one of them.

CarmJos avatar Sep 17 '24 10:09 CarmJos

I fount that it is impossible to support this function if not change the original codes.

So may you make it

  1. a "selectable" settings like builder.permissionPredicate(MODE), with "Strict"(Need all claimed permissions) and "Parallel"(Need one of the @Permission("") group claimed) ?

Or

  1. a functional interface like builder.hanlePermisisons(((MultiList<String>)perms)-> /**do something **/ ). With implemented STRICT and PARALLEL handlers to choose/recode.

Whatever the solution you choose, all means you may need to move "@Permission" meta from a single List to a MultiList<String> or List<List<String>>, to make this function possiable.

Anyway, many thanks for you hard-working!

CarmJos avatar Jan 14 '25 00:01 CarmJos

Notice:

Whatevet the mode is, if a player want to execute one subcommand, he should have the command's parents' permissions, e.g.


@Permission("server.admin")
@Permission("cmd.super","cmd.execute")
class SuperCommand{
   
   @Permission("server.admin")
   @Permission("cmd.super.sub")
   void subCommand(){


   }

}

which means if i want to execute /super sub, i need to have "server.admin" or "cmd.super"+"cmd.execute", then i also need to have "cmd.super.sub" or "server.admin".

CarmJos avatar Jan 14 '25 00:01 CarmJos

@huanmeng-qwq and I have finished this feature, but there're some problems need for discuss, please see the pull request.

CarmJos avatar Jan 16 '25 22:01 CarmJos