Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d58cefd
chore(auth): added clearly defined permissions
infirit89 Jul 14, 2025
6bbbed1
added authorization handler interface
infirit89 Jul 16, 2025
20df7ba
(BROKEN DOES NOT BUILD) started new authorization system refactor
infirit89 Aug 4, 2025
6d15573
(BROKEN DOES NOT BUILD) refactored queries to use the new auth system
infirit89 Aug 5, 2025
a31b189
fixed compilation of application layer
infirit89 Aug 5, 2025
8de4799
added unit tests for the authorization handlers
infirit89 Aug 7, 2025
e5a5d4e
moved some helper functions to more appropriate places
infirit89 Aug 7, 2025
bdab273
optimized queries made by auth handlers
infirit89 Aug 7, 2025
4e0ede1
added occuapnt authorization handler tests
infirit89 Aug 8, 2025
0b49c38
fixed delete user and entrance command handler tests
infirit89 Aug 8, 2025
9e3fcb1
reworked occupant auth handler, reimplemented a bunch of tests
infirit89 Aug 10, 2025
7473b51
added codeowners
infirit89 Aug 10, 2025
32fed79
Merge branch 'main' into authorization-refactor
infirit89 Aug 10, 2025
7c2c1ad
fixed AddAuthorizersFromAssembly adding the DefaultAuthorizationHandl…
infirit89 Aug 10, 2025
83ad91b
Merge branch 'authorization-refactor' of github.com:infirit89/Condomi…
infirit89 Aug 10, 2025
344a7f4
fixed AddAuthorizersFromAssembly adding the wrong interface
infirit89 Aug 10, 2025
42452d4
changed buildings route to entrances; fixed client to work with new a…
infirit89 Aug 12, 2025
27019ec
(BROKEN DOES NOT BUILD) started refactoring the client's authorizatio…
infirit89 Aug 31, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,6 @@ appsettings.json
# MacOs
.DS_Store


#Claude
CLAUDE.md
9 changes: 4 additions & 5 deletions backend/ECondo.Api/Controllers/PropertyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
using ECondo.Application.Commands.Properties.Create;
using ECondo.Application.Commands.Properties.Delete;
using ECondo.Application.Commands.Properties.Update;
using ECondo.Application.Data;
using ECondo.Application.Data.Property;
using ECondo.Application.Queries.Properties.GetAll;
using ECondo.Application.Queries.Properties.GetById;
using ECondo.Application.Queries.Properties.GetForUser;
using ECondo.Application.Queries.Properties.GetInBuilding;
using ECondo.Application.Queries.Properties.GetInEntrance;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -19,15 +18,15 @@ namespace ECondo.Api.Controllers;
public class PropertyController(ISender sender) : ControllerBase
{
[Authorize]
[HttpGet(nameof(GetPropertiesInBuilding))]
[HttpGet(nameof(GetPropertiesInEntrance))]
[ProducesResponseType(StatusCodes.Status200OK,
Type = typeof(PagedListResponse<PropertyOccupantResult>))]
[ProducesResponseType(StatusCodes.Status400BadRequest,
Type = typeof(HttpValidationProblemDetails))]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IResult>
GetPropertiesInBuilding(
[FromQuery] GetPropertiesInBuildingQuery request)
GetPropertiesInEntrance(
[FromQuery] GetPropertiesInEntranceQuery request)
{
var result = await sender.Send(request);

Expand Down
2 changes: 1 addition & 1 deletion backend/ECondo.Api/Extensions/ApiErrorExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Http.HttpResults;
using System.Diagnostics;
using ECondo.Domain.Shared;
using ECondo.SharedKernel.Result;

namespace ECondo.Api.Extensions;
public static class ApiErrorExtension
Expand Down
2 changes: 1 addition & 1 deletion backend/ECondo.Api/Extensions/CustomResults.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ECondo.Domain.Shared;
using ECondo.SharedKernel.Result;

namespace ECondo.Api.Extensions;

Expand Down
2 changes: 1 addition & 1 deletion backend/ECondo.Api/Extensions/PagedListExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ECondo.Domain.Shared;
using ECondo.SharedKernel.Collections;

namespace ECondo.Api.Extensions;

Expand Down
2 changes: 1 addition & 1 deletion backend/ECondo.Api/Extensions/ResultExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ECondo.Domain.Shared;
using ECondo.SharedKernel.Result;

namespace ECondo.Api.Extensions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using ECondo.Application.Commands.PropertyOccupants.AcceptInvitation;
using ECondo.Application.Repositories;
using ECondo.Application.Services;
using ECondo.Domain;
using ECondo.Domain.Buildings;
using ECondo.Domain.Shared;
using ECondo.Domain.Users;
using ECondo.Infrastructure.Contexts;
using ECondo.SharedKernel.Result;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using NSubstitute;
using Xunit;

namespace ECondo.Application.IntegrationTests.Commands.PropertyOccupants.AcceptInvitation;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
using ECondo.Application.Commands.PropertyOccupants.AddToProperty;
using ECondo.Application.Events.PropertyOccupant;
using ECondo.Application.Repositories;
using ECondo.Domain;
using ECondo.Domain.Buildings;
using ECondo.Domain.Shared;
using ECondo.Infrastructure.Contexts;
using ECondo.SharedKernel.Result;
using FluentAssertions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using NSubstitute;
using Xunit;

namespace ECondo.Application.IntegrationTests.Commands.PropertyOccupants.AddToProperty;

public class AddOccupantToPropertyCommandHandlerTests
{
private readonly IApplicationDbContext _dbContext;
private readonly IPublisher _publisher;
private readonly AddOccupantToPropertyCommandHandler _handler;

public AddOccupantToPropertyCommandHandlerTests()
Expand All @@ -26,8 +22,8 @@ public AddOccupantToPropertyCommandHandlerTests()
.Options;

_dbContext = new ECondoDbContext(options);
_publisher = Substitute.For<IPublisher>();
_handler = new AddOccupantToPropertyCommandHandler(_dbContext, _publisher);
var publisher = Substitute.For<IPublisher>();
_handler = new AddOccupantToPropertyCommandHandler(_dbContext, publisher);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using ECondo.Application.Commands.Payment.ConnectStripeAccount;
using ECondo.Application.Repositories;
using ECondo.Application.Services;
using ECondo.Domain;
using ECondo.Domain.Buildings;
using ECondo.Domain.Shared;
using ECondo.Infrastructure.Contexts;
using ECondo.SharedKernel.Result;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using NSubstitute;
using Xunit;

namespace ECondo.Application.IntegrationTests.Commands.Payment.ConnectStripeAccount;


public class ConnectStripeAccountCommandHandlerTests
{
private readonly IApplicationDbContext _dbContext;
Expand All @@ -33,12 +32,11 @@ public ConnectStripeAccountCommandHandlerTests()
public async Task Handle_ShouldConnectStripeAccount_WhenValid()
{
// Arrange
var buildingId = Guid.NewGuid();
var entranceId = Guid.NewGuid();
var entrance = new Entrance
{
Id = Guid.NewGuid(),
BuildingId = buildingId,
Number = "Entrance1"
Id = entranceId,
Number = "1",
};

_dbContext.Entrances.Add(entrance);
Expand All @@ -52,8 +50,7 @@ public async Task Handle_ShouldConnectStripeAccount_WhenValid()
.Returns(onboardingLink);

var command = new ConnectStripeAccountCommand(
buildingId,
"Entrance1",
entranceId,
"https://example.com/return"
);

Expand All @@ -74,12 +71,11 @@ public async Task Handle_ShouldConnectStripeAccount_WhenValid()
public async Task Handle_ShouldUpdateDatabaseCorrectly_WhenStripeAccountConnected()
{
// Arrange
var buildingId = Guid.NewGuid();
var entranceId = Guid.NewGuid();
var entrance = new Entrance
{
Id = Guid.NewGuid(),
BuildingId = buildingId,
Number = "Entrance1"
Id = entranceId,
Number = "1",
};

_dbContext.Entrances.Add(entrance);
Expand All @@ -93,8 +89,7 @@ public async Task Handle_ShouldUpdateDatabaseCorrectly_WhenStripeAccountConnecte
.Returns(onboardingLink);

var command = new ConnectStripeAccountCommand(
buildingId,
"Entrance1",
entranceId,
"https://example.com/return"
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using ECondo.Application.Commands.Payment.CreateBill;
using ECondo.Application.Repositories;
using ECondo.Application.Services;
using ECondo.Domain;
using ECondo.Domain.Buildings;
using ECondo.Domain.Payments;
using ECondo.Domain.Shared;
using ECondo.Infrastructure.Contexts;
using ECondo.SharedKernel.Result;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using NSubstitute;
using Xunit;

namespace ECondo.Application.IntegrationTests.Commands.Payment.CreateBill;

Expand All @@ -34,11 +32,10 @@ public CreateBillCommandHandlerTests()
public async Task Handle_ShouldCreateBill_WhenValid()
{
// Arrange
var buildingId = Guid.NewGuid();
var entrance = new Entrance
{
Id = Guid.NewGuid(),
BuildingId = buildingId,
BuildingId = Guid.NewGuid(),
Number = "Entrance1"
};

Expand All @@ -48,8 +45,7 @@ public async Task Handle_ShouldCreateBill_WhenValid()
_userContext.UserId.Returns(Guid.NewGuid());

var command = new CreateBillCommand(
buildingId,
"Entrance1",
entrance.Id,
"Test Bill",
"Test Description",
100.0m,
Expand All @@ -65,7 +61,9 @@ public async Task Handle_ShouldCreateBill_WhenValid()
// Assert
result.IsOk().Should().BeTrue();

var createdBill = await _dbContext.Bills.FirstOrDefaultAsync(b => b.Title == "Test Bill");
var createdBill = await _dbContext
.Bills
.FirstOrDefaultAsync(b => b.Title == "Test Bill");
createdBill.Should().NotBeNull();
createdBill!.Amount.Should().Be(100.0m);
createdBill.IsRecurring.Should().BeFalse();
Expand All @@ -75,11 +73,10 @@ public async Task Handle_ShouldCreateBill_WhenValid()
public async Task Handle_ShouldGeneratePayments_ForOneTimeBill()
{
// Arrange
var buildingId = Guid.NewGuid();
var entrance = new Entrance
{
Id = Guid.NewGuid(),
BuildingId = buildingId,
BuildingId = Guid.NewGuid(),
Number = "Entrance1"
};

Expand All @@ -105,8 +102,7 @@ public async Task Handle_ShouldGeneratePayments_ForOneTimeBill()
_userContext.UserId.Returns(Guid.NewGuid());

var command = new CreateBillCommand(
buildingId,
"Entrance1",
entrance.Id,
"One-Time Bill",
"Test Description",
200.0m,
Expand All @@ -122,7 +118,12 @@ public async Task Handle_ShouldGeneratePayments_ForOneTimeBill()
// Assert
result.IsOk().Should().BeTrue();

var payments = await _dbContext.Payments.Where(p => p.BillId == result.ToSuccess().Data).ToListAsync();
var payments = await _dbContext
.Payments
.Where(p =>
p.BillId == result.ToSuccess().Data)
.ToListAsync();

payments.Should().HaveCount(2);
payments.All(p => p.AmountPaid == 100.0m).Should().BeTrue();
}
Expand All @@ -131,11 +132,10 @@ public async Task Handle_ShouldGeneratePayments_ForOneTimeBill()
public async Task Handle_ShouldNotGeneratePayments_ForRecurringBill()
{
// Arrange
var buildingId = Guid.NewGuid();
var entrance = new Entrance
{
Id = Guid.NewGuid(),
BuildingId = buildingId,
BuildingId = Guid.NewGuid(),
Number = "Entrance1"
};

Expand All @@ -145,8 +145,7 @@ public async Task Handle_ShouldNotGeneratePayments_ForRecurringBill()
_userContext.UserId.Returns(Guid.NewGuid());

var command = new CreateBillCommand(
buildingId,
"Entrance1",
entrance.Id,
"Recurring Bill",
"Test Description",
300.0m,
Expand All @@ -162,7 +161,11 @@ public async Task Handle_ShouldNotGeneratePayments_ForRecurringBill()
// Assert
result.IsOk().Should().BeTrue();

var payments = await _dbContext.Payments.Where(p => p.BillId == result.ToSuccess().Data).ToListAsync();
var payments = await _dbContext
.Payments
.Where(p =>
p.BillId == result.ToSuccess().Data)
.ToListAsync();
payments.Should().BeEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using ECondo.Application.Commands.Payment.CreateIntent;
using ECondo.Application.Repositories;
using ECondo.Application.Services;
using ECondo.Domain;
using ECondo.Domain.Buildings;
using ECondo.Domain.Shared;
using ECondo.Infrastructure.Contexts;
using ECondo.SharedKernel.Result;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using NSubstitute;
using Xunit;

namespace ECondo.Application.IntegrationTests.Commands.Payment.CreateIntent;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using ECondo.Application.Commands.Profiles.Create;
using ECondo.Application.Repositories;
using ECondo.Application.Services;
using ECondo.Domain.Profiles;
using ECondo.Domain.Shared;
using ECondo.Domain.Users;
using ECondo.Infrastructure.Contexts;
using ECondo.SharedKernel.Result;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using NSubstitute;
using Xunit;

namespace ECondo.Application.IntegrationTests.Commands.Profiles.Create;

Expand Down
Loading