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.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs b/HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs index 1ab2fe869..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] @@ -42,13 +43,17 @@ public SolutionsController(ISolutionsServiceClient solutionsClient, IAuthService 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); } [HttpGet("taskSolution/{taskId}/{studentId}")] - [Authorize] [ProducesResponseType(typeof(UserTaskSolutionsPageData), (int)HttpStatusCode.OK)] public async Task GetStudentSolution(long taskId, string studentId) { @@ -145,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) @@ -504,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) 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.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": { 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 {