Merge branch '604-default-permissions-on-nodes' of https://github.com/AuthMe-Team/AuthMeReloaded
This commit is contained in:
@@ -256,21 +256,16 @@ public class CommandInitializerTest {
|
||||
BiConsumer adminPermissionChecker = new BiConsumer() {
|
||||
@Override
|
||||
public void accept(CommandDescription command, int depth) {
|
||||
CommandPermissions permissions = command.getCommandPermissions();
|
||||
if (permissions != null && OP_ONLY.equals(permissions.getDefaultPermission())
|
||||
&& !hasAdminNode(permissions)) {
|
||||
PermissionNode permission = command.getPermission();
|
||||
if (permission != null && OP_ONLY.equals(permission.getDefaultPermission())
|
||||
&& !hasAdminNode(permission)) {
|
||||
fail("The command with labels " + command.getLabels() + " has OP_ONLY default "
|
||||
+ "permission but no permission node on admin level");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasAdminNode(CommandPermissions permissions) {
|
||||
for (PermissionNode node : permissions.getPermissionNodes()) {
|
||||
if (node instanceof AdminPermission) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
private boolean hasAdminNode(PermissionNode permission) {
|
||||
return permission instanceof AdminPermission;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.command.executable.HelpCommand;
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
|
||||
@@ -43,8 +43,8 @@ public final class TestCommandsUtil {
|
||||
.description("test").detailedDescription("Test.").withArgument("Query", "", false).build();
|
||||
|
||||
// Register /unregister <player>, alias: /unreg
|
||||
CommandDescription unregisterBase = createCommand(null, null, asList("unregister", "unreg"),
|
||||
newArgument("player", false));
|
||||
CommandDescription unregisterBase = createCommand(AdminPermission.UNREGISTER, null,
|
||||
asList("unregister", "unreg"), newArgument("player", false));
|
||||
|
||||
return newHashSet(authMeBase, emailBase, unregisterBase);
|
||||
}
|
||||
@@ -84,18 +84,10 @@ public final class TestCommandsUtil {
|
||||
/** Shortcut command to initialize a new test command. */
|
||||
private static CommandDescription createCommand(PermissionNode permission, CommandDescription parent,
|
||||
List<String> labels, CommandArgumentDescription... arguments) {
|
||||
PermissionNode[] notNullPermission;
|
||||
if (permission == null) {
|
||||
notNullPermission = new PermissionNode[0];
|
||||
} else {
|
||||
notNullPermission = new PermissionNode[1];
|
||||
notNullPermission[0] = permission;
|
||||
}
|
||||
|
||||
CommandDescription.CommandBuilder command = CommandDescription.builder()
|
||||
.labels(labels)
|
||||
.parent(parent)
|
||||
.permissions(DefaultPermission.OP_ONLY, notNullPermission)
|
||||
.permission(permission)
|
||||
.description(labels.get(0) + " cmd")
|
||||
.detailedDescription("'" + labels.get(0) + "' test command")
|
||||
.executableCommand(mock(ExecutableCommand.class));
|
||||
|
||||
@@ -4,8 +4,8 @@ import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.FoundResultStatus;
|
||||
import fr.xephi.authme.command.TestCommandsUtil;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -126,10 +126,10 @@ public class HelpProviderTest {
|
||||
@Test
|
||||
public void shouldShowAndEvaluatePermissions() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "login");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
|
||||
CommandDescription command = getCommandWithLabel(commands, "unregister");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("unreg"));
|
||||
given(sender.isOp()).willReturn(true);
|
||||
given(permissionsManager.hasPermission(sender, PlayerPermission.LOGIN)).willReturn(true);
|
||||
given(permissionsManager.hasPermission(sender, AdminPermission.UNREGISTER)).willReturn(true);
|
||||
given(permissionsManager.hasPermission(sender, command)).willReturn(true);
|
||||
|
||||
// when
|
||||
@@ -139,7 +139,7 @@ public class HelpProviderTest {
|
||||
assertThat(lines, hasSize(5));
|
||||
assertThat(removeColors(lines.get(1)), containsString("Permissions:"));
|
||||
assertThat(removeColors(lines.get(2)),
|
||||
containsString(PlayerPermission.LOGIN.getNode() + " (You have permission)"));
|
||||
containsString(AdminPermission.UNREGISTER.getNode() + " (You have permission)"));
|
||||
assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (You have permission)"));
|
||||
assertThat(removeColors(lines.get(4)), containsString("Result: You have permission"));
|
||||
}
|
||||
@@ -147,10 +147,10 @@ public class HelpProviderTest {
|
||||
@Test
|
||||
public void shouldShowAndEvaluateForbiddenPermissions() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "login");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
|
||||
CommandDescription command = getCommandWithLabel(commands, "unregister");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("unregister"));
|
||||
given(sender.isOp()).willReturn(false);
|
||||
given(permissionsManager.hasPermission(sender, PlayerPermission.LOGIN)).willReturn(false);
|
||||
given(permissionsManager.hasPermission(sender, AdminPermission.UNREGISTER)).willReturn(false);
|
||||
given(permissionsManager.hasPermission(sender, command)).willReturn(false);
|
||||
|
||||
// when
|
||||
@@ -160,7 +160,7 @@ public class HelpProviderTest {
|
||||
assertThat(lines, hasSize(5));
|
||||
assertThat(removeColors(lines.get(1)), containsString("Permissions:"));
|
||||
assertThat(removeColors(lines.get(2)),
|
||||
containsString(PlayerPermission.LOGIN.getNode() + " (No permission)"));
|
||||
containsString(AdminPermission.UNREGISTER.getNode() + " (No permission)"));
|
||||
assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (No permission)"));
|
||||
assertThat(removeColors(lines.get(4)), containsString("Result: No permission"));
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class HelpProviderTest {
|
||||
public void shouldNotShowAnythingForNullPermissionsOnCommand() {
|
||||
// given
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getCommandPermissions()).willReturn(null);
|
||||
given(command.getPermission()).willReturn(null);
|
||||
given(command.getLabels()).willReturn(Collections.singletonList("test"));
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("test"));
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package tools.commands;
|
||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandInitializer;
|
||||
import fr.xephi.authme.command.CommandPermissions;
|
||||
import fr.xephi.authme.command.CommandUtils;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.initialization.AuthMeServiceInitializer;
|
||||
@@ -58,7 +57,7 @@ public class CommandPageCreater implements AutoToolTask {
|
||||
.put("command", CommandUtils.constructCommandPath(command))
|
||||
.put("description", command.getDetailedDescription())
|
||||
.put("arguments", formatArguments(command.getArguments()))
|
||||
.put("permissions", formatPermissions(command.getCommandPermissions()));
|
||||
.put("permissions", formatPermissions(command.getPermission()));
|
||||
commandTags.add(tags);
|
||||
|
||||
if (!command.getChildren().isEmpty()) {
|
||||
@@ -67,15 +66,12 @@ public class CommandPageCreater implements AutoToolTask {
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatPermissions(CommandPermissions permissions) {
|
||||
if (permissions == null) {
|
||||
private static String formatPermissions(PermissionNode permission) {
|
||||
if (permission == null) {
|
||||
return "";
|
||||
} else {
|
||||
return permission.getNode();
|
||||
}
|
||||
String result = "";
|
||||
for (PermissionNode node : permissions.getPermissionNodes()) {
|
||||
result += node.getNode() + " ";
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
|
||||
private static String formatArguments(Iterable<CommandArgumentDescription> arguments) {
|
||||
|
||||
Reference in New Issue
Block a user