diff --git a/CHANGELOG.md b/CHANGELOG.md index e8409f1..e12d8b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.7.2](https://github.com/sondresjolyst/garge-api/compare/v1.7.1...v1.7.2) (2026-04-16) + + +### Bug Fixes + +* replace string.Equals with ToUpper comparison in SwitchesController ([#94](https://github.com/sondresjolyst/garge-api/issues/94)) ([#95](https://github.com/sondresjolyst/garge-api/issues/95)) ([18d842f](https://github.com/sondresjolyst/garge-api/commit/18d842f1143f37ce4e7c4b1e20932ad8982f82f9)) + ## [1.7.1](https://github.com/sondresjolyst/garge-api/compare/v1.7.0...v1.7.1) (2026-04-16) diff --git a/Constants/RoleNames.cs b/Constants/RoleNames.cs index 10aa660..535df44 100644 --- a/Constants/RoleNames.cs +++ b/Constants/RoleNames.cs @@ -2,7 +2,7 @@ { public static class RoleNames { - public static readonly string[] AllRoles = { "Default", "Electricity" }; + public static readonly string[] AllRoles = { "Default", "Electricity", "Admin", "SensorAdmin", "MqttAdmin", "AutomationAdmin", "SwitchAdmin" }; public static readonly Dictionary RolePermissions = new Dictionary { { "Default", new string[] { "Electricity" } }, diff --git a/Controllers/BatteryHealthController.cs b/Controllers/BatteryHealthController.cs index 52c7f52..455d94a 100644 --- a/Controllers/BatteryHealthController.cs +++ b/Controllers/BatteryHealthController.cs @@ -20,7 +20,7 @@ public class BatteryHealthController : ControllerBase private readonly ApplicationDbContext _context; private readonly IMapper _mapper; private readonly ILogger _logger; - private static readonly List AdminRoles = new() { "sensor_admin", "admin" }; + private static readonly List AdminRoles = new() { "SensorAdmin", "admin" }; public BatteryHealthController(ApplicationDbContext context, IMapper mapper, ILogger logger) { diff --git a/Controllers/MqttController.cs b/Controllers/MqttController.cs index 3c3e3bb..937bb5e 100644 --- a/Controllers/MqttController.cs +++ b/Controllers/MqttController.cs @@ -20,7 +20,7 @@ namespace garge_api.Controllers public class MqttController : ControllerBase { private readonly ApplicationDbContext _context; - private static readonly List AdminRoles = new() { "mqtt_admin", "admin" }; + private static readonly List AdminRoles = new() { "MqttAdmin", "admin" }; private readonly ILogger _logger; public MqttController(ApplicationDbContext context, ILogger logger) diff --git a/Controllers/SensorController.cs b/Controllers/SensorController.cs index 02f98a5..37a778a 100644 --- a/Controllers/SensorController.cs +++ b/Controllers/SensorController.cs @@ -23,7 +23,7 @@ public class SensorController : ControllerBase private readonly ApplicationDbContext _context; private readonly IMapper _mapper; private readonly ILogger _logger; - private static readonly List AdminRoles = new() { "sensor_admin", "admin" }; + private static readonly List AdminRoles = new() { "SensorAdmin", "admin" }; public SensorController(ApplicationDbContext context, IMapper mapper, ILogger logger) { diff --git a/Controllers/SwitchesController.cs b/Controllers/SwitchesController.cs index d990486..8f6df78 100644 --- a/Controllers/SwitchesController.cs +++ b/Controllers/SwitchesController.cs @@ -34,7 +34,7 @@ private async Task UserHasRequiredRoleAsync(Switch switchEntity) // Admins always have access if (userRoles.Contains("admin", StringComparer.OrdinalIgnoreCase) || - userRoles.Contains("switch_admin", StringComparer.OrdinalIgnoreCase)) + userRoles.Contains("SwitchAdmin", StringComparer.OrdinalIgnoreCase)) { return true; } @@ -71,7 +71,7 @@ public async Task GetAllSwitches() _logger.LogInformation("GetAllSwitches called by {@LogData}", new { User = User.Identity?.Name }); var allSwitches = await _context.Switches - .Where(sw => sw.Type.Equals("SOCKET", StringComparison.OrdinalIgnoreCase)) + .Where(sw => sw.Type.ToUpper() == "SOCKET") .ToListAsync(); var accessibleSwitches = new List(); @@ -150,7 +150,7 @@ public async Task CreateSwitch([FromBody] CreateSwitchDto switchD _logger.LogInformation("CreateSwitch called by {@LogData}", new { User = User.Identity?.Name, switchDto.Name, switchDto.Type }); var userRoles = User.FindAll(ClaimTypes.Role).Select(r => r.Value).ToList(); - if (!userRoles.Contains("switch_admin", StringComparer.OrdinalIgnoreCase) && + if (!userRoles.Contains("SwitchAdmin", StringComparer.OrdinalIgnoreCase) && !userRoles.Contains("admin", StringComparer.OrdinalIgnoreCase)) { _logger.LogWarning("CreateSwitch forbidden for {@LogData}", new { User = User.Identity?.Name }); diff --git a/Migrations/20250420120848_AddSwitchTable.cs b/Migrations/20250420120848_AddSwitchTable.cs index 3d24644..219275c 100644 --- a/Migrations/20250420120848_AddSwitchTable.cs +++ b/Migrations/20250420120848_AddSwitchTable.cs @@ -26,10 +26,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_Switches", x => x.Id); }); - migrationBuilder.CreateIndex( - name: "IX_SensorData_Timestamp", - table: "SensorData", - column: "Timestamp"); } ///