mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-22 02:55:52 -05:00
Ban feature
This commit is contained in:
@@ -37,6 +37,7 @@ export interface User {
|
||||
favoriteBadgeId: number | null;
|
||||
commissionsOpen: number;
|
||||
commissionText: string | null;
|
||||
banned: number;
|
||||
}
|
||||
|
||||
/** User table after joined with PlusTier table */
|
||||
|
||||
@@ -105,6 +105,8 @@ export const loader: LoaderFunction = async ({ request }) => {
|
||||
|
||||
invariant(process.env["BASE_URL"], "BASE_URL env var is not set");
|
||||
|
||||
if (user?.banned) throw new Response(null, { status: 403 });
|
||||
|
||||
return json<RootLoaderData>(
|
||||
{
|
||||
locale,
|
||||
|
||||
@@ -19,7 +19,7 @@ import { findVods } from "~/features/vods";
|
||||
import { useTranslation } from "~/hooks/useTranslation";
|
||||
import { useUser } from "~/modules/auth";
|
||||
import { getUserId } from "~/modules/auth/user.server";
|
||||
import { canAddCustomizedColorsToUserProfile } from "~/permissions";
|
||||
import { canAddCustomizedColorsToUserProfile, isAdmin } from "~/permissions";
|
||||
import styles from "~/styles/u.css";
|
||||
import { notFoundIfFalsy, type SendouRouteHandle } from "~/utils/remix";
|
||||
import { discordFullName, makeTitle } from "~/utils/strings";
|
||||
@@ -103,6 +103,7 @@ export const loader = async ({ params, request }: LoaderArgs) => {
|
||||
weapons: user.weapons,
|
||||
team: user.team,
|
||||
country: user.country,
|
||||
banned: isAdmin(loggedInUser) ? user.banned : undefined,
|
||||
css: canAddCustomizedColorsToUserProfile(user) ? user.css : undefined,
|
||||
badges: db.badges.findByOwnerId(user.id),
|
||||
// TODO: could load only on results page
|
||||
@@ -167,6 +168,7 @@ export default function UserPageLayout() {
|
||||
</SubNavLink>
|
||||
)}
|
||||
</SubNav>
|
||||
{data.banned ? <div className="text-warning">Banned</div> : null}
|
||||
<Outlet />
|
||||
</Main>
|
||||
);
|
||||
|
||||
5
migrations/033-banned.js
Normal file
5
migrations/033-banned.js
Normal file
@@ -0,0 +1,5 @@
|
||||
module.exports.up = function (db) {
|
||||
db.prepare(
|
||||
/* sql */ `alter table "User" add "banned" integer default 0`
|
||||
).run();
|
||||
};
|
||||
@@ -26,6 +26,8 @@
|
||||
"hex-to-filter": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/hex-to-filter.ts",
|
||||
"sync-xp-badges": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/sync-xp-badges.ts",
|
||||
"delete-user": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/delete-user.ts",
|
||||
"ban-user": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/ban-user.ts",
|
||||
"delete-skill": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/delete-skill.ts",
|
||||
"lint:ts": "eslint . --ext .ts,.tsx",
|
||||
"lint:css": "stylelint \"app/styles/**/*.css\"",
|
||||
"prettier:check": "prettier --check . --loglevel warn",
|
||||
|
||||
14
scripts/ban-user.ts
Normal file
14
scripts/ban-user.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/* eslint-disable no-console */
|
||||
import "dotenv/config";
|
||||
import invariant from "tiny-invariant";
|
||||
import { sql } from "~/db/sql";
|
||||
|
||||
const discordId = process.argv[2]?.trim();
|
||||
|
||||
invariant(discordId, "discord id is required (argument 1)");
|
||||
|
||||
sql
|
||||
.prepare('update "User" set banned = 1 where discordId = @discordId')
|
||||
.run({ discordId });
|
||||
|
||||
console.log(`Banned user with discord id: ${discordId}`);
|
||||
16
scripts/delete-skill.ts
Normal file
16
scripts/delete-skill.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/* eslint-disable no-console */
|
||||
import "dotenv/config";
|
||||
import invariant from "tiny-invariant";
|
||||
import { sql } from "~/db/sql";
|
||||
|
||||
const discordId = process.argv[2]?.trim();
|
||||
|
||||
invariant(discordId, "discord id is required (argument 1)");
|
||||
|
||||
sql
|
||||
.prepare(
|
||||
'delete from "Skill" where "userId" = (select id from "User" where discordId = @discordId)'
|
||||
)
|
||||
.run({ discordId });
|
||||
|
||||
console.log(`Deleted skill of user with discord id: ${discordId}`);
|
||||
Reference in New Issue
Block a user