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()) {