Skip to content
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
48 changes: 21 additions & 27 deletions src/Umbraco.Core/Constants-UdiEntityType.cs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Besides adding Relation, User and UserGroup, I've re-ordered the existing ones alphabetically, grouped per 'UDI type'.

Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,42 @@ public static class UdiEntityType
// need to keep it around in a field nor to make it readonly
public const string Unknown = "unknown";

// guid entity types
// GUID entity types
public const string AnyGuid = "any-guid"; // that one is for tests

public const string Element = "element";
public const string DataType = "data-type";
public const string DataTypeContainer = "data-type-container";
public const string DictionaryItem = "dictionary-item";
public const string Document = "document";

public const string DocumentBlueprint = "document-blueprint";

public const string Media = "media";
public const string Member = "member";

public const string DictionaryItem = "dictionary-item";
public const string Template = "template";

public const string DocumentBlueprintContainer = "document-blueprint-container";
public const string DocumentType = "document-type";
public const string DocumentTypeContainer = "document-type-container";

public const string DocumentBlueprintContainer = "document-blueprint-container";
public const string Element = "element";
public const string Media = "media";
public const string MediaType = "media-type";
public const string MediaTypeContainer = "media-type-container";
public const string DataType = "data-type";
public const string DataTypeContainer = "data-type-container";
public const string MemberType = "member-type";
public const string Member = "member";
public const string MemberGroup = "member-group";

public const string MemberType = "member-type";
public const string Relation = "relation";
public const string RelationType = "relation-type";

public const string Template = "template";
public const string User = "user";
public const string UserGroup = "user-group";
public const string Webhook = "webhook";

// forms
public const string FormsForm = "forms-form";
public const string FormsPreValue = "forms-prevalue";
public const string FormsDataSource = "forms-datasource";

// string entity types
// String entity types
public const string AnyString = "any-string"; // that one is for tests

public const string Language = "language";
public const string MediaFile = "media-file";
public const string TemplateFile = "template-file";
public const string PartialView = "partial-view";
public const string Script = "script";
public const string Stylesheet = "stylesheet";
public const string PartialView = "partial-view";
public const string TemplateFile = "template-file";

// Forms entity types
public const string FormsDataSource = "forms-datasource";
public const string FormsForm = "forms-form";
public const string FormsPreValue = "forms-prevalue";
}
}
106 changes: 76 additions & 30 deletions src/Umbraco.Core/Extensions/UdiGetterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Models.Membership;

namespace Umbraco.Extensions;

Expand All @@ -27,8 +28,6 @@ public static Udi GetUdi(this IEntity entity)
{
// Concrete types
EntityContainer container => container.GetUdi(),
Script script => script.GetUdi(),
Stylesheet stylesheet => stylesheet.GetUdi(),
// Interfaces
IContentBase contentBase => contentBase.GetUdi(),
IContentTypeComposition contentTypeComposition => contentTypeComposition.GetUdi(),
Expand All @@ -37,8 +36,13 @@ public static Udi GetUdi(this IEntity entity)
ILanguage language => language.GetUdi(),
IMemberGroup memberGroup => memberGroup.GetUdi(),
IPartialView partialView => partialView.GetUdi(),
IRelation relation => relation.GetUdi(),
IRelationType relationType => relationType.GetUdi(),
IScript script => script.GetUdi(),
IStylesheet stylesheet => stylesheet.GetUdi(),
ITemplate template => template.GetUdi(),
IUser user => user.GetUdi(),
IUserGroup userGroup => userGroup.GetUdi(),
IWebhook webhook => webhook.GetUdi(),
_ => throw new NotSupportedException($"Entity type {entity.GetType().FullName} is not supported."),
};
Expand Down Expand Up @@ -80,34 +84,6 @@ public static GuidUdi GetUdi(this EntityContainer entity)
return new GuidUdi(entityType, entity.Key).EnsureClosed();
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>
/// The entity identifier of the entity.
/// </returns>
public static StringUdi GetUdi(this Script entity)
{
ArgumentNullException.ThrowIfNull(entity);

return GetUdiFromPath(Constants.UdiEntityType.Script, entity.Path);
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>
/// The entity identifier of the entity.
/// </returns>
public static StringUdi GetUdi(this Stylesheet entity)
{
ArgumentNullException.ThrowIfNull(entity);

return GetUdiFromPath(Constants.UdiEntityType.Stylesheet, entity.Path);
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
Expand Down Expand Up @@ -304,6 +280,20 @@ public static StringUdi GetUdi(this IPartialView entity)
return GetUdiFromPath(Constants.UdiEntityType.PartialView, entity.Path);
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>
/// The entity identifier of the entity.
/// </returns>
public static GuidUdi GetUdi(this IRelation entity)
{
ArgumentNullException.ThrowIfNull(entity);

return new GuidUdi(Constants.UdiEntityType.Relation, entity.Key).EnsureClosed();
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
Expand All @@ -318,6 +308,34 @@ public static GuidUdi GetUdi(this IRelationType entity)
return new GuidUdi(Constants.UdiEntityType.RelationType, entity.Key).EnsureClosed();
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>
/// The entity identifier of the entity.
/// </returns>
public static StringUdi GetUdi(this IScript entity)
{
ArgumentNullException.ThrowIfNull(entity);

return GetUdiFromPath(Constants.UdiEntityType.Script, entity.Path);
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>
/// The entity identifier of the entity.
/// </returns>
public static StringUdi GetUdi(this IStylesheet entity)
{
ArgumentNullException.ThrowIfNull(entity);

return GetUdiFromPath(Constants.UdiEntityType.Stylesheet, entity.Path);
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
Expand All @@ -332,6 +350,34 @@ public static GuidUdi GetUdi(this ITemplate entity)
return new GuidUdi(Constants.UdiEntityType.Template, entity.Key).EnsureClosed();
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>
/// The entity identifier of the entity.
/// </returns>
public static GuidUdi GetUdi(this IUser entity)
{
ArgumentNullException.ThrowIfNull(entity);

return new GuidUdi(Constants.UdiEntityType.User, entity.Key).EnsureClosed();
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
/// <param name="entity">The entity.</param>
/// <returns>
/// The entity identifier of the entity.
/// </returns>
public static GuidUdi GetUdi(this IUserGroup entity)
{
ArgumentNullException.ThrowIfNull(entity);

return new GuidUdi(Constants.UdiEntityType.UserGroup, entity.Key).EnsureClosed();
}

/// <summary>
/// Gets the entity identifier of the entity.
/// </summary>
Expand Down
34 changes: 20 additions & 14 deletions src/Umbraco.Core/UdiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,34 +200,40 @@ public static Dictionary<string, UdiType> GetKnownUdiTypes() =>
new()
{
{ Constants.UdiEntityType.Unknown, UdiType.Unknown },
// GUID UDI types
{ Constants.UdiEntityType.AnyGuid, UdiType.GuidUdi },
{ Constants.UdiEntityType.Element, UdiType.GuidUdi },
{ Constants.UdiEntityType.DataType, UdiType.GuidUdi },
{ Constants.UdiEntityType.DataTypeContainer, UdiType.GuidUdi },
{ Constants.UdiEntityType.DictionaryItem, UdiType.GuidUdi },
{ Constants.UdiEntityType.Document, UdiType.GuidUdi },
{ Constants.UdiEntityType.DocumentBlueprint, UdiType.GuidUdi },
{ Constants.UdiEntityType.DocumentBlueprintContainer, UdiType.GuidUdi },
{ Constants.UdiEntityType.Media, UdiType.GuidUdi },
{ Constants.UdiEntityType.Member, UdiType.GuidUdi },
{ Constants.UdiEntityType.DictionaryItem, UdiType.GuidUdi },
{ Constants.UdiEntityType.Template, UdiType.GuidUdi },
{ Constants.UdiEntityType.DocumentType, UdiType.GuidUdi },
{ Constants.UdiEntityType.DocumentTypeContainer, UdiType.GuidUdi },
{ Constants.UdiEntityType.Element, UdiType.GuidUdi },
{ Constants.UdiEntityType.Media, UdiType.GuidUdi },
{ Constants.UdiEntityType.MediaType, UdiType.GuidUdi },
{ Constants.UdiEntityType.MediaTypeContainer, UdiType.GuidUdi },
{ Constants.UdiEntityType.DataType, UdiType.GuidUdi },
{ Constants.UdiEntityType.DataTypeContainer, UdiType.GuidUdi },
{ Constants.UdiEntityType.MemberType, UdiType.GuidUdi },
{ Constants.UdiEntityType.Member, UdiType.GuidUdi },
{ Constants.UdiEntityType.MemberGroup, UdiType.GuidUdi },
{ Constants.UdiEntityType.MemberType, UdiType.GuidUdi },
{ Constants.UdiEntityType.Relation, UdiType.GuidUdi },
{ Constants.UdiEntityType.RelationType, UdiType.GuidUdi },
{ Constants.UdiEntityType.FormsForm, UdiType.GuidUdi },
{ Constants.UdiEntityType.FormsPreValue, UdiType.GuidUdi },
{ Constants.UdiEntityType.FormsDataSource, UdiType.GuidUdi },
{ Constants.UdiEntityType.Template, UdiType.GuidUdi },
{ Constants.UdiEntityType.User, UdiType.GuidUdi },
{ Constants.UdiEntityType.UserGroup, UdiType.GuidUdi },
{ Constants.UdiEntityType.Webhook, UdiType.GuidUdi },
// String UDI types
{ Constants.UdiEntityType.AnyString, UdiType.StringUdi },
{ Constants.UdiEntityType.Language, UdiType.StringUdi },
{ Constants.UdiEntityType.MediaFile, UdiType.StringUdi },
{ Constants.UdiEntityType.TemplateFile, UdiType.StringUdi },
{ Constants.UdiEntityType.Script, UdiType.StringUdi },
{ Constants.UdiEntityType.PartialView, UdiType.StringUdi },
{ Constants.UdiEntityType.Script, UdiType.StringUdi },
{ Constants.UdiEntityType.Stylesheet, UdiType.StringUdi },
{ Constants.UdiEntityType.Webhook, UdiType.GuidUdi },
{ Constants.UdiEntityType.TemplateFile, UdiType.StringUdi },
// Forms UDI types
{ Constants.UdiEntityType.FormsDataSource, UdiType.GuidUdi },
{ Constants.UdiEntityType.FormsForm, UdiType.GuidUdi },
{ Constants.UdiEntityType.FormsPreValue, UdiType.GuidUdi },
};
}
3 changes: 3 additions & 0 deletions src/Umbraco.Core/UdiParserServiceConnectors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Umbraco.Cms.Core;

[Obsolete("This class will be removed in a future version.")]
public static class UdiParserServiceConnectors
{
private static readonly object ScanLocker = new();
Expand All @@ -19,6 +20,7 @@ public static class UdiParserServiceConnectors
/// Scan for deploy <see cref="IServiceConnector" /> in assemblies for known UDI types.
/// </summary>
/// <param name="typeLoader"></param>
[Obsolete("Use UdiParser.RegisterUdiType() instead. This method will be removed in a future version.")]
public static void ScanDeployServiceConnectorsForUdiTypes(TypeLoader typeLoader)
{
if (typeLoader is null)
Expand Down Expand Up @@ -72,6 +74,7 @@ public static void ScanDeployServiceConnectorsForUdiTypes(TypeLoader typeLoader)
/// Registers a single <see cref="IServiceConnector" /> to add it's UDI type.
/// </summary>
/// <typeparam name="T"></typeparam>
[Obsolete("Use UdiParser.RegisterUdiType() instead. This method will be removed in a future version.")]
public static void RegisterServiceConnector<T>()
where T : IServiceConnector
{
Expand Down
15 changes: 12 additions & 3 deletions tests/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.

using System.Collections.Generic;
using System.Linq;
using Moq;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Strings;
Expand All @@ -22,6 +20,7 @@ public UserGroupBuilder()
public class UserGroupBuilder<TParent>
: ChildBuilderBase<TParent, IUserGroup>,
IWithIdBuilder,
IWithKeyBuilder,
IWithIconBuilder,
IWithAliasBuilder,
IWithNameBuilder
Expand All @@ -30,6 +29,7 @@ public class UserGroupBuilder<TParent>
private IEnumerable<string> _allowedSections = Enumerable.Empty<string>();
private string _icon;
private int? _id;
private Guid? _key;
private string _name;
private ISet<string> _permissions = new HashSet<string>();
private int? _startContentId;
Expand Down Expand Up @@ -60,6 +60,12 @@ string IWithIconBuilder.Icon
set => _id = value;
}

Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}

string IWithNameBuilder.Name
{
get => _name;
Expand Down Expand Up @@ -117,11 +123,13 @@ public IReadOnlyUserGroup BuildReadOnly(IUserGroup userGroup) =>
x.StartContentId == userGroup.StartContentId &&
x.StartMediaId == userGroup.StartMediaId &&
x.AllowedSections == userGroup.AllowedSections &&
x.Id == userGroup.Id);
x.Id == userGroup.Id &&
x.Key == userGroup.Key);

public override IUserGroup Build()
{
var id = _id ?? 0;
var key = _key ?? Guid.NewGuid();
var name = _name ?? "TestUserGroup" + _suffix;
var alias = _alias ?? "testUserGroup" + _suffix;
var userCount = _userCount ?? 0;
Expand All @@ -134,6 +142,7 @@ public override IUserGroup Build()
var userGroup = new UserGroup(shortStringHelper, userCount, alias, name, icon)
{
Id = id,
Key = key,
StartContentId = startContentId,
StartMediaId = startMediaId
};
Expand Down
Loading