diff --git a/src/ClientServer/Config/Constants.cs b/src/ClientServer/Config/Constants.cs index 260ad43b2424f0360d17b13fd5bf6dfaf9c2d1d5..074938eef6efc8bd65733589e5f9d5faf72fef6b 100644 --- a/src/ClientServer/Config/Constants.cs +++ b/src/ClientServer/Config/Constants.cs @@ -13,7 +13,7 @@ namespace ClientServer.Helpers /// </summary> public static class Constants { - public static string VersionString = "2.6.2"; + public static string VersionString = "2.6.3"; /// <summary> /// this is only set once at program.cs!! diff --git a/src/ClientServer/Controllers/Core/Exercises/DoExerciseAfterSolution/DoExerciseAfterSolutionController.cs b/src/ClientServer/Controllers/Core/Exercises/DoExerciseAfterSolution/DoExerciseAfterSolutionController.cs index 5df260b90727319ed67abbf1a5a4674efd848f6c..81331a1e937adfb09db3e7e46d56b0e73870f844 100644 --- a/src/ClientServer/Controllers/Core/Exercises/DoExerciseAfterSolution/DoExerciseAfterSolutionController.cs +++ b/src/ClientServer/Controllers/Core/Exercises/DoExerciseAfterSolution/DoExerciseAfterSolutionController.cs @@ -422,12 +422,12 @@ namespace ClientServer.Controllers.Core.Exercises.DoExerciseAfterSolution else { //create a new file (template exists) - - if (oldTemplate.IsEditableByUser) //use user content - { + + if (oldTemplate.IsEditableByUser && oldTemplate.IsContentVisibleForUser) { + file = new AfterSolutionFile() { - Content = oldTemplate.IsContentVisibleForUser ? solutionFile.Content : "", + Content = solutionFile.Content, FileNameWithExtension = solutionFile.FileNameWithExtension, TemplateFile = oldTemplate, IsDisplayed = solutionFile.UiIsDisplayed @@ -443,7 +443,7 @@ namespace ClientServer.Controllers.Core.Exercises.DoExerciseAfterSolution //better use the file from the template here... file = new AfterSolutionFile() { - Content = oldTemplate.IsContentVisibleForUser ? oldTemplate.Content : "", + Content = oldTemplate.Content, FileNameWithExtension = oldTemplate.FileNameWithExtension, TemplateFile = oldTemplate, IsDisplayed = solutionFile.UiIsDisplayed @@ -563,6 +563,15 @@ namespace ClientServer.Controllers.Core.Exercises.DoExerciseAfterSolution //return after solution e.g. we corrected some files... + var errorMsg = UserSolutionHelper.ReplaceReadonlyFiles(oldAfterSolution, oldCodeTemplateForPLang, true, false); + + if (errorMsg != null) + { + await + Response.WriteAsync( + Jc.Serialize(new BasicResponse(ResponseCode.ServerError, errorMsg))); + return; + } var solutionVersionForFrontend = new AfterSolutionDoExerciseFullBase() { diff --git a/src/ClientServer/Controllers/Core/Exercises/DoExerciseController.cs b/src/ClientServer/Controllers/Core/Exercises/DoExerciseController.cs index c4ec07b1c073308ce42926b71cd7cfd12eb87947..26e4658a401a960d9f8de41f7609da555d710737 100644 --- a/src/ClientServer/Controllers/Core/Exercises/DoExerciseController.cs +++ b/src/ClientServer/Controllers/Core/Exercises/DoExerciseController.cs @@ -867,7 +867,7 @@ namespace ClientServer.Controllers.Core.Exercises { var files = new SolutionFile() { - Content = templateFile.IsContentVisibleForUser ? templateFile.Content : "", + Content = templateFile.Content, //always create initial content even if file is hidden or readonly, api must ensure that this is not send to the user DisplayIndex = templateFile.DisplayIndex, FileNameWithExtension = templateFile.FileNameWithExtension, IsDisplayed = true, @@ -1932,6 +1932,15 @@ namespace ClientServer.Controllers.Core.Exercises return; } + string errorMsg = UserSolutionHelper.ReplaceReadonlyFiles(oldSolution, oldCodeTemplateForPLang, true, false); + + if (string.IsNullOrEmpty(errorMsg) == false) + { + await + Response.WriteAsync( + Jc.Serialize(new BasicResponse(ResponseCode.ServerError, "could not replace readonly or hiden files"))); + return; + } var solutionVersionForFrontend = new SolutionDoExerciseFullBase() { @@ -2093,6 +2102,17 @@ namespace ClientServer.Controllers.Core.Exercises oldExerciseReleaseWithUserAsParticipation); if (resetSolution == null) return; + + + string errorMsg = UserSolutionHelper.ReplaceReadonlyFiles(resetSolution, oldCodeTemplateForPLang, true, false); + + if (string.IsNullOrEmpty(errorMsg) == false) + { + await + Response.WriteAsync( + Jc.Serialize(new BasicResponse(ResponseCode.ServerError, "could not replace readonly or hiden files"))); + return; + } var solutionVersionForFrontend = new SolutionDoExerciseFullBase() diff --git a/src/ClientServer/Controllers/Core/Testing/TestingController.cs b/src/ClientServer/Controllers/Core/Testing/TestingController.cs index 36b12ee1102bbd28879b25983fcf24d999843d49..02991854ccec2665c8940412b500b0dcbb286d23 100644 --- a/src/ClientServer/Controllers/Core/Testing/TestingController.cs +++ b/src/ClientServer/Controllers/Core/Testing/TestingController.cs @@ -1112,7 +1112,7 @@ namespace ClientServer.Controllers.Core.Testing var solution = new Solution() { CreatedAt = DateTime.Now, - Note = "compile single file", + Note = "Just run program", SolutionFiles = files, MainFile = mainFile, MainFileId = mainFile.Id, diff --git a/src/ClientServer/Helpers/UserSolutionHelper.cs b/src/ClientServer/Helpers/UserSolutionHelper.cs index 77aac1111468f3b29c965a3e03bd50c8385d4413..dc30de2cccea16608c9283c945bcd870f9676828 100644 --- a/src/ClientServer/Helpers/UserSolutionHelper.cs +++ b/src/ClientServer/Helpers/UserSolutionHelper.cs @@ -14,7 +14,7 @@ namespace ClientServer.Helpers public static class UserSolutionHelper { /// <summary> - /// replaces all readonly file content (an name) with the contents from the coe template file + /// replaces all readonly file content (and name) with the contents from the code template file /// also replaces hidden files with the real content /// </summary> /// <param name="solutionWithFiles">the solution with template files loaded</param> diff --git a/src/ClientServer/Models/Exercises/TemplateFile.cs b/src/ClientServer/Models/Exercises/TemplateFile.cs index 1a4d774cd297a02ade5cc231fe0901461f1c21c6..8e6aa4e15c3e6f0bc227735b5e2c4233decc9c8e 100644 --- a/src/ClientServer/Models/Exercises/TemplateFile.cs +++ b/src/ClientServer/Models/Exercises/TemplateFile.cs @@ -30,11 +30,13 @@ namespace ClientServer.Models.Exercises /// <summary> /// true: content is visible for the user, - /// false: the content is set to the empty string before sending to frontend, + /// false: the content is set to the empty string before sending to frontend (this file content is not changed in the db), + /// normally the initial solution will contain the template file code when the user solution was created + /// this is that we have a "working" old user solution even if the exercise changes... /// this only applies for the do exercise view (exercise creators and tutors need to see the content) /// this means that the user cannot edit this file (content or name) /// - /// IF IsEditableByUser is true then this is false the content is hidden and the file is readonly! + /// IF IsEditableByUser is true and this is false the content is hidden and the file is readonly! /// </summary> public bool IsContentVisibleForUser { get; set; }