This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
namespace AyaNova.Api.Controllers
|
||||||
@@ -78,7 +81,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>On success returns information about the currently installed license in AyaNova</returns>
|
/// <returns>On success returns information about the currently installed license in AyaNova</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult FetchLicense()
|
public async Task<IActionResult> FetchLicense()
|
||||||
{
|
{
|
||||||
//Open or opsOnly and user is opsadminfull
|
//Open or opsOnly and user is opsadminfull
|
||||||
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
|
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
|
||||||
@@ -98,7 +101,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AyaNova.Core.License.FetchKeyAsync(serverState, ct, log);
|
await AyaNova.Core.License.FetchKeyAsync(serverState, ct, log);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -121,8 +124,8 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
var ret = AyaNova.Core.License.LicenseInfoAsJson;
|
var ret = AyaNova.Core.License.LicenseInfoAsJson;
|
||||||
//Log
|
//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));
|
return Ok(ApiOkResponse.Response(ret, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,12 +140,13 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns>HTTP 204 No Content result code on success or fail code with explanation</returns>
|
/// <returns>HTTP 204 No Content result code on success or fail code with explanation</returns>
|
||||||
[HttpPost("trial")]
|
[HttpPost("trial")]
|
||||||
public ActionResult RequestTrial([FromBody] dtoTrialRequestData requestData)
|
public async Task<IActionResult> RequestTrial([FromBody] dtoTrialRequestData requestData)
|
||||||
{
|
{
|
||||||
//Open or opsOnly and user is opsadminfull
|
//Open or opsOnly and user is opsadminfull
|
||||||
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.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));
|
||||||
|
//return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Authorized.HasCreateRole(HttpContext.Items, AyaType.License))
|
if (!Authorized.HasCreateRole(HttpContext.Items, AyaType.License))
|
||||||
@@ -155,7 +159,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
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."));
|
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)
|
//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
|
//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));
|
return Ok(ApiOkResponse.Response(ret, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -7,7 +6,6 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.JsonPatch;
|
using Microsoft.AspNetCore.JsonPatch;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
|
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.JsonPatch;
|
using Microsoft.AspNetCore.JsonPatch;
|
||||||
using EnumsNET;
|
using EnumsNET;
|
||||||
using AyaNova.Util;
|
using AyaNova.Util;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Biz;
|
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
@@ -36,7 +34,8 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
var ct = ServiceProviderProvider.DBContext;
|
var ct = ServiceProviderProvider.DBContext;
|
||||||
var ret = await ct.User.Where(x => x.Active == true && (x.UserType == UserType.Schedulable || x.UserType == UserType.Subcontractor)).LongCountAsync();
|
var ret = await ct.User.Where(x => x.Active == true && (x.UserType == UserType.Schedulable || x.UserType == UserType.Subcontractor)).LongCountAsync();
|
||||||
return ret;
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static UserBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
|
internal static UserBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ using System.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.AspNetCore.JsonPatch;
|
||||||
|
using EnumsNET;
|
||||||
|
using AyaNova.Util;
|
||||||
|
using AyaNova.Api.ControllerHelpers;
|
||||||
|
using AyaNova.Models;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AyaNova.Util
|
namespace AyaNova.Util
|
||||||
{
|
{
|
||||||
@@ -325,7 +336,7 @@ namespace AyaNova.Util
|
|||||||
// Check if DB is empty
|
// Check if DB is empty
|
||||||
// CALLED BY LICENSE CONTROLLER AND LICENSE.CS FOR TRIAL Request check
|
// CALLED BY LICENSE CONTROLLER AND LICENSE.CS FOR TRIAL Request check
|
||||||
// Also called by Import
|
// Also called by Import
|
||||||
internal static bool DBIsEmpty(AyContext ct, ILogger _log)
|
internal static async Task<bool> DBIsEmptyAsync(AyContext ct, ILogger _log)
|
||||||
{
|
{
|
||||||
//TODO: This needs to be way more thorough, only the main tables though, no need to get crazy with it
|
//TODO: This needs to be way more thorough, only the main tables though, no need to get crazy with it
|
||||||
//just stuff that would be shitty to have to re-enter
|
//just stuff that would be shitty to have to re-enter
|
||||||
@@ -333,7 +344,8 @@ namespace AyaNova.Util
|
|||||||
_log.LogDebug("DB empty check");
|
_log.LogDebug("DB empty check");
|
||||||
|
|
||||||
//An empty db contains only one User
|
//An empty db contains only one User
|
||||||
if (ct.User.Count() > 1) return false;
|
if (await ct.User.LongCountAsync() > 1) return false;
|
||||||
|
|
||||||
|
|
||||||
//No clients
|
//No clients
|
||||||
//if(ctx.Client.Count()>0) return false;
|
//if(ctx.Client.Count()>0) return false;
|
||||||
|
|||||||
@@ -11,12 +11,9 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
//JSON KEY
|
//JSON KEY
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Org.BouncyCastle.Security;
|
using Org.BouncyCastle.Security;
|
||||||
using Org.BouncyCastle.Crypto;
|
|
||||||
using Org.BouncyCastle.OpenSsl;
|
using Org.BouncyCastle.OpenSsl;
|
||||||
//using System.Security.Cryptography;
|
|
||||||
//using Microsoft.AspNetCore.Cryptography.KeyDerivation;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -522,7 +519,7 @@ namespace AyaNova.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Can't install a trial into a non-empty db
|
//Can't install a trial into a non-empty db
|
||||||
if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmptyAsync(ct, log))
|
if (ParsedNewKey.TrialLicense && ! DbUtil.DBIsEmptyAsync(ct, log))
|
||||||
{
|
{
|
||||||
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
|
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user