mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
feat: API bulk privacy endpoints
This commit is contained in:
parent
70cf472fb5
commit
8629e38edd
1 changed files with 44 additions and 0 deletions
|
|
@ -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<IActionResult> 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<IActionResult> 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue