mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-15 23:29:16 -05:00
Add scanner access to specific user
This commit is contained in:
@@ -9,6 +9,9 @@ export const STAFF_IDS = [11329, 9719, 9342, 20774, 23094];
|
||||
export const DEV_IDS = [27883];
|
||||
// hfcRed Dreamy Cafy Acing
|
||||
export const QA_IDS: number[] = [27883, 38176, 10654, 9342];
|
||||
// xi
|
||||
/** Users who can access the scanner while it is not yet enabled for everyone */
|
||||
export const SCANNER_TESTER_IDS: number[] = [30228];
|
||||
|
||||
export const STAFF_DISCORD_IDS = [
|
||||
"138757634500067328",
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { ActionFunction } from "react-router";
|
||||
import { Config } from "~/config";
|
||||
import { requireUser } from "~/features/auth/core/user.server";
|
||||
import type { ScannerMatch } from "~/features/scanner/core/scanner-match";
|
||||
import { isAdmin, isDev } from "~/modules/permissions/utils";
|
||||
import { isAdmin, isDev, isScannerTester } from "~/modules/permissions/utils";
|
||||
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
import { logger } from "~/utils/logger";
|
||||
import { forbidden, parseBody } from "~/utils/remix.server";
|
||||
@@ -24,7 +24,12 @@ const CONTENT_RESOLUTION_WINDOW_DAYS = 365;
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
const user = requireUser();
|
||||
|
||||
if (!Config.scannerEnabled && !isAdmin(user) && !isDev(user)) {
|
||||
if (
|
||||
!Config.scannerEnabled &&
|
||||
!isAdmin(user) &&
|
||||
!isDev(user) &&
|
||||
!isScannerTester(user)
|
||||
) {
|
||||
forbidden();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,9 @@ export default function ScannerPage() {
|
||||
const isHydrated = useHydrated();
|
||||
const isAdmin = useHasRole("ADMIN");
|
||||
const isDev = useHasRole("DEV");
|
||||
const isScannerTester = useHasRole("SCANNER_TESTER");
|
||||
|
||||
if (!Config.scannerEnabled && !isAdmin && !isDev) {
|
||||
if (!Config.scannerEnabled && !isAdmin && !isDev && !isScannerTester) {
|
||||
return <Redirect to="/" />;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import type { UserWithPlusTier } from "~/utils/kysely.server";
|
||||
import { userDiscordIdIsAged } from "~/utils/users";
|
||||
import type { Role } from "./types";
|
||||
import { isAdmin, isDev, isQa, isStaff, isSupporter } from "./utils";
|
||||
import {
|
||||
isAdmin,
|
||||
isDev,
|
||||
isQa,
|
||||
isScannerTester,
|
||||
isStaff,
|
||||
isSupporter,
|
||||
} from "./utils";
|
||||
|
||||
export function userRoles(
|
||||
user: Pick<
|
||||
@@ -34,6 +41,10 @@ export function userRoles(
|
||||
result.push("QA");
|
||||
}
|
||||
|
||||
if (isScannerTester(user)) {
|
||||
result.push("SCANNER_TESTER");
|
||||
}
|
||||
|
||||
if (typeof user.patronTier === "number") {
|
||||
result.push("MINOR_SUPPORT");
|
||||
}
|
||||
|
||||
@@ -16,5 +16,6 @@ export type Role =
|
||||
| "API_ACCESSER"
|
||||
| "QA"
|
||||
| "DEV"
|
||||
| "SCANNER_TESTER"
|
||||
| "SUPPORTER" // patrons of "Supporter" tier or higher
|
||||
| "MINOR_SUPPORT"; // patrons of "Support" tier or higher
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
ADMIN_ID,
|
||||
DEV_IDS,
|
||||
QA_IDS,
|
||||
SCANNER_TESTER_IDS,
|
||||
STAFF_IDS,
|
||||
} from "~/features/admin/admin-constants";
|
||||
|
||||
@@ -27,6 +28,12 @@ export function isQa(user?: { id: number }) {
|
||||
return QA_IDS.includes(user.id);
|
||||
}
|
||||
|
||||
export function isScannerTester(user?: { id: number }) {
|
||||
if (!user) return false;
|
||||
|
||||
return SCANNER_TESTER_IDS.includes(user.id);
|
||||
}
|
||||
|
||||
export function isSupporter(user?: { patronTier: number | null }) {
|
||||
return typeof user?.patronTier === "number" && user.patronTier >= 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user