From 4bfe947ce1b64e86e0600336342608234444a0c7 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Thu, 8 Feb 2024 15:30:24 -0700 Subject: [PATCH 1/6] added garage level supplies --- Controllers/VehicleController.cs | 7 +- Views/Home/Index.cshtml | 15 +++++ wwwroot/js/garage.js | 26 ++++++++ wwwroot/js/shared.js | 110 +++++++++++++++++++++++++++++++ wwwroot/js/vehicle.js | 109 ------------------------------ 5 files changed, 153 insertions(+), 114 deletions(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index fdada44..d3b1f1e 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -161,10 +161,6 @@ namespace CarCareTracker.Controllers [HttpGet] public IActionResult ExportFromVehicleToCsv(int vehicleId, ImportMode mode) { - if (vehicleId == default) - { - return Json(false); - } string uploadDirectory = "temp/"; string uploadPath = Path.Combine(_webEnv.WebRootPath, uploadDirectory); if (!Directory.Exists(uploadPath)) @@ -349,7 +345,7 @@ namespace CarCareTracker.Controllers [HttpPost] public IActionResult ImportToVehicleIdFromCsv(int vehicleId, ImportMode mode, string fileName) { - if (vehicleId == default || string.IsNullOrWhiteSpace(fileName)) + if (string.IsNullOrWhiteSpace(fileName)) { return Json(false); } @@ -1522,6 +1518,7 @@ namespace CarCareTracker.Controllers public IActionResult GetSupplyRecordsForRecordsByVehicleId(int vehicleId) { var result = _supplyRecordDataAccess.GetSupplyRecordsByVehicleId(vehicleId); + result.AddRange(_supplyRecordDataAccess.GetSupplyRecordsByVehicleId(0)); // add shop supplies result.RemoveAll(x => x.Quantity <= 0); bool _useDescending = _config.GetUserConfig(User).UseDescending; if (_useDescending) diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index b3391e5..a08028e 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -13,12 +13,16 @@ } @section Scripts { + }
+
+
@@ -88,6 +97,12 @@ + + }
+
+ + +
@if (User.IsInRole(nameof(UserData.IsRootUser))) {
@@ -256,6 +260,7 @@ useMarkDownOnSavedNotes: $("#useMarkDownOnSavedNotes").is(":checked"), enableAutoReminderRefresh: $("#enableAutoReminderRefresh").is(":checked"), enableAutoOdometerInsert: $("#enableAutoOdometerInsert").is(":checked"), + enableShopSupplies: $("#enableShopSupplies").is(":checked"), preferredGasUnit: $("#preferredGasUnit").val(), preferredGasMileageUnit: $("#preferredFuelMileageUnit").val(), userLanguage: $("#defaultLanguage").val(), diff --git a/appsettings.json b/appsettings.json index 149256d..bbe7c1b 100644 --- a/appsettings.json +++ b/appsettings.json @@ -14,6 +14,7 @@ "HideZero": false, "EnableAutoReminderRefresh": false, "EnableAutoOdometerInsert": false, + "EnableShopSupplies": false, "UseUKMPG": false, "UseThreeDecimalGasCost": true, "UseMarkDownOnSavedNotes": false, From 08ace8b08d826dbaa32504e670a8eadc195b8fec Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Thu, 8 Feb 2024 16:54:01 -0700 Subject: [PATCH 4/6] consolidated settings into confighelper, fixed shop supplies access issue for non root user. --- Controllers/VehicleController.cs | 5 ++++- Filter/CollaboratorFilter.cs | 9 ++++++--- Helper/ConfigHelper.cs | 5 +++++ Views/Home/Index.cshtml | 5 ++--- Views/Vehicle/_SupplyUsage.cshtml | 6 ++++-- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index d3b1f1e..809c8f3 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -1518,7 +1518,10 @@ namespace CarCareTracker.Controllers public IActionResult GetSupplyRecordsForRecordsByVehicleId(int vehicleId) { var result = _supplyRecordDataAccess.GetSupplyRecordsByVehicleId(vehicleId); - result.AddRange(_supplyRecordDataAccess.GetSupplyRecordsByVehicleId(0)); // add shop supplies + if (_config.GetServerEnableShopSupplies()) + { + result.AddRange(_supplyRecordDataAccess.GetSupplyRecordsByVehicleId(0)); // add shop supplies + } result.RemoveAll(x => x.Quantity <= 0); bool _useDescending = _config.GetUserConfig(User).UseDescending; if (_useDescending) diff --git a/Filter/CollaboratorFilter.cs b/Filter/CollaboratorFilter.cs index 550c458..7940d3c 100644 --- a/Filter/CollaboratorFilter.cs +++ b/Filter/CollaboratorFilter.cs @@ -17,10 +17,13 @@ namespace CarCareTracker.Filter if (!filterContext.HttpContext.User.IsInRole(nameof(UserData.IsRootUser))) { var vehicleId = int.Parse(filterContext.ActionArguments["vehicleId"].ToString()); - var userId = int.Parse(filterContext.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)); - if (!_userLogic.UserCanEditVehicle(userId, vehicleId)) + if (vehicleId != default) { - filterContext.Result = new RedirectResult("/Error/Unauthorized"); + var userId = int.Parse(filterContext.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)); + if (!_userLogic.UserCanEditVehicle(userId, vehicleId)) + { + filterContext.Result = new RedirectResult("/Error/Unauthorized"); + } } } } diff --git a/Helper/ConfigHelper.cs b/Helper/ConfigHelper.cs index 41dffe2..e00345f 100644 --- a/Helper/ConfigHelper.cs +++ b/Helper/ConfigHelper.cs @@ -11,6 +11,7 @@ namespace CarCareTracker.Helper bool SaveUserConfig(ClaimsPrincipal user, UserConfig configData); string GetLogoUrl(); string GetServerLanguage(); + bool GetServerEnableShopSupplies(); public bool DeleteUserConfig(int userId); } public class ConfigHelper : IConfigHelper @@ -40,6 +41,10 @@ namespace CarCareTracker.Helper var serverLanguage = _config[nameof(UserConfig.UserLanguage)] ?? "en_US"; return serverLanguage; } + public bool GetServerEnableShopSupplies() + { + return bool.Parse(_config[nameof(UserConfig.EnableShopSupplies)] ?? "false"); + } public bool SaveUserConfig(ClaimsPrincipal user, UserConfig configData) { var storedUserId = user.FindFirstValue(ClaimTypes.NameIdentifier); diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index 5a9e669..eed9813 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -1,6 +1,5 @@ @using CarCareTracker.Helper @inject IConfigHelper config -@inject IConfiguration serverConfig @inject ITranslationHelper translator @{ var userConfig = config.GetUserConfig(User); @@ -22,7 +21,7 @@ - @if(bool.Parse(serverConfig[nameof(UserConfig.EnableShopSupplies)] ?? "false")) + @if(config.GetServerEnableShopSupplies()) { - @if (bool.Parse(serverConfig[nameof(UserConfig.EnableShopSupplies)] ?? "false")) + @if (config.GetServerEnableShopSupplies()) {