Skip to content

Commit 23de304

Browse files
committed
Fix issue with permitted node after not-permitted node
1 parent d25f256 commit 23de304

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

cloud-core/src/main/java/org/incendo/cloud/CommandManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@
9898
@API(status = API.Status.STABLE)
9999
public abstract class CommandManager<C> implements Stateful<RegistrationState>, CommandBuilderSource<C> {
100100

101-
private final Configurable<ManagerSetting> settings = Configurable.enumConfigurable(ManagerSetting.class)
102-
.set(ManagerSetting.ENFORCE_INTERMEDIARY_PERMISSIONS, true);
101+
private final Configurable<ManagerSetting> settings = Configurable.enumConfigurable(ManagerSetting.class);
103102
private final ServicePipeline servicePipeline = ServicePipeline.builder().build();
104103
private final ParserRegistry<C> parserRegistry = new StandardParserRegistry<>();
105104
private final Collection<Command<C>> commands = new LinkedList<>();

cloud-core/src/main/java/org/incendo/cloud/CommandTree.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ public void verifyAndRegister() {
10451045
}
10461046
});
10471047

1048-
this.getLeavesRaw(this.internalTree).forEach(this::propagateRequirements);
1048+
this.getExecutorNodes(this.internalTree).forEach(this::propagateRequirements);
10491049
}
10501050

10511051
/**
@@ -1071,34 +1071,19 @@ private void propagateRequirements(final @NonNull CommandNode<C> leafNode) {
10711071
if (senderType == null) {
10721072
senderType = Object.class;
10731073
}
1074-
/* All leaves must necessarily have an owning command */
1075-
leafNode.nodeMeta().put(CommandNode.META_KEY_PERMISSION, commandPermission);
1076-
leafNode.nodeMeta().put(CommandNode.META_KEY_SENDER_TYPES, new HashSet<>(Collections.singletonList(senderType)));
1077-
// Get chain and order it tail->head then skip the tail (leaf node)
1074+
// Get chain and order it tail->head
10781075
List<CommandNode<C>> chain = this.getChain(leafNode);
10791076
Collections.reverse(chain);
1080-
chain = chain.subList(1, chain.size());
1081-
// Go through all nodes from the tail upwards until a collision occurs
10821077
for (final CommandNode<C> commandArgumentNode : chain) {
10831078
final Permission existingPermission = (Permission) commandArgumentNode.nodeMeta().get(CommandNode.META_KEY_PERMISSION);
10841079

1085-
Permission permission;
1080+
final Permission permission;
10861081
if (existingPermission != null) {
10871082
permission = Permission.anyOf(commandPermission, existingPermission);
10881083
} else {
10891084
permission = commandPermission;
10901085
}
10911086

1092-
/* Now also check if there's a command handler attached to an upper level node */
1093-
if (commandArgumentNode.component() != null && commandArgumentNode.command() != null) {
1094-
final Command<C> command = commandArgumentNode.command();
1095-
if (this.commandManager().settings().get(ManagerSetting.ENFORCE_INTERMEDIARY_PERMISSIONS)) {
1096-
permission = command.commandPermission();
1097-
} else {
1098-
permission = Permission.anyOf(permission, command.commandPermission());
1099-
}
1100-
}
1101-
11021087
commandArgumentNode.nodeMeta().put(CommandNode.META_KEY_PERMISSION, permission);
11031088

11041089
final Set<Type> senderTypes = (Set<Type>) commandArgumentNode.nodeMeta()
@@ -1190,6 +1175,19 @@ private void checkAmbiguity(final @NonNull CommandNode<C> node) throws Ambiguous
11901175
return leaves;
11911176
}
11921177

1178+
private @NonNull List<@NonNull CommandNode<C>> getExecutorNodes(
1179+
final @NonNull CommandNode<C> node
1180+
) {
1181+
final List<CommandNode<C>> leaves = new LinkedList<>();
1182+
if (node.command() != null) {
1183+
leaves.add(node);
1184+
}
1185+
for (final CommandNode<C> child : node.children()) {
1186+
leaves.addAll(this.getExecutorNodes(child));
1187+
}
1188+
return leaves;
1189+
}
1190+
11931191
/**
11941192
* Returns all leaf nodes attached to the given {@code node} or its children.
11951193
*

cloud-core/src/main/java/org/incendo/cloud/setting/ManagerSetting.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
*/
3434
@API(status = API.Status.STABLE)
3535
public enum ManagerSetting implements Setting {
36-
/**
37-
* Do not create a compound permission and do not look greedily
38-
* for child permission values, if a preceding command in the tree path
39-
* has a command handler attached
40-
*/
41-
ENFORCE_INTERMEDIARY_PERMISSIONS,
42-
4336
/**
4437
* Force sending of an empty suggestion (i.e. a singleton list containing an empty string)
4538
* when no suggestions are present
@@ -52,14 +45,12 @@ public enum ManagerSetting implements Setting {
5245
* For example, if a platform serializes the command tree and sends it to clients,
5346
* this will allow modifying the command tree after it has been sent, as long as these modifications are not blocked by
5447
* the underlying platform
55-
*
5648
*/
5749
@API(status = API.Status.STABLE)
5850
ALLOW_UNSAFE_REGISTRATION,
5951

6052
/**
6153
* Enables overriding of existing commands on supported platforms.
62-
*
6354
*/
6455
@API(status = API.Status.STABLE)
6556
OVERRIDE_EXISTING_COMMANDS,
@@ -68,7 +59,6 @@ public enum ManagerSetting implements Setting {
6859
* Allows parsing flags at any position after the last literal by appending flag argument nodes between each command node.
6960
* It can have some conflicts when integrating with other command systems like Brigadier,
7061
* and code inspecting the command tree may need to be adjusted.
71-
*
7262
*/
7363
@API(status = API.Status.EXPERIMENTAL)
7464
LIBERAL_FLAG_PARSING

0 commit comments

Comments
 (0)