Skip to content

Commit

Permalink
Merge pull request #308 from nikcio/feature/refactor-to-fewer-projects
Browse files Browse the repository at this point in the history
V5 development
  • Loading branch information
nikcio authored Apr 12, 2024
2 parents 3fb9403 + ef6186b commit 7e06c19
Show file tree
Hide file tree
Showing 349 changed files with 8,634 additions and 19,621 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Build UHeadless

on:
push:
branches: [ v**/contrib ]
branches: [ contrib ]
paths:
- 'src/**'
- '.github/workflows/build.yml'
pull_request:
branches: [ v**/contrib ]
branches: [ contrib ]
paths:
- 'src/**'
- '.github/workflows/build.yml'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ name: "CodeQL"

on:
push:
branches: [ v**/contrib ]
branches: [ contrib ]
paths:
- 'src/**'
- '.github/workflows/codeql-analysis.yml'
pull_request:
branches: [ v**/contrib ]
branches: [ contrib ]
paths:
- 'src/**'
- '.github/workflows/codeql-analysis.yml'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy docs to GitHub Pages

on:
push:
branches: [ v4/contrib ]
branches: [ contrib ]
paths:
- 'docs/**'
- '.github/workflows/deploy-docs.yml'
Expand Down
55 changes: 3 additions & 52 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,56 +50,7 @@ jobs:
run: dotnet nuget push "Nikcio.UHeadless.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
working-directory: ./src/releases

- name: Push (Nikcio.UHeadless.Base) to NuGet
run: dotnet nuget push "Nikcio.UHeadless.Base.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
- name: Push (Nikcio.UHeadless.Defaults) to NuGet
run: dotnet nuget push "Nikcio.UHeadless.Defaults.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
working-directory: ./src/releases

- name: Push (Nikcio.UHeadless.Content) to NuGet
run: dotnet nuget push "Nikcio.UHeadless.Content.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
working-directory: ./src/releases

- name: Push (Nikcio.UHeadless.Media) to NuGet
run: dotnet nuget push "Nikcio.UHeadless.Media.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
working-directory: ./src/releases

- name: Push (Nikcio.UHeadless.Members) to NuGet
run: dotnet nuget push "Nikcio.UHeadless.Members.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
working-directory: ./src/releases

- name: Push (Nikcio.UHeadless.ContentTypes) to NuGet
run: dotnet nuget push "Nikcio.UHeadless.ContentTypes.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
working-directory: ./src/releases

# Not ready

# - name: Push (Nikcio.UHeadless.Cache) to NuGet
# run: dotnet nuget push "Nikcio.UHeadless.Cache.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
# working-directory: ./src/releases

# - name: Push (Nikcio.UHeadless.Cache.InMemory) to NuGet
# run: dotnet nuget push "Nikcio.UHeadless.Cache.InMemory.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
# working-directory: ./src/releases

# - name: Push (Nikcio.UHeadless.Cache.Redis) to NuGet
# run: dotnet nuget push "Nikcio.UHeadless.Cache.Redis.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
# working-directory: ./src/releases

# - name: Push (Nikcio.UHeadless.Cache.TextFiles) to NuGet
# run: dotnet nuget push "Nikcio.UHeadless.Cache.TextFiles.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
# working-directory: ./src/releases

# - name: Push (Nikcio.UHeadless.DataTypes) to NuGet
# run: dotnet nuget push "Nikcio.UHeadless.DataTypes.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
# working-directory: ./src/releases

# - name: Push (Nikcio.UHeadless.Dictionary) to NuGet
# run: dotnet nuget push "Nikcio.UHeadless.Dictionary.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
# working-directory: ./src/releases

# - name: Push (Nikcio.UHeadless.MediaTypes) to NuGet
# run: dotnet nuget push "Nikcio.UHeadless.MediaTypes.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
# working-directory: ./src/releases

# - name: Push (Nikcio.UHeadless.MemberTypes) to NuGet
# run: dotnet nuget push "Nikcio.UHeadless.MemberTypes.${VERSION}.nupkg" --api-key ${{secrets.NUGET_API_TOKEN}} --source https://api.nuget.org/v3/index.json
# working-directory: ./src/releases

4 changes: 2 additions & 2 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: SonarCloud
on:
push:
branches: [ v**/contrib ]
branches: [ contrib ]
paths:
- 'src/**'
- '.github/workflows/sonar.yml'
pull_request_target:
branches: [ v**/contrib ]
branches: [ contrib ]
paths:
- 'src/**'
- '.github/workflows/sonar.yml'
Expand Down
3 changes: 3 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<PropertyGroup>
<AnalysisMode>All</AnalysisMode>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28">
Expand Down
114 changes: 114 additions & 0 deletions src/Examples/Docs/Content/ContentItem.cs
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; }
}
}
49 changes: 0 additions & 49 deletions src/Examples/Docs/Content/MyContent.cs

This file was deleted.

85 changes: 85 additions & 0 deletions src/Examples/Docs/Content/PublicAccessExample/ContentItem.cs
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;
}
}
Loading

0 comments on commit 7e06c19

Please sign in to comment.