added append password and forceemail options to seeder

This commit is contained in:
2022-03-15 23:26:06 +00:00
parent d129192c9f
commit 62a2f6d7bc
4 changed files with 158 additions and 138 deletions

View File

@@ -7,6 +7,7 @@ using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
namespace AyaNova.Api.Controllers
{
@@ -47,13 +48,15 @@ namespace AyaNova.Api.Controllers
/// "Medium" - Local service company with multiple employees and departments dataset
/// "Large" - Large corporate multi regional dataset
/// "Huge" - Used for automated testing and development, if you choose this it will take a very long time (15 minutes to overnight)
/// TimeZoneOffset - Value in hours of local time zone offset from UTC / GMT. This ensures that data is generated relative to the desired time zone
/// E2e - End to end testing mode for development automated testing; false is default and faster
/// ForceEmail - set every generated object with an email address to this email address
/// AppendPassword - append this string to the stock passwords, useful when testing on the public internet
/// </summary>
/// <param name="size">Valid values are "Small", "Medium", "Large", "Huge"</param>
/// <param name="timeZoneOffset">Value in hours of local time zone offset from UTC / GMT. This ensures that data is generated relative to the desired time zone</param>
/// <param name="e2e">End to end testing mode for automated testing; false is default and faster</param>
/// <param name="seedOptions"></param>
/// <returns>Job Id</returns>
[HttpPost("seed/{size}/{timeZoneOffset}/{e2e}")]
public async Task<IActionResult> SeedTrialDatabase([FromRoute] string size, [FromRoute] decimal timeZoneOffset, [FromRoute] bool e2e = false)
[HttpPost("seed")]
public async Task<IActionResult> SeedTrialDatabase([FromBody] SeedOptions seedOptions)
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
@@ -68,7 +71,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Current license is not a trial license key. Only a trial can be seeded."));
}
Seeder.Level.SeedLevel seedLevel = Seeder.Level.StringToSeedLevel(size);
Seeder.Level.SeedLevel seedLevel = Seeder.Level.StringToSeedLevel(seedOptions.Size);
if (seedLevel == Seeder.Level.SeedLevel.NotValid)
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "size", "Valid values are \"small\", \"medium\", \"large\", \"huge\""));
@@ -76,25 +79,38 @@ namespace AyaNova.Api.Controllers
JObject o = JObject.FromObject(new
{
seedLevel = seedLevel,
timeZoneOffset = timeZoneOffset,
e2e = e2e
seedLevel = seedOptions.Size,
timeZoneOffset = seedOptions.TimeZoneOffset,
e2e = seedOptions.E2e,
forceEmail=seedOptions.ForceEmail,
appendPassword=seedOptions.AppendPassword
});
OpsJob j = new OpsJob();
j.Name = $"Seed test data (size={size})";
j.Name = $"Seed test data (size={seedOptions.Size})";
j.JobType = JobType.SeedTestData;
j.Exclusive = true;//don't run other jobs, this will erase the db
j.JobInfo = o.ToString();
await JobsBiz.AddJobAsync(j);
//Log
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.TrialSeeder, AyaEvent.Created, size), ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.TrialSeeder, AyaEvent.Created, seedOptions.Size), ct);
return Accepted(new { JobId = j.GId });//202 accepted
}
public class SeedOptions
{
[Required]
public string Size { get; set; }
[Required]
public decimal TimeZoneOffset { get; set; }
public bool E2e { get; set; } = false;
[EmailAddress]
public string ForceEmail { get; set; }
public string AppendPassword { get; set; }
}
//------------