diff --git a/src/Application/Features/Assessments/PostAssessmentCommand/PostAssessmentCommand.cs b/src/Application/Features/Assessments/PostAssessmentCommand/PostAssessmentCommand.cs index f31ee67f..b405fd35 100644 --- a/src/Application/Features/Assessments/PostAssessmentCommand/PostAssessmentCommand.cs +++ b/src/Application/Features/Assessments/PostAssessmentCommand/PostAssessmentCommand.cs @@ -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; diff --git a/src/Application/Features/Assessments/Queries/GetAssessment/GetAssessmentQuery.cs b/src/Application/Features/Assessments/Queries/GetAssessment/GetAssessmentQuery.cs index e3ee7aea..d34a222b 100644 --- a/src/Application/Features/Assessments/Queries/GetAssessment/GetAssessmentQuery.cs +++ b/src/Application/Features/Assessments/Queries/GetAssessment/GetAssessmentQuery.cs @@ -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> { public string CacheKey diff --git a/src/Application/Features/AuditTrails/Queries/PaginationQuery/AuditTrailsWithPaginationQuery.cs b/src/Application/Features/AuditTrails/Queries/PaginationQuery/AuditTrailsWithPaginationQuery.cs index 4ec3f3fe..561c0c71 100644 --- a/src/Application/Features/AuditTrails/Queries/PaginationQuery/AuditTrailsWithPaginationQuery.cs +++ b/src/Application/Features/AuditTrails/Queries/PaginationQuery/AuditTrailsWithPaginationQuery.cs @@ -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> diff --git a/src/Application/Features/Candidates/Queries/Search/CandidateSearchQuery.cs b/src/Application/Features/Candidates/Queries/Search/CandidateSearchQuery.cs index 5f35c88a..24530906 100644 --- a/src/Application/Features/Candidates/Queries/Search/CandidateSearchQuery.cs +++ b/src/Application/Features/Candidates/Queries/Search/CandidateSearchQuery.cs @@ -4,6 +4,7 @@ namespace Cfo.Cats.Application.Features.Candidates.Queries.Search; +[RequestAuthorize(Roles = "Admin, Basic")] public class CandidateSearchQuery : ICacheableRequest> { public required string ExternalIdentifier { get; set; } diff --git a/src/Application/Features/Documents/Commands/Upload/UploadDocumentCommand.cs b/src/Application/Features/Documents/Commands/Upload/UploadDocumentCommand.cs index 04a76073..0885689e 100644 --- a/src/Application/Features/Documents/Commands/Upload/UploadDocumentCommand.cs +++ b/src/Application/Features/Documents/Commands/Upload/UploadDocumentCommand.cs @@ -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> { public string CacheKey { get; } = string.Empty; diff --git a/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommand.cs b/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommand.cs index bba6ab0d..f767c3b9 100644 --- a/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommand.cs +++ b/src/Application/Features/KeyValues/Commands/AddEdit/AddEditKeyValueCommand.cs @@ -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> { [Description("Id")] public int Id { get; set; } diff --git a/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommand.cs b/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommand.cs index fb890a7e..a5d4a88b 100644 --- a/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommand.cs +++ b/src/Application/Features/KeyValues/Commands/Delete/DeleteKeyValueCommand.cs @@ -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> { public DeleteKeyValueCommand(int[] id) diff --git a/src/Application/Features/KeyValues/Commands/Import/CreateKeyValueTemplateCommand.cs b/src/Application/Features/KeyValues/Commands/Import/CreateKeyValueTemplateCommand.cs index 94707bce..1cf79fc3 100644 --- a/src/Application/Features/KeyValues/Commands/Import/CreateKeyValueTemplateCommand.cs +++ b/src/Application/Features/KeyValues/Commands/Import/CreateKeyValueTemplateCommand.cs @@ -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 { } \ No newline at end of file diff --git a/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommand.cs b/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommand.cs index dc2a807f..99a3ccf9 100644 --- a/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommand.cs +++ b/src/Application/Features/KeyValues/Commands/Import/ImportKeyValuesCommand.cs @@ -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 { public ImportKeyValuesCommand(string fileName, byte[] data) diff --git a/src/Application/Features/KeyValues/Queries/ByName/KeyValuesQueryByName.cs b/src/Application/Features/KeyValues/Queries/ByName/KeyValuesQueryByName.cs index a3130ed0..64e68a7f 100644 --- a/src/Application/Features/KeyValues/Queries/ByName/KeyValuesQueryByName.cs +++ b/src/Application/Features/KeyValues/Queries/ByName/KeyValuesQueryByName.cs @@ -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> { public KeyValuesQueryByName(Picklist name) diff --git a/src/Application/Features/KeyValues/Queries/Export/ExportKeyValuesQuery.cs b/src/Application/Features/KeyValues/Queries/Export/ExportKeyValuesQuery.cs index d1c0872d..417f7b7b 100644 --- a/src/Application/Features/KeyValues/Queries/Export/ExportKeyValuesQuery.cs +++ b/src/Application/Features/KeyValues/Queries/Export/ExportKeyValuesQuery.cs @@ -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 { public string? Keyword { get; set; } diff --git a/src/Application/Features/KeyValues/Queries/GetAll/GetAllKeyValuesQuery.cs b/src/Application/Features/KeyValues/Queries/GetAll/GetAllKeyValuesQuery.cs index 853a2507..7ab3bccb 100644 --- a/src/Application/Features/KeyValues/Queries/GetAll/GetAllKeyValuesQuery.cs +++ b/src/Application/Features/KeyValues/Queries/GetAll/GetAllKeyValuesQuery.cs @@ -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> { public string CacheKey => KeyValueCacheKey.GetAllCacheKey; diff --git a/src/Application/Features/KeyValues/Queries/PaginationQuery/KeyValuesWithPaginationQuery.cs b/src/Application/Features/KeyValues/Queries/PaginationQuery/KeyValuesWithPaginationQuery.cs index 72fb2b1d..9dfbb1dc 100644 --- a/src/Application/Features/KeyValues/Queries/PaginationQuery/KeyValuesWithPaginationQuery.cs +++ b/src/Application/Features/KeyValues/Queries/PaginationQuery/KeyValuesWithPaginationQuery.cs @@ -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> { public KeyValueAdvancedSpecification Specification => new(this); diff --git a/src/Application/Features/Locations/Queries/GetAll/GetAllLocationsQuery.cs b/src/Application/Features/Locations/Queries/GetAll/GetAllLocationsQuery.cs index e3e42298..f524f578 100644 --- a/src/Application/Features/Locations/Queries/GetAll/GetAllLocationsQuery.cs +++ b/src/Application/Features/Locations/Queries/GetAll/GetAllLocationsQuery.cs @@ -5,6 +5,7 @@ namespace Cfo.Cats.Application.Features.Locations.Queries.GetAll; +[RequestAuthorize(Roles = "Admin, Basic")] public class GetAllLocationsQuery : ICacheableRequest> { public required UserProfile UserProfile { get; set; } diff --git a/src/Application/Features/Participants/Commands/Enrol/EnrolParticipantCommand.cs b/src/Application/Features/Participants/Commands/Enrol/EnrolParticipantCommand.cs index 38e8a004..c1954fb3 100644 --- a/src/Application/Features/Participants/Commands/Enrol/EnrolParticipantCommand.cs +++ b/src/Application/Features/Participants/Commands/Enrol/EnrolParticipantCommand.cs @@ -5,6 +5,7 @@ namespace Cfo.Cats.Application.Features.Participants.Commands.Enrol; +[RequestAuthorize(Roles = "Admin, Basic")] public class EnrolParticipantCommand : ICacheInvalidatorRequest> { /// diff --git a/src/Application/Features/Tenants/Commands/AddEdit/AddEditTenantCommand.cs b/src/Application/Features/Tenants/Commands/AddEdit/AddEditTenantCommand.cs index b7e2595e..2720d5e8 100644 --- a/src/Application/Features/Tenants/Commands/AddEdit/AddEditTenantCommand.cs +++ b/src/Application/Features/Tenants/Commands/AddEdit/AddEditTenantCommand.cs @@ -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> { [Description("Tenant Id")] diff --git a/src/Application/Features/Tenants/Commands/Delete/DeleteTenantCommand.cs b/src/Application/Features/Tenants/Commands/Delete/DeleteTenantCommand.cs index 3f142f3f..98b20895 100644 --- a/src/Application/Features/Tenants/Commands/Delete/DeleteTenantCommand.cs +++ b/src/Application/Features/Tenants/Commands/Delete/DeleteTenantCommand.cs @@ -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> { public DeleteTenantCommand(string[] id) diff --git a/src/Application/Features/Tenants/Queries/Export/ExportTenantsQuery.cs b/src/Application/Features/Tenants/Queries/Export/ExportTenantsQuery.cs index 0e2cd60b..59edbdb6 100644 --- a/src/Application/Features/Tenants/Queries/Export/ExportTenantsQuery.cs +++ b/src/Application/Features/Tenants/Queries/Export/ExportTenantsQuery.cs @@ -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> { public TenantAdvancedSpecification Specification => new(this); diff --git a/src/Application/Features/Tenants/Queries/GetAll/GetAllTenantsQuery.cs b/src/Application/Features/Tenants/Queries/GetAll/GetAllTenantsQuery.cs index 6f17a89b..b01584ec 100644 --- a/src/Application/Features/Tenants/Queries/GetAll/GetAllTenantsQuery.cs +++ b/src/Application/Features/Tenants/Queries/GetAll/GetAllTenantsQuery.cs @@ -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> { public string CacheKey => TenantCacheKey.GetAllCacheKey; diff --git a/src/Application/Features/Tenants/Queries/Pagination/TenantsWithPaginationQuery.cs b/src/Application/Features/Tenants/Queries/Pagination/TenantsWithPaginationQuery.cs index 3dec15d3..c9f0b424 100644 --- a/src/Application/Features/Tenants/Queries/Pagination/TenantsWithPaginationQuery.cs +++ b/src/Application/Features/Tenants/Queries/Pagination/TenantsWithPaginationQuery.cs @@ -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> diff --git a/test/ArchitectureTests/ApplicationTests/RequestTests.cs b/test/ArchitectureTests/ApplicationTests/RequestTests.cs index fce091dc..611177f9 100644 --- a/test/ArchitectureTests/ApplicationTests/RequestTests.cs +++ b/test/ArchitectureTests/ApplicationTests/RequestTests.cs @@ -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(); @@ -43,5 +45,4 @@ public void Commands_Should_HaveAuthorizeAttribute() } - } \ No newline at end of file