Skip to content

Commit

Permalink
Prevent for save a file with a null binary field
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Oct 28, 2021
1 parent e726dc1 commit 236a5e6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Web/Grand.Web.Admin/Controllers/SettingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task<IActionResult> Content()
NewsSettings = newsSettings.ToModel(),
KnowledgebaseSettings = knowledgebaseSettings.ToModel()
};

model.ActiveStore = storeScope;
return View(model);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public async Task<IActionResult> Vendor()
var storeScope = await GetActiveStore();
var vendorSettings = _settingService.LoadSetting<VendorSettings>(storeScope);
var model = vendorSettings.ToModel();

model.ActiveStore = storeScope;

return View(model);
Expand All @@ -176,7 +176,7 @@ public async Task<IActionResult> Vendor(VendorSettingsModel model)
var storeScope = await GetActiveStore();
var vendorSettings = _settingService.LoadSetting<VendorSettings>(storeScope);
vendorSettings = model.ToEntity(vendorSettings);

await _settingService.SaveSetting(vendorSettings, storeScope);

//now clear cache
Expand Down Expand Up @@ -630,9 +630,12 @@ private async Task SavePictureStorage(bool storeIdDb)
if (storeIdDb)
await _pictureService.DeletePictureOnFileSystem(picture);
else
{
//now on file system
await _pictureService.SavePictureInFile(picture.Id, pictureBinary, picture.MimeType);
picture.PictureBinary = storeIdDb ? pictureBinary : new byte[0];
if (pictureBinary != null)
await _pictureService.SavePictureInFile(picture.Id, pictureBinary, picture.MimeType);
}
picture.PictureBinary = storeIdDb ? pictureBinary : Array.Empty<byte>();
picture.IsNew = true;

await _pictureService.UpdatePicture(picture);
Expand Down Expand Up @@ -687,7 +690,7 @@ public async Task<IActionResult> Customer(CustomerSettingsModel model)

return RedirectToAction("Customer");
}

public async Task<IActionResult> GeneralCommon()
{
var model = new GeneralCommonSettingsModel();
Expand Down Expand Up @@ -749,7 +752,7 @@ public async Task<IActionResult> GeneralCommon()
//display menu settings
var displayMenuItemSettings = _settingService.LoadSetting<MenuItemSettings>(storeScope);
model.DisplayMenuSettings = displayMenuItemSettings.ToModel();

return View(model);
}

Expand Down Expand Up @@ -781,7 +784,7 @@ public async Task<IActionResult> GeneralCommon(GeneralCommonSettingsModel model)

//security settings
var securitySettings = _settingService.LoadSetting<SecuritySettings>(storeScope);

if (securitySettings.AdminAreaAllowedIpAddresses == null)
securitySettings.AdminAreaAllowedIpAddresses = new List<string>();
securitySettings.AdminAreaAllowedIpAddresses.Clear();
Expand All @@ -807,7 +810,7 @@ public async Task<IActionResult> GeneralCommon(GeneralCommonSettingsModel model)
var pdfSettings = _settingService.LoadSetting<PdfSettings>(storeScope);
pdfSettings = model.PdfSettings.ToEntity(pdfSettings);
await _settingService.SaveSetting(pdfSettings, storeScope);

//googleanalytics settings
var googleAnalyticsSettings = _settingService.LoadSetting<GoogleAnalyticsSettings>(storeScope);
googleAnalyticsSettings = model.GoogleAnalyticsSettings.ToEntity(googleAnalyticsSettings);
Expand Down Expand Up @@ -910,7 +913,7 @@ private void SavePushNotificationsToFile(PushNotificationsSettingsModel model)
throw new ArgumentNullException($"{oryginalFilePath} not exist");

}

public IActionResult AdminSearch()
{
var settings = _settingService.LoadSetting<AdminSearchSettings>();
Expand Down

0 comments on commit 236a5e6

Please sign in to comment.