2020-08-01 09:17:17 -05:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Logging;
|
|
|
|
using BTCPayServer.Services;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
{
|
|
|
|
// All logic that would otherwise be duplicated across solution goes into this utility class
|
|
|
|
// ~If~ Once this starts growing out of control, begin extracting action logic classes out of here
|
|
|
|
// Also some of logic in here may be result of parallel development of Greenfield API
|
|
|
|
// It's much better that we extract those common methods then copy paste and maintain same code across codebase
|
|
|
|
internal static class ActionLogicExtensions
|
|
|
|
{
|
2021-12-31 16:59:02 +09:00
|
|
|
internal static async Task FirstAdminRegistered(this SettingsRepository settingsRepository, PoliciesSettings policies,
|
2021-11-22 17:16:08 +09:00
|
|
|
bool updateCheck, bool disableRegistrations, Logs logs)
|
2020-08-01 09:17:17 -05:00
|
|
|
{
|
|
|
|
if (updateCheck)
|
|
|
|
{
|
2021-11-22 17:16:08 +09:00
|
|
|
logs.PayServer.LogInformation("First admin created, enabling checks for new versions");
|
2020-08-01 09:17:17 -05:00
|
|
|
policies.CheckForNewVersions = updateCheck;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disableRegistrations)
|
|
|
|
{
|
|
|
|
// Once the admin user has been created lock subsequent user registrations (needs to be disabled for unit tests that require multiple users).
|
2021-11-22 17:16:08 +09:00
|
|
|
logs.PayServer.LogInformation("First admin created, disabling subscription (disable-registration is set to true)");
|
2020-08-01 09:17:17 -05:00
|
|
|
policies.LockSubscription = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateCheck || disableRegistrations)
|
|
|
|
await settingsRepository.UpdateSetting(policies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|