diff --git a/Oqtane.Client/Modules/Admin/Settings/ImportSettings.razor b/Oqtane.Client/Modules/Admin/Settings/ImportSettings.razor index 0c9f2620..5fdface0 100644 --- a/Oqtane.Client/Modules/Admin/Settings/ImportSettings.razor +++ b/Oqtane.Client/Modules/Admin/Settings/ImportSettings.razor @@ -31,8 +31,8 @@ if (!string.IsNullOrEmpty(_settings)) { ShowProgressIndicator(); - var success = await SettingService.ImportSettingsAsync(_settings); - if (success) + var result = await SettingService.ImportSettingsAsync(new Result { Message = _settings }); + if (result.Success) { AddModuleMessage(Localizer["Message.Import.Success"], MessageType.Success); } diff --git a/Oqtane.Client/Services/SettingService.cs b/Oqtane.Client/Services/SettingService.cs index 18bf471a..5bcbf414 100644 --- a/Oqtane.Client/Services/SettingService.cs +++ b/Oqtane.Client/Services/SettingService.cs @@ -258,7 +258,7 @@ namespace Oqtane.Services /// /// /// - Task ImportSettingsAsync(string settings); + Task ImportSettingsAsync(Result settings); /// /// Gets the value of the given settingName (key) from the given key-value dictionary @@ -524,9 +524,9 @@ namespace Oqtane.Services return await GetJsonAsync>($"{Apiurl}/entityids?entityname={entityName}"); } - public async Task ImportSettingsAsync(string settings) + public async Task ImportSettingsAsync(Result settings) { - return await PostJsonAsync($"{Apiurl}/import?settings={settings}", true); + return await PostJsonAsync($"{Apiurl}/import", settings); } public string GetSetting(Dictionary settings, string settingName, string defaultValue) diff --git a/Oqtane.Server/Controllers/SettingController.cs b/Oqtane.Server/Controllers/SettingController.cs index 38c376cd..ee777360 100644 --- a/Oqtane.Server/Controllers/SettingController.cs +++ b/Oqtane.Server/Controllers/SettingController.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.Extensions.Options; using System.IO; using System.Text.RegularExpressions; +using Oqtane.Migrations.Tenant; namespace Oqtane.Controllers { @@ -269,11 +270,13 @@ namespace Oqtane.Controllers // POST api//import?settings=x [HttpPost("import")] [Authorize(Roles = RoleNames.Host)] - public bool Import(string settings) + public Result Import([FromBody] Result settings) { - if (!string.IsNullOrEmpty(settings)) + if (ModelState.IsValid && !string.IsNullOrEmpty(settings.Message)) { - using (StringReader reader = new StringReader(settings)) + int rows = 0; + + using (StringReader reader = new StringReader(settings.Message)) { // regex to split by comma - ignoring commas within double quotes string pattern = ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"; @@ -316,17 +319,23 @@ namespace Oqtane.Controllers setting.IsPrivate = isPrivate; _settings.UpdateSetting(setting); } + rows++; } } } - return true; + _logger.Log(LogLevel.Information, this, LogFunction.Create, "Settings Imported {Settings}", settings.Message); + settings.Message = $"{rows} Settings Imported"; + settings.Success = true; + return settings; } else { - _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Settings Import Attempt {Settings}", settings); + _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Settings Import Attempt {Settings}", settings.Message); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; - return false; + settings.Message = ""; + settings.Success = false; + return settings; } }