SpongeAPI icon indicating copy to clipboard operation
SpongeAPI copied to clipboard

Permission api - no way to reorder parents

Open XakepSDK opened this issue 7 years ago • 10 comments

There is no way to reorder parents! Only one way is to get all parents in all contexts, find required context, create mutable copy of parents list, order it in a correct way, clear all parents in a context and then re-ad them in a loop using

addParent(Set<Context> contexts, SubjectReference parent);

Suggestion: add method setParents(Set<Context> contexts, List<SubjectReference>); to set all parents directly. Why? You can say, that i can just write in first way, but addParent returns CompletableFuture<Boolean>, this means, that this operation should write data to a storage. Many calls may decrease IO performance, also, it prevents implementation to use optimizations for bulk changes.

XakepSDK avatar Jul 25 '18 11:07 XakepSDK

@lucko

XakepSDK avatar Jul 25 '18 11:07 XakepSDK

Does the order even matter?

lucko avatar Jul 25 '18 16:07 lucko

Parents are in List, list is ordered, so, order matters. 3 parents allow permission my.best.perm and third denies it. How it calculates, what to apply?

XakepSDK avatar Jul 25 '18 16:07 XakepSDK

It depends on the implementation

lucko avatar Jul 25 '18 17:07 lucko

Ok. Btw, method to set parents in given context may be useful.

XakepSDK avatar Jul 25 '18 19:07 XakepSDK

I don't understand what you mean

lucko avatar Jul 31 '18 02:07 lucko

API has this method: https://github.com/SpongePowered/SpongeAPI/blob/stable-7/src/main/java/org/spongepowered/api/service/permission/SubjectData.java#L182 clearParents(Set<Context> contexts) But there is no setParents(Set<Context> contexts, List<Subject> parents) method.

XakepSDK avatar Jul 31 '18 06:07 XakepSDK

It makes sense that if you're using a List, it implies that there's an order, and potentially duplicate entires in said list. If the order is not supposed to matter, or that having duplicate entities is not supposed to happen, then the signature should be changed to use a Set.

This is the point I believe is trying to be made.

gabizou avatar Jul 31 '18 19:07 gabizou

Indeed a Set would be a more reasonable way to store parents.

I don't see why a set method accepting the full list is necessary, no such method exists for permissions or options.

lucko avatar Jul 31 '18 22:07 lucko

Possibly tangentially related to https://github.com/SpongePowered/SpongeAPI/issues/977

ryantheleach avatar Aug 03 '18 11:08 ryantheleach