Skip to content

Commit

Permalink
Merge pull request #696 from hargata/Hargata/custom.widgets
Browse files Browse the repository at this point in the history
require environment variable to be injected for security reasons.
  • Loading branch information
hargata authored Nov 4, 2024
2 parents ada0715 + c1b3613 commit 89ece41
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
24 changes: 18 additions & 6 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,22 +527,34 @@ public ActionResult GetVehicleSelector(int vehicleId)
[HttpGet]
public IActionResult GetCustomWidgetEditor()
{
var customWidgetData = _fileHelper.GetWidgets();
return PartialView("_WidgetEditor", customWidgetData);
if (_config.GetCustomWidgetsEnabled())
{
var customWidgetData = _fileHelper.GetWidgets();
return PartialView("_WidgetEditor", customWidgetData);
}
return Json(string.Empty);
}
[Authorize(Roles = nameof(UserData.IsRootUser))]
[HttpPost]
public IActionResult SaveCustomWidgets(string widgetsData)
{
var saveResult = _fileHelper.SaveWidgets(widgetsData);
return Json(saveResult);
if (_config.GetCustomWidgetsEnabled())
{
var saveResult = _fileHelper.SaveWidgets(widgetsData);
return Json(saveResult);
}
return Json(false);
}
[Authorize(Roles = nameof(UserData.IsRootUser))]
[HttpPost]
public IActionResult DeleteCustomWidgets()
{
var deleteResult = _fileHelper.DeleteWidgets();
return Json(deleteResult);
if (_config.GetCustomWidgetsEnabled())
{
var deleteResult = _fileHelper.DeleteWidgets();
return Json(deleteResult);
}
return Json(false);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
Expand Down
5 changes: 5 additions & 0 deletions Helper/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IConfigHelper
bool AuthenticateRootUser(string username, string password);
bool AuthenticateRootUserOIDC(string email);
string GetWebHookUrl();
bool GetCustomWidgetsEnabled();
string GetMOTD();
string GetLogoUrl();
string GetServerLanguage();
Expand Down Expand Up @@ -45,6 +46,10 @@ public string GetWebHookUrl()
}
return webhook;
}
public bool GetCustomWidgetsEnabled()
{
return bool.Parse(_config["LUBELOGGER_CUSTOM_WIDGETS"] ?? "false");
}
public string GetMOTD()
{
var motd = _config["LUBELOGGER_MOTD"];
Expand Down
8 changes: 6 additions & 2 deletions wwwroot/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,12 @@ function showCustomWidgets() {
}).then(function (result) {
if (result.isConfirmed) {
$.get('/Home/GetCustomWidgetEditor', function (data) {
$("#customWidgetModalContent").html(data);
$("#customWidgetModal").modal('show');
if (data.trim() != '') {
$("#customWidgetModalContent").html(data);
$("#customWidgetModal").modal('show');
} else {
errorToast("Custom Widgets Not Enabled");
}
});
}
});
Expand Down

0 comments on commit 89ece41

Please sign in to comment.