-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #308 from nikcio/feature/refactor-to-fewer-projects
V5 development
- Loading branch information
Showing
349 changed files
with
8,634 additions
and
19,621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using HotChocolate; | ||
using Nikcio.UHeadless.Common; | ||
using Nikcio.UHeadless.Common.Properties; | ||
using Nikcio.UHeadless.Common.Reflection; | ||
using Nikcio.UHeadless.ContentItems; | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
using Umbraco.Extensions; | ||
|
||
namespace Examples.Docs.Content; | ||
|
||
public partial class ContentItem : ContentItemBase | ||
{ | ||
private readonly IVariationContextAccessor _variationContextAccessor; | ||
private readonly IDependencyReflectorFactory _dependencyReflectorFactory; | ||
|
||
public ContentItem(CreateCommand command, IVariationContextAccessor variationContextAccessor, IDependencyReflectorFactory dependencyReflectorFactory) : base(command) | ||
{ | ||
ArgumentNullException.ThrowIfNull(variationContextAccessor); | ||
ArgumentNullException.ThrowIfNull(dependencyReflectorFactory); | ||
ArgumentNullException.ThrowIfNull(command); | ||
|
||
_variationContextAccessor = variationContextAccessor; | ||
_dependencyReflectorFactory = dependencyReflectorFactory; | ||
|
||
StatusCode = command.StatusCode; | ||
Redirect = command.Redirect == null ? null : new RedirectInfo() | ||
{ | ||
IsPermanent = command.Redirect.IsPermanent, | ||
RedirectUrl = command.Redirect.RedirectUrl | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the url segment of the content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the url segment of the content item.")] | ||
public string? UrlSegment => PublishedContent?.UrlSegment(_variationContextAccessor, Culture); | ||
|
||
/// <summary> | ||
/// Gets the url of a content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the url of a content item.")] | ||
public string? Url(UrlMode urlMode) | ||
{ | ||
return PublishedContent?.Url(Culture, urlMode); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of a content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the name of a content item.")] | ||
public string? Name => PublishedContent?.Name(_variationContextAccessor, Culture); | ||
|
||
/// <summary> | ||
/// Gets the id of a content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the id of a content item.")] | ||
public int? Id => PublishedContent?.Id; | ||
|
||
/// <summary> | ||
/// Gets the key of a content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the key of a content item.")] | ||
public Guid? Key => PublishedContent?.Key; | ||
|
||
/// <summary> | ||
/// Gets the identifier of the template to use to render the content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the identifier of the template to use to render the content item.")] | ||
public int? TemplateId => PublishedContent?.TemplateId; | ||
|
||
/// <summary> | ||
/// Gets the date the content item was last updated | ||
/// </summary> | ||
[GraphQLDescription("Gets the date the content item was last updated.")] | ||
public DateTime? UpdateDate => PublishedContent?.UpdateDate; | ||
|
||
/// <summary> | ||
/// Gets the parent of the content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the parent of the content item.")] | ||
public ContentItem? Parent => PublishedContent?.Parent != null ? CreateContentItem<ContentItem>(new CreateCommand() | ||
{ | ||
PublishedContent = PublishedContent.Parent, | ||
ResolverContext = ResolverContext, | ||
Redirect = null, | ||
StatusCode = 200, | ||
}, _dependencyReflectorFactory) : default; | ||
|
||
/// <summary> | ||
/// Gets the properties of the content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the properties of the content item.")] | ||
public TypedProperties Properties() | ||
{ | ||
ResolverContext.SetScopedState(ContextDataKeys.PublishedContent, PublishedContent); | ||
return new TypedProperties(); | ||
} | ||
|
||
public int StatusCode { get; } | ||
|
||
/// <summary> | ||
/// Gets the redirect information for the content item | ||
/// </summary> | ||
[GraphQLDescription("Gets the redirect information for the content item.")] | ||
public RedirectInfo? Redirect { get; } | ||
|
||
public class RedirectInfo | ||
{ | ||
public required string? RedirectUrl { get; init; } | ||
|
||
public required bool IsPermanent { get; init; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
src/Examples/Docs/Content/PublicAccessExample/ContentItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using HotChocolate; | ||
using Nikcio.UHeadless.ContentItems; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Web; | ||
|
||
namespace Examples.Docs.Content.PublicAccessExample; | ||
|
||
[GraphQLDescription("Represents an extended content item.")] | ||
public class ContentItem : ContentItemBase | ||
{ | ||
private readonly IPublicAccessService _publicAccessService; | ||
private readonly IContentService _contentService; | ||
private readonly IUmbracoContextAccessor _umbracoContext; | ||
private readonly ILogger<ContentItem> _logger; | ||
|
||
[GraphQLDescription("Gets the restrict public access settings of the content item.")] | ||
public PermissionsModel? Permissions() | ||
{ | ||
|
||
if (PublishedContent == null) | ||
{ | ||
_logger.LogWarning("Content is null"); | ||
return null; | ||
} | ||
|
||
IContent? content = _contentService.GetById(PublishedContent.Id); | ||
|
||
if (content == null) | ||
{ | ||
_logger.LogWarning("Content from content service is null. Id: {ContentId}", PublishedContent.Id); | ||
return null; | ||
} | ||
|
||
PublicAccessEntry? entry = _publicAccessService.GetEntryForContent(content); | ||
|
||
if (entry == null) | ||
{ | ||
_logger.LogWarning("Public access entry is null. ContentId: {ContentId}", PublishedContent.Id); | ||
return null; | ||
} | ||
|
||
IUmbracoContext cache = _umbracoContext.GetRequiredUmbracoContext(); | ||
|
||
if (cache.Content == null) | ||
{ | ||
_logger.LogWarning("Content cache is null on Umbraco context"); | ||
return null; | ||
} | ||
|
||
IPublishedContent? loginContent = cache.Content.GetById(entry.LoginNodeId); | ||
IPublishedContent? noAccessContent = cache.Content.GetById(entry.NoAccessNodeId); | ||
|
||
var permissions = new PermissionsModel | ||
{ | ||
UrlLogin = loginContent?.Url(), | ||
UrlNoAccess = noAccessContent?.Url() | ||
}; | ||
|
||
foreach (PublicAccessRule rule in entry.Rules) | ||
{ | ||
permissions.AccessRules.Add(new AccessRuleModel(rule.RuleType, rule.RuleValue)); | ||
} | ||
|
||
return permissions; | ||
} | ||
|
||
public ContentItem( | ||
CreateCommand command, | ||
IPublicAccessService publicAccessService, | ||
IContentService contentService, | ||
IUmbracoContextAccessor umbracoContext, | ||
ILogger<ContentItem> logger) : base(command) | ||
{ | ||
ArgumentNullException.ThrowIfNull(logger); | ||
ArgumentNullException.ThrowIfNull(publicAccessService); | ||
ArgumentNullException.ThrowIfNull(contentService); | ||
|
||
_publicAccessService = publicAccessService; | ||
_contentService = contentService; | ||
_umbracoContext = umbracoContext; | ||
_logger = logger; | ||
} | ||
} |
Oops, something went wrong.