feat: API bulk privacy endpoints
This commit is contained in:
parent
70cf472fb5
commit
8629e38edd
@ -1,5 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
using SqlKata;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
@ -47,6 +49,48 @@ public class PrivateController: PKControllerBase
|
|||||||
|
|
||||||
return Ok(o);
|
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
|
public static class PrivateJsonExt
|
||||||
|
Loading…
Reference in New Issue
Block a user