Skip to content

Commit

Permalink
user view page
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Dec 10, 2023
1 parent 4281188 commit e102f67
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 47 deletions.
13 changes: 9 additions & 4 deletions src/core/main/java/org/comroid/mcsd/core/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,14 +42,14 @@ public class User extends AbstractEntity {

@JsonIgnore
public CompletableFuture<String> 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
Expand Down Expand Up @@ -82,6 +83,10 @@ public CompletableFuture<DisplayUser> getDiscordDisplayUser() {
});
}

public String blockingMinecraftName() {
return getMinecraftName().join();
}

@Override
public String toString() {
return "User " + getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand All @@ -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";
Expand All @@ -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);
Expand All @@ -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";
}

Expand Down
19 changes: 19 additions & 0 deletions src/hub/main/resources/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ <h2>Servers</h2>
<a class="ui-button" th:href="@{'/server/delete/'+${server.id}}">Delete</a></td>
</tr></tbody>
</table>
<div th:if="${canManageUsers}">
<h2>Users</h2>
<table>
<thead><tr>
<th></th>
<th>Name</th>
<th>E-Mail</th>
<th>Minecraft Profile</th>
<th>Discord ID</th>
</tr></thead>
<tbody><tr th:each="user: ${userRepo}">
<td><a class="ui-button" th:href="@{'/user/view/'+${user.id}}">View</a></td>
<td th:text="${user.bestName}">Name</td>
<td th:text="${user.email}">E-Mail</td>
<td><a th:href="${user.nameMcURL}" th:text="${user.blockingMinecraftName()}">Minecraft Profile</a></td>
<td th:text="${user.discordId}">Discord ID</td>
</tr></tbody>
</table>
</div>
</div>
</div>
<div class="ui-footer" th:insert="~{/footer}"></div>
Expand Down
58 changes: 29 additions & 29 deletions src/hub/main/resources/templates/server/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,58 @@
<div class="ui-container-page">
<div class="ui-content">
<form action="/api/webapp/server/edit" method="post">
<h2>Server <b th:text="${server.getBestName()}"></b>
<h2>Server <b th:text="${target.getBestName()}"></b>
- <a class="ui-button" th:href="@{'/server/edit/'+${id}}">Edit</a>
- <a class="ui-button" th:href="@{'/server/permissions/'+${server.id}+'/'+${user.id}}">Edit Permissions</a></h2>
- <a class="ui-button" th:href="@{'/server/permissions/'+${target.id}+'/'+${user.id}}">Edit Permissions</a></h2>
<h3>General</h3>
<table>
<tbody>
<tr>
<td>Name</td>
<td><input name="name" th:readonly="${!edit}" th:value="${server.name}" type="text"></td>
<td><input name="name" th:readonly="${!edit}" th:value="${target.name}" type="text"></td>
</tr>
<tr>
<td>Displayname</td>
<td><input name="displayName" th:readonly="${!edit}" th:value="${server.displayName}" type="text">
<td><input name="displayName" th:readonly="${!edit}" th:value="${target.displayName}" type="text">
</td>
</tr>
<tr>
<td>Owner</td>
<td><input name="owner" th:readonly="${!edit}"
th:value="${edit?server.owner.id:server.owner.bestName}"
th:value="${edit?target.owner.id:target.owner.bestName}"
type="text"></td>
</tr>
<tr>
<td>ID</td>
<td><input name="id" readonly th:value="${server.id}" type="text"></td>
<td><input name="id" readonly th:value="${target.id}" type="text"></td>
</tr>
<tr>
<td>Minecraft Version</td>
<td><input name="mcVersion" th:readonly="${!edit}" th:value="${server.mcVersion}" type="text"></td>
<td><input name="mcVersion" th:readonly="${!edit}" th:value="${target.mcVersion}" type="text"></td>
</tr>
<tr>
<td>Loader</td>
<td><input name="loader" readonly
th:value="${server.forceCustomJar} ? 'Custom JAR' : ${server.loaderName}"
th:value="${target.forceCustomJar} ? 'Custom JAR' : ${target.loaderName}"
type="text"></td>
</tr>
<tr>
<td th:if="${server.customCommand != null}">Runscript</td>
<td th:if="${server.customCommand != null}"><input name="customCommand" th:readonly="${!edit}"
th:value="${server.customCommand}"
<td th:if="${target.customCommand != null}">Runscript</td>
<td th:if="${target.customCommand != null}"><input name="customCommand" th:readonly="${!edit}"
th:value="${target.customCommand}"
type="text"></td>
</tr>
<tr>
<td>Host</td>
<td><input name="host" th:readonly="${!edit}" th:value="${server.host}"
<td><input name="host" th:readonly="${!edit}" th:value="${target.host}"
type="text"></td>
<td><input max="65535" min="1" name="port" th:readonly="${!edit}" th:value="${server.port}"
<td><input max="65535" min="1" name="port" th:readonly="${!edit}" th:value="${target.port}"
type="number"></td>
</tr>
<tr>
<td>Homepage</td>
<td><a th:href="${server.homepage}"><input name="homepage" th:if="${edit}"
th:value="${server.homepage}"
<td><a th:href="${target.homepage}"><input name="homepage" th:if="${edit}"
th:value="${target.homepage}"
type="url"></a></td>
</tr>
</tbody>
Expand All @@ -68,72 +68,72 @@ <h3>Advanced configuration</h3>
<tbody>
<tr>
<td>Managed</td>
<td><input name="managed" th:readonly="${!edit}" th:value="${server.managed}" type="checkbox"></td>
<td><input name="managed" th:readonly="${!edit}" th:value="${target.managed}" type="checkbox"></td>
</tr>
<tr>
<td>Autostart</td>
<td><input name="enabled" th:readonly="${!edit}" th:value="${server.enabled}" type="checkbox"></td>
<td><input name="enabled" th:readonly="${!edit}" th:value="${target.enabled}" type="checkbox"></td>
</tr>
<tr>
<td>Whitelist</td>
<td><input name="whitelist" th:readonly="${!edit}" th:value="${server.whitelist}" type="checkbox">
<td><input name="whitelist" th:readonly="${!edit}" th:value="${target.whitelist}" type="checkbox">
</td>
</tr>
<tr>
<td>Query Port</td>
<td><input max="65535" min="1" name="queryPort" th:readonly="${!edit}"
th:value="${server.queryPort}"
th:value="${target.queryPort}"
type="number"></td>
</tr>
<tr>
<td>Rcon Port</td>
<td><input max="65535" min="1" name="rConPort" th:readonly="${!edit}" th:value="${server.RConPort}"
<td><input max="65535" min="1" name="rConPort" th:readonly="${!edit}" th:value="${target.RConPort}"
type="number"></td>
</tr>
<tr>
<td>Rcon Password</td>
<td><input name="rConPassword"
th:readonly="${!edit}"
th:value="${edit?'':(server.getRConPassword()!=null?'hidden':'rcon disabled')}"
th:value="${edit?'':(target.getRConPassword()!=null?'hidden':'rcon disabled')}"
type="password"></td>
</tr>
</tbody>
</table>
<h3>Discord Integration</h3>
<h5 class="error-text" th:unless="${server.getDiscordBot() != null}">Not configured</h5>
<table th:if="${server.getDiscordBot() != null}">
<h5 class="error-text" th:unless="${target.getDiscordBot() != null}">Not configured</h5>
<table th:if="${target.getDiscordBot() != null}">
<tbody>
<tr>
<td>Bot</td>
<td><input name="discordBot" th:readonly="${!edit}"
th:value="${edit?server.discordBot.id:server.discordBot.bestName}"
th:value="${edit?target.discordBot.id:target.discordBot.bestName}"
type="text"></td>
</tr>
<tr>
<td>Public Channel ID</td>
<td><input name="publicChannelId" th:readonly="${!edit}" th:value="${server.publicChannelId}"
<td><input name="publicChannelId" th:readonly="${!edit}" th:value="${target.publicChannelId}"
type="number"></td>
</tr>
<tr>
<td>Moderation Channel ID</td>
<td><input name="moderationChannelId" th:readonly="${!edit}"
th:value="${server.moderationChannelId}"
th:value="${target.moderationChannelId}"
type="number"></td>
</tr>
<tr>
<td>Console Channel ID</td>
<td><input name="consoleChannelId" th:readonly="${!edit}" th:value="${server.consoleChannelId}"
<td><input name="consoleChannelId" th:readonly="${!edit}" th:value="${target.consoleChannelId}"
type="number"></td>
</tr>
<tr>
<td>Console Prefix</td>
<td><input name="consoleChannelPrefix" th:readonly="${!edit}"
th:value="${server.consoleChannelPrefix}"
th:value="${target.consoleChannelPrefix}"
type="text"></td>
</tr>
<tr>
<td>Fancier Console</td>
<td><input name="fancyConsole" th:readonly="${!edit}" th:value="${server.fancyConsole}"
<td><input name="fancyConsole" th:readonly="${!edit}" th:value="${target.fancyConsole}"
type="checkbox">
</td>
</tr>
Expand Down
18 changes: 9 additions & 9 deletions src/hub/main/resources/templates/user/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<div class="ui-menubar" th:insert="~{/menubar}"></div>
<div class="ui-container-page">
<div class="ui-content">
<form action="/api/webapp/subject/edit" method="post">
<h2>User <b th:text="${subject.getBestName()}"></b>
<form action="/api/webapp/user/edit" method="post">
<h2>User <b th:text="${target.getBestName()}"></b>
- <a class="ui-button" th:if="${canManageUsers}" th:href="@{'/user/edit/'+${id}}">Edit</a>
<h3>General</h3>
<table>
<tbody>
<tr><td>Name</td><td><input name="name" th:readonly="${!edit}" th:value="${subject.name}" type="text"></td></tr>
<tr><td>Displayname</td><td><input name="name" th:readonly="${!edit}" th:value="${subject.displayName}" type="text"></td></tr>
<tr><td>Email</td><td><input email="email" th:readonly="${!edit}" th:value="${subject.email}" type="email"></td></tr>
<tr><td>HubId</td><td><input hubId="hubId" th:readonly="${!edit}" th:value="${subject.hubId}" type="text"></td></tr>
<tr><td>MinecraftId</td><td><input minecraftId="minecraftId" th:readonly="${!edit}" th:value="${subject.minecraftId}" type="text"></td></tr>
<tr><td>DiscordId</td><td><input discordId="discordId" th:readonly="${!edit}" th:value="${subject.discordId}" type="number"></td></tr>
<tr><td>Name</td><td><input name="name" th:readonly="${!edit}" th:value="${target.name}" type="text"></td></tr>
<tr><td>Displayname</td><td><input name="name" th:readonly="${!edit}" th:value="${target.displayName}" type="text"></td></tr>
<tr><td>Email</td><td><input name="email" th:readonly="${!edit}" th:value="${target.email}" type="email"></td></tr>
<tr><td>HubId</td><td><input name="hubId" th:readonly="${!edit}" th:value="${target.hubId}" type="text"></td></tr>
<tr><td>MinecraftId</td><td><input name="minecraftId" th:readonly="${!edit}" th:value="${target.minecraftId}" type="text"></td></tr>
<tr><td>DiscordId</td><td><input name="discordId" th:readonly="${!edit}" th:value="${target.discordId}" type="number"></td></tr>
</tbody>
</table>
<input th:if="${editKey!=null}" type="hidden" name="auth_key" th:value="${editKey}">
<input th:if="${edit}" type="submit" value="Apply">
</form>
Expand Down

0 comments on commit e102f67

Please sign in to comment.