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

Set default for seo settings #183

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 7 additions & 17 deletions src/SeoToolkit.Umbraco.Common.Core/Composers/SeoToolkitComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
using SeoToolkit.Umbraco.Common.Core.Repositories.SeoSettingsRepository;
using SeoToolkit.Umbraco.Common.Core.Sections;
using SeoToolkit.Umbraco.Common.Core.Services.SeoSettingsService;
using SeoToolkit.Umbraco.Common.Core.Services.SettingsService;
using SeoToolkit.Umbraco.Common.Core.Models.Config;

namespace SeoToolkit.Umbraco.Common.Core.Composers
{
public class SeoToolkitComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
var section = builder.Config.GetSection("SeoToolkit:Global");
builder.Services.Configure<GlobalAppSettingsModel>(section);
builder.Services.AddSingleton(typeof(ISettingsService<GlobalConfig>), typeof(GlobalConfigService));

builder.Sections().Append<SeoToolkitSection>();

builder.Dashboards().Add<WelcomeDashboard>();
Expand All @@ -26,23 +32,7 @@ public void Compose(IUmbracoBuilder builder)

builder.Services.AddUnique<ISeoSettingsRepository, SeoSettingsRepository>();
builder.Services.AddUnique<ISeoSettingsService, SeoSettingsService>();

/*builder.Services.AddTransient(sp =>
{
var languageFiles = new List<LocalizedTextServiceSupplementaryFileSource>();
var webhostEnvironment = sp.GetRequiredService<IWebHostEnvironment>();

var seoToolkitFolder = webhostEnvironment.ContentRootFileProvider.GetDirectoryContents("/App_Plugins/SeoToolkit/");
foreach (var dir in seoToolkitFolder.Where(it => it.IsDirectory))
{
foreach (var langDir in new DirectoryInfo(dir.PhysicalPath).EnumerateDirectories().Where(d => d.Exists && d.Name.InvariantEquals("lang")))
{
languageFiles.AddRange(langDir.EnumerateFiles("*.xml").Select(langFile => new LocalizedTextServiceSupplementaryFileSource(langFile, false)));
}
}
languageFiles.Add(new LocalizedTextServiceSupplementaryFileSource(new FileInfo(webhostEnvironment.ContentRootFileProvider.GetFileInfo("/App_Plugins/SeoToolkit/lang/en-us.xml").PhysicalPath), false));
return (IEnumerable<LocalizedTextServiceSupplementaryFileSource>)languageFiles;
});*/

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SeoToolkit.Umbraco.Common.Core.Models.Config
{
public class GlobalAppSettingsModel
{
public bool AutomaticSitemapsInRobotsTxt { get; set; } = true;
public bool EnableSeoSettingsByDefault { get; set; } = false; // TODO: Change this in a major version to true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SeoToolkit.Umbraco.Common.Core.Models.Config
{
public class GlobalConfig
{
public bool AutomaticSitemapsInRobotsTxt { get; set; }
public bool EnableSeoSettingsByDefault { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
using Umbraco.Extensions;
using SeoToolkit.Umbraco.Common.Core.Models.Database;
using Umbraco.Cms.Infrastructure.Scoping;
using SeoToolkit.Umbraco.Common.Core.Services.SettingsService;
using SeoToolkit.Umbraco.Common.Core.Models.Config;

namespace SeoToolkit.Umbraco.Common.Core.Repositories.SeoSettingsRepository
{
public class SeoSettingsRepository : ISeoSettingsRepository
{
private readonly IScopeProvider _scopeProvider;
private readonly ISettingsService<GlobalConfig> _settingsService;

public SeoSettingsRepository(IScopeProvider scopeProvider)
public SeoSettingsRepository(IScopeProvider scopeProvider, ISettingsService<GlobalConfig> settingsService)
{
_scopeProvider = scopeProvider;
_settingsService = settingsService;
}

public bool IsEnabled(int contentTypeId)
Expand All @@ -24,7 +28,7 @@ public bool IsEnabled(int contentTypeId)

//Default is disabled.
if (entity is null)
return false;
return _settingsService.GetSettings().EnableSeoSettingsByDefault;
return entity.Enabled;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Extensions.Options;
using SeoToolkit.Umbraco.Common.Core.Models.Config;
using System;

namespace SeoToolkit.Umbraco.Common.Core.Services.SettingsService
{
public class GlobalConfigService : DefaultAppSettingsService<GlobalConfig>
{
private readonly IOptionsMonitor<GlobalAppSettingsModel> _config;

public GlobalConfigService(IOptionsMonitor<GlobalAppSettingsModel> config)
{
_config = config;
}

public override GlobalConfig GetSettings()
{
var settings = _config.CurrentValue;
return new GlobalConfig
{
AutomaticSitemapsInRobotsTxt = settings.AutomaticSitemapsInRobotsTxt,
EnableSeoSettingsByDefault = settings.EnableSeoSettingsByDefault
};
}
}
}
7 changes: 0 additions & 7 deletions src/SeoToolkit.Umbraco.Core/Config/GlobalAppSettingsModel.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/SeoToolkit.Umbraco.Core/Startup/SeoToolkitComposer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SeoToolkit.Umbraco.Core.Config;
using SeoToolkit.Umbraco.Common.Core.Models.Config;
using SeoToolkit.Umbraco.Core.Connectors;
using SeoToolkit.Umbraco.RobotsTxt.Core.Interfaces;
using Umbraco.Cms.Core.Composing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,14 @@ public IActionResult Get(int nodeId, string culture)

[HttpPost]
public IActionResult Save(MetaFieldsSettingsPostViewModel postModel)
{
var settings = _documentTypeSettingsService.Get(postModel.ContentTypeId);

{
if (!_seoSettingsService.IsEnabled(postModel.ContentTypeId))
return BadRequest("SEO settings are turned off for this node!");

EnsureLanguage(postModel.Culture);
var isDirty = false;
var values = new Dictionary<string, object>();
foreach (var (seoField, _) in settings.Fields)
foreach (var seoField in _fieldCollection)
{
if (!postModel.UserValues.ContainsKey(seoField.Alias))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.BackOffice.Trees;
using Umbraco.Cms.Web.Common.Attributes;

namespace SeoToolkit.Umbraco.MetaFields.Core.Controllers
{
/*[Tree("SeoToolkit", "MetaFields", TreeTitle = "MetaFields", TreeGroup = "SeoToolkit", SortOrder = 5)]
[PluginController("SeoToolkit")]
public class MetaFieldsTreeController : TreeController
{
public MetaFieldsTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
}

protected override ActionResult<TreeNode> CreateRootNode(FormCollection queryStrings)
{
var root = base.CreateRootNode(queryStrings);

root.Value.Icon = "icon-trafic";
root.Value.HasChildren = false;
root.Value.RoutePath = $"{SectionAlias}/{TreeAlias}/settings";
root.Value.MenuUrl = null;

return root.Value;
}

protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
{
return null;
}

protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
return null;
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public MetaTagsModel Get(IPublishedContent content, bool includeUserValues)
_eventAggregator.Publish(new BeforeMetaTagsNotification(content.ContentType.Alias, metaTags));

var settings = _documentTypeSettingsService.Get(content.ContentType.Id);
if (settings is null)
return null;
if (_seoSettingsService.IsEnabled(content.ContentType.Id) != true)
return null;
var userValues = includeUserValues ? _seoValueService.GetUserValues(content.Id) : null;
Expand All @@ -79,7 +77,7 @@ public MetaTagsModel Get(IPublishedContent content, bool includeUserValues)
intermediateObject = result;
}

if (intermediateObject is null)
if (intermediateObject is null && settings != null)
{
var documentTypeValue = settings.Get(it.Alias);
if (documentTypeValue != null && documentTypeValue.UseInheritedValue)
Expand All @@ -88,7 +86,7 @@ public MetaTagsModel Get(IPublishedContent content, bool includeUserValues)
while (inheritance != null)
{
var inheritedSettings = _documentTypeSettingsService.Get(inheritance.Id);
documentTypeValue = inheritedSettings.Get(it.Alias);
documentTypeValue = inheritedSettings?.Get(it.Alias);
if (documentTypeValue != null && documentTypeValue.UseInheritedValue)
inheritance = inheritedSettings.Inheritance;
else
Expand Down
3 changes: 2 additions & 1 deletion src/SeoToolkit.Umbraco.MetaFields/ManifestLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void Filter(List<PackageManifest> manifests)
"/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/PropertyEditor/noSelectCheckboxList.controller.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/Components/ItemGroupPicker/itemGroupPicker.controller.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/seoFieldEditor.directive.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/Previewers/previewer.directive.js"
"/App_Plugins/SeoToolkit/MetaFields/Interface/Previewers/previewer.directive.js",
"/App_Plugins/SeoToolkit/backoffice/MetaFields/settings.controller.js"
},
Stylesheets = new[]
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(function () {

function globalSettingsController() {
var vm = this;
}

angular.module("umbraco").controller("SeoToolkit.MetaFields.GlobalSettingsController", globalSettingsController);
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div ng-controller="SeoToolkit.MetaFields.GlobalSettingsController as vm">
Hello
</div>