feat: pk;config
This commit is contained in:
@@ -54,10 +54,11 @@ public class GroupControllerV2: PKControllerBase
|
||||
public async Task<IActionResult> GroupCreate([FromBody] JObject data)
|
||||
{
|
||||
var system = await ResolveSystem("@me");
|
||||
var config = await _repo.GetSystemConfig(system.Id);
|
||||
|
||||
// Check group cap
|
||||
var existingGroupCount = await _repo.GetSystemGroupCount(system.Id);
|
||||
var groupLimit = system.GroupLimitOverride ?? Limits.MaxGroupCount;
|
||||
var groupLimit = config.GroupLimitOverride ?? Limits.MaxGroupCount;
|
||||
if (existingGroupCount >= groupLimit)
|
||||
throw Errors.GroupLimitReached;
|
||||
|
||||
|
@@ -37,9 +37,10 @@ public class MemberControllerV2: PKControllerBase
|
||||
public async Task<IActionResult> MemberCreate([FromBody] JObject data)
|
||||
{
|
||||
var system = await ResolveSystem("@me");
|
||||
var config = await _repo.GetSystemConfig(system.Id);
|
||||
|
||||
var memberCount = await _repo.GetSystemMemberCount(system.Id);
|
||||
var memberLimit = system.MemberLimitOverride ?? Limits.MaxMemberCount;
|
||||
var memberLimit = config.MemberLimitOverride ?? Limits.MaxMemberCount;
|
||||
if (memberCount >= memberLimit)
|
||||
throw Errors.MemberLimitReached;
|
||||
|
||||
|
@@ -34,4 +34,32 @@ public class SystemControllerV2: PKControllerBase
|
||||
var newSystem = await _repo.UpdateSystem(system.Id, patch);
|
||||
return Ok(newSystem.ToJson(LookupContext.ByOwner, APIVersion.V2));
|
||||
}
|
||||
|
||||
[HttpGet("{systemRef}/settings")]
|
||||
public async Task<IActionResult> GetSystemSettings(string systemRef)
|
||||
{
|
||||
var system = await ResolveSystem(systemRef);
|
||||
if (ContextFor(system) != LookupContext.ByOwner)
|
||||
throw Errors.GenericMissingPermissions;
|
||||
|
||||
var config = await _repo.GetSystemConfig(system.Id);
|
||||
return Ok(config.ToJson());
|
||||
}
|
||||
|
||||
[HttpPatch("{systemRef}/settings")]
|
||||
public async Task<IActionResult> DoSystemSettingsPatch(string systemRef, [FromBody] JObject data)
|
||||
{
|
||||
var system = await ResolveSystem(systemRef);
|
||||
if (ContextFor(system) != LookupContext.ByOwner)
|
||||
throw Errors.GenericMissingPermissions;
|
||||
|
||||
var patch = SystemConfigPatch.FromJson(data);
|
||||
|
||||
patch.AssertIsValid();
|
||||
if (patch.Errors.Count > 0)
|
||||
throw new ModelParseError(patch.Errors);
|
||||
|
||||
var newConfig = await _repo.UpdateSystemConfig(system.Id, patch);
|
||||
return Ok(newConfig.ToJson());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user