Skip to content

Commit

Permalink
fix #174
Browse files Browse the repository at this point in the history
  • Loading branch information
Sben65 authored and kbeaugrand committed Feb 24, 2022
1 parent 9c2853b commit 349c28e
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@

protected override async Task OnInitializedAsync()
{
var result = await httpClient.GetFromJsonAsync<string>("api/settings/lora");
Boolean.TryParse(result, out this.activateLoRaFeature);
this.activateLoRaFeature = await httpClient.GetFromJsonAsync<bool>("api/settings/lora");
}

private void SetLoRaDeviceModel()
Expand Down
3 changes: 1 addition & 2 deletions src/AzureIoTHub.Portal/Client/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@

protected async override void OnInitialized()
{
var result = await this.httpClient.GetFromJsonAsync<string>("api/settings/lora");
Boolean.TryParse(result, out activateLoRaFeature);
activateLoRaFeature = await this.httpClient.GetFromJsonAsync<bool>("api/settings/lora");
}

void DrawerToggle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN
using Azure;
using Azure.Data.Tables;
using AzureIoTHub.Portal.Server.Factories;
using AzureIoTHub.Portal.Server.Filters;
using AzureIoTHub.Portal.Server.Mappers;
using AzureIoTHub.Portal.Shared.Models.V10.LoRaWAN.LoRaDeviceModel;
using Microsoft.AspNetCore.Http;
Expand All @@ -19,6 +20,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN
[ApiVersion("1.0")]
[Route("api/lorawan/models/{id}/commands")]
[ApiExplorerSettings(GroupName = "LoRa WAN")]
[LoRaFeatureActiveFilter]
public class LoRaWANCommandsController : ControllerBase
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Server.Filters;
using AzureIoTHub.Portal.Server.Managers;
using AzureIoTHub.Portal.Server.Mappers;
using AzureIoTHub.Portal.Server.Services;
Expand All @@ -22,6 +23,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN
[ApiVersion("1.0")]
[Route("api/lorawan/concentrators")]
[ApiExplorerSettings(GroupName = "LoRa WAN")]
[LoRaFeatureActiveFilter]
public class LoRaWANConcentratorsController : ControllerBase
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN
{
using AzureIoTHub.Portal.Server.Factories;
using AzureIoTHub.Portal.Server.Filters;
using AzureIoTHub.Portal.Server.Managers;
using AzureIoTHub.Portal.Server.Services;
using AzureIoTHub.Portal.Shared.Models.V10.DeviceModel;
Expand All @@ -18,6 +19,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN
[ApiVersion("1.0")]
[Route("api/lorawan/models")]
[ApiExplorerSettings(GroupName = "LoRa WAN")]
[LoRaFeatureActiveFilter]
public class LoRaWANDeviceModelsController : DeviceModelsControllerBase<DeviceModel, LoRaDeviceModel>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10
{
using Azure.Data.Tables;
using AzureIoTHub.Portal.Server.Factories;
using AzureIoTHub.Portal.Server.Filters;
using AzureIoTHub.Portal.Server.Managers;
using AzureIoTHub.Portal.Server.Mappers;
using AzureIoTHub.Portal.Server.Services;
Expand All @@ -22,6 +23,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10
[ApiVersion("1.0")]
[Route("api/lorawan/devices")]
[ApiExplorerSettings(GroupName = "LoRa WAN")]
[LoRaFeatureActiveFilter]
public class LoRaWANDevicesController : DevicesControllerBase<DeviceListItem, LoRaDeviceDetails>
{
private readonly ITableClientFactory tableClientFactory;
Expand All @@ -35,7 +37,7 @@ public LoRaWANDevicesController(
ITableClientFactory tableClientFactory,
ILoraDeviceMethodManager loraDeviceMethodManager,
IDeviceModelCommandMapper deviceModelCommandMapper)
: base (logger, devicesService, deviceTwinMapper)
: base(logger, devicesService, deviceTwinMapper)
{
this.tableClientFactory = tableClientFactory;
this.loraDeviceMethodManager = loraDeviceMethodManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ public IActionResult GetOIDCSettings()
return this.Ok(this.configuration);
}

/// <summary>
/// Get the a boolean for LoRa feature enable on the portal or not.
/// </summary>
/// <returns>The LoRa support setting.</returns>
/// <response code="200">Returns the LoRa support setting.</response>
/// <response code="500">Internal server error.</response>
[HttpGet("lora", Name = "GET LoRa settings")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetLoRaActivationSetting()
{
return this.Ok(this.configHandler.LoRaFeatureSetting);
return this.Ok(this.configHandler.IsLoRaEnabled);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using System;
using static AzureIoTHub.Portal.Server.Startup;

namespace AzureIoTHub.Portal.Server.Filters
{
public class LoRaFeatureActiveFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
var configHandler = context.HttpContext.RequestServices.GetService<ConfigHandler>();

if (configHandler.IsLoRaEnabled == false)
{
context.Result = new BadRequestObjectResult(context.ModelState)
{
Value = "LoRa features are disabled."
};
}
}
}
}
6 changes: 3 additions & 3 deletions src/AzureIoTHub.Portal/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ internal static ConfigHandler Create(IWebHostEnvironment env, IConfiguration con

internal abstract string OIDCAuthority { get; }

internal abstract string LoRaFeatureSetting { get; }
internal abstract bool IsLoRaEnabled { get; }

internal abstract string StorageAccountBlobContainerName { get; }

Expand Down Expand Up @@ -340,7 +340,7 @@ internal ProductionConfigHandler(IConfiguration config)

internal override string OIDCApiClientId => this.config[OIDCApiClientIdKey];

internal override string LoRaFeatureSetting => this.config[LoRaFeatureSettingKey];
internal override bool IsLoRaEnabled => bool.Parse(this.config[LoRaFeatureSettingKey]);

internal override string StorageAccountBlobContainerName => this.config[StorageAccountBlobContainerNameKey];

Expand Down Expand Up @@ -382,7 +382,7 @@ internal DevelopmentConfigHandler(IConfiguration config)

internal override string OIDCApiClientId => this.config[OIDCApiClientIdKey];

internal override string LoRaFeatureSetting => this.config[LoRaFeatureSettingKey];
internal override bool IsLoRaEnabled => bool.Parse(this.config[LoRaFeatureSettingKey]);

internal override string StorageAccountBlobContainerName => this.config[StorageAccountBlobContainerNameKey];

Expand Down

0 comments on commit 349c28e

Please sign in to comment.