From 8629e38eddbbf2cefc9b4668a4edae259856c831 Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 7 Apr 2022 03:49:06 -0400 Subject: [PATCH] feat: API bulk privacy endpoints --- .../Controllers/PrivateController.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/PluralKit.API/Controllers/PrivateController.cs b/PluralKit.API/Controllers/PrivateController.cs index a3c143c7..eebc71a6 100644 --- a/PluralKit.API/Controllers/PrivateController.cs +++ b/PluralKit.API/Controllers/PrivateController.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Mvc; +using SqlKata; + using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -47,6 +49,48 @@ public class PrivateController: PKControllerBase return Ok(o); } + + [HttpPost("bulk_privacy/member")] + public async Task BulkMemberPrivacy([FromBody] JObject inner) + { + HttpContext.Items.TryGetValue("SystemId", out var systemId); + if (systemId == null) + throw Errors.GenericAuthError; + + var data = new JObject(); + data.Add("privacy", inner); + + var patch = MemberPatch.FromJSON(data, APIVersion.V2); + + patch.AssertIsValid(); + if (patch.Errors.Count > 0) + throw new ModelParseError(patch.Errors); + + await _db.ExecuteQuery(patch.Apply(new Query("members").Where("system", systemId))); + + return NoContent(); + } + + [HttpPost("bulk_privacy/group")] + public async Task BulkGroupPrivacy([FromBody] JObject inner) + { + HttpContext.Items.TryGetValue("SystemId", out var systemId); + if (systemId == null) + throw Errors.GenericAuthError; + + var data = new JObject(); + data.Add("privacy", inner); + + var patch = GroupPatch.FromJson(data); + + patch.AssertIsValid(); + if (patch.Errors.Count > 0) + throw new ModelParseError(patch.Errors); + + await _db.ExecuteQuery(patch.Apply(new Query("groups").Where("system", systemId))); + + return NoContent(); + } } public static class PrivateJsonExt