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

Refactor and consolidate Shared project structure. #1045

Merged
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
29 changes: 14 additions & 15 deletions src/FSH.Starter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSSQL", "api\migrations\MSS
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostgreSQL", "api\migrations\PostgreSQL\PostgreSQL.csproj", "{D64AD07C-A711-42D8-8653-EDCD7A825A44}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "api\modules\Shared\Shared.csproj", "{E54C7411-6CB4-4AE7-B583-4E669C3C0059}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Todo", "api\modules\Todo\Todo.csproj", "{B3866EEF-8F46-4302-ABAC-A95EE2F27331}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Catalog.Application", "api\modules\Catalog\Catalog.Application\Catalog.Application.csproj", "{8C7DAF8E-F792-4092-8BBF-31A6B898B39A}"
Expand All @@ -59,6 +57,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceDefaults", "aspire\s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Host", "aspire\host\Host.csproj", "{2119CE89-308D-4932-BFCE-8CDC0A05EB9E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,18 +129,6 @@ Global
{D64AD07C-A711-42D8-8653-EDCD7A825A44}.Release|x64.Build.0 = Release|Any CPU
{D64AD07C-A711-42D8-8653-EDCD7A825A44}.Release|x86.ActiveCfg = Release|Any CPU
{D64AD07C-A711-42D8-8653-EDCD7A825A44}.Release|x86.Build.0 = Release|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Debug|x64.ActiveCfg = Debug|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Debug|x64.Build.0 = Debug|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Debug|x86.ActiveCfg = Debug|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Debug|x86.Build.0 = Debug|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Release|Any CPU.Build.0 = Release|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Release|x64.ActiveCfg = Release|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Release|x64.Build.0 = Release|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Release|x86.ActiveCfg = Release|Any CPU
{E54C7411-6CB4-4AE7-B583-4E669C3C0059}.Release|x86.Build.0 = Release|Any CPU
{B3866EEF-8F46-4302-ABAC-A95EE2F27331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3866EEF-8F46-4302-ABAC-A95EE2F27331}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3866EEF-8F46-4302-ABAC-A95EE2F27331}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -249,6 +237,18 @@ Global
{2119CE89-308D-4932-BFCE-8CDC0A05EB9E}.Release|x64.Build.0 = Release|Any CPU
{2119CE89-308D-4932-BFCE-8CDC0A05EB9E}.Release|x86.ActiveCfg = Release|Any CPU
{2119CE89-308D-4932-BFCE-8CDC0A05EB9E}.Release|x86.Build.0 = Release|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Debug|x64.ActiveCfg = Debug|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Debug|x64.Build.0 = Debug|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Debug|x86.ActiveCfg = Debug|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Debug|x86.Build.0 = Debug|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Release|Any CPU.Build.0 = Release|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Release|x64.ActiveCfg = Release|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Release|x64.Build.0 = Release|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Release|x86.ActiveCfg = Release|Any CPU
{49AA63BF-3DBA-4490-9470-5AE0EB7F49F0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -265,7 +265,6 @@ Global
{86BD3DF6-A3E9-4839-8036-813A20DC8AD6} = {CE64E92B-E088-46FB-9028-7FB6B67DEC55}
{ECCEA352-8953-49D6-8F87-8AB361499420} = {12F8343D-20A6-4E24-B0F5-3A66F2228CF6}
{D64AD07C-A711-42D8-8653-EDCD7A825A44} = {12F8343D-20A6-4E24-B0F5-3A66F2228CF6}
{E54C7411-6CB4-4AE7-B583-4E669C3C0059} = {32F5383E-4201-4527-98DB-40715BB9F574}
{B3866EEF-8F46-4302-ABAC-A95EE2F27331} = {79981A5A-207A-4A16-A21B-5E80394082F6}
{8C7DAF8E-F792-4092-8BBF-31A6B898B39A} = {93324D12-DE1B-4C1B-934A-92AA140FF6F6}
{B15705B5-041C-4F1E-8342-AD03182EDD42} = {93324D12-DE1B-4C1B-934A-92AA140FF6F6}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.ObjectModel;

namespace FSH.Starter.Blazor.Shared;
namespace FSH.Starter.Shared.Authorization;
public static class AppConstants
{
public static readonly Collection<string> SupportedImageFormats = new()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Security.Claims;

namespace FSH.Starter.Blazor.Shared;
namespace FSH.Starter.Shared.Authorization;
public static class ClaimsPrincipalExtensions
{
public static string? GetEmail(this ClaimsPrincipal principal)
=> principal.FindFirstValue(ClaimTypes.Email);

public static string? GetTenant(this ClaimsPrincipal principal)
=> principal.FindFirstValue(IdentityConstants.Claims.Tenant);
=> principal.FindFirstValue(FshClaims.Tenant);

public static string? GetFullName(this ClaimsPrincipal principal)
=> principal?.FindFirst(IdentityConstants.Claims.Fullname)?.Value;
=> principal?.FindFirst(FshClaims.Fullname)?.Value;

public static string? GetFirstName(this ClaimsPrincipal principal)
=> principal?.FindFirst(ClaimTypes.Name)?.Value;
Expand All @@ -26,13 +26,13 @@ public static class ClaimsPrincipalExtensions

public static Uri? GetImageUrl(this ClaimsPrincipal principal)
{
var imageUrl = principal.FindFirstValue(IdentityConstants.Claims.ImageUrl);
var imageUrl = principal.FindFirstValue(FshClaims.ImageUrl);
return Uri.TryCreate(imageUrl, UriKind.Absolute, out var uri) ? uri : null;
}

public static DateTimeOffset GetExpiration(this ClaimsPrincipal principal) =>
DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(
principal.FindFirstValue(IdentityConstants.Claims.Expiration)));
principal.FindFirstValue(FshClaims.Expiration)));

private static string? FindFirstValue(this ClaimsPrincipal principal, string claimType) =>
principal is null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FSH.Starter.Blazor.Shared;
namespace FSH.Starter.Shared.Authorization;
public static class FshActions
{
public const string View = nameof(View);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FSH.Starter.Blazor.Shared;
namespace FSH.Starter.Shared.Authorization;

public static class FshClaims
{
Expand Down
69 changes: 69 additions & 0 deletions src/Shared/Authorization/FshPermissions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Collections.ObjectModel;

namespace FSH.Starter.Shared.Authorization;

public static class FshPermissions
{
private static readonly FshPermission[] allPermissions =
{
//tenants
new("View Tenants", FshActions.View, FshResources.Tenants, IsRoot: true),
new("Create Tenants", FshActions.Create, FshResources.Tenants, IsRoot: true),
new("Update Tenants", FshActions.Update, FshResources.Tenants, IsRoot: true),
new("Upgrade Tenant Subscription", FshActions.UpgradeSubscription, FshResources.Tenants, IsRoot: true),

//identity
new("View Users", FshActions.View, FshResources.Users),
new("Search Users", FshActions.Search, FshResources.Users),
new("Create Users", FshActions.Create, FshResources.Users),
new("Update Users", FshActions.Update, FshResources.Users),
new("Delete Users", FshActions.Delete, FshResources.Users),
new("Export Users", FshActions.Export, FshResources.Users),
new("View UserRoles", FshActions.View, FshResources.UserRoles),
new("Update UserRoles", FshActions.Update, FshResources.UserRoles),
new("View Roles", FshActions.View, FshResources.Roles),
new("Create Roles", FshActions.Create, FshResources.Roles),
new("Update Roles", FshActions.Update, FshResources.Roles),
new("Delete Roles", FshActions.Delete, FshResources.Roles),
new("View RoleClaims", FshActions.View, FshResources.RoleClaims),
new("Update RoleClaims", FshActions.Update, FshResources.RoleClaims),

//products
new("View Products", FshActions.View, FshResources.Products, IsBasic: true),
new("Search Products", FshActions.Search, FshResources.Products, IsBasic: true),
new("Create Products", FshActions.Create, FshResources.Products),
new("Update Products", FshActions.Update, FshResources.Products),
new("Delete Products", FshActions.Delete, FshResources.Products),
new("Export Products", FshActions.Export, FshResources.Products),

//todos
new("View Todos", FshActions.View, FshResources.Todos, IsBasic: true),
new("Search Todos", FshActions.Search, FshResources.Todos, IsBasic: true),
new("Create Todos", FshActions.Create, FshResources.Todos),
new("Update Todos", FshActions.Update, FshResources.Todos),
new("Delete Todos", FshActions.Delete, FshResources.Todos),
new("Export Todos", FshActions.Export, FshResources.Todos),

new("View Hangfire", FshActions.View, FshResources.Hangfire),
new("View Dashboard", FshActions.View, FshResources.Dashboard),

//audit
new("View Audit Trails", FshActions.View, FshResources.AuditTrails),
};

public static IReadOnlyList<FshPermission> All { get; } = new ReadOnlyCollection<FshPermission>(allPermissions);
public static IReadOnlyList<FshPermission> Root { get; } = new ReadOnlyCollection<FshPermission>(allPermissions.Where(p => p.IsRoot).ToArray());
public static IReadOnlyList<FshPermission> Admin { get; } = new ReadOnlyCollection<FshPermission>(allPermissions.Where(p => !p.IsRoot).ToArray());
public static IReadOnlyList<FshPermission> Basic { get; } = new ReadOnlyCollection<FshPermission>(allPermissions.Where(p => p.IsBasic).ToArray());
}

public record FshPermission(string Description, string Action, string Resource, bool IsBasic = false, bool IsRoot = false)
{
public string Name => NameFor(Action, Resource);
public static string NameFor(string action, string resource)
{
return $"Permissions.{resource}.{action}";
}
}


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FSH.Starter.Blazor.Shared;
namespace FSH.Starter.Shared.Authorization;
public static class FshResources
{
public const string Tenants = nameof(Tenants);
Expand All @@ -11,4 +11,5 @@ public static class FshResources
public const string Products = nameof(Products);
public const string Brands = nameof(Brands);
public const string Todos = nameof(Todos);
public const string AuditTrails = nameof(AuditTrails);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.ObjectModel;

namespace FSH.Starter.WebApi.Shared.Authorization;
namespace FSH.Starter.Shared.Authorization;

public static class FshRoles
{
Expand Down
6 changes: 6 additions & 0 deletions src/Shared/Authorization/IdentityConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace FSH.Starter.Shared.Authorization;
public static class IdentityConstants
{
public const int PasswordLength = 6;
public const string SchemaName = "identity";
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace FSH.Framework.Core.Tenant;
namespace FSH.Starter.Shared.Authorization;
public static class TenantConstants
{
public static class Root
{
public const string Id = "root";
public const string Name = "Root";
public const string EmailAddress = "[email protected]";
public const string DefaultProfilePicture = "assets/defaults/profile-picture.webp";
}

public const string DefaultPassword = "123Pa$$word!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FSH.Starter.WebApi.Shared</RootNamespace>
<AssemblyName>FSH.Starter.WebApi.Shared</AssemblyName>
</PropertyGroup>

</Project>
3 changes: 3 additions & 0 deletions src/api/framework/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<ItemGroup>
<Folder Include="Identity\Users\Features\GetRoles\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel;
using FluentValidation;
using FSH.Framework.Core.Tenant;
using FSH.Starter.Shared.Authorization;

namespace FSH.Framework.Core.Identity.Tokens.Features.Generate;
public record TokenGenerationCommand(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FSH.Framework.Core.Identity.Users.Abstractions;
using FSH.Framework.Infrastructure.Identity.Users;
using FSH.Starter.Shared.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using FSH.Framework.Core.Identity.Users.Abstractions;
using FSH.Framework.Infrastructure.Auth.Policy;
using FSH.Framework.Infrastructure.Identity.Users.Endpoints;
using System.Text.Json;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
Expand Down
1 change: 1 addition & 0 deletions src/api/framework/Infrastructure/Identity/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using IdentityConstants = FSH.Starter.Shared.Authorization.IdentityConstants;

namespace FSH.Framework.Infrastructure.Identity;
internal static class Extensions
Expand Down
31 changes: 0 additions & 31 deletions src/api/framework/Infrastructure/Identity/IdentityConstants.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using IdentityConstants = FSH.Starter.Shared.Authorization.IdentityConstants;

namespace FSH.Framework.Infrastructure.Identity.Persistence;

Expand Down
Loading