using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using SlpModularCms.Core.Availability;
using SlpModularCms.Core.Email;
namespace SlpModularCms.Core.Hosting;
///
/// Exposes which optional modules are loaded on this instance, so clients (e.g. the
/// frontend) can tell a master-only feature apart from an instance without that module
/// (see the local master/slave dev setup) without guessing from a 404.
///
[ApiController]
[Route("[controller]")]
public class SystemController : ControllerBase
{
private readonly ModuleOrchestrator _orchestrator;
private readonly IMailAvailability _mail;
private readonly IOptions _app;
public SystemController(ModuleOrchestrator orchestrator, IMailAvailability mail, IOptions app)
{
_orchestrator = orchestrator;
_mail = mail;
_app = app;
}
[HttpGet("capabilities")]
[AllowAnonymous]
[PublicSiteEndpoint]
public IActionResult GetCapabilities()
{
// EmailEnabled tells the UI whether mail actions exist on this site; DefaultLanguage is the
// site's mail language fallback. Neither exposes configuration values beyond that.
return Ok(new
{
Modules = _orchestrator.ModuleNames,
EmailEnabled = _mail.IsEnabled,
DefaultLanguage = MailLanguages.Normalize(_app.Value.DefaultLanguage) ?? MailLanguages.Dutch
});
}
}