mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2024-10-31 17:37:10 +00:00
Admins Endpoint Reformat
- Reduced repeated code - Allow IPs & booleans for admins - Disallow IPs & booleans for non-admins - Disallow punishments and notes for everyone
This commit is contained in:
parent
41a2475e3d
commit
34cf55f21b
@ -1,6 +1,7 @@
|
|||||||
package dev.plex.request.impl;
|
package dev.plex.request.impl;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import dev.plex.HTTPDModule;
|
import dev.plex.HTTPDModule;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
@ -23,6 +24,12 @@ public class AdminsEndpoint extends AbstractServlet
|
|||||||
{
|
{
|
||||||
private static final String TITLE = "Admins - Plex HTTPD";
|
private static final String TITLE = "Admins - Plex HTTPD";
|
||||||
|
|
||||||
|
GsonBuilder json = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting();
|
||||||
|
|
||||||
|
String adminJson = json.create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setNotes(Lists.newArrayList())).collect(Collectors.toList()));
|
||||||
|
|
||||||
|
String nonAdminJson = json.create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setVanished(false)).peek(plexPlayer -> plexPlayer.setCommandSpy(false)).peek(plexPlayer -> plexPlayer.setAdminActive(false)).peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setNotes(Lists.newArrayList())).collect(Collectors.toList()));
|
||||||
|
|
||||||
@GetMapping(endpoint = "/api/admins/")
|
@GetMapping(endpoint = "/api/admins/")
|
||||||
public String getAdmins(HttpServletRequest request, HttpServletResponse response)
|
public String getAdmins(HttpServletRequest request, HttpServletResponse response)
|
||||||
{
|
{
|
||||||
@ -35,7 +42,7 @@ public class AdminsEndpoint extends AbstractServlet
|
|||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
// This likely means they've never joined the server before. That's okay. We can just not return IPs.
|
// This likely means they've never joined the server before. That's okay. We can just not return IPs.
|
||||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList()));
|
return nonAdminJson;
|
||||||
}
|
}
|
||||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
|
if (Plex.get().getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
@ -43,7 +50,7 @@ public class AdminsEndpoint extends AbstractServlet
|
|||||||
if (!player.getRankFromString().isAtLeast(Rank.ADMIN))
|
if (!player.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||||
{
|
{
|
||||||
// Don't return IPs either if the person is not an Admin or above.
|
// Don't return IPs either if the person is not an Admin or above.
|
||||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList()));
|
return nonAdminJson;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
|
else if (Plex.get().getSystem().equalsIgnoreCase("permissions"))
|
||||||
@ -53,10 +60,10 @@ public class AdminsEndpoint extends AbstractServlet
|
|||||||
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.admins.access"))
|
if (!HTTPDModule.getPermissions().playerHas(null, offlinePlayer, "plex.httpd.admins.access"))
|
||||||
{
|
{
|
||||||
// If the person doesn't have permission, don't return IPs
|
// If the person doesn't have permission, don't return IPs
|
||||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers().stream().peek(plexPlayer -> plexPlayer.setIps(Lists.newArrayList())).peek(plexPlayer -> plexPlayer.setPunishments(Lists.newArrayList())).collect(Collectors.toList()));
|
return nonAdminJson;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(Plex.get().getAdminList().getAllAdminPlayers());
|
return adminJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String adminsHTML(String message)
|
private String adminsHTML(String message)
|
||||||
|
Loading…
Reference in New Issue
Block a user