From 8d258a8339c0e248bfcb8122cecb175df5f192e3 Mon Sep 17 00:00:00 2001 From: PSThiago Date: Thu, 12 Oct 2023 17:57:24 -0300 Subject: [PATCH 1/2] fix: Correction on project opening. --- src/Application/UseCases/Project/OpenProject.cs | 10 ++++++---- .../Persistence/Repositories/ProjectRepository.cs | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Application/UseCases/Project/OpenProject.cs b/src/Application/UseCases/Project/OpenProject.cs index 212cdcd2..d9bf6f46 100644 --- a/src/Application/UseCases/Project/OpenProject.cs +++ b/src/Application/UseCases/Project/OpenProject.cs @@ -62,7 +62,7 @@ public async Task ExecuteAsync(OpenProjectInput input) EProjectStatus.Opened, EProjectStatus.Opened.GetDescription(), null, - DateTime.UtcNow, + null, null, null, null); @@ -90,9 +90,11 @@ public async Task ExecuteAsync(OpenProjectInput input) ?? throw UseCaseException.NotFoundEntityById(nameof(Domain.Entities.Professor)); // Verifica se o professor está suspenso - UseCaseException.BusinessRuleViolation( - professor.SuspensionEndDate != null && professor.SuspensionEndDate > DateTime.UtcNow, - $"O acesso ao professor está suspenso até {professor.SuspensionEndDate!.Value:dd/MM/yyyy}, devido à pendência na entrega do relatório final em outro projeto."); + if (professor.SuspensionEndDate.HasValue) + { + UseCaseException.BusinessRuleViolation(professor.SuspensionEndDate! > DateTime.UtcNow, + $"O acesso ao professor está suspenso até {professor.SuspensionEndDate!.Value:dd/MM/yyyy}, devido à pendência na entrega do relatório final em outro projeto."); + } // Caso tenha sido informado algum aluno no processo de abertura do projeto if (project.StudentId.HasValue) diff --git a/src/Infrastructure/Persistence/Repositories/ProjectRepository.cs b/src/Infrastructure/Persistence/Repositories/ProjectRepository.cs index 382a052e..d8a61cfb 100644 --- a/src/Infrastructure/Persistence/Repositories/ProjectRepository.cs +++ b/src/Infrastructure/Persistence/Repositories/ProjectRepository.cs @@ -62,7 +62,7 @@ public async Task> GetProfessorProjectsAsync(int skip, int .Include(x => x.Notice) .IgnoreQueryFilters() .AsAsyncEnumerable() - .Where(x => x.StudentId == id + .Where(x => x.ProfessorId == id && (x.Status == EProjectStatus.Closed || x.Status == EProjectStatus.Canceled)) .OrderByDescending(x => x.Notice?.RegistrationStartDate) // Traz os projetos mais recentes primeiro. @@ -78,7 +78,7 @@ public async Task> GetProfessorProjectsAsync(int skip, int .Include(x => x.Notice) .IgnoreQueryFilters() .AsAsyncEnumerable() - .Where(x => x.StudentId == id + .Where(x => x.ProfessorId == id && x.Status != EProjectStatus.Closed && x.Status != EProjectStatus.Canceled) .OrderByDescending(x => x.Notice?.RegistrationStartDate) // Traz os projetos mais recentes primeiro. @@ -132,7 +132,7 @@ public async Task> GetStudentProjectsAsync(int skip, int ta .Include(x => x.Notice) .IgnoreQueryFilters() .AsAsyncEnumerable() - .Where(x => x.ProfessorId == id + .Where(x => x.StudentId == id && (x.Status == EProjectStatus.Closed || x.Status == EProjectStatus.Canceled)) .OrderByDescending(x => x.Notice?.RegistrationStartDate) // Traz os projetos mais recentes primeiro. From 98688510d106b00fd28f75f433854dace1bc6588 Mon Sep 17 00:00:00 2001 From: eduardo Date: Wed, 25 Oct 2023 09:02:58 -0300 Subject: [PATCH 2/2] fix: Disable CORS policy for tests --- src/Infrastructure/WebAPI/Startup.cs | 50 ++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Infrastructure/WebAPI/Startup.cs b/src/Infrastructure/WebAPI/Startup.cs index c4b39f1b..ddaa4d23 100644 --- a/src/Infrastructure/WebAPI/Startup.cs +++ b/src/Infrastructure/WebAPI/Startup.cs @@ -40,26 +40,41 @@ public void ConfigureServices(IServiceCollection services) // Definição de política de CORS services.AddCors(options => { - options.AddPolicy(name: CORS_POLICY_NAME, - policy => - { - // Busca os valores de ALLOW_ORIGINS do arquivo .env - policy.WithOrigins( - origins: Environment.GetEnvironmentVariable("ALLOW_ORIGINS").Split(',')!) - .AllowAnyHeader() - .AllowAnyMethod(); - }); + // Permite qualquer origem, cabeçalho e método + options.AddDefaultPolicy( + builder => + { + builder.AllowAnyOrigin() + .AllowAnyHeader() + .AllowAnyMethod(); + }); + + // // Busca os valores de ALLOW_ORIGINS do arquivo .env + // var allowedOrigins = Environment.GetEnvironmentVariable("ALLOW_ORIGINS") + // ?? throw new Exception("ALLOW_ORIGINS não definido nas variáveis de ambiente."); + + // // Permite apenas as origens definidas no arquivo .env + // options.AddPolicy(name: CORS_POLICY_NAME, + // policy => + // { + // // Busca os valores de ALLOW_ORIGINS do arquivo .env + // policy.WithOrigins( + // origins: allowedOrigins.Split(',')!) + // .AllowAnyHeader() + // .AllowAnyMethod(); + // }); }); #endregion CORS #region Rate Limit - services.AddMemoryCache(); - services.AddInMemoryRateLimiting(); - services.Configure(_configuration.GetSection("IpRateLimiting")); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + // Definido através do API Gateway + // services.AddMemoryCache(); + // services.AddInMemoryRateLimiting(); + // services.Configure(_configuration.GetSection("IpRateLimiting")); + // services.AddSingleton(); + // services.AddSingleton(); + // services.AddSingleton(); + // services.AddSingleton(); #endregion Rate Limit } @@ -95,7 +110,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseHttpsRedirection(); // Enable CORS - app.UseCors(CORS_POLICY_NAME); + app.UseCors(); + // app.UseCors(CORS_POLICY_NAME); // Enable routing for incoming requests app.UseRouting();