From d7839a8a0550f6dfb4deec519c849cd0cf5716a4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Wed, 19 Mar 2025 12:57:25 -0600 Subject: [PATCH 1/5] Allow users to see server configuration passed in via environment variables or appsettings.json --- Controllers/HomeController.cs | 17 ++++++ Models/Settings/ServerSettingsViewModel.cs | 17 ++++++ Views/Home/_ServerConfig.cshtml | 62 ++++++++++++++++++++++ Views/Home/_Settings.cshtml | 15 +++++- wwwroot/js/settings.js | 9 ++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 Models/Settings/ServerSettingsViewModel.cs create mode 100644 Views/Home/_ServerConfig.cshtml diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 535fbe1..b80dbe9 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -555,6 +555,23 @@ namespace CarCareTracker.Controllers } return Json(false); } + [Authorize(Roles = nameof(UserData.IsRootUser))] + public IActionResult GetServerConfiguration() + { + var viewModel = new ServerSettingsViewModel + { + PostgresConnection = _config.GetServerPostgresConnection(), + AllowedFileExtensions = _config.GetAllowedFileUploadExtensions(), + CustomLogoURL = _config.GetLogoUrl(), + MessageOfTheDay = _config.GetMOTD(), + WebHookURL = _config.GetWebHookUrl(), + CustomWidgetsEnabled = _config.GetCustomWidgetsEnabled(), + InvariantAPIEnabled = _config.GetInvariantApi(), + SMTPConfig = _config.GetMailConfig(), + OIDCConfig = _config.GetOpenIDConfig() + }; + return PartialView("_ServerConfig", viewModel); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Models/Settings/ServerSettingsViewModel.cs b/Models/Settings/ServerSettingsViewModel.cs new file mode 100644 index 0000000..1b4e286 --- /dev/null +++ b/Models/Settings/ServerSettingsViewModel.cs @@ -0,0 +1,17 @@ +namespace CarCareTracker.Models +{ + public class ServerSettingsViewModel + { + public string LocaleInfo { get; set; } + public string PostgresConnection { get; set; } + public string AllowedFileExtensions { get; set; } + public string CustomLogoURL { get; set; } + public string MessageOfTheDay { get; set; } + public string WebHookURL { get; set; } + public bool CustomWidgetsEnabled { get; set; } + public bool InvariantAPIEnabled { get; set; } + public MailConfig SMTPConfig { get; set; } = new MailConfig(); + public OpenIDConfig OIDCConfig { get; set; } = new OpenIDConfig(); + + } +} diff --git a/Views/Home/_ServerConfig.cshtml b/Views/Home/_ServerConfig.cshtml new file mode 100644 index 0000000..73d6b6e --- /dev/null +++ b/Views/Home/_ServerConfig.cshtml @@ -0,0 +1,62 @@ +@using CarCareTracker.Helper +@inject IConfigHelper config +@inject ITranslationHelper translator +@model ServerSettingsViewModel +@{ + var userConfig = config.GetUserConfig(User); + var userLanguage = userConfig.UserLanguage; +} + + +@* *@ \ No newline at end of file diff --git a/Views/Home/_Settings.cshtml b/Views/Home/_Settings.cshtml index 2240d2c..10ef3e0 100644 --- a/Views/Home/_Settings.cshtml +++ b/Views/Home/_Settings.cshtml @@ -253,7 +253,14 @@
- @translator.Translate(userLanguage, "Server-wide Settings") +
+
+ @translator.Translate(userLanguage, "Server-wide Settings") +
+
+ +
+
@@ -355,6 +362,12 @@
+