Skip to content

Commit

Permalink
Add obsidian vault for documentation, rename generic items, update Nu…
Browse files Browse the repository at this point in the history
…Get packages, and fix login on the WebUI
  • Loading branch information
CorruptComputer committed Oct 20, 2024
1 parent 3c1149c commit f730b53
Show file tree
Hide file tree
Showing 75 changed files with 26,263 additions and 416 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet-sonarscanner begin /k:"CorruptComputer_Bones" /o:"corruptcomputer" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths=./Tests/*/*.UnitTests/TestResults/*/coverage.opencover.xml
dotnet-sonarscanner begin /k:"CorruptComputer_Bones" /o:"corruptcomputer" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths=./Tests/*/*.UnitTests/TestResults/*/coverage.opencover.xml /d:sonar.scanner.scanAll=false
dotnet build --no-incremental
dotnet test --no-build --collect:"XPlat Code Coverage;Format=opencover"
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
8 changes: 8 additions & 0 deletions .vscode/Bones.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {}
}
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch and Debug Standalone Blazor WebAssembly App",
"type": "blazorwasm",
"request": "launch",
"cwd": "${workspaceFolder}/Frontend/Bones.WebUI"
},
{
"name": "C#: Bones.BackgroundService Debug",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/Backend/Bones.BackgroundService/Bones.BackgroundService.csproj",
},
{
"name": "C#: Bones.Api Debug",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/Backend/Bones.Api/Bones.Api.csproj",
}
]
}
10 changes: 5 additions & 5 deletions Backend/Bones.Api/Bones.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="6.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="6.9.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.9.0" />
</ItemGroup>

<Target Name="CreateSwaggerJson" AfterTargets="Build" Condition="$(Configuration) == 'Debug'">
Expand Down
57 changes: 13 additions & 44 deletions Backend/Bones.Api/Controllers/AccountManagementController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.ComponentModel.DataAnnotations;
using Bones.Api.Models;
using Bones.Backend.Features.AccountManagement.ConfirmEmail;
using Bones.Backend.Features.AccountManagement.GetUserByClaimsPrincipal;
using Bones.Backend.Features.AccountManagement.QueueForgotPasswordEmail;
using Bones.Backend.Features.AccountManagement.QueueResendConfirmationEmail;
using Bones.Backend.Features.AccountManagement.RegisterUser;
Expand Down Expand Up @@ -86,6 +85,10 @@ public async Task<ActionResult> LoginAsync([FromBody] LoginUserApiRequest login)
{
result = await signInManager.TwoFactorRecoveryCodeSignInAsync(login.TwoFactorRecoveryCode);
}
else
{
return Unauthorized(EmptyResponse.Value);
}
}

if (!result.Succeeded)
Expand Down Expand Up @@ -118,23 +121,17 @@ public async Task<ActionResult> ConfirmEmailAsync([FromQuery][Required] Guid use
return Ok(EmptyResponse.Value);
}

/// <summary>
///
/// </summary>
/// <param name="Email"></param>
public sealed record ResendConfirmationEmailApiRequest([Required] string Email);

/// <summary>
/// Re-queues the confirmation email to send
/// </summary>
/// <param name="resendRequest"></param>
/// <param name="email"></param>
/// <returns></returns>
[HttpPost("resend-confirmation-email", Name = "ResendConfirmationEmailAsync")]
[ProducesResponseType<ActionResult<EmptyResponse>>(StatusCodes.Status200OK)]
[AllowAnonymous]
public async Task<ActionResult> ResendConfirmationEmailAsync([FromBody][Required] ResendConfirmationEmailApiRequest resendRequest)
public async Task<ActionResult> ResendConfirmationEmailAsync([FromQuery][Required] string email)
{
CommandResponse result = await Sender.Send(new QueueResendConfirmationEmailCommand(resendRequest.Email));
CommandResponse result = await Sender.Send(new QueueResendConfirmationEmailCommand(email));

if (!result.Success)
{
Expand Down Expand Up @@ -183,48 +180,20 @@ public ActionResult LogoutAsync()
/// </summary>
/// <param name="Email"></param>
/// <param name="DisplayName"></param>
public record GetMyBasicInfoResponse(string? Email, string? DisplayName);
public record GetMyBasicInfoResponse(string Email, string DisplayName);

/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet("my/basic-info", Name = "GetMyBasicInfoAsync")]
[ProducesResponseType<ActionResult<GetMyBasicInfoResponse>>(StatusCodes.Status200OK)]
[ProducesResponseType<GetMyBasicInfoResponse>(StatusCodes.Status200OK)]
public async Task<ActionResult> GetMyBasicInfoAsync()
{
QueryResponse<BonesUser> user = await Sender.Send(new GetUserByClaimsPrincipalQuery(User));

if (!user.Success || user.Result == null)
{
return Unauthorized(EmptyResponse.Value);
}

return Ok(new GetMyBasicInfoResponse(user.Result.Email, user.Result.DisplayName));
}

private static Dictionary<string, string[]> ReadErrorsFromIdentityResult(IdentityResult result)
{
Dictionary<string, string[]> errorDictionary = new();

foreach (IdentityError error in result.Errors)
{
string[] newDescriptions;

if (errorDictionary.TryGetValue(error.Code, out string[]? descriptions))
{
newDescriptions = new string[descriptions.Length + 1];
Array.Copy(descriptions, newDescriptions, descriptions.Length);
newDescriptions[descriptions.Length] = error.Description;
}
else
{
newDescriptions = [error.Description];
}

errorDictionary[error.Code] = newDescriptions;
}
BonesUser user = await GetCurrentBonesUserAsync();

return errorDictionary;
return Ok(new GetMyBasicInfoResponse(
user.Email ?? string.Empty,
user.DisplayName ?? user.Email ?? string.Empty));
}
}
31 changes: 31 additions & 0 deletions Backend/Bones.Api/Controllers/BonesControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Bones.Database.DbSets.AccountManagement;
using Bones.Shared.Exceptions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;

namespace Bones.Api.Controllers;
Expand Down Expand Up @@ -39,4 +40,34 @@ protected async Task<BonesUser> GetCurrentBonesUserAsync()
// I don't think this should really happen, if their claims principal was invalid the auth should have stopped the request already
return user ?? throw new ForbiddenAccessException();
}

/// <summary>
/// Gets the errors from an IdentityResult in a format that we can return.
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
protected static Dictionary<string, string[]> ReadErrorsFromIdentityResult(IdentityResult result)
{
Dictionary<string, string[]> errorDictionary = new();

foreach (IdentityError error in result.Errors)
{
string[] newDescriptions;

if (errorDictionary.TryGetValue(error.Code, out string[]? descriptions))
{
newDescriptions = new string[descriptions.Length + 1];
Array.Copy(descriptions, newDescriptions, descriptions.Length);
newDescriptions[descriptions.Length] = error.Description;
}
else
{
newDescriptions = [error.Description];
}

errorDictionary[error.Code] = newDescriptions;
}

return errorDictionary;
}
}
46 changes: 11 additions & 35 deletions Backend/Bones.Api/OpenApi/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,17 @@
],
"summary": "Re-queues the confirmation email to send",
"operationId": "ResendConfirmationEmailAsync",
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ResendConfirmationEmailApiRequest"
}
"parameters": [
{
"name": "email",
"in": "query",
"description": "",
"required": true,
"schema": {
"type": "string"
}
},
"required": true
},
}
],
"responses": {
"401": {
"description": "Unauthorized",
Expand Down Expand Up @@ -444,7 +444,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetMyBasicInfoResponseActionResult"
"$ref": "#/components/schemas/GetMyBasicInfoResponse"
}
}
}
Expand Down Expand Up @@ -678,18 +678,6 @@
"additionalProperties": false,
"description": ""
},
"GetMyBasicInfoResponseActionResult": {
"type": "object",
"properties": {
"result": {
"$ref": "#/components/schemas/ActionResult"
},
"value": {
"$ref": "#/components/schemas/GetMyBasicInfoResponse"
}
},
"additionalProperties": false
},
"LoginUserApiRequest": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -734,18 +722,6 @@
"additionalProperties": false,
"description": "Request to register a new user"
},
"ResendConfirmationEmailApiRequest": {
"type": "object",
"properties": {
"email": {
"type": "string",
"description": "",
"nullable": true
}
},
"additionalProperties": false,
"description": ""
},
"StringStringArrayDictionaryActionResult": {
"type": "object",
"properties": {
Expand Down
4 changes: 2 additions & 2 deletions Backend/Bones.Backend/Bones.Backend.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.10" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task<CommandResponse> Handle(QueueForgotPasswordEmailCommand reques
BonesUser? user = await userManager.FindByEmailAsync(request.Email);
if (user is not null && await userManager.IsEmailConfirmedAsync(user))
{
string? code = await userManager.GeneratePasswordResetTokenAsync(user);
string code = await userManager.GeneratePasswordResetTokenAsync(user);
code = code.Base64UrlSafeEncode();

// Generate ResetPassword URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ namespace Bones.Backend.Features.ProjectManagement.WorkItems.CreateWorkItem;
/// </summary>
/// <param name="Name">Name of the item</param>
/// <param name="QueueId">Internal ID of the queue this item is in</param>
/// <param name="WorkItemLayoutVersionId">Internal ID of the layout version this item is using</param>
/// <param name="Values">Internal ID of the queue</param>
public sealed record CreateWorkItemCommand(string Name, Guid QueueId, Guid WorkItemLayoutVersionId, Dictionary<string, object> Values) : IRequest<CommandResponse>;
/// <param name="ItemLayoutId">Internal ID of the layout this item is using</param>
public sealed record CreateWorkItemCommand(string Name, Guid QueueId, Guid ItemLayoutId) : IRequest<CommandResponse>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ internal sealed class CreateWorkItemHandler(ISender sender) : IRequestHandler<Cr
{
public async Task<CommandResponse> Handle(CreateWorkItemCommand request, CancellationToken cancellationToken)
{
return await sender.Send(new CreateWorkItemDbCommand(request.Name, request.QueueId, request.WorkItemLayoutVersionId, request.Values), cancellationToken);
return await sender.Send(new CreateWorkItemDbCommand(request.Name, request.QueueId, request.ItemLayoutId), cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>

Expand Down
20 changes: 0 additions & 20 deletions Backend/Bones.BackgroundTasks/Bones.BackgroundTasks.csproj

This file was deleted.

3 changes: 0 additions & 3 deletions Backend/Bones.BackgroundTasks/GlobalUsings.cs

This file was deleted.

10 changes: 5 additions & 5 deletions Backend/Bones.Database/Bones.Database.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit f730b53

Please sign in to comment.