Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Site settings Deployment Step #6570

Merged
merged 22 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions OrchardCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.ShortCodes", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.ShortCodes.Abstractions", "src\OrchardCore\OrchardCore.ShortCodes.Abstractions\OrchardCore.ShortCodes.Abstractions.csproj", "{901DA1A3-E5C7-4965-80EA-A1780BE1B820}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Settings.Core", "src\OrchardCore\OrchardCore.Settings.Core\OrchardCore.Settings.Core.csproj", "{1286E568-BAFE-45E2-BF60-4350DB99FF83}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1010,6 +1012,10 @@ Global
{901DA1A3-E5C7-4965-80EA-A1780BE1B820}.Debug|Any CPU.Build.0 = Debug|Any CPU
{901DA1A3-E5C7-4965-80EA-A1780BE1B820}.Release|Any CPU.ActiveCfg = Release|Any CPU
{901DA1A3-E5C7-4965-80EA-A1780BE1B820}.Release|Any CPU.Build.0 = Release|Any CPU
{1286E568-BAFE-45E2-BF60-4350DB99FF83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1286E568-BAFE-45E2-BF60-4350DB99FF83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1286E568-BAFE-45E2-BF60-4350DB99FF83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1286E568-BAFE-45E2-BF60-4350DB99FF83}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1186,6 +1192,7 @@ Global
{38EE0258-F010-425B-949F-9ECCE886584B} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{9EEEB83D-85C5-4025-8367-CD7D1ACBBB1A} = {90030E85-0C4F-456F-B879-443E8A3F220D}
{901DA1A3-E5C7-4965-80EA-A1780BE1B820} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{1286E568-BAFE-45E2-BF60-4350DB99FF83} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46A1D25A-78D1-4476-9CBF-25B75E296341}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>$(AspNetCoreTargetFramework)</TargetFramework>
Expand All @@ -15,8 +15,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Data.Abstractions\OrchardCore.Data.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />

<ProjectReference Include="..\OrchardCore.Settings\OrchardCore.Settings.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Settings.Core\OrchardCore.Settings.Core.csproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Admin.Controllers;
using OrchardCore.Admin.Drivers;
using OrchardCore.Admin.Models;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Theming;
using OrchardCore.Environment.Shell.Configuration;
Expand All @@ -18,6 +21,7 @@
using OrchardCore.Navigation;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
using OrchardCore.Settings.Deployment;

namespace OrchardCore.Admin
{
Expand Down Expand Up @@ -81,4 +85,19 @@ public override void ConfigureServices(IServiceCollection services)
});
}
}

[RequireFeatures("OrchardCore.Deployment")]
public class DeploymentStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IDeploymentSource, SiteSettingsPropertyDeploymentSource<AdminSettings>>();
services.AddScoped<IDisplayDriver<DeploymentStep>>(sp =>
{
var S = sp.GetService<IStringLocalizer<Startup>>();
return new SiteSettingsPropertyDeploymentStepDriver<AdminSettings>(S["Admin settings"], S["Exports the admin site settings."]);
});
services.AddSingleton<IDeploymentStepFactory>(new SiteSettingsPropertyDeploymentStepFactory<AdminSettings>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Settings.Core\OrchardCore.Settings.Core.csproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this reference

</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.BackgroundTasks.Controllers;
using OrchardCore.BackgroundTasks.Services;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Modules;
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Navigation;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings.Deployment;

namespace OrchardCore.BackgroundTasks
{
Expand Down Expand Up @@ -66,5 +70,19 @@ public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilde
defaults: new { controller = backgroundTaskControllerName, action = nameof(BackgroundTaskController.Disable) }
);
}

[RequireFeatures("OrchardCore.Deployment")]
public class DeploymentStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IDeploymentSource, SiteSettingsPropertyDeploymentSource<BackgroundTaskSettings>>();
services.AddScoped<IDisplayDriver<DeploymentStep>>((sp => {
var S = sp.GetService<IStringLocalizer<Startup>>();
return new SiteSettingsPropertyDeploymentStepDriver<BackgroundTaskSettings>(S["Background Tasks settings"], S["Exports the background tasks site settings."]);
}));
services.AddSingleton<IDeploymentStepFactory>(new DeploymentStepFactory<SiteSettingsPropertyDeploymentStep<BackgroundTaskSettings>>());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Liquid.Abstractions\OrchardCore.Liquid.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Settings.Core\OrchardCore.Settings.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Setup.Abstractions\OrchardCore.Setup.Abstractions.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json.Linq;
using OrchardCore.Environment.Cache;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OrchardCore.Settings
{
// When updating class also update SiteSettingsDeploymentSource and SettingsStep.
// When updating class also update GeneralSiteSettingsDeploymentSource and GeneralSettingsStep.
public class SiteSettings : Entity, ISite
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using OrchardCore.Environment.Cache;

namespace OrchardCore.Settings.ViewModels
{
public class SiteSettingsViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@model SiteSettingsPropertyDeploymentStepViewModel
<h5>@Model.Title</h5>

<div class="form-group">
<span class="hint">@Model.Description</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to test here we don't get double encoding. Should be ok, but just put an accent in one of the localized values, and check the page source after to make sure the encoding is correct

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested is all good

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@model SiteSettingsPropertyDeploymentStepViewModel

<h5>@Model.Title</h5>
<span>@Model.Description</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@model SiteSettingsPropertyDeploymentStepViewModel

<h4 class="card-title">@Model.Title</h4>
<p>@Model.Description</p>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Liquid.Abstractions\OrchardCore.Liquid.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Localization.Abstractions\OrchardCore.Localization.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Settings.Core\OrchardCore.Settings.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Setup.Abstractions\OrchardCore.Setup.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Workflows.Abstractions\OrchardCore.Workflows.Abstractions.csproj" />
</ItemGroup>
Expand Down
41 changes: 41 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Users/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.Data.Migration;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Theming;
Expand All @@ -25,6 +27,7 @@
using OrchardCore.Security;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
using OrchardCore.Settings.Deployment;
using OrchardCore.Setup.Events;
using OrchardCore.Users.Commands;
using OrchardCore.Users.Controllers;
Expand All @@ -38,6 +41,7 @@

namespace OrchardCore.Users
{
// [RequireFeatures("OrchardCore.Deployment")]
public class Startup : StartupBase
{
private readonly AdminOptions _adminOptions;
Expand Down Expand Up @@ -189,6 +193,14 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IDisplayDriver<User>, UserButtonsDisplayDriver>();

services.AddScoped<IThemeSelector, UsersThemeSelector>();

services.AddTransient<IDeploymentSource, SiteSettingsPropertyDeploymentSource<LoginSettings>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to go in a separate startup with RequiresFeatures just for the default login settings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, please check.

services.AddScoped<IDisplayDriver<DeploymentStep>>(sp =>
{
var S = sp.GetService<IStringLocalizer<Startup>>();
return new SiteSettingsPropertyDeploymentStepDriver<LoginSettings>(S["Login settings"], S["Exports the Login site settings."]);
});
services.AddSingleton<IDeploymentStepFactory>(new SiteSettingsPropertyDeploymentStepFactory<LoginSettings>());
}
}

Expand All @@ -205,6 +217,7 @@ public override void ConfigureServices(IServiceCollection services)
}

[Feature("OrchardCore.Users.ChangeEmail")]
[RequireFeatures("OrchardCore.Deployment")]
public class ChangeEmailStartup : StartupBase
{
private const string ChangeEmailPath = "ChangeEmail";
Expand Down Expand Up @@ -236,10 +249,21 @@ public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<INavigationProvider, ChangeEmailAdminMenu>();
services.AddScoped<IDisplayDriver<ISite>, ChangeEmailSettingsDisplayDriver>();
//TODO this needs to be a seperate startup, just for the deployment step
// [Feature("OrchardCore.Users.ChangeEmail")]
// [RequireFeatures("OrchardCore.Deployment")]
services.AddTransient<IDeploymentSource, SiteSettingsPropertyDeploymentSource<ChangeEmailSettings>>();
services.AddScoped<IDisplayDriver<DeploymentStep>>(sp =>
{
var S = sp.GetService<IStringLocalizer<Startup>>();
return new SiteSettingsPropertyDeploymentStepDriver<ChangeEmailSettings>(S["Change Email settings"], S["Exports the Change Email site settings."]);
});
services.AddSingleton<IDeploymentStepFactory>(new SiteSettingsPropertyDeploymentStepFactory<ChangeEmailSettings>());
}
}

[Feature("OrchardCore.Users.Registration")]
[RequireFeatures("OrchardCore.Deployment")]
public class RegistrationStartup : StartupBase
{
private const string RegisterPath = "Register";
Expand All @@ -263,10 +287,19 @@ public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<INavigationProvider, RegistrationAdminMenu>();
services.AddScoped<IDisplayDriver<ISite>, RegistrationSettingsDisplayDriver>();
//TODO this needs to be a seperate startup, just for the deployment step
services.AddTransient<IDeploymentSource, SiteSettingsPropertyDeploymentSource<RegistrationSettings>>();
services.AddScoped<IDisplayDriver<DeploymentStep>>(sp =>
{
var S = sp.GetService<IStringLocalizer<Startup>>();
return new SiteSettingsPropertyDeploymentStepDriver<RegistrationSettings>(S["Registration settings"], S["Exports the Registration site settings."]);
});
services.AddSingleton<IDeploymentStepFactory>(new SiteSettingsPropertyDeploymentStepFactory<RegistrationSettings>());
}
}

[Feature("OrchardCore.Users.ResetPassword")]
[RequireFeatures("OrchardCore.Deployment")]
public class ResetPasswordStartup : StartupBase
{
private const string ForgotPasswordPath = "ForgotPassword";
Expand Down Expand Up @@ -311,6 +344,14 @@ public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<INavigationProvider, ResetPasswordAdminMenu>();
services.AddScoped<IDisplayDriver<ISite>, ResetPasswordSettingsDisplayDriver>();
//TODO this needs to be a seperate startup, just for the deployment step
services.AddTransient<IDeploymentSource, SiteSettingsPropertyDeploymentSource<ResetPasswordSettings>>();
services.AddScoped<IDisplayDriver<DeploymentStep>>(sp =>
{
var S = sp.GetService<IStringLocalizer<Startup>>();
return new SiteSettingsPropertyDeploymentStepDriver<ResetPasswordSettings>(S["Reset Password settings"], S["Exports the Reset Password site settings."]);
});
services.AddSingleton<IDeploymentStepFactory>(new SiteSettingsPropertyDeploymentStepFactory<ResetPasswordSettings>());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using OrchardCore.Deployment;
using OrchardCore.Entities;

namespace OrchardCore.Settings.Deployment
{
public class SiteSettingsPropertyDeploymentSource<TModel> : IDeploymentSource where TModel : class, new()
{
private readonly ISiteService _siteService;

public SiteSettingsPropertyDeploymentSource(ISiteService siteService)
{
_siteService = siteService;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
{
var settingsStep = step as SiteSettingsPropertyDeploymentStep<TModel>;
if (settingsStep == null)
{
return;
}

var siteSettings = await _siteService.GetSiteSettingsAsync();

result.Steps.Add(new JObject(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should find the property if it exists already, so it is only one step that is being added.
I will do this, while I am checking the registration with both attributes (i.e. Feature and RequiresFeature works ok)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agriffard have changed it to look for an existings Settings property rather than creating a new one every time.

output changes from

  "steps": [
    {
      "name": "Settings", <-- first Settings step
      "AdminSettings": {
        "DisplayMenuFilter": false
      }
    },
    {
      "name": "Settings", <-- second Settings step
      "LoginSettings": {
        "UseSiteTheme": false,
        "UseExternalProviderIfOnlyOneDefined": false,
        "DisableLocalLogin": false,
        "UseScriptToSyncRoles": false,
        "SyncRolesScript": null
      }
    }
  ]
  "steps": [
    {
      "name": "Settings", <-- Single Settings step
      "AdminSettings": {
        "DisplayMenuFilter": false
      },
      "LoginSettings": {
        "UseSiteTheme": false,
        "UseExternalProviderIfOnlyOneDefined": false,
        "DisableLocalLogin": false,
        "UseScriptToSyncRoles": false,
        "SyncRolesScript": null
      },
      "HttpsSettings": {
        "EnableStrictTransportSecurity": false,
        "RequireHttps": false,
        "RequireHttpsPermanent": false,
        "SslPort": null
      }
    }
  ]

An optimization, and makes it clearer that all the steps are contained in one

If you are happy with the change let me know, and I think we can merge it.

I've checked the Feature and RequiresFeature are working fine together. i.e. if you disable deployment but still have registration the startup doesn't fire.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

new JProperty("name", "Settings"),
new JProperty(typeof(TModel).Name, JObject.FromObject(siteSettings.As<TModel>()))
));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using OrchardCore.Deployment;

namespace OrchardCore.Settings.Deployment
{
/// <summary>
/// Adds a site setting from the properties dictionary to a <see cref="DeploymentPlanResult"/>.
/// </summary>
public class SiteSettingsPropertyDeploymentStep<TModel> : DeploymentStep where TModel : class, new()
{
public SiteSettingsPropertyDeploymentStep()
{
Name = "SiteSettingsPropertyDeploymentStep_" + typeof(TModel).Name;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Settings.ViewModels;

namespace OrchardCore.Settings.Deployment
{
public class SiteSettingsPropertyDeploymentStepDriver<TModel> : DisplayDriver<DeploymentStep, SiteSettingsPropertyDeploymentStep<TModel>> where TModel : class, new()
{
private readonly string _title;
private readonly string _description;

public SiteSettingsPropertyDeploymentStepDriver(string title, string description)
{
_title = title;
_description = description;
}

public override IDisplayResult Display(SiteSettingsPropertyDeploymentStep<TModel> step)
{
// TODO move this initialization to a BuildViewModel method.
return
Combine(
Initialize<SiteSettingsPropertyDeploymentStepViewModel>("SiteSettingsPropertyDeploymentStep_Fields_Summary", model =>
{
model.Title = _title;
model.Description = _description;
}).Location("Summary", "Content"),
Initialize<SiteSettingsPropertyDeploymentStepViewModel>("SiteSettingsPropertyDeploymentStep_Fields_Thumbnail", model =>
{
model.Title = _title;
model.Description = _description;
}).Location("Thumbnail", "Content")
);
}

public override IDisplayResult Edit(SiteSettingsPropertyDeploymentStep<TModel> step)
{
return Initialize<SiteSettingsPropertyDeploymentStepViewModel>("SiteSettingsPropertyDeploymentStep_Fields_Edit", model =>
{
model.Title = _title;
model.Description = _description;
}).Location("Content");
}
}
}
Loading