feat(groups): add fail-closed admission management
This commit is contained in:
@@ -5,9 +5,9 @@ import { db } from "@/lib/database";
|
||||
|
||||
const UI_ACCESSED = "games.minecraft.account-manager.ui.accessed";
|
||||
|
||||
export async function recordAdminEvent(
|
||||
export async function recordAdminSubjectEvent(
|
||||
admin: { email: string | null; name: string | null },
|
||||
targetUserId: string,
|
||||
subject: string,
|
||||
type: string,
|
||||
data: Record<string, unknown>,
|
||||
) {
|
||||
@@ -16,12 +16,21 @@ export async function recordAdminEvent(
|
||||
return recordEvent(db, {
|
||||
type,
|
||||
source: "/web/admin",
|
||||
subject: `user/${targetUserId}`,
|
||||
subject,
|
||||
ipAddress: ipAddress ?? undefined,
|
||||
data: { ...data, adminEmail: admin.email, adminName: admin.name },
|
||||
});
|
||||
}
|
||||
|
||||
export async function recordAdminEvent(
|
||||
admin: { email: string | null; name: string | null },
|
||||
targetUserId: string,
|
||||
type: string,
|
||||
data: Record<string, unknown>,
|
||||
) {
|
||||
return recordAdminSubjectEvent(admin, `user/${targetUserId}`, type, data);
|
||||
}
|
||||
|
||||
export async function recordUserEvent(
|
||||
user: { id: string },
|
||||
type: string,
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { getGuildMemberIdentity } from "@minecraft-account-manager/minecraft";
|
||||
import { logger } from "@/lib/logger";
|
||||
|
||||
export async function discordIdentity(input: {
|
||||
discordUserId: string;
|
||||
discordUsername: string;
|
||||
discordGlobalName: string | null;
|
||||
}) {
|
||||
const guildId = process.env.DISCORD_GUILD_ID?.trim();
|
||||
const botToken = process.env.DISCORD_BOT_TOKEN?.trim();
|
||||
const fallback = {
|
||||
id: input.discordUserId,
|
||||
username: input.discordUsername,
|
||||
globalName: input.discordGlobalName,
|
||||
nickname: null as string | null,
|
||||
live: false,
|
||||
};
|
||||
if (!guildId || !botToken) return fallback;
|
||||
|
||||
try {
|
||||
return { ...await getGuildMemberIdentity({
|
||||
guildId,
|
||||
discordUserId: input.discordUserId,
|
||||
botToken,
|
||||
}), live: true };
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
{ err: error, event: "discord.identity_lookup_failed", discordUserId: input.discordUserId },
|
||||
"Discord guild identity lookup failed",
|
||||
);
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user