Moved more files to abstractions
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Net.Mail;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
|
||||
namespace Umbraco.Core
|
||||
@@ -13,21 +14,22 @@ namespace Umbraco.Core
|
||||
{
|
||||
// TODO: This should encapsulate a BackgroundTaskRunner with a queue to send these emails!
|
||||
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly bool _enableEvents;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public EmailSender() : this(false)
|
||||
public EmailSender(IGlobalSettings globalSettings) : this(globalSettings, false)
|
||||
{
|
||||
}
|
||||
|
||||
internal EmailSender(bool enableEvents)
|
||||
internal EmailSender(IGlobalSettings globalSettings, bool enableEvents)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_enableEvents = enableEvents;
|
||||
|
||||
_smtpConfigured = new Lazy<bool>(() => _globalSettings.IsSmtpServerConfigured);
|
||||
}
|
||||
|
||||
private static readonly Lazy<bool> SmtpConfigured = new Lazy<bool>(() => Current.Configs.Global().IsSmtpServerConfigured);
|
||||
private readonly Lazy<bool> _smtpConfigured;
|
||||
|
||||
/// <summary>
|
||||
/// Sends the message non-async
|
||||
@@ -35,7 +37,7 @@ namespace Umbraco.Core
|
||||
/// <param name="message"></param>
|
||||
public void Send(MailMessage message)
|
||||
{
|
||||
if (SmtpConfigured.Value == false && _enableEvents)
|
||||
if (_smtpConfigured.Value == false && _enableEvents)
|
||||
{
|
||||
OnSendEmail(new SendEmailEventArgs(message));
|
||||
}
|
||||
@@ -55,7 +57,7 @@ namespace Umbraco.Core
|
||||
/// <returns></returns>
|
||||
public async Task SendAsync(MailMessage message)
|
||||
{
|
||||
if (SmtpConfigured.Value == false && _enableEvents)
|
||||
if (_smtpConfigured.Value == false && _enableEvents)
|
||||
{
|
||||
OnSendEmail(new SendEmailEventArgs(message));
|
||||
}
|
||||
@@ -81,10 +83,7 @@ namespace Umbraco.Core
|
||||
/// <remarks>
|
||||
/// We assume this is possible if either an event handler is registered or an smtp server is configured
|
||||
/// </remarks>
|
||||
internal static bool CanSendRequiredEmail
|
||||
{
|
||||
get { return EventHandlerRegistered || SmtpConfigured.Value; }
|
||||
}
|
||||
internal static bool CanSendRequiredEmail(IGlobalSettings globalSettings) => EventHandlerRegistered || globalSettings.IsSmtpServerConfigured;
|
||||
|
||||
/// <summary>
|
||||
/// returns true if an event handler has been registered
|
||||
@@ -18,7 +18,7 @@ namespace Umbraco.Core
|
||||
/// <para>Supports emitting constructors, instance and static methods, instance property getters and
|
||||
/// setters. Does not support static properties yet.</para>
|
||||
/// </remarks>
|
||||
public static partial class ReflectionUtilities
|
||||
public static class ReflectionUtilities
|
||||
{
|
||||
#region Fields
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="4.6.0" />
|
||||
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
|
||||
<PackageReference Include="System.Runtime.Caching" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Core.Runtime
|
||||
@@ -6,10 +7,12 @@ namespace Umbraco.Core.Runtime
|
||||
public class CoreInitialComponent : IComponent
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
|
||||
public CoreInitialComponent(IIOHelper ioHelper)
|
||||
public CoreInitialComponent(IIOHelper ioHelper, IGlobalSettings globalSettings)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
@@ -17,7 +20,7 @@ namespace Umbraco.Core.Runtime
|
||||
// ensure we have some essential directories
|
||||
// every other component can then initialize safely
|
||||
_ioHelper.EnsurePathExists(Constants.SystemDirectories.Data);
|
||||
_ioHelper.EnsurePathExists(Current.Configs.Global().UmbracoMediaPath);
|
||||
_ioHelper.EnsurePathExists(_globalSettings.UmbracoMediaPath);
|
||||
_ioHelper.EnsurePathExists(Constants.SystemDirectories.MvcViews);
|
||||
_ioHelper.EnsurePathExists(Constants.SystemDirectories.PartialViews);
|
||||
_ioHelper.EnsurePathExists(Constants.SystemDirectories.MacroPartials);
|
||||
|
||||
@@ -314,7 +314,6 @@
|
||||
<Compile Include="PropertyEditors\ConfigurationEditor.cs" />
|
||||
<Compile Include="PropertyEditors\LabelConfigurationEditor.cs" />
|
||||
<Compile Include="PropertyEditors\LabelPropertyEditor.cs" />
|
||||
<Compile Include="ReflectionUtilities-Unused.cs" />
|
||||
<Compile Include="RuntimeOptions.cs" />
|
||||
<Compile Include="Runtime\CoreRuntime.cs" />
|
||||
<Compile Include="Runtime\CoreInitialComponent.cs" />
|
||||
@@ -325,7 +324,6 @@
|
||||
<Compile Include="Migrations\Expressions\Delete\KeysAndIndexes\DeleteKeysAndIndexesBuilder.cs" />
|
||||
<Compile Include="Migrations\Install\DatabaseBuilder.cs" />
|
||||
<Compile Include="Diagnostics\MiniDump.cs" />
|
||||
<Compile Include="EmailSender.cs" />
|
||||
<Compile Include="Composing\LightInject\LightInjectException.cs" />
|
||||
<Compile Include="FileResources\Files.Designer.cs" />
|
||||
<Compile Include="Logging\Serilog\SerilogLogger.cs" />
|
||||
@@ -701,7 +699,6 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PropertyEditors\DataEditor.cs" />
|
||||
<Compile Include="PropertyEditors\DataValueEditor.cs" />
|
||||
<Compile Include="ReflectionUtilities.cs" />
|
||||
<Compile Include="RuntimeState.cs" />
|
||||
<Compile Include="Runtime\CoreInitialComposer.cs" />
|
||||
<Compile Include="Scoping\IScope.cs" />
|
||||
|
||||
@@ -145,8 +145,8 @@ namespace Umbraco.Tests.Benchmarks
|
||||
//_expressionMethod3 = (Func<IFoo, IFoo>) Delegate.CreateDelegate(typeof (Func<IFoo, IFoo>), _expressionMethod.Method);
|
||||
|
||||
// but, our utilities know how to do it!
|
||||
_expressionMethod3 = ReflectionUtilities.CompileToDelegate(expr);
|
||||
_expressionMethod4 = ReflectionUtilities.GetCtor<Foo, IFoo>();
|
||||
_expressionMethod3 = ReflectionUtilitiesForTest.CompileToDelegate(expr);
|
||||
_expressionMethod4 = ReflectionUtilitiesForTest.GetCtor<Foo, IFoo>();
|
||||
|
||||
// however, unfortunately, the generated "compiled to delegate" code cannot access private stuff :(
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@ using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
|
||||
namespace Umbraco.Core
|
||||
namespace Umbraco.Tests.Benchmarks
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides utilities to simplify reflection.
|
||||
/// </summary>
|
||||
public static partial class ReflectionUtilities
|
||||
public static class ReflectionUtilitiesForTest
|
||||
{
|
||||
// the code below should NOT be used
|
||||
//
|
||||
@@ -363,4 +363,4 @@ namespace Umbraco.Core
|
||||
return module.DefineType("Class", TypeAttributes.Public | TypeAttributes.Abstract);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@
|
||||
<Compile Include="ModelToSqlExpressionHelperBenchmarks.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ReflectionUtilities-Unused.cs" />
|
||||
<Compile Include="SqlTemplatesBenchmark.cs" />
|
||||
<Compile Include="StringReplaceManyBenchmarks.cs" />
|
||||
<Compile Include="TryConvertToBenchmarks.cs" />
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace Umbraco.Web.Editors
|
||||
/// <returns></returns>
|
||||
internal Dictionary<string, object> GetServerVariables()
|
||||
{
|
||||
var globalSettings = Current.Configs.Global();
|
||||
var defaultVals = new Dictionary<string, object>
|
||||
{
|
||||
{
|
||||
@@ -319,7 +320,7 @@ namespace Umbraco.Web.Editors
|
||||
"umbracoSettings", new Dictionary<string, object>
|
||||
{
|
||||
{"umbracoPath", _globalSettings.Path},
|
||||
{"mediaPath", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoMediaPath).TrimEnd('/')},
|
||||
{"mediaPath", Current.IOHelper.ResolveUrl(globalSettings.UmbracoMediaPath).TrimEnd('/')},
|
||||
{"appPluginsPath", Current.IOHelper.ResolveUrl(Constants.SystemDirectories.AppPlugins).TrimEnd('/')},
|
||||
{
|
||||
"imageFileTypes",
|
||||
@@ -339,11 +340,11 @@ namespace Umbraco.Web.Editors
|
||||
},
|
||||
{"keepUserLoggedIn", Current.Configs.Settings().Security.KeepUserLoggedIn},
|
||||
{"usernameIsEmail", Current.Configs.Settings().Security.UsernameIsEmail},
|
||||
{"cssPath", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoCssPath).TrimEnd('/')},
|
||||
{"cssPath", Current.IOHelper.ResolveUrl(globalSettings.UmbracoCssPath).TrimEnd('/')},
|
||||
{"allowPasswordReset", Current.Configs.Settings().Security.AllowPasswordReset},
|
||||
{"loginBackgroundImage", Current.Configs.Settings().Content.LoginBackgroundImage},
|
||||
{"showUserInvite", EmailSender.CanSendRequiredEmail},
|
||||
{"canSendRequiredEmail", EmailSender.CanSendRequiredEmail},
|
||||
{"showUserInvite", EmailSender.CanSendRequiredEmail(globalSettings)},
|
||||
{"canSendRequiredEmail", EmailSender.CanSendRequiredEmail(globalSettings)},
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -40,9 +40,12 @@ namespace Umbraco.Web.Editors
|
||||
[IsCurrentUserModelFilter]
|
||||
public class UsersController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
|
||||
public UsersController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -343,7 +346,7 @@ namespace Umbraco.Web.Editors
|
||||
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
|
||||
}
|
||||
|
||||
if (EmailSender.CanSendRequiredEmail == false)
|
||||
if (EmailSender.CanSendRequiredEmail(_globalSettings) == false)
|
||||
{
|
||||
throw new HttpResponseException(
|
||||
Request.CreateNotificationValidationErrorResponse("No Email server is configured"));
|
||||
@@ -473,7 +476,7 @@ namespace Umbraco.Web.Editors
|
||||
await UserManager.EmailService.SendAsync(
|
||||
//send the special UmbracoEmailMessage which configures it's own sender
|
||||
//to allow for events to handle sending the message if no smtp is configured
|
||||
new UmbracoEmailMessage(new EmailSender(true))
|
||||
new UmbracoEmailMessage(new EmailSender(_globalSettings, true))
|
||||
{
|
||||
Body = emailBody,
|
||||
Destination = userDisplay.Email,
|
||||
|
||||
@@ -17,8 +17,9 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
|
||||
private readonly ILocalizedTextService _textService;
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
|
||||
public EmailNotificationMethod(ILocalizedTextService textService, IRuntimeState runtimeState, ILogger logger)
|
||||
public EmailNotificationMethod(ILocalizedTextService textService, IRuntimeState runtimeState, ILogger logger, IGlobalSettings globalSettings)
|
||||
{
|
||||
var recipientEmail = Settings["recipientEmail"]?.Value;
|
||||
if (string.IsNullOrWhiteSpace(recipientEmail))
|
||||
@@ -32,6 +33,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
|
||||
_textService = textService ?? throw new ArgumentNullException(nameof(textService));
|
||||
_runtimeState = runtimeState;
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
public string RecipientEmail { get; }
|
||||
@@ -61,7 +63,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
|
||||
|
||||
var subject = _textService.Localize("healthcheck/scheduledHealthCheckEmailSubject", new[] { host.ToString() });
|
||||
|
||||
var mailSender = new EmailSender();
|
||||
var mailSender = new EmailSender(_globalSettings);
|
||||
using (var mailMessage = CreateMailMessage(subject, message))
|
||||
{
|
||||
await mailSender.SendAsync(mailMessage);
|
||||
|
||||
@@ -96,7 +96,8 @@ namespace Umbraco.Web.Security
|
||||
customUserStore,
|
||||
contentSettings,
|
||||
passwordConfiguration,
|
||||
ipResolver));
|
||||
ipResolver,
|
||||
globalSettings));
|
||||
|
||||
app.SetBackOfficeUserManagerType<BackOfficeUserManager, BackOfficeIdentityUser>();
|
||||
|
||||
|
||||
@@ -28,11 +28,12 @@ namespace Umbraco.Web.Security
|
||||
IdentityFactoryOptions<BackOfficeUserManager> options,
|
||||
IContentSection contentSectionConfig,
|
||||
IPasswordConfiguration passwordConfiguration,
|
||||
IIpResolver ipResolver)
|
||||
IIpResolver ipResolver,
|
||||
IGlobalSettings globalSettings)
|
||||
: base(store, passwordConfiguration, ipResolver)
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException("options");
|
||||
InitUserManager(this, passwordConfiguration, options.DataProtectionProvider, contentSectionConfig);
|
||||
InitUserManager(this, passwordConfiguration, options.DataProtectionProvider, contentSectionConfig, globalSettings);
|
||||
}
|
||||
|
||||
#region Static Create methods
|
||||
@@ -64,7 +65,7 @@ namespace Umbraco.Web.Security
|
||||
if (externalLoginService == null) throw new ArgumentNullException("externalLoginService");
|
||||
|
||||
var store = new BackOfficeUserStore(userService, entityService, externalLoginService, globalSettings, mapper);
|
||||
var manager = new BackOfficeUserManager(store, options, contentSectionConfig, passwordConfiguration, ipResolver);
|
||||
var manager = new BackOfficeUserManager(store, options, contentSectionConfig, passwordConfiguration, ipResolver, globalSettings);
|
||||
return manager;
|
||||
}
|
||||
|
||||
@@ -81,9 +82,10 @@ namespace Umbraco.Web.Security
|
||||
BackOfficeUserStore customUserStore,
|
||||
IContentSection contentSectionConfig,
|
||||
IPasswordConfiguration passwordConfiguration,
|
||||
IIpResolver ipResolver)
|
||||
IIpResolver ipResolver,
|
||||
IGlobalSettings globalSettings)
|
||||
{
|
||||
var manager = new BackOfficeUserManager(customUserStore, options, contentSectionConfig, passwordConfiguration, ipResolver);
|
||||
var manager = new BackOfficeUserManager(customUserStore, options, contentSectionConfig, passwordConfiguration, ipResolver, globalSettings);
|
||||
return manager;
|
||||
}
|
||||
#endregion
|
||||
@@ -157,7 +159,8 @@ namespace Umbraco.Web.Security
|
||||
BackOfficeUserManager<T> manager,
|
||||
IPasswordConfiguration passwordConfig,
|
||||
IDataProtectionProvider dataProtectionProvider,
|
||||
IContentSection contentSectionConfig)
|
||||
IContentSection contentSectionConfig,
|
||||
IGlobalSettings globalSettings)
|
||||
{
|
||||
// Configure validation logic for usernames
|
||||
manager.UserValidator = new BackOfficeUserValidator<T>(manager)
|
||||
@@ -192,7 +195,7 @@ namespace Umbraco.Web.Security
|
||||
|
||||
manager.EmailService = new EmailService(
|
||||
contentSectionConfig.NotificationEmailAddress,
|
||||
new EmailSender());
|
||||
new EmailSender(globalSettings));
|
||||
|
||||
//NOTE: Not implementing these, if people need custom 2 factor auth, they'll need to implement their own UserStore to support it
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Umbraco.Web.Trees
|
||||
{
|
||||
private readonly UmbracoTreeSearcher _treeSearcher;
|
||||
private readonly ActionCollection _actions;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
|
||||
protected override int RecycleBinId => Constants.System.RecycleBinContent;
|
||||
|
||||
@@ -53,6 +54,7 @@ namespace Umbraco.Web.Trees
|
||||
{
|
||||
_treeSearcher = treeSearcher;
|
||||
_actions = actions;
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -240,7 +242,7 @@ namespace Umbraco.Web.Trees
|
||||
AddActionNode<ActionRights>(item, menu, opensDialog: true);
|
||||
AddActionNode<ActionProtect>(item, menu, true, opensDialog: true);
|
||||
|
||||
if (EmailSender.CanSendRequiredEmail)
|
||||
if (EmailSender.CanSendRequiredEmail(_globalSettings))
|
||||
{
|
||||
menu.Items.Add(new MenuItem("notify", Services.TextService)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user