Skip to content

Commit

Permalink
Add basic authorization attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
carlsixsmith-moj committed Jun 3, 2024
1 parent 02c0e5b commit faee01a
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Cfo.Cats.Application.Features.Assessments.DTOs;
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.Assessments.DTOs;

namespace Cfo.Cats.Application.Features.Assessments.PostAssessmentCommand;

[RequestAuthorize(Roles = "Admin, Basic")]
public record PostAssessmentCommand(AssessmentDto assessment) : IRequest<bool>;
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Cfo.Cats.Application.Features.Assessments.Caching;
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.Assessments.Caching;
using Cfo.Cats.Application.Features.Assessments.DTOs;

namespace Cfo.Cats.Application.Features.Assessments.Queries.GetAssessment;


[RequestAuthorize(Roles = "Admin, Basic")]
public class GetAssessmentQuery : ICacheableRequest<Result<AssessmentDto>>
{
public string CacheKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Cfo.Cats.Application.Features.AuditTrails.Caching;
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.AuditTrails.Caching;
using Cfo.Cats.Application.Features.AuditTrails.DTOs;
using Cfo.Cats.Application.Features.AuditTrails.Specifications;
using DocumentFormat.OpenXml.Wordprocessing;

namespace Cfo.Cats.Application.Features.AuditTrails.Queries.PaginationQuery;

[RequestAuthorize(Roles = "Admin")]
public class AuditTrailsWithPaginationQuery
: AuditTrailAdvancedFilter,
ICacheableRequest<PaginatedData<AuditTrailDto>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cfo.Cats.Application.Features.Candidates.Queries.Search;

[RequestAuthorize(Roles = "Admin, Basic")]
public class CandidateSearchQuery : ICacheableRequest<IEnumerable<CandidateDto>>
{
public required string ExternalIdentifier { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Cfo.Cats.Application.Features.Documents.Caching;
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.Documents.Caching;

namespace Cfo.Cats.Application.Features.Documents.Commands.Upload;

[RequestAuthorize(Roles = "Admin, Basic")]
public class UploadDocumentCommand : ICacheInvalidatorRequest<Result<Guid>>
{
public string CacheKey { get; } = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.KeyValues.Caching;
using Cfo.Cats.Application.Features.KeyValues.DTOs;

namespace Cfo.Cats.Application.Features.KeyValues.Commands.AddEdit;

[RequestAuthorize(Roles = "Admin, Basic")]
public class AddEditKeyValueCommand : ICacheInvalidatorRequest<Result<int>>
{
[Description("Id")] public int Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.KeyValues.Caching;

namespace Cfo.Cats.Application.Features.KeyValues.Commands.Delete;

[RequestAuthorize(Roles = "Admin, Basic")]
public class DeleteKeyValueCommand : ICacheInvalidatorRequest<Result<int>>
{
public DeleteKeyValueCommand(int[] id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Cfo.Cats.Application.Common.Security;

namespace Cfo.Cats.Application.Features.KeyValues.Commands.Import;

[RequestAuthorize(Roles = "Admin, Basic")]
public record CreateKeyValueTemplateCommand : IRequest<byte[]>
{
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.KeyValues.Caching;

namespace Cfo.Cats.Application.Features.KeyValues.Commands.Import;

[RequestAuthorize(Roles = "Admin")]
public class ImportKeyValuesCommand : ICacheInvalidatorRequest<Result>
{
public ImportKeyValuesCommand(string fileName, byte[] data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.KeyValues.Caching;
using Cfo.Cats.Application.Features.KeyValues.DTOs;

namespace Cfo.Cats.Application.Features.KeyValues.Queries.ByName;

[RequestAuthorize(Roles = "Admin, Basic")]
public class KeyValuesQueryByName : ICacheableRequest<IEnumerable<KeyValueDto>>
{
public KeyValuesQueryByName(Picklist name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Cfo.Cats.Application.Common.Security;

namespace Cfo.Cats.Application.Features.KeyValues.Queries.Export;

[RequestAuthorize(Roles = "Admin, Basic")]
public class ExportKeyValuesQuery : IRequest<byte[]>
{
public string? Keyword { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.KeyValues.Caching;
using Cfo.Cats.Application.Features.KeyValues.DTOs;

namespace Cfo.Cats.Application.Features.KeyValues.Queries.GetAll;

[RequestAuthorize(Roles = "Admin, Basic")]
public class GetAllKeyValuesQuery : ICacheableRequest<IEnumerable<KeyValueDto>>
{
public string CacheKey => KeyValueCacheKey.GetAllCacheKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@


using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.KeyValues.Caching;
using Cfo.Cats.Application.Features.KeyValues.DTOs;
using Cfo.Cats.Application.Features.KeyValues.Specifications;

namespace Cfo.Cats.Application.Features.KeyValues.Queries.PaginationQuery;

[RequestAuthorize(Roles = "Admin, Basic")]
public class KeyValuesWithPaginationQuery : KeyValueAdvancedFilter, ICacheableRequest<PaginatedData<KeyValueDto>>
{
public KeyValueAdvancedSpecification Specification => new(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Cfo.Cats.Application.Features.Locations.Queries.GetAll;

[RequestAuthorize(Roles = "Admin, Basic")]
public class GetAllLocationsQuery : ICacheableRequest<Result<LocationDto[]>>
{
public required UserProfile UserProfile { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Cfo.Cats.Application.Features.Participants.Commands.Enrol;

[RequestAuthorize(Roles = "Admin, Basic")]
public class EnrolParticipantCommand : ICacheInvalidatorRequest<Result<string>>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Cfo.Cats.Application.Features.Tenants.Caching;
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.Tenants.Caching;
using Cfo.Cats.Application.Features.Tenants.DTOs;
using Cfo.Cats.Domain.Entities.Administration;

namespace Cfo.Cats.Application.Features.Tenants.Commands.AddEdit;

[RequestAuthorize(Roles = "Admin")]
public class AddEditTenantCommand : ICacheInvalidatorRequest<Result<string>>
{
[Description("Tenant Id")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Cfo.Cats.Application.Features.Tenants.Caching;
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.Tenants.Caching;

namespace Cfo.Cats.Application.Features.Tenants.Commands.Delete;

[RequestAuthorize(Roles = "Admin")]
public class DeleteTenantCommand : ICacheInvalidatorRequest<Result<int>>
{
public DeleteTenantCommand(string[] id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.Tenants.Specifications;

namespace Cfo.Cats.Application.Features.Tenants.Queries.Export;

[RequestAuthorize(Roles = "Admin")]
public class ExportTenantsQuery : TenantAdvancedFilter, IRequest<Result<byte[]>>
{
public TenantAdvancedSpecification Specification => new(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Cfo.Cats.Application.Features.Tenants.Caching;
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.Tenants.Caching;
using Cfo.Cats.Application.Features.Tenants.DTOs;

namespace Cfo.Cats.Application.Features.Tenants.Queries.GetAll;

[RequestAuthorize(Roles = "Admin, Basic")]
public class GetAllTenantsQuery : ICacheableRequest<IEnumerable<TenantDto>>
{
public string CacheKey => TenantCacheKey.GetAllCacheKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Cfo.Cats.Application.Features.Tenants.Caching;
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Features.Tenants.Caching;
using Cfo.Cats.Application.Features.Tenants.DTOs;
using DocumentFormat.OpenXml.Wordprocessing;

namespace Cfo.Cats.Application.Features.Tenants.Queries.Pagination;

[RequestAuthorize(Roles = "Admin, Basic")]
public class TenantsWithPaginationQuery
: PaginationFilter,
ICacheableRequest<PaginatedData<TenantDto>>
Expand Down
5 changes: 3 additions & 2 deletions test/ArchitectureTests/ApplicationTests/RequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public void Commands_Should_HaveAuthorizeAttribute()
{
var result = Types.InAssembly(ApplicationAssembly)
.That()
.AreNotInterfaces()
.And()
.ImplementInterface(typeof(IRequest<>))
.Or()
.ImplementInterface(typeof(ICacheableRequest<>))
.Or()
.ImplementInterface(typeof(ICacheInvalidatorRequest<>))
.Should()
.HaveCustomAttribute(typeof(AuthorAttribute))
.HaveCustomAttribute(typeof(RequestAuthorizeAttribute))
.Or()
.HaveCustomAttribute(typeof(AllowAnonymousAttribute))
.GetResult();
Expand All @@ -43,5 +45,4 @@ public void Commands_Should_HaveAuthorizeAttribute()

}


}

0 comments on commit faee01a

Please sign in to comment.