From 7bf6c2064f23178a9c5582719b5be9b369376503 Mon Sep 17 00:00:00 2001 From: spiral Date: Wed, 1 Dec 2021 17:27:43 -0500 Subject: [PATCH] feat(api): throw error when patching autoproxy member with autoproxy mode set to latch --- .../Controllers/v2/DiscordControllerV2.cs | 14 ++++++++++++++ PluralKit.API/Errors.cs | 1 + 2 files changed, 15 insertions(+) diff --git a/PluralKit.API/Controllers/v2/DiscordControllerV2.cs b/PluralKit.API/Controllers/v2/DiscordControllerV2.cs index 7d830da2..72a1042a 100644 --- a/PluralKit.API/Controllers/v2/DiscordControllerV2.cs +++ b/PluralKit.API/Controllers/v2/DiscordControllerV2.cs @@ -68,6 +68,7 @@ public class DiscordControllerV2: PKControllerBase // this is less than great, but at least it's legible if (patch.AutoproxyMember.Value == null) + { if (patch.AutoproxyMode.IsPresent) { if (patch.AutoproxyMode.Value == AutoproxyMode.Member) @@ -77,6 +78,19 @@ public class DiscordControllerV2: PKControllerBase { throw Errors.MissingAutoproxyMember; } + } + else + { + if (patch.AutoproxyMode.IsPresent) + { + if (patch.AutoproxyMode.Value == AutoproxyMode.Latch) + throw Errors.PatchLatchMemberError; + } + else if (settings.AutoproxyMode == AutoproxyMode.Latch) + { + throw Errors.PatchLatchMemberError; + } + } var newSettings = await _repo.UpdateSystemGuild(system.Id, guild_id, patch); diff --git a/PluralKit.API/Errors.cs b/PluralKit.API/Errors.cs index 261ac47d..d1a73c13 100644 --- a/PluralKit.API/Errors.cs +++ b/PluralKit.API/Errors.cs @@ -111,6 +111,7 @@ public static class Errors public static PKError InvalidSwitchId = new(400, 40006, "Invalid switch ID."); public static PKError MemberLimitReached = new(400, 40007, "Member limit reached."); public static PKError GroupLimitReached = new(400, 40008, "Group limit reached."); + public static PKError PatchLatchMemberError = new(400, 40009, "Cannot patch autoproxy member with latch-mode autoproxy."); public static PKError Unimplemented = new(501, 50001, "Unimplemented"); }