fix: missing systemRef in patch /system, crash when system not found

This commit is contained in:
spiral 2021-12-01 08:43:16 -05:00
parent ab5484892f
commit a0d2773ef4
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
2 changed files with 12 additions and 3 deletions

View File

@ -81,6 +81,7 @@ public class SwitchControllerV2: PKControllerBase
public async Task<IActionResult> SwitchCreate(string systemRef, [FromBody] PostSwitchParams data)
{
var system = await ResolveSystem(systemRef);
if (system == null) throw Errors.SystemNotFound;
if (ContextFor(system) != LookupContext.ByOwner)
throw Errors.GenericMissingPermissions;
@ -163,6 +164,7 @@ public class SwitchControllerV2: PKControllerBase
// for now, don't need to make a PatchObject for this, since it's only one param
var system = await ResolveSystem(systemRef);
if (system == null) throw Errors.SystemNotFound;
if (ContextFor(system) != LookupContext.ByOwner)
throw Errors.GenericMissingPermissions;
@ -197,6 +199,7 @@ public class SwitchControllerV2: PKControllerBase
public async Task<IActionResult> SwitchMemberPatch(string systemRef, string switchRef, [FromBody] JArray data)
{
var system = await ResolveSystem(systemRef);
if (system == null) throw Errors.SystemNotFound;
if (ContextFor(system) != LookupContext.ByOwner)
throw Errors.GenericMissingPermissions;
@ -244,6 +247,7 @@ public class SwitchControllerV2: PKControllerBase
public async Task<IActionResult> SwitchDelete(string systemRef, string switchRef)
{
var system = await ResolveSystem(systemRef);
if (system == null) throw Errors.SystemNotFound;
if (ContextFor(system) != LookupContext.ByOwner)
throw Errors.GenericMissingPermissions;

View File

@ -21,10 +21,13 @@ public class SystemControllerV2: PKControllerBase
return Ok(system.ToJson(ContextFor(system), APIVersion.V2));
}
[HttpPatch("@me")]
public async Task<IActionResult> DoSystemPatch([FromBody] JObject data)
[HttpPatch("{systemRef}")]
public async Task<IActionResult> DoSystemPatch(string systemRef, [FromBody] JObject data)
{
var system = await ResolveSystem("@me");
var system = await ResolveSystem(systemRef);
if (system == null) throw Errors.SystemNotFound;
if (ContextFor(system) != LookupContext.ByOwner)
throw Errors.GenericMissingPermissions;
var patch = SystemPatch.FromJSON(data, APIVersion.V2);
patch.AssertIsValid();
@ -39,6 +42,7 @@ public class SystemControllerV2: PKControllerBase
public async Task<IActionResult> GetSystemSettings(string systemRef)
{
var system = await ResolveSystem(systemRef);
if (system == null) throw Errors.SystemNotFound;
if (ContextFor(system) != LookupContext.ByOwner)
throw Errors.GenericMissingPermissions;
@ -50,6 +54,7 @@ public class SystemControllerV2: PKControllerBase
public async Task<IActionResult> DoSystemSettingsPatch(string systemRef, [FromBody] JObject data)
{
var system = await ResolveSystem(systemRef);
if (system == null) throw Errors.SystemNotFound;
if (ContextFor(system) != LookupContext.ByOwner)
throw Errors.GenericMissingPermissions;