Do not cleanup unreachable stores (#5025)

This commit is contained in:
Nicolas Dorier
2023-05-31 11:22:37 +09:00
committed by GitHub
parent 16b988d097
commit 0a0cf97c55
5 changed files with 16 additions and 21 deletions

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Amazon.S3.Transfer;
using BTCPayServer.Abstractions.Constants; using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Abstractions.Extensions; using BTCPayServer.Abstractions.Extensions;
using BTCPayServer.Abstractions.Models; using BTCPayServer.Abstractions.Models;
@@ -167,9 +166,17 @@ namespace BTCPayServer.Controllers
[FromServices] StoreRepository storeRepository, [FromServices] StoreRepository storeRepository,
string role) string role)
{ {
await storeRepository.SetDefaultRole(role); var resolved = await storeRepository.ResolveStoreRoleId(null, role);
if (resolved is null)
TempData[WellKnownTempData.SuccessMessage] = "Role set default"; {
TempData[WellKnownTempData.ErrorMessage] = "Role could not be set as default";
}
else
{
await storeRepository.SetDefaultRole(role);
TempData[WellKnownTempData.SuccessMessage] = "Role set default";
}
return RedirectToAction(nameof(ListRoles)); return RedirectToAction(nameof(ListRoles));
} }

View File

@@ -111,12 +111,6 @@ namespace BTCPayServer.Hosting
settings.DeprecatedLightningConnectionStringCheck = true; settings.DeprecatedLightningConnectionStringCheck = true;
await _Settings.UpdateSetting(settings); await _Settings.UpdateSetting(settings);
} }
if (!settings.UnreachableStoreCheck)
{
await UnreachableStoreCheck();
settings.UnreachableStoreCheck = true;
await _Settings.UpdateSetting(settings);
}
if (!settings.ConvertMultiplierToSpread) if (!settings.ConvertMultiplierToSpread)
{ {
await ConvertMultiplierToSpread(); await ConvertMultiplierToSpread();
@@ -1068,11 +1062,6 @@ retry:
} }
} }
private Task UnreachableStoreCheck()
{
return _StoreRepository.CleanUnreachableStores();
}
private async Task DeprecatedLightningConnectionStringCheck() private async Task DeprecatedLightningConnectionStringCheck()
{ {
using var ctx = _DBContextFactory.CreateContext(); using var ctx = _DBContextFactory.CreateContext();

View File

@@ -7,7 +7,6 @@ namespace BTCPayServer.Services
[JsonProperty("MigrateHotwalletProperty2")] [JsonProperty("MigrateHotwalletProperty2")]
public bool MigrateHotwalletProperty { get; set; } public bool MigrateHotwalletProperty { get; set; }
public bool MigrateU2FToFIDO2 { get; set; } public bool MigrateU2FToFIDO2 { get; set; }
public bool UnreachableStoreCheck { get; set; }
public bool DeprecatedLightningConnectionStringCheck { get; set; } public bool DeprecatedLightningConnectionStringCheck { get; set; }
public bool ConvertMultiplierToSpread { get; set; } public bool ConvertMultiplierToSpread { get; set; }
public bool ConvertNetworkFeeProperty { get; set; } public bool ConvertNetworkFeeProperty { get; set; }

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Amazon.S3;
using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Client; using BTCPayServer.Client;
using BTCPayServer.Data; using BTCPayServer.Data;
@@ -229,18 +230,19 @@ namespace BTCPayServer.Services.Stores
/// <param name="storeId"></param> /// <param name="storeId"></param>
/// <param name="role"></param> /// <param name="role"></param>
/// <returns></returns> /// <returns></returns>
public async Task<StoreRoleId?> ResolveStoreRoleId(string storeId, string? role) public async Task<StoreRoleId?> ResolveStoreRoleId(string? storeId, string? role)
{ {
if (string.IsNullOrWhiteSpace(role)) if (string.IsNullOrWhiteSpace(role))
return null; return null;
var isStoreRole = role.Contains("::", StringComparison.OrdinalIgnoreCase); if (storeId?.Contains("::", StringComparison.OrdinalIgnoreCase) is true)
if(isStoreRole && (string.IsNullOrEmpty(storeId) || !role.Contains(storeId, StringComparison.InvariantCultureIgnoreCase)))
return null; return null;
var roleId = StoreRoleId.Parse(role); var roleId = StoreRoleId.Parse(role);
if (roleId.StoreId != null && roleId.StoreId != storeId) if (roleId.StoreId != null && roleId.StoreId != storeId)
return null; return null;
if ((await GetStoreRole(roleId)) != null) if ((await GetStoreRole(roleId)) != null)
return roleId; return roleId;
if (string.IsNullOrEmpty(storeId))
return null;
if (roleId.IsServerRole) if (roleId.IsServerRole)
roleId = new StoreRoleId(storeId, role); roleId = new StoreRoleId(storeId, role);
if ((await GetStoreRole(roleId)) != null) if ((await GetStoreRole(roleId)) != null)

View File

@@ -157,8 +157,6 @@ namespace BTCPayServer.Services
{ {
_logger.LogError($"Failed to delete user {user.Id}"); _logger.LogError($"Failed to delete user {user.Id}");
} }
await _storeRepository.CleanUnreachableStores();
} }