using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using Microsoft.AspNetCore.Authorization;
using System.Linq;
using AyaNova.Biz;
namespace AyaNova.Api.Controllers
{
///
/// Meta controller class
///
[Asp.Versioning.ApiVersion("8.0")]
[Route("api/v{version:apiVersion}/")]
[Authorize]
[ApiController]
public class ApiMetaController : ControllerBase
{
private readonly ApiServerState serverState;
private readonly ILogger _log;
///
///
///
///
///
public ApiMetaController(ILogger logger, ApiServerState apiServerState)
{
_log = logger;
serverState = apiServerState;
}
private static string SupportUrl()
{
/*
contactSupportUrl() {
let dbId = encodeURIComponent(
window.$gz.store.state.globalSettings.serverDbId
);
let company = encodeURIComponent(
window.$gz.store.state.globalSettings.company
);
return `https://contact.ayanova.com/contact?dbid=${dbId}&company=${company}`;
}
*/
//case 4727 (F11, F39): this page is anonymous, so the link no longer carries the DB ID and licensee;
//the About form's support link (logged in) still fills them in
return "https://contact.ayanova.com/contact";
}
///
/// Server landing page
///
///
[AllowAnonymous]
[HttpGet]
public ContentResult Index()
{
//https://superuser.com/questions/361297/what-colour-is-the-dark-green-on-old-fashioned-green-screen-computer-displays
var errorBlock = string.Empty;
if (serverState.IsSystemLocked)
errorBlock = $@"
";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"(?<=\s)\s+");
resp = reg.Replace(resp, string.Empty).Replace("\n", "").Replace("\t", "");
return new ContentResult
{
ContentType = "text/html",
StatusCode = 200,
Content = resp
};
}
///
/// Get API server info for ABOUT form AyaNova display
///
/// API server info
[HttpGet("server-info")]
public ActionResult ServerInfo()
{
//case 4727 (F29): the DB ID and licence go to staff only (Service, NotService), as the About form shows them
var userType = UserTypeFromContext.Type(HttpContext.Items);
bool staff = userType == UserType.Service || userType == UserType.NotService;
return Ok(new
{
data = new
{
ServerVersion = AyaNovaVersion.FullNameAndVersion,
DBSchemaVersion = AySchema.currentSchema,
ServerLocalTime = DateUtil.ServerDateTimeString(System.DateTime.UtcNow),
ServerTimeZone = TimeZoneInfo.Local.Id,
ServerDbId = staff ? AyaNova.Core.License.ServerDbId : string.Empty,
License = staff ? AyaNova.Core.License.LicenseInfoAsJson : null,
#if (SUBSCRIPTION_BUILD)
Build = "Subscription"
#else
Build = "Perpetual"
#endif
}
});
}
///
/// Get list of types and roles required
///
/// A list of AyaType role rights
[HttpGet("role-rights")]
public ActionResult RoleRights()
{
return Ok(new
{
data = new
{
AyaTypes = BizRoles.roles.OrderBy(z => z.Key.ToString()).Select(z => new { AyaType = z.Key.ToString(), Change = z.Value.Change.ToString(), ReadFullRecord = z.Value.ReadFullRecord.ToString(), Select = z.Value.Select.ToString() }).ToList()
}
});
}
#if (DEBUG)
///
/// Get build mode of server, used for automated testing purposes
///
/// "DEBUG" or "RELEASE"
[HttpGet("build-mode")]
public ActionResult BuildMode()
{
return Ok(new { data = new { BuildMode = "DEBUG" } });
}
#else
///
/// Get build mode of server, used for automated testing purposes
///
/// "DEBUG" or "RELEASE"
[HttpGet("build-mode")]
public ActionResult BuildMode()
{
return Ok(new { data = new { BuildMode = "RELEASE" } });
}
#endif
}
}
#region sigtest script
/*