case 4221

This commit is contained in:
2022-10-26 21:49:22 +00:00
parent 0a80ceaf1c
commit 3806cca559
2 changed files with 66 additions and 21 deletions

View File

@@ -233,13 +233,14 @@ namespace AyaNova.Api.Controllers
/// <summary>
/// Permanently erase all data and all attachments
/// Permanently erase most data and all attachments for seeding or migration purposes
///
/// Posting to this route causes AyaNova completely erase all data in it's database and erase all attachment files
/// returning the database to an empty state
/// This route is used by the v8-migration utility and by the AyaNova UI when seeding a trial database
///
/// The only items retained are the SuperUser account and the license key
///
/// Items retained are documented here with the exception of Tax codes:
/// https://ayanova.com/docs/adm-license/#erase-database
/// However not Tax Codes as documented because seeding or migration will create tax codes
///
/// (Only *the* SuperUser account can use this route)
/// </summary>
/// <param name="acceptCode">Must be "I understand"</param>
@@ -265,7 +266,51 @@ namespace AyaNova.Api.Controllers
//empty the db
await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, Guid.Empty, serverState.IsMigrateMode);
await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
//Log
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData), ct);
return NoContent();
}
/// <summary>
/// Permanently erase most data and all attachments
///
/// This route is used by the by the AyaNova UI when a user selects to manually erase the database
/// or when they are evaluating and request another trial period with a database that already has a trial license in it
///
/// Items retained are documented here:
/// https://ayanova.com/docs/adm-license/#erase-database
///
///
/// (Only *the* SuperUser account can use this route)
/// </summary>
/// <param name="acceptCode">Must be "I understand"</param>
/// <returns>HTTP 204 No Content result code on success or fail code with explanation</returns>
[HttpPost("permanently-erase-all-data-keep-tax-codes")]
public async Task<IActionResult> RemoveAllDataKeepTaxCodes([FromBody] string acceptCode)
{
if (serverState.IsClosed)
{
//Exception for SuperUser account to handle licensing issues
if (UserIdFromContext.Id(HttpContext.Items) != 1)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
}
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
long UserId = UserIdFromContext.Id(HttpContext.Items);
//SuperUser only and must have accept code
if (UserId != 1 || string.IsNullOrWhiteSpace(acceptCode) || acceptCode.ToLowerInvariant() != "i understand")
return StatusCode(403, new ApiNotAuthorizedResponse());
//empty the db
await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, true);
//Log
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData), ct);
@@ -292,7 +337,7 @@ namespace AyaNova.Api.Controllers
return StatusCode(403, new ApiNotAuthorizedResponse());
await Core.License.FlagEULA(ct, log);
//Log
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.Modified, "End user license agreement consent obtained"), ct);