Separate admin access from finance lock
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Microsoft.Extensions.Options;
|
||||
using TrafagSalesExporter.Security;
|
||||
|
||||
namespace TrafagSalesExporter.Services;
|
||||
|
||||
public interface ILandingPageSettingsService
|
||||
{
|
||||
bool ShowWalkingLabFigure { get; }
|
||||
void SetShowWalkingLabFigure(bool value);
|
||||
}
|
||||
|
||||
public sealed class LandingPageSettingsService : ILandingPageSettingsService
|
||||
{
|
||||
private static readonly object FileLock = new();
|
||||
private readonly LandingPageOptions _options;
|
||||
private readonly IHostEnvironment _environment;
|
||||
|
||||
public LandingPageSettingsService(IOptions<LandingPageOptions> options, IHostEnvironment environment)
|
||||
{
|
||||
_options = options.Value;
|
||||
_environment = environment;
|
||||
}
|
||||
|
||||
public bool ShowWalkingLabFigure => _options.ShowWalkingLabFigure;
|
||||
|
||||
public void SetShowWalkingLabFigure(bool value)
|
||||
{
|
||||
_options.ShowWalkingLabFigure = value;
|
||||
SaveSetting(value);
|
||||
}
|
||||
|
||||
private void SaveSetting(bool value)
|
||||
{
|
||||
var path = Path.Combine(_environment.ContentRootPath, "appsettings.json");
|
||||
|
||||
lock (FileLock)
|
||||
{
|
||||
var json = File.Exists(path)
|
||||
? File.ReadAllText(path, Encoding.UTF8)
|
||||
: "{}";
|
||||
|
||||
var root = JsonNode.Parse(json)?.AsObject() ?? new JsonObject();
|
||||
var section = root[LandingPageOptions.SectionName] as JsonObject;
|
||||
if (section is null)
|
||||
{
|
||||
section = new JsonObject();
|
||||
root[LandingPageOptions.SectionName] = section;
|
||||
}
|
||||
|
||||
section[nameof(LandingPageOptions.ShowWalkingLabFigure)] = value;
|
||||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||
File.WriteAllText(path, root.ToJsonString(options), new UTF8Encoding(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,9 @@ public sealed class UiTextService : IUiTextService
|
||||
["Passwort konnte nicht geändert werden. Name oder aktuelles Passwort prüfen."] = "No se pudo cambiar la contraseña. Compruebe el nombre o la contraseña actual.",
|
||||
["Passwort wurde geändert."] = "La contraseña se ha cambiado.",
|
||||
["HR-/Finance-Cockpit Sessions"] = "Sesiones de cockpit HR/Finance",
|
||||
["Startseite"] = "Página de inicio",
|
||||
["Optionale Animation unter dem Willkommens-Text."] = "Animación opcional debajo del texto de bienvenida.",
|
||||
["Strichmännchen anzeigen"] = "Mostrar figura de líneas",
|
||||
["Gezählt werden App-interne Entsperrungen seit dem letzten App-Start."] = "Se cuentan los desbloqueos internos de la app desde el último inicio.",
|
||||
["Bereich"] = "Área",
|
||||
["IP-Adresse"] = "Dirección IP",
|
||||
@@ -299,6 +302,9 @@ public sealed class UiTextService : IUiTextService
|
||||
["Passwort konnte nicht geändert werden. Name oder aktuelles Passwort prüfen."] = "Impossibile modificare la password. Controllare nome o password attuale.",
|
||||
["Passwort wurde geändert."] = "La password è stata modificata.",
|
||||
["HR-/Finance-Cockpit Sessions"] = "Sessioni cockpit HR/Finance",
|
||||
["Startseite"] = "Pagina iniziale",
|
||||
["Optionale Animation unter dem Willkommens-Text."] = "Animazione opzionale sotto il testo di benvenuto.",
|
||||
["Strichmännchen anzeigen"] = "Mostra omino",
|
||||
["Gezählt werden App-interne Entsperrungen seit dem letzten App-Start."] = "Vengono contati gli sblocchi interni dell'app dall'ultimo avvio.",
|
||||
["Bereich"] = "Area",
|
||||
["IP-Adresse"] = "Indirizzo IP",
|
||||
@@ -529,6 +535,9 @@ public sealed class UiTextService : IUiTextService
|
||||
["Passwort konnte nicht geändert werden. Name oder aktuelles Passwort prüfen."] = "पासवर्ड बदला नहीं जा सका. नाम या वर्तमान पासवर्ड जांचें.",
|
||||
["Passwort wurde geändert."] = "पासवर्ड बदल दिया गया.",
|
||||
["HR-/Finance-Cockpit Sessions"] = "HR/Finance cockpit sessions",
|
||||
["Startseite"] = "होम पेज",
|
||||
["Optionale Animation unter dem Willkommens-Text."] = "स्वागत पाठ के नीचे वैकल्पिक animation.",
|
||||
["Strichmännchen anzeigen"] = "स्टिक फिगर दिखाएं",
|
||||
["Gezählt werden App-interne Entsperrungen seit dem letzten App-Start."] = "ऐप के पिछले प्रारंभ के बाद से आंतरिक अनलॉक गिने जाते हैं.",
|
||||
["Bereich"] = "क्षेत्र",
|
||||
["IP-Adresse"] = "IP पता",
|
||||
|
||||
Reference in New Issue
Block a user