This commit is contained in:
2020-01-27 22:36:56 +00:00
parent 0d6fa8a072
commit 3402eb0a17
5 changed files with 32 additions and 22 deletions

View File

@@ -1,13 +1,16 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using System.ComponentModel.DataAnnotations;
namespace AyaNova.Api.Controllers
@@ -78,7 +81,7 @@ namespace AyaNova.Api.Controllers
/// </summary>
/// <returns>On success returns information about the currently installed license in AyaNova</returns>
[HttpPost]
public ActionResult FetchLicense()
public async Task<IActionResult> FetchLicense()
{
//Open or opsOnly and user is opsadminfull
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
@@ -98,7 +101,7 @@ namespace AyaNova.Api.Controllers
try
{
AyaNova.Core.License.FetchKeyAsync(serverState, ct, log);
await AyaNova.Core.License.FetchKeyAsync(serverState, ct, log);
}
catch (Exception ex)
{
@@ -121,8 +124,8 @@ namespace AyaNova.Api.Controllers
}
var ret = AyaNova.Core.License.LicenseInfoAsJson;
//Log
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct);
return Ok(ApiOkResponse.Response(ret, true));
}
@@ -137,12 +140,13 @@ namespace AyaNova.Api.Controllers
/// <param name="requestData"></param>
/// <returns>HTTP 204 No Content result code on success or fail code with explanation</returns>
[HttpPost("trial")]
public ActionResult RequestTrial([FromBody] dtoTrialRequestData requestData)
public async Task<IActionResult> RequestTrial([FromBody] dtoTrialRequestData requestData)
{
//Open or opsOnly and user is opsadminfull
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
//return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
if (!Authorized.HasCreateRole(HttpContext.Items, AyaType.License))
@@ -155,7 +159,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
}
if (!AyaNova.Util.DbUtil.DBIsEmptyAsync(ct, log))
if (!await AyaNova.Util.DbUtil.DBIsEmptyAsync(ct, log))
{
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Only an empty AyaNova database can request a trial key. Erase the database to proceed with a new trial."));
}
@@ -166,11 +170,11 @@ namespace AyaNova.Api.Controllers
}
//Send the request to RockFish here (or at least start the job to do it in which case return Accepted instead of no content and update comment above)
var ret = Core.License.RequestTrialAsync(requestData.EmailAddress, requestData.RegisteredTo, log);
var ret = await Core.License.RequestTrialAsync(requestData.EmailAddress, requestData.RegisteredTo, log);
//Log
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct);
return Ok(ApiOkResponse.Response(ret, true));
}