From 1260f1329360f091844621a40d287e4df5efffe1 Mon Sep 17 00:00:00 2001 From: Bruce Berrios <58147810+Bruception@users.noreply.github.com> Date: Tue, 7 Jun 2022 17:41:37 -0400 Subject: [PATCH] Add config for discord integration (#3081) Bruception --- backend/src/api/routes/users.ts | 14 +++++++++++++- backend/src/constants/base-configuration.ts | 13 +++++++++++++ backend/src/types/types.d.ts | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/backend/src/api/routes/users.ts b/backend/src/api/routes/users.ts index 99b13b964..3480f039f 100644 --- a/backend/src/api/routes/users.ts +++ b/backend/src/api/routes/users.ts @@ -2,7 +2,11 @@ import joi from "joi"; import { authenticateRequest } from "../../middlewares/auth"; import { Router } from "express"; import * as UserController from "../controllers/user"; -import { asyncHandler, validateRequest } from "../../middlewares/api-utils"; +import { + asyncHandler, + validateRequest, + validateConfiguration, +} from "../../middlewares/api-utils"; import * as RateLimit from "../../middlewares/rate-limit"; import apeRateLimit from "../../middlewares/ape-rate-limit"; import { isUsernameValid } from "../../utils/validation"; @@ -268,9 +272,17 @@ router.patch( asyncHandler(UserController.editCustomTheme) ); +const requireDiscordIntegrationEnabled = validateConfiguration({ + criteria: (configuration) => { + return configuration.discordIntegration.enabled; + }, + invalidMessage: "Discord integration is not available at this time", +}); + router.post( "/discord/link", RateLimit.userDiscordLink, + requireDiscordIntegrationEnabled, authenticateRequest(), validateRequest({ body: { diff --git a/backend/src/constants/base-configuration.ts b/backend/src/constants/base-configuration.ts index 5a13df3a3..8fc3533ce 100644 --- a/backend/src/constants/base-configuration.ts +++ b/backend/src/constants/base-configuration.ts @@ -39,6 +39,9 @@ export const BASE_CONFIGURATION: MonkeyTypes.Configuration = { dailyLeaderboardCacheSize: 1, topResultsToAnnounce: 1, // This should never be 0. Setting to zero will announce all results. }, + discordIntegration: { + enabled: false, + }, }; export const CONFIGURATION_FORM_SCHEMA = { @@ -49,6 +52,16 @@ export const CONFIGURATION_FORM_SCHEMA = { type: "boolean", label: "In Maintenance", }, + discordIntegration: { + type: "object", + label: "Discord Integration", + fields: { + enabled: { + type: "boolean", + label: "Enabled", + }, + }, + }, results: { type: "object", label: "Results", diff --git a/backend/src/types/types.d.ts b/backend/src/types/types.d.ts index 8ca10c872..43f5a2d2c 100644 --- a/backend/src/types/types.d.ts +++ b/backend/src/types/types.d.ts @@ -44,6 +44,9 @@ declare namespace MonkeyTypes { dailyLeaderboardCacheSize: number; topResultsToAnnounce: number; }; + discordIntegration: { + enabled: boolean; + }; } interface DecodedToken {