From e67db883e3458101af35d283b91ac1f516c22f3b Mon Sep 17 00:00:00 2001 From: kirillbenga Date: Sun, 30 Nov 2025 16:01:33 +0300 Subject: [PATCH 1/3] fix: made it possible to run on macOS --- .gitignore | 1 + HwProj.AuthService/HwProj.AuthService.API/appsettings.json | 2 +- HwProj.Common/HwProj.Common.Net8/ConnectionString.cs | 3 ++- HwProj.Common/HwProj.Utils/Configuration/ConnectionString.cs | 3 ++- .../HwProj.ContentService.API/appsettings.json | 2 +- .../HwProj.NotificationsService.API/appsettings.json | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 7ed326a27..dae2af57f 100644 --- a/.gitignore +++ b/.gitignore @@ -362,3 +362,4 @@ StyleCop.Cache swagger-codegen hwproj.front/static_dist/ hwproj.front/dist/ +.DS_Store diff --git a/HwProj.AuthService/HwProj.AuthService.API/appsettings.json b/HwProj.AuthService/HwProj.AuthService.API/appsettings.json index bb18739ae..c2777316b 100644 --- a/HwProj.AuthService/HwProj.AuthService.API/appsettings.json +++ b/HwProj.AuthService/HwProj.AuthService.API/appsettings.json @@ -1,7 +1,7 @@ { "ConnectionStrings": { "DefaultConnectionForWindows": "Server=(localdb)\\mssqllocaldb;Database=AuthServiceDB;Trusted_Connection=True;TrustServerCertificate=true;", - "DefaultConnectionForLinux": "Server=localhost,1433;Database=AuthServiceDB;User ID=SA;Password=password_1234;" + "DefaultConnectionForLinux": "Server=localhost,1433;Database=AuthServiceDB;User ID=SA;Password=password_1234;TrustServerCertificate=True;" }, "Logging": { "LogLevel": { diff --git a/HwProj.Common/HwProj.Common.Net8/ConnectionString.cs b/HwProj.Common/HwProj.Common.Net8/ConnectionString.cs index 32bc4db97..be9dd0c40 100644 --- a/HwProj.Common/HwProj.Common.Net8/ConnectionString.cs +++ b/HwProj.Common/HwProj.Common.Net8/ConnectionString.cs @@ -8,7 +8,8 @@ public static class ConnectionString { public static string GetConnectionString(IConfiguration configuration) { - var option = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) + var option = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || + RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "DefaultConnectionForLinux" : "DefaultConnectionForWindows"; return configuration.GetConnectionString(option) ?? ""; diff --git a/HwProj.Common/HwProj.Utils/Configuration/ConnectionString.cs b/HwProj.Common/HwProj.Utils/Configuration/ConnectionString.cs index 2c0ea9135..3e130809a 100644 --- a/HwProj.Common/HwProj.Utils/Configuration/ConnectionString.cs +++ b/HwProj.Common/HwProj.Utils/Configuration/ConnectionString.cs @@ -8,7 +8,8 @@ public static class ConnectionString { public static string GetConnectionString(IConfiguration configuration) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || + RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { return configuration.GetConnectionString("DefaultConnectionForLinux"); } diff --git a/HwProj.ContentService/HwProj.ContentService.API/appsettings.json b/HwProj.ContentService/HwProj.ContentService.API/appsettings.json index de0b9bc31..25f5a1090 100644 --- a/HwProj.ContentService/HwProj.ContentService.API/appsettings.json +++ b/HwProj.ContentService/HwProj.ContentService.API/appsettings.json @@ -1,7 +1,7 @@ { "ConnectionStrings": { "DefaultConnectionForWindows": "Server=(localdb)\\mssqllocaldb;Database=ContentServiceDB;Trusted_Connection=True;TrustServerCertificate=true;", - "DefaultConnectionForLinux": "Server=localhost,1433;Database=ContentServiceDB;User ID=SA;Password=password_1234;" + "DefaultConnectionForLinux": "Server=localhost,1433;Database=ContentServiceDB;User ID=SA;Password=password_1234;TrustServerCertificate=True;" }, "Logging": { "LogLevel": { diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.API/appsettings.json b/HwProj.NotificationsService/HwProj.NotificationsService.API/appsettings.json index f6fe217f3..f196fffa6 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.API/appsettings.json +++ b/HwProj.NotificationsService/HwProj.NotificationsService.API/appsettings.json @@ -1,7 +1,7 @@ { "ConnectionStrings": { "DefaultConnectionForWindows": "Server=(localdb)\\mssqllocaldb;Database=NotificationsServiceDB;Trusted_Connection=True;TrustServerCertificate=true;MultipleActiveResultSets=True", - "DefaultConnectionForLinux": "Server=localhost,1433;Database=NotificationsServiceDB;User ID=SA;Password=password_1234;" + "DefaultConnectionForLinux": "Server=localhost,1433;Database=NotificationsServiceDB;User ID=SA;Password=password_1234;TrustServerCertificate=True;" }, "Logging": { "LogLevel": { From ec414d07353186a835d25be6f914a5bf764fd536 Mon Sep 17 00:00:00 2001 From: kirillbenga Date: Tue, 24 Feb 2026 14:13:04 +0300 Subject: [PATCH 2/3] refactor: updated security in SolutionsController and StatisticsController --- .../Controllers/SolutionsController.cs | 7 +++++++ .../Controllers/StatisticsController.cs | 2 ++ .../Controllers/SolutionsController.cs | 5 ----- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs b/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs index 1ab2fe869..8d8e37c5b 100644 --- a/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs +++ b/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs @@ -38,10 +38,16 @@ public SolutionsController(ISolutionsServiceClient solutionsClient, IAuthService } [HttpGet("{solutionId}")] + [Authorize] [ProducesResponseType(typeof(Solution), (int)HttpStatusCode.OK)] public async Task GetSolutionById(long solutionId) { var result = await _solutionsClient.GetSolutionById(solutionId); + if (result.StudentId != UserId && !User.IsInRole(Roles.LecturerRole)) + { + return Forbid(); + } + return result == null ? NotFound() : Ok(result); @@ -429,6 +435,7 @@ public async Task RateSolution(long solutionId, } [HttpGet("actuality/{solutionId}")] + [Authorize] [ProducesResponseType(typeof(SolutionActualityDto), (int)HttpStatusCode.OK)] public async Task GetSolutionActuality(long solutionId) { diff --git a/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/StatisticsController.cs b/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/StatisticsController.cs index dfd6c567f..e35d1de4f 100644 --- a/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/StatisticsController.cs +++ b/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/StatisticsController.cs @@ -53,6 +53,7 @@ public async Task GetLecturersStatistics(long courseId) } [HttpGet("{courseId}")] + [Authorize] [ProducesResponseType(typeof(StatisticsCourseMatesModel[]), (int)HttpStatusCode.OK)] public async Task GetCourseStatistics(long courseId) { @@ -85,6 +86,7 @@ public async Task GetCourseStatistics(long courseId) } [HttpGet("{courseId}/charts")] + [Authorize] [ProducesResponseType(typeof(AdvancedCourseStatisticsViewModel), (int)HttpStatusCode.OK)] public async Task GetChartStatistics(long courseId) { diff --git a/HwProj.SolutionsService/HwProj.SolutionsService.API/Controllers/SolutionsController.cs b/HwProj.SolutionsService/HwProj.SolutionsService.API/Controllers/SolutionsController.cs index 0cd2215a7..3cdfceaa5 100644 --- a/HwProj.SolutionsService/HwProj.SolutionsService.API/Controllers/SolutionsController.cs +++ b/HwProj.SolutionsService/HwProj.SolutionsService.API/Controllers/SolutionsController.cs @@ -1,28 +1,23 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Threading.Tasks; using AutoMapper; using HwProj.CoursesService.Client; using HwProj.Models.CoursesService; -using HwProj.Models.CoursesService.ViewModels; using HwProj.Models.SolutionsService; using HwProj.Models.StatisticsService; using HwProj.SolutionsService.API.Domains; using HwProj.SolutionsService.API.Models; using HwProj.SolutionsService.API.Repositories; using HwProj.SolutionsService.API.Services; -using HwProj.Utils.Auth; using HwProj.Utils.Authorization; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; namespace HwProj.SolutionsService.API.Controllers { [Route("api/[controller]")] - [Authorize(AuthenticationSchemes = AuthSchemeConstants.UserIdAuthentication)] [ApiController] public class SolutionsController : Controller { From eb211571c9310c6a55ea6b4afa06e6b456a5abf3 Mon Sep 17 00:00:00 2001 From: kirillbenga Date: Sun, 22 Mar 2026 13:57:16 +0300 Subject: [PATCH 3/3] refactor: placed the attribute on the entire controller --- .../Controllers/SolutionsController.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs b/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs index 8d8e37c5b..088cfe2f8 100644 --- a/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs +++ b/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs @@ -21,6 +21,7 @@ namespace HwProj.APIGateway.API.Controllers; +[Authorize] [Route("api/[controller]")] [ApiController] [ForbiddenExceptionFilter] @@ -38,7 +39,6 @@ public SolutionsController(ISolutionsServiceClient solutionsClient, IAuthService } [HttpGet("{solutionId}")] - [Authorize] [ProducesResponseType(typeof(Solution), (int)HttpStatusCode.OK)] public async Task GetSolutionById(long solutionId) { @@ -54,7 +54,6 @@ public async Task GetSolutionById(long solutionId) } [HttpGet("taskSolution/{taskId}/{studentId}")] - [Authorize] [ProducesResponseType(typeof(UserTaskSolutionsPageData), (int)HttpStatusCode.OK)] public async Task GetStudentSolution(long taskId, string studentId) { @@ -151,7 +150,6 @@ public async Task GetStudentSolution(long taskId, string studentI } // Научить без конкретного taskId по courseId получать данные - [Authorize] [HttpGet("tasks/{taskId}")] [ProducesResponseType(typeof(TaskSolutionStatisticsPageData), (int)HttpStatusCode.OK)] public async Task GetTaskSolutionsPageData(long taskId, string? secondMentorId = null) @@ -435,7 +433,6 @@ public async Task RateSolution(long solutionId, } [HttpGet("actuality/{solutionId}")] - [Authorize] [ProducesResponseType(typeof(SolutionActualityDto), (int)HttpStatusCode.OK)] public async Task GetSolutionActuality(long solutionId) { @@ -511,7 +508,6 @@ public async Task GetUnratedSolutions(long? taskId) }; } - [Authorize] [HttpGet("solutionAchievement")] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] public async Task GetSolutionAchievement(long taskId, long solutionId)