From e102f678cdfbb9d321cfde5e2f1fa6379511661a Mon Sep 17 00:00:00 2001 From: "Tobias Burdow [Kaleidox]" Date: Sun, 10 Dec 2023 23:03:04 +0100 Subject: [PATCH] user view page --- .../org/comroid/mcsd/core/entity/User.java | 13 +++-- .../hub/controller/GenericController.java | 15 +++-- .../main/resources/templates/dashboard.html | 19 ++++++ .../main/resources/templates/server/view.html | 58 +++++++++---------- .../main/resources/templates/user/view.html | 18 +++--- 5 files changed, 76 insertions(+), 47 deletions(-) diff --git a/src/core/main/java/org/comroid/mcsd/core/entity/User.java b/src/core/main/java/org/comroid/mcsd/core/entity/User.java index 8ed32464..4f536ccf 100644 --- a/src/core/main/java/org/comroid/mcsd/core/entity/User.java +++ b/src/core/main/java/org/comroid/mcsd/core/entity/User.java @@ -7,6 +7,7 @@ import org.comroid.api.BitmaskAttribute; import org.comroid.api.SupplierX; import org.comroid.mcsd.core.module.discord.DiscordAdapter; +import org.comroid.util.Cache; import org.comroid.util.Constraint; import org.comroid.util.REST; import org.jetbrains.annotations.Nullable; @@ -41,14 +42,14 @@ public class User extends AbstractEntity { @JsonIgnore public CompletableFuture getMinecraftName() { - Constraint.notNull(minecraftId, this+".minecraftId").run(); - return REST.get(getMojangAccountUrl(minecraftId)) + Constraint.notNull(minecraftId, this + ".minecraftId").run(); + return Cache.get(minecraftId + ".username", () -> REST.get(getMojangAccountUrl(minecraftId)) .thenApply(REST.Response::validate2xxOK) .thenApply(rsp -> rsp.getBody().get("name").asString()) - .exceptionally(t-> { + .exceptionally(t -> { log.log(Level.WARNING, "Could not retrieve Minecraft Username for user " + minecraftId, t); return "Steve"; - }); + })); } @JsonIgnore @@ -82,6 +83,10 @@ public CompletableFuture getDiscordDisplayUser() { }); } + public String blockingMinecraftName() { + return getMinecraftName().join(); + } + @Override public String toString() { return "User " + getName(); diff --git a/src/hub/main/java/org/comroid/mcsd/hub/controller/GenericController.java b/src/hub/main/java/org/comroid/mcsd/hub/controller/GenericController.java index fd197aa4..eabe52d6 100644 --- a/src/hub/main/java/org/comroid/mcsd/hub/controller/GenericController.java +++ b/src/hub/main/java/org/comroid/mcsd/hub/controller/GenericController.java @@ -78,7 +78,11 @@ public String dash(Model model, HttpSession session) { .toList()) .addAttribute("shRepo", Streams.of(shRepo.findAll()) .filter(x -> x.hasPermission(user, AbstractEntity.Permission.Administrate)) - .toList()); + .toList()) + .addAttribute("userRepo", Streams.of(userRepo.findAll()) + .filter(x -> x.hasPermission(user, AbstractEntity.Permission.Administrate)) + .toList()) + .addAttribute("canManageUsers", user.hasPermission(user, AbstractEntity.Permission.ManageUsers)); return "dashboard"; } @@ -87,7 +91,7 @@ public String serverView(Model model, HttpSession session, @PathVariable("id") U var user = userRepo.get(session).assertion(); var server = serverRepo.findById(serverId).orElseThrow(() -> new EntityNotFoundException(Server.class, serverId)); model.addAttribute("user", user) - .addAttribute("server", server) + .addAttribute("target", server) .addAttribute("edit", false) .addAttribute("editKey", null); return "server/view"; @@ -98,7 +102,7 @@ public String userView(Model model, HttpSession session, @PathVariable("id") UUI var user = userRepo.get(session).assertion(); var subject = userRepo.findById(userId).orElseThrow(() -> new EntityNotFoundException(User.class, userId)); model.addAttribute("user", user) - .addAttribute("subject", subject) + .addAttribute("target", subject) .addAttribute("canManageUsers", user.hasPermission(user, AbstractEntity.Permission.ManageUsers)) .addAttribute("edit", false) .addAttribute("editKey", null); @@ -119,8 +123,9 @@ public String entityEdit(HttpSession session, Model model, .addAttribute("edit", true) .addAttribute("editKey", null) .addAttribute("target", target) - .addAttribute("type", type) - .addAttribute(type, target); + .addAttribute("type", type); + if (!type.equals("user")) + model.addAttribute(type, target); return type + "/view"; } diff --git a/src/hub/main/resources/templates/dashboard.html b/src/hub/main/resources/templates/dashboard.html index 8cd51049..ff3b7adf 100644 --- a/src/hub/main/resources/templates/dashboard.html +++ b/src/hub/main/resources/templates/dashboard.html @@ -32,6 +32,25 @@

Servers

Delete +
+

Users

+ + + + + + + + + + + + + + + +
NameE-MailMinecraft ProfileDiscord ID
ViewNameE-MailMinecraft ProfileDiscord ID
+
diff --git a/src/hub/main/resources/templates/server/view.html b/src/hub/main/resources/templates/server/view.html index e3319291..801546e8 100644 --- a/src/hub/main/resources/templates/server/view.html +++ b/src/hub/main/resources/templates/server/view.html @@ -7,58 +7,58 @@
-

Server +

Server - Edit - - Edit Permissions

+ - Edit Permissions

General

- + - - + - + - - + - - - @@ -68,72 +68,72 @@

Advanced configuration

- + - + - -
Name
Displayname +
Owner
ID
Minecraft Version
Loader
RunscriptRunscript
Host
Homepage
Managed
Autostart
Whitelist +
Query Port
Rcon Port
Rcon Password

Discord Integration

-
Not configured
- +
Not configured
+
- - - diff --git a/src/hub/main/resources/templates/user/view.html b/src/hub/main/resources/templates/user/view.html index 1ad1763d..61d74e86 100644 --- a/src/hub/main/resources/templates/user/view.html +++ b/src/hub/main/resources/templates/user/view.html @@ -6,19 +6,19 @@
- -

User + +

User - Edit -

General

Bot
Public Channel ID
Moderation Channel ID
Console Channel ID
Console Prefix
Fancier Console
- - - - - - + + + + + + +
Name
Displayname
Email
HubId
MinecraftId
DiscordId
Name
Displayname
Email
HubId
MinecraftId
DiscordId