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

Generic Site settings Deployment Step #6570

merged 22 commits into from
Jul 8, 2020

Conversation

agriffard
Copy link
Member

Fixes #5325, #5558

/cc @sebastienros @deanmarcussen As explained during today's meeting.

@agriffard
Copy link
Member Author

Just implemented it in OrchardCore.Admin with AdminSetting for the moment.

Please tell me if it is the correct way to do it:

    [RequireFeatures("OrchardCore.Deployment")]
    public class DeploymentStartup : StartupBase
    {
        public override void ConfigureServices(IServiceCollection services)
        {
            var serviceProvider = services.BuildServiceProvider();
            var S = serviceProvider.GetService<IStringLocalizer<Startup>>();
            services.AddSingleton<IDeploymentStepFactory>(s => new GenericSiteSettingsDeploymentStepFactory(nameof(AdminSettings), S["Admin settings"], S["Exports the admin site settings."]));
        }
    }

@agriffard
Copy link
Member Author

Add Step:
image

Edit Step:
image

Deployment plan:
image

@agriffard agriffard mentioned this pull request Jul 2, 2020
Copy link
Member

@deanmarcussen deanmarcussen left a comment

Choose a reason for hiding this comment

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

@agriffard good start :)

We're going to have to move it to generics, i.e. GenericDriver<AdminSiteSettings> or the drivers are going to be fired multiple times for each registration. Same with the stepfactory.

And it's going to have to go into a Core project to sort out referencing.

This is easier to explain over skype. I should be free later on if you want?

@deanmarcussen
Copy link
Member

        public override void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<IDeploymentStepFactory>(sp => {
           var S = sp.GetService<IStringLocalizer<Startup>>();
 
return new GenericSiteSettingsDeploymentStepFactory(nameof(AdminSettings), S["Admin settings"], S["Exports the admin site settings."])
});
        }

For infos. But also will have to be generics, and I think in this case we can get away with out a custom factory, just a generic class, but would have to check

@agriffard
Copy link
Member Author

Added OrchardCore.Settings.Core with generic SiteSettingsDeploymentStep, source and driver.
Renamed the existing SiteSettingsDeploymentStep in OrchardCore.Settings into GeneralSiteSettingsDeploymentStep.

Copy link
Member

@deanmarcussen deanmarcussen left a comment

Choose a reason for hiding this comment

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

@agriffard should be updated and working now.

For infos, @sebastienros , this had to be made to use generics, not for the step factory, but for the DisplayDriver which needs to be a specific type, in order to only fire for that specific type.

It doesn't make me happy to use generics, but it is the right solution in this case, I think

Additionally we can't have a simple extension method to register these, because of the string localizer, which I believe needs to visibly show a variable var S = ... in the Startup class where we want to register these localized strings.

so

services.AddSiteSettingsPropertyDeployment<AdminSettings>(() => S["Admin settings"));

would (probably) not be found by the extractor
and


services.AddSiteSettingsPropertyDeployment<AdminSettings>((sp) => {
  var S = sp.GetRequiredService<IStringLocalizer<Startup>>();
  return S["Admin settings");
},
... (for the `Description`) 
... etc
);

is to wordy for an extension method to be useful, I figure

<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

@@ -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.

@agriffard
Copy link
Member Author

agriffard commented Jul 4, 2020

image

@deanmarcussen
Copy link
Member

Merged dev, and added the Taxonomy Filters settings too

@agriffard
Copy link
Member Author

Do we keep the GraphQL settings?

@deanmarcussen
Copy link
Member

deanmarcussen commented Jul 5, 2020

@agriffard I have evaluated and updated your list on #5558

Some of the ones you have done here, have their own recipe step, so cannot be included in a generic design.

Others have secrets, so also must be custom.

GraphQL is not a ISite setting, it's configured via IOptions so was just not named as per the convention originally.

@agriffard agriffard requested a review from deanmarcussen July 6, 2020 12:03
Copy link
Member

@deanmarcussen deanmarcussen left a comment

Choose a reason for hiding this comment

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

@agriffard I think it's good - but I've helped write some of it, so I would think that ;)

Can we demo tomorrow or review Thursday? I would like to be sure we're doing the right thing with the generics, and the localization

@@ -19,6 +19,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Module.Targets\OrchardCore.Module.Targets.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.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

@@ -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

@@ -21,6 +21,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.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.

same

@@ -18,6 +18,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.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.

same

@@ -17,6 +17,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.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.

same

@@ -18,6 +18,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.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.

same

@@ -18,6 +18,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.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.

same

<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.

Tested is all good


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

@agriffard
Copy link
Member Author

I prefixed the Factory key with the name instead of suffixing it :
private static readonly string GenericTypeKey = typeof(TModel).Name + "_SiteSettingsPropertyDeploymentStep";

Thanks to this, the steps will be sorted a bit more alphabetically in the modal.

@deanmarcussen
Copy link
Member

I prefixed the Factory key with the name instead of suffixing it
Thanks to this, the steps will be sorted a bit more alphabetically in the modal.

Cool, can you do the same in the

        public SiteSettingsPropertyDeploymentStep()
        {
            Name = "SiteSettingsPropertyDeploymentStep_" + typeof(TModel).Name;
        }

so the match I have a vague memory this is important ;)

@agriffard agriffard merged commit c9aae15 into dev Jul 8, 2020
@delete-merged-branch delete-merged-branch bot deleted the ag/genericSiteSettings branch July 8, 2020 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There is no way to export custom site settings like Login settings
2 participants