Skip to content

Commit

Permalink
✨ Only highest staff can see IPs
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasGruber committed Oct 25, 2024
1 parent 08947a5 commit 50e58f9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/src/app/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BriefcaseBusiness } from "lucide-react";
import Table, { type ColumnDefinitionType } from "@/layout/Table";
import Loader from "@/layout/Loader";
import NavTabs from "@/layout/NavTabs";
import { canSeeSecretData } from "@/utils/permissions";
import { canSeeIps } from "@/utils/permissions";
import { ExternalLink } from "lucide-react";
import { api } from "@/utils/api";
import { useInfinitePagination } from "@/libs/pagination";
Expand Down Expand Up @@ -77,7 +77,7 @@ export default function Users() {
} else if (activeTab === "PvP") {
columns.push({ key: "pvpStreak", header: "PvP Streak", type: "string" });
}
if (userData && canSeeSecretData(userData.role)) {
if (userData && canSeeIps(userData.role)) {
columns.push({ key: "lastIp", header: "LastIP", type: "string" });
}

Expand Down
16 changes: 9 additions & 7 deletions app/src/layout/PublicUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from "lucide-react";
import { updateUserSchema } from "@/validators/user";
import { canChangeUserRole } from "@/utils/permissions";
import { canSeeSecretData } from "@/utils/permissions";
import { canSeeSecretData, canSeeIps } from "@/utils/permissions";
import { canModifyUserBadges, canUnstuckVillage } from "@/utils/permissions";
import { api } from "@/utils/api";
import { showMutationToast } from "@/libs/toast";
Expand Down Expand Up @@ -308,12 +308,14 @@ const PublicUserComponent: React.FC<PublicUserComponentProps> = ({
<br />
<b>Information</b>
<p>Too fast infractions: {profile.movedTooFastCount}</p>
<Link
href={`/users/ipsearch/${profile.lastIp}`}
className="hover:text-orange-500 hover:cursor-pointer"
>
Last IP: {profile.lastIp}
</Link>
{canSeeIps(userData.role) && (
<Link
href={`/users/ipsearch/${profile.lastIp}`}
className="hover:text-orange-500 hover:cursor-pointer"
>
Last IP: {profile.lastIp}
</Link>
)}
<div>
{profile.deletionAt
? `To be deleted on: ${profile.deletionAt.toLocaleString()}`
Expand Down
1 change: 0 additions & 1 deletion app/src/libs/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const callDiscordTicket = async (
**Username:** ${user.username}
**User ID:** ${user.userId}
**Role:** ${user.role}
**Last IP:** ${user.lastIp}
**Banned**: ${user.isBanned ? "true" : "false"}
**Silenced**: ${user.isSilenced ? "true" : "false"}
**Federal Status:** ${user.federalStatus}
Expand Down
8 changes: 5 additions & 3 deletions app/src/server/api/routers/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
village,
battleHistory,
} from "@/drizzle/schema";
import { canSeeSecretData, canDeleteUsers } from "@/utils/permissions";
import { canSeeSecretData, canDeleteUsers, canSeeIps } from "@/utils/permissions";
import { canChangeContent, canModerateRoles } from "@/utils/permissions";
import { usernameSchema } from "@/validators/register";
import { insertNextQuest } from "@/routers/quests";
Expand Down Expand Up @@ -850,9 +850,11 @@ export const profileRouter = createTRPCRouter({
// Hide secrets
if (!canSeeSecretData(requester.role)) {
user.earnedExperience = 8008;
user.lastIp = "hidden";
user.isBanned = false;
}
if (!canSeeIps(requester.role)) {
user.lastIp = "hidden";
}
// Return
return {
...user,
Expand Down Expand Up @@ -1381,7 +1383,7 @@ export const fetchPublicUsers = async (
}
// Hide stuff
users.filter((u) => !u.lastIp).forEach((u) => (u.lastIp = "Proxied"));
if (!user || !canSeeSecretData(user.role)) {
if (!user || !canSeeIps(user.role)) {
users.forEach((u) => (u.lastIp = "hidden"));
}
// Return
Expand Down
4 changes: 4 additions & 0 deletions app/src/utils/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export const canSeeSecretData = (role: UserRole) => {
);
};

export const canSeeIps = (role: UserRole) => {
return ["HEAD_MODERATOR", "CODING-ADMIN", "MODERATOR-ADMIN"].includes(role);
};

export const canModifyUserBadges = (role: UserRole) => {
return ["CODING-ADMIN", "CONTENT-ADMIN", "EVENT", "CONTENT"].includes(role);
};
Expand Down

0 comments on commit 50e58f9

Please sign in to comment.