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

Add notifcation when publishing varying culture without domains configured #11328

Merged
merged 35 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1921fd8
Verify that root node has domains when multilingual content is published
Oct 6, 2021
740dfcc
Verify that published culture has domain
Oct 6, 2021
a605944
Localize speech bubble text
Oct 6, 2021
9e05bf1
Add translations
Oct 6, 2021
7b6bf78
Add GetAncestorIds extension method
Oct 6, 2021
a8bd71b
Check ancestors for any configured domains
Oct 6, 2021
9e5520f
Only warn about cultures actually being published
Oct 6, 2021
0f803ec
Add ContentCultureInfosCollectionBuilder test builder
Oct 7, 2021
df1d456
Add ContentCultureInfosBuilder
Oct 7, 2021
11bfef4
Add unit test
Oct 7, 2021
501ba24
Add more unit tests
Oct 7, 2021
f0f8874
Add integration test
Oct 7, 2021
8e7fb89
Use proper notifications instead of event messages
Oct 8, 2021
5a82d8e
Also display warning when publishing with descendants
Oct 8, 2021
8112e1a
Add intergration test
Oct 8, 2021
597b6f4
Add final integration test
Oct 8, 2021
161fc7d
Use hashset instead of list for assigned domains
Oct 8, 2021
7c2f5c9
Add EN translations
Oct 12, 2021
6fcef7b
Ensure current thread culture
Zeegaan Oct 12, 2021
ab0ac0f
Ensure current thread culture
Zeegaan Oct 12, 2021
ee22d26
Merge remote-tracking branch 'origin/v9/feature/add-notifcation-for-u…
Zeegaan Oct 12, 2021
e64d1ff
Removed check for message
Zeegaan Oct 14, 2021
4c616dc
Merge branch 'v9/dev' into v9/feature/add-notifcation-for-url-collision
Zeegaan Oct 14, 2021
7379387
Added logging
Zeegaan Oct 14, 2021
76a8d4c
Added logging in test
Zeegaan Oct 14, 2021
6e540de
Added additional logging
Zeegaan Oct 14, 2021
885281f
Added Assembly attributes
Zeegaan Oct 14, 2021
d992a6e
Changed default language for Unit & Integration tests to en-US
Zeegaan Oct 14, 2021
d184f82
Added removed language array back
Zeegaan Oct 14, 2021
563babd
Removed logging from tests
Zeegaan Oct 14, 2021
e0cac5e
Apply suggestions from code review
nikolajlauridsen Oct 15, 2021
28c9b9b
Add constants for ISO codes in ContentControllerTests
Oct 15, 2021
ebd0d95
Merge branch 'v9/feature/add-notifcation-for-url-collision' of https:…
Oct 15, 2021
cc74e3f
Remove unused using
Oct 15, 2021
48003e0
Check ancestors for published culture
Oct 15, 2021
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
14 changes: 11 additions & 3 deletions src/Umbraco.Core/Extensions/ContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;

Expand Down Expand Up @@ -165,7 +165,15 @@ public static ContentStatus GetStatus(this IContent content, string culture = nu
return ContentStatus.Unpublished;
}


/// <summary>
/// Gets a collection containing the ids of all ancestors.
/// </summary>
/// <param name="content"><see cref="IContent"/> to retrieve ancestors for</param>
/// <returns>An Enumerable list of integer ids</returns>
public static IEnumerable<int> GetAncestorIds(this IContent content) =>
content.Path.Split(Constants.CharArrays.Comma)
.Where(x => x != Constants.System.RootString && x != content.Id.ToString(CultureInfo.InvariantCulture)).Select(s =>
int.Parse(s, CultureInfo.InvariantCulture));

#endregion

Expand Down
16 changes: 9 additions & 7 deletions src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,18 +531,20 @@ public IEnumerable<IContent> GetAncestors(int id)
public IEnumerable<IContent> GetAncestors(IContent content)
{
//null check otherwise we get exceptions
if (content.Path.IsNullOrWhiteSpace()) return Enumerable.Empty<IContent>();
if (content.Path.IsNullOrWhiteSpace())
{
return Enumerable.Empty<IContent>();
}

var rootId = Cms.Core.Constants.System.RootString;
var ids = content.Path.Split(Constants.CharArrays.Comma)
.Where(x => x != rootId && x != content.Id.ToString(CultureInfo.InvariantCulture)).Select(s =>
int.Parse(s, CultureInfo.InvariantCulture)).ToArray();
var ids = content.GetAncestorIds().ToArray();
if (ids.Any() == false)
{
return new List<IContent>();
}

using (var scope = ScopeProvider.CreateScope(autoComplete: true))
using (IScope scope = ScopeProvider.CreateScope(autoComplete: true))
{
scope.ReadLock(Cms.Core.Constants.Locks.ContentTree);
scope.ReadLock(Constants.Locks.ContentTree);
return _documentRepository.GetMany(ids);
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/Umbraco.Tests.Common/Builders/ContentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Umbraco.Cms.Tests.Common.Builders
public class ContentBuilder
: BuilderBase<Content>,
IBuildContentTypes,
IBuildContentCultureInfosCollection,
IWithIdBuilder,
IWithKeyBuilder,
IWithParentIdBuilder,
Expand All @@ -31,6 +32,7 @@ public class ContentBuilder
IWithPropertyValues
{
private ContentTypeBuilder _contentTypeBuilder;
private ContentCultureInfosCollectionBuilder _contentCultureInfosCollectionBuilder;
private GenericDictionaryBuilder<ContentBuilder, string, object> _propertyDataBuilder;

private int? _id;
Expand All @@ -48,6 +50,7 @@ public class ContentBuilder
private bool? _trashed;
private CultureInfo _cultureInfo;
private IContentType _contentType;
private ContentCultureInfosCollection _contentCultureInfosCollection;
private readonly IDictionary<string, string> _cultureNames = new Dictionary<string, string>();
private object _propertyValues;
private string _propertyValuesCulture;
Expand All @@ -73,6 +76,14 @@ public ContentBuilder WithContentType(IContentType contentType)
return this;
}

public ContentBuilder WithContentCultureInfosCollection(
ContentCultureInfosCollection contentCultureInfosCollection)
{
_contentCultureInfosCollectionBuilder = null;
_contentCultureInfosCollection = contentCultureInfosCollection;
return this;
}

Zeegaan marked this conversation as resolved.
Show resolved Hide resolved
public ContentBuilder WithCultureName(string culture, string name = "")
{
if (string.IsNullOrWhiteSpace(name))
Expand Down Expand Up @@ -105,6 +116,14 @@ public GenericDictionaryBuilder<ContentBuilder, string, object> AddPropertyData(
return builder;
}

public ContentCultureInfosCollectionBuilder AddContentCultureInfosCollection()
{
_contentCultureInfosCollection = null;
var builder = new ContentCultureInfosCollectionBuilder(this);
_contentCultureInfosCollectionBuilder = builder;
return builder;
}

public override Content Build()
{
var id = _id ?? 0;
Expand Down Expand Up @@ -176,6 +195,13 @@ public override Content Build()
content.ResetDirtyProperties(false);
}

if (_contentCultureInfosCollection is not null || _contentCultureInfosCollectionBuilder is not null)
{
ContentCultureInfosCollection contentCultureInfos =
_contentCultureInfosCollection ?? _contentCultureInfosCollectionBuilder.Build();
content.PublishCultureInfos = contentCultureInfos;
}

return content;
}

Expand Down
45 changes: 45 additions & 0 deletions src/Umbraco.Tests.Common/Builders/ContentCultureInfosBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Tests.Common.Builders.Interfaces;

namespace Umbraco.Cms.Tests.Common.Builders
{
public class ContentCultureInfosBuilder : ChildBuilderBase<ContentCultureInfosCollectionBuilder, ContentCultureInfos>,
IWithNameBuilder,
IWithDateBuilder
{
private string _name;
private string _cultureIso;
private DateTime? _date;
public ContentCultureInfosBuilder(ContentCultureInfosCollectionBuilder parentBuilder) : base(parentBuilder)
{
}

public ContentCultureInfosBuilder WithCultureIso(string cultureIso)
{
_cultureIso = cultureIso;
return this;
}

public override ContentCultureInfos Build()
{
var name = _name ?? Guid.NewGuid().ToString();
var cultureIso = _cultureIso ?? "en-us";
DateTime date = _date ?? DateTime.Now;

return new ContentCultureInfos(cultureIso) { Name = name, Date = date };
}

public string Name
{
get => _name;
set => _name = value;
}

public DateTime? Date
{
get => _date;
set => _date = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Tests.Common.Builders.Interfaces;

namespace Umbraco.Cms.Tests.Common.Builders
{
public class ContentCultureInfosCollectionBuilder : ChildBuilderBase<ContentBuilder, ContentCultureInfosCollection>, IBuildContentCultureInfosCollection
{
private readonly List<ContentCultureInfosBuilder> _cultureInfosBuilders;
public ContentCultureInfosCollectionBuilder(ContentBuilder parentBuilder) : base(parentBuilder) => _cultureInfosBuilders = new List<ContentCultureInfosBuilder>();

public ContentCultureInfosBuilder AddCultureInfos()
{
var builder = new ContentCultureInfosBuilder(this);
_cultureInfosBuilders.Add(builder);
return builder;
}

public override ContentCultureInfosCollection Build()
{
if (_cultureInfosBuilders.Count < 1)
{
throw new InvalidOperationException("You must add at least one culture infos to the collection builder");
}
var cultureInfosCollection = new ContentCultureInfosCollection();

foreach (ContentCultureInfosBuilder cultureInfosBuilder in _cultureInfosBuilders)
{
cultureInfosCollection.Add(cultureInfosBuilder.Build());
}

return cultureInfosCollection;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,11 @@ public static T WithPropertyValues<T>(this T builder, object propertyValues, str
builder.PropertyValuesSegment = segment;
return builder;
}

public static T WithDate<T>(this T builder, DateTime date) where T : IWithDateBuilder
{
builder.Date = date;
return builder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces
{
public interface IBuildContentCultureInfosCollection
{

}
}
Zeegaan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Umbraco.Cms.Tests.Common.Builders.Interfaces
{
public interface IWithDateBuilder
{
DateTime? Date { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Umbraco.Tests.Integration/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using NUnit.Framework;

[assembly: SetCulture("en-US")]
[assembly: SetUICulture("en-US")]
Loading