mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 05:54:26 +01:00
Policies: Cleanup and improvements (#5731)
* Policies: Turn checkboxes into toggles * Move email policy to server email settings * Move maintenance policies to server maintenance settings * Policies: Adjust spacings * Policies: Remove DisableInstantNotifications setting * Wording updates * Move maintenance settings back
This commit is contained in:
@@ -122,21 +122,24 @@ namespace BTCPayServer.Controllers
|
||||
_transactionLinkProviders = transactionLinkProviders;
|
||||
}
|
||||
|
||||
[Route("server/maintenance")]
|
||||
[HttpGet("server/maintenance")]
|
||||
public IActionResult Maintenance()
|
||||
{
|
||||
MaintenanceViewModel vm = new MaintenanceViewModel();
|
||||
vm.CanUseSSH = _sshState.CanUseSSH;
|
||||
var vm = new MaintenanceViewModel
|
||||
{
|
||||
CanUseSSH = _sshState.CanUseSSH,
|
||||
DNSDomain = Request.Host.Host
|
||||
};
|
||||
|
||||
if (!vm.CanUseSSH)
|
||||
TempData[WellKnownTempData.ErrorMessage] = "Maintenance feature requires access to SSH properly configured in BTCPay Server configuration.";
|
||||
vm.DNSDomain = this.Request.Host.Host;
|
||||
if (IPAddress.TryParse(vm.DNSDomain, out var unused))
|
||||
vm.DNSDomain = null;
|
||||
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
[Route("server/maintenance")]
|
||||
[HttpPost]
|
||||
[HttpPost("server/maintenance")]
|
||||
public async Task<IActionResult> Maintenance(MaintenanceViewModel vm, string command)
|
||||
{
|
||||
vm.CanUseSSH = _sshState.CanUseSSH;
|
||||
@@ -302,8 +305,8 @@ namespace BTCPayServer.Controllers
|
||||
[Route("server/policies")]
|
||||
public async Task<IActionResult> Policies()
|
||||
{
|
||||
ViewBag.AppsList = await GetAppSelectList();
|
||||
ViewBag.UpdateUrlPresent = _Options.UpdateUrl != null;
|
||||
ViewBag.AppsList = await GetAppSelectList();
|
||||
return View(_policiesSettings);
|
||||
}
|
||||
|
||||
@@ -1134,13 +1137,17 @@ namespace BTCPayServer.Controllers
|
||||
[Route("server/emails")]
|
||||
public async Task<IActionResult> Emails()
|
||||
{
|
||||
var data = (await _SettingsRepository.GetSettingAsync<EmailSettings>()) ?? new EmailSettings();
|
||||
return View(new EmailsViewModel(data));
|
||||
var email = await _SettingsRepository.GetSettingAsync<EmailSettings>() ?? new EmailSettings();
|
||||
var vm = new ServerEmailsViewModel(email)
|
||||
{
|
||||
EnableStoresToUseServerEmailSettings = !_policiesSettings.DisableStoresToUseServerEmailSettings
|
||||
};
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
[Route("server/emails")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Emails(EmailsViewModel model, string command)
|
||||
public async Task<IActionResult> Emails(ServerEmailsViewModel model, string command)
|
||||
{
|
||||
if (command == "Test")
|
||||
{
|
||||
@@ -1170,6 +1177,13 @@ namespace BTCPayServer.Controllers
|
||||
}
|
||||
return View(model);
|
||||
}
|
||||
|
||||
if (_policiesSettings.DisableStoresToUseServerEmailSettings == model.EnableStoresToUseServerEmailSettings)
|
||||
{
|
||||
_policiesSettings.DisableStoresToUseServerEmailSettings = !model.EnableStoresToUseServerEmailSettings;
|
||||
await _SettingsRepository.UpdateSetting(_policiesSettings);
|
||||
}
|
||||
|
||||
if (command == "ResetPassword")
|
||||
{
|
||||
var settings = await _SettingsRepository.GetSettingAsync<EmailSettings>() ?? new EmailSettings();
|
||||
@@ -1178,22 +1192,22 @@ namespace BTCPayServer.Controllers
|
||||
TempData[WellKnownTempData.SuccessMessage] = "Email server password reset";
|
||||
return RedirectToAction(nameof(Emails));
|
||||
}
|
||||
else // if (command == "Save")
|
||||
|
||||
// save
|
||||
if (model.Settings.From is not null && !MailboxAddressValidator.IsMailboxAddress(model.Settings.From))
|
||||
{
|
||||
if (model.Settings.From is not null && !MailboxAddressValidator.IsMailboxAddress(model.Settings.From))
|
||||
{
|
||||
ModelState.AddModelError("Settings.From", "Invalid email");
|
||||
return View(model);
|
||||
}
|
||||
var oldSettings = await _SettingsRepository.GetSettingAsync<EmailSettings>() ?? new EmailSettings();
|
||||
if (new EmailsViewModel(oldSettings).PasswordSet)
|
||||
{
|
||||
model.Settings.Password = oldSettings.Password;
|
||||
}
|
||||
await _SettingsRepository.UpdateSetting(model.Settings);
|
||||
TempData[WellKnownTempData.SuccessMessage] = "Email settings saved";
|
||||
return RedirectToAction(nameof(Emails));
|
||||
ModelState.AddModelError("Settings.From", "Invalid email");
|
||||
return View(model);
|
||||
}
|
||||
var oldSettings = await _SettingsRepository.GetSettingAsync<EmailSettings>() ?? new EmailSettings();
|
||||
if (new EmailsViewModel(oldSettings).PasswordSet)
|
||||
{
|
||||
model.Settings.Password = oldSettings.Password;
|
||||
}
|
||||
|
||||
await _SettingsRepository.UpdateSetting(model.Settings);
|
||||
TempData[WellKnownTempData.SuccessMessage] = "Email settings saved";
|
||||
return RedirectToAction(nameof(Emails));
|
||||
}
|
||||
|
||||
[Route("server/logs/{file?}")]
|
||||
|
||||
Reference in New Issue
Block a user