App Service: Validate IDs when parsing items template (#6228)

Validates missing and duplicate IDs on the edit actions and when creating/updating apps via the API.
Fails gracefully by excluding existing items without ID or with duplicate ID for the rest of the cases.

Fixes #6227.
This commit is contained in:
d11n
2024-09-26 08:52:16 +02:00
committed by GitHub
parent 7013e618de
commit 443a350bad
10 changed files with 130 additions and 24 deletions

View File

@@ -402,11 +402,11 @@ namespace BTCPayServer.Controllers.Greenfield
try
{
// Just checking if we can serialize
AppService.SerializeTemplate(AppService.Parse(request.Template));
AppService.SerializeTemplate(AppService.Parse(request.Template, true, true));
}
catch
catch (Exception ex)
{
ModelState.AddModelError(nameof(request.Template), "Invalid template");
ModelState.AddModelError(nameof(request.Template), ex.Message);
}
}
}
@@ -486,11 +486,11 @@ namespace BTCPayServer.Controllers.Greenfield
try
{
// Just checking if we can serialize
AppService.SerializeTemplate(AppService.Parse(request.PerksTemplate));
AppService.SerializeTemplate(AppService.Parse(request.PerksTemplate, true, true));
}
catch
catch (Exception ex)
{
ModelState.AddModelError(nameof(request.PerksTemplate), "Invalid template");
ModelState.AddModelError(nameof(request.PerksTemplate), $"Invalid template: {ex.Message}");
}
}