Skip to content

Commit

Permalink
all template test cases pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Sep 6, 2024
1 parent 7bfada3 commit 79536b7
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 41 deletions.
52 changes: 37 additions & 15 deletions templates/Coalesce.Vue.Template/TestLocal.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
$dir = $PSScriptRoot
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $false

dotnet new uninstall IntelliTect.Coalesce.Vue.Template
Remove-Item -Path "$dir/IntelliTect.Coalesce.Vue.*.nupkg"
Remove-Item -Path "$dir/IntelliTect.Coalesce.Vue.Template.*.nupkg" -ErrorAction SilentlyContinue

dotnet pack -o $dir/.
$PSNativeCommandUseErrorActionPreference = $true

dotnet new install $(Get-ChildItem -Path "IntelliTect.Coalesce.Vue.*.nupkg").Name
dotnet pack $(Get-ChildItem -Path "$dir/*.csproj") -o $dir/.

dotnet new install $(Get-ChildItem -Path "$dir/IntelliTect.Coalesce.Vue.Template.*.nupkg").FullName

rm $dir/Test.Template.Instance/* -Recurse
dotnet new coalescevue --help
dotnet new coalescevue -o $dir/Test.Template.Instance

Push-Location $dir/Test.Template.Instance/*.Web
try {
dotnet restore
dotnet coalesce
npm ci
npm run build
dotnet build
} finally {
Pop-Location

$testCases =
# Nothing:
"",
# Everything:
"--Identity --MicrosoftAuth --GoogleAuth --UserPictures --AuditLogs --ExampleModel --DarkMode --TrackingBase --AppInsights --OpenAPI",
# Assorted partial variants:
"--Identity --UserPictures --TrackingBase"

foreach ($testCase in $testCases) {
echo "----------------------"
echo "-------TEST CASE------"
echo "----------------------"
echo (!$testCase ? "<no options enabled>" : $testCase);
echo ""

rm $dir/Test.Template.Instance/* -Recurse
Invoke-Expression "dotnet new coalescevue -o $dir/Test.Template.Instance $testcase"

Push-Location $dir/Test.Template.Instance/*.Web
try {
dotnet restore
dotnet coalesce
npm ci
npm run build
dotnet build
}
finally {
Pop-Location
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"**/SignIn.cshtml",
"**/SignIn.cshtml.cs",
"**/AppClaimTypes.cs",
"**/ClaimsPrincipalExtensions.cs",
"**/ClaimsPrincipalFactory.cs",
"**/Permission.cs",
"**/User.cs",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace Coalesce.Starter.Vue.Data.Utilities;
namespace Coalesce.Starter.Vue.Data.Auth;

public static class ClaimsPrincipalExtensions
{
#if Identity
public static string? GetUserId(this ClaimsPrincipal user)
=> user.FindFirstValue(AppClaimTypes.UserId);

Expand All @@ -13,4 +14,13 @@ public static class ClaimsPrincipalExtensions

public static bool Can(this ClaimsPrincipal user, params Permission[] permissions)
=> permissions.Any(p => user.HasClaim(AppClaimTypes.Permission, p.ToString()));

#else

public static string? GetUserId(this ClaimsPrincipal user)
=> user.FindFirstValue(ClaimTypes.NameIdentifier);

public static string? GetUserName(this ClaimsPrincipal user)
=> user.FindFirstValue(ClaimTypes.Name);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
/// </summary>
public enum Permission
{
// Note about usage of Permission values:
// The numeric values are stored in the database on `Role.Permissions`.
// The string value are stored in the user claims,
// issused by `ClaimsPrincipalFactory` and consumed by role-based security attributes with `nameof`.

// Therefore, use caution and avoid editing existing roles.
// Always assign new roles the next highest value, never reusing old numbers.

[Display(Name = "Admin - General", Description = "Modify application configuration and other administrative functions excluding user/role management.")]
Admin = 1,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Coalesce.Starter.Vue.Data.Utilities;


namespace Coalesce.Starter.Vue.Data.Auth;

[Coalesce, Service]
Expand All @@ -10,10 +9,10 @@ public UserInfo WhoAmI(ClaimsPrincipal user)
{
return new UserInfo
{
#if Identity
Id = user.GetUserId(),
UserName = user.GetUserName(),

#if Identity
Email = user.GetEmail(),
FullName = user.FindFirstValue(AppClaimTypes.FullName),

Expand All @@ -26,6 +25,9 @@ public UserInfo WhoAmI(ClaimsPrincipal user)
.Where(c => c.Type == AppClaimTypes.Permission)
.Select(c => c.Value)
.ToList(),
#else
Id = user.FindFirstValue(ClaimTypes.NameIdentifier),
UserName = user.Identity?.Name,
#endif
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Coalesce.Starter.Vue.Data.Models;
using Coalesce.Starter.Vue.Data.Auth;
using Coalesce.Starter.Vue.Data.Models;
using IntelliTect.Coalesce.AuditLogging;
using IntelliTect.Coalesce.Utilities;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore.ChangeTracking;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IntelliTect.Coalesce.Utilities;
using Coalesce.Starter.Vue.Data.Auth;
using IntelliTect.Coalesce.Utilities;

namespace Coalesce.Starter.Vue.Data.Models;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Coalesce.Starter.Vue.Data.Auth;
using Coalesce.Starter.Vue.Data.Coalesce;
using IntelliTect.Coalesce.Helpers;
using IntelliTect.Coalesce.Utilities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Coalesce.Starter.Vue.Data.Utilities;
using Coalesce.Starter.Vue.Data.Auth;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
"Authentication": {
//#if MicrosoftAuth
"Microsoft": {
// Configuration instructions: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/microsoft-logins
"ClientId": "",
"ClientSecret": ""
},
//#endif
//#if GoogleAuth
"Google": {
// Configuration instructions: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins
"ClientId": "",
"ClientSecret": ""
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.6.0",
"@microsoft/applicationinsights-web": "^3.3.2",
"@vueuse/core": "^11.0.3",
"coalesce-vue": "5.0.0-ci.20240830.2",
"coalesce-vue-vuetify3": "5.0.0-ci.20240830.2",
"coalesce-vue": "5.0.0-ci.20240905.3",
"coalesce-vue-vuetify3": "5.0.0-ci.20240905.3",
"typeface-roboto": "1.1.13",
"vue": "^3.5.0",
"vue-router": "^4.4.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ document.addEventListener(
refreshUserInfo();

// Make useful properties available in vue <template>s
declare module "@vue/runtime-core" {
declare module "vue" {
interface ComponentCustomProperties {
//#if Identity
Permission: typeof Permission;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
</template>

<template #text>
<!-- This is deliberately off the bottom of the screen for mild obscurity -->
<h3
v-if="permissions?.length"
class="text-center text-body-2 my-3 font-weight-light"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>5.5</TypeScriptToolsVersion>

<CoalesceVersion>5.0.0-ci.20240828.1</CoalesceVersion>
<CoalesceVersion>5.0.0-ci.20240905.3</CoalesceVersion>

<!--#if (KeepTemplateOnly) -->
<DefineConstants>KeepTemplateOnly;AppInsights;OpenAPI;Identity;MicrosoftAuth;GoogleAuth;AuditLogs;UserPictures;TrackingBase;ExampleModel</DefineConstants>
Expand Down

0 comments on commit 79536b7

Please sign in to comment.