mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-02 08:07:40 -05:00
User search (#1468)
* Initial * Search users from API * Better feeling search * Fix TODO * Search via url, discord id & id * Load initial user * UserSearch on admin page * UserSearch on tournaments page * UserSearch for badges * Plus suggestions * Vod page * Remove unused code * Fix test
This commit is contained in:
@@ -27,6 +27,7 @@ export async function selectUser({
|
||||
|
||||
await combobox.clear();
|
||||
await combobox.type(userName);
|
||||
await expect(page.getByTestId("combobox-option-0")).toBeVisible();
|
||||
await page.keyboard.press("Enter");
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,6 @@ export const FRONT_GIRL_PATH = "/static-assets/img/layout/front-girl";
|
||||
export const FRONT_BOY_BG_PATH = "/static-assets/img/layout/front-boy-bg";
|
||||
export const FRONT_GIRL_BG_PATH = "/static-assets/img/layout/front-girl-bg";
|
||||
|
||||
export const GET_ALL_USERS_ROUTE = "/users";
|
||||
export const GET_ALL_EVENTS_WITH_MAP_POOLS_ROUTE = "/calendar/map-pool-events";
|
||||
|
||||
interface UserLinkArgs {
|
||||
|
||||
44
app/utils/users.test.ts
Normal file
44
app/utils/users.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { suite } from "uvu";
|
||||
import * as assert from "uvu/assert";
|
||||
import { queryToUserIdentifier } from "./users";
|
||||
|
||||
const QueryToUserIdentifier = suite("queryToUserIdentifier()");
|
||||
|
||||
QueryToUserIdentifier("returns null if no match", () => {
|
||||
assert.equal(queryToUserIdentifier("foo"), null);
|
||||
});
|
||||
|
||||
QueryToUserIdentifier("gets custom url from url", () => {
|
||||
assert.equal(queryToUserIdentifier("https://sendou.ink/u/sendou"), {
|
||||
customUrl: "sendou",
|
||||
});
|
||||
});
|
||||
|
||||
QueryToUserIdentifier("gets discord id from url", () => {
|
||||
assert.equal(
|
||||
queryToUserIdentifier("https://sendou.ink/u/79237403620945920"),
|
||||
{
|
||||
discordId: "79237403620945920",
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
QueryToUserIdentifier("gets custom url from url (without https://)", () => {
|
||||
assert.equal(queryToUserIdentifier("sendou.ink/u/sendou"), {
|
||||
customUrl: "sendou",
|
||||
});
|
||||
});
|
||||
|
||||
QueryToUserIdentifier("gets discord id", () => {
|
||||
assert.equal(queryToUserIdentifier("79237403620945920"), {
|
||||
discordId: "79237403620945920",
|
||||
});
|
||||
});
|
||||
|
||||
QueryToUserIdentifier("gets id", () => {
|
||||
assert.equal(queryToUserIdentifier("1"), {
|
||||
id: 1,
|
||||
});
|
||||
});
|
||||
|
||||
QueryToUserIdentifier.run();
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { User } from "~/db/types";
|
||||
import { isAdmin } from "~/permissions";
|
||||
import { isCustomUrl } from "./urls";
|
||||
|
||||
export function isAtLeastFiveDollarTierPatreon(
|
||||
user?: Pick<User, "patronTier" | "id">
|
||||
@@ -8,3 +9,32 @@ export function isAtLeastFiveDollarTierPatreon(
|
||||
|
||||
return isAdmin(user) || (user.patronTier && user.patronTier >= 2);
|
||||
}
|
||||
|
||||
const urlRegExp = new RegExp("(https://)?sendou.ink/u/(.+)");
|
||||
const DISCORD_ID_MIN_LENGTH = 17;
|
||||
export function queryToUserIdentifier(
|
||||
query: string
|
||||
): { id: number } | { discordId: string } | { customUrl: string } | null {
|
||||
const match = query.match(urlRegExp);
|
||||
|
||||
if (match) {
|
||||
const [, , identifier] = match;
|
||||
|
||||
if (isCustomUrl(identifier)) {
|
||||
return { customUrl: identifier };
|
||||
}
|
||||
|
||||
return { discordId: identifier };
|
||||
}
|
||||
|
||||
// = it's numeric
|
||||
if (!isCustomUrl(query)) {
|
||||
if (query.length >= DISCORD_ID_MIN_LENGTH) {
|
||||
return { discordId: query };
|
||||
}
|
||||
|
||||
return { id: Number(query) };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user