Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
2 changes: 1 addition & 1 deletion Constants/RoleNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string[]> RolePermissions = new Dictionary<string, string[]>
{
{ "Default", new string[] { "Electricity" } },
Expand Down
2 changes: 1 addition & 1 deletion Controllers/BatteryHealthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BatteryHealthController : ControllerBase
private readonly ApplicationDbContext _context;
private readonly IMapper _mapper;
private readonly ILogger<BatteryHealthController> _logger;
private static readonly List<string> AdminRoles = new() { "sensor_admin", "admin" };
private static readonly List<string> AdminRoles = new() { "SensorAdmin", "admin" };

public BatteryHealthController(ApplicationDbContext context, IMapper mapper, ILogger<BatteryHealthController> logger)
{
Expand Down
2 changes: 1 addition & 1 deletion Controllers/MqttController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace garge_api.Controllers
public class MqttController : ControllerBase
{
private readonly ApplicationDbContext _context;
private static readonly List<string> AdminRoles = new() { "mqtt_admin", "admin" };
private static readonly List<string> AdminRoles = new() { "MqttAdmin", "admin" };
private readonly ILogger<MqttController> _logger;

public MqttController(ApplicationDbContext context, ILogger<MqttController> logger)
Expand Down
2 changes: 1 addition & 1 deletion Controllers/SensorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SensorController : ControllerBase
private readonly ApplicationDbContext _context;
private readonly IMapper _mapper;
private readonly ILogger<SensorController> _logger;
private static readonly List<string> AdminRoles = new() { "sensor_admin", "admin" };
private static readonly List<string> AdminRoles = new() { "SensorAdmin", "admin" };

public SensorController(ApplicationDbContext context, IMapper mapper, ILogger<SensorController> logger)
{
Expand Down
6 changes: 3 additions & 3 deletions Controllers/SwitchesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private async Task<bool> 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;
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public async Task<IActionResult> 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<Switch>();

Expand Down Expand Up @@ -150,7 +150,7 @@ public async Task<IActionResult> 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 });
Expand Down
4 changes: 0 additions & 4 deletions Migrations/20250420120848_AddSwitchTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/// <inheritdoc />
Expand Down
Loading