Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and changes to JsonModelBinder, OrdersController, Images and Categories. #184

Open
wants to merge 15 commits into
base: nopCommerce_4.10
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.suo
*.user
_ReSharper.*
bin
obj
packages
Original file line number Diff line number Diff line change
@@ -1,95 +1,89 @@
namespace Nop.Plugin.Api.Controllers.Admin
{
using Microsoft.AspNetCore.Mvc;
using Core;
using Constants;
using Domain;
using MappingExtensions;
using Models;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Logging;
using Nop.Services.Stores;
using Web.Framework;
using Nop.Web.Framework.Controllers;
using Web.Framework.Mvc.Filters;

[AuthorizeAdmin]
[Area(AreaNames.Admin)]
public class ApiAdminController : BasePluginController
{
private readonly IStoreService _storeService;
private readonly IStoreContext _storeContext;
private readonly IWorkContext _workContext;
private readonly ISettingService _settingService;
private readonly ICustomerActivityService _customerActivityService;
private readonly ILocalizationService _localizationService;

public ApiAdminController(
IStoreService storeService,
IStoreContext storeContext,
IWorkContext workContext,
ISettingService settingService,
ICustomerActivityService customerActivityService,
ILocalizationService localizationService)
{
_storeService = storeService;
_storeContext = storeContext;
_workContext = workContext;
_settingService = settingService;
_customerActivityService = customerActivityService;
_localizationService = localizationService;
}

[HttpGet]
public ActionResult Settings()
{

var storeScope = _storeContext.ActiveStoreScopeConfiguration;

var apiSettings = _settingService.LoadSetting<ApiSettings>(storeScope);

var model = apiSettings.ToModel();

// Store Settings
model.ActiveStoreScopeConfiguration = storeScope;

if (model.EnableApi_OverrideForStore || storeScope == 0)
_settingService.SaveSetting(apiSettings, x => x.EnableApi, storeScope, false);
if (model.AllowRequestsFromSwagger_OverrideForStore || storeScope == 0)
_settingService.SaveSetting(apiSettings, x => x.AllowRequestsFromSwagger, storeScope, false);

//now clear settings cache
_settingService.ClearCache();

return View(ViewNames.AdminApiSettings, model);
}

[HttpPost]
public ActionResult Settings(ConfigurationModel configurationModel)
{
//load settings for a chosen store scope
var storeScope = _storeContext.ActiveStoreScopeConfiguration;

var settings = configurationModel.ToEntity();

/* We do not clear cache after each setting update.
* This behavior can increase performance because cached settings will not be cleared
* and loaded from database after each update */

if (configurationModel.EnableApi_OverrideForStore || storeScope == 0)
_settingService.SaveSetting(settings, x => x.EnableApi, storeScope, false);
if (configurationModel.AllowRequestsFromSwagger_OverrideForStore || storeScope == 0)
_settingService.SaveSetting(settings, x => x.AllowRequestsFromSwagger, storeScope, false);

//now clear settings cache
_settingService.ClearCache();

_customerActivityService.InsertActivity("EditApiSettings", "Edit Api Settings");

SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

return View(ViewNames.AdminApiSettings, configurationModel);
}
}
}
using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Plugin.Api.Areas.Admin.Models;
using Nop.Plugin.Api.Domain;
using Nop.Plugin.Api.MappingExtensions;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Logging;
using Nop.Services.Messages;
using Nop.Web.Framework;
using Nop.Web.Framework.Controllers;
using Nop.Web.Framework.Mvc.Filters;

namespace Nop.Plugin.Api.Areas.Admin.Controllers
{
[AuthorizeAdmin]
[Area(AreaNames.Admin)]
public class ApiAdminController : BasePluginController
{
private readonly ICustomerActivityService _customerActivityService;
private readonly ILocalizationService _localizationService;
private readonly INotificationService _notificationService;
private readonly ISettingService _settingService;
private readonly IStoreContext _storeContext;

public ApiAdminController(
IStoreContext storeContext,
ISettingService settingService,
ICustomerActivityService customerActivityService,
ILocalizationService localizationService,
INotificationService notificationService)
{
_storeContext = storeContext;
_settingService = settingService;
_customerActivityService = customerActivityService;
_localizationService = localizationService;
_notificationService = notificationService;
}

[HttpGet]
public IActionResult Settings()
{
var storeScope = _storeContext.ActiveStoreScopeConfiguration;
var apiSettings = _settingService.LoadSetting<ApiSettings>(storeScope);
var model = apiSettings.ToModel();

// Store Settings
model.ActiveStoreScopeConfiguration = storeScope;

if (model.EnableApi_OverrideForStore || storeScope == 0)
{
_settingService.SaveSetting(apiSettings, x => x.EnableApi, storeScope, false);
}

//now clear settings cache
_settingService.ClearCache();

return View($"~/Plugins/Nop.Plugin.Api/Areas/Admin/Views/ApiAdmin/Settings.cshtml", model);
}

[HttpPost]
public IActionResult Settings(ConfigurationModel model)
{
//load settings for a chosen store scope
var storeScope = _storeContext.ActiveStoreScopeConfiguration;

var settings = model.ToEntity();

/* We do not clear cache after each setting update.
* This behavior can increase performance because cached settings will not be cleared
* and loaded from database after each update */

if (model.EnableApi_OverrideForStore || storeScope == 0)
{
_settingService.SaveSetting(settings, x => x.EnableApi, storeScope, false);
}

//now clear settings cache
_settingService.ClearCache();

_customerActivityService.InsertActivity("EditApiSettings", "Edit Api Settings");

_notificationService.SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

return View($"~/Plugins/Nop.Plugin.Api/Areas/Admin/Views/ApiAdmin/Settings.cshtml", model);
}
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Nop.Plugin.Api.Models
{
using Nop.Web.Framework.Mvc.ModelBinding;
using Nop.Web.Framework.Mvc.ModelBinding;

namespace Nop.Plugin.Api.Areas.Admin.Models
{
public class ConfigurationModel
{
[NopResourceDisplayName("Plugins.Api.Admin.EnableApi")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@model ConfigurationModel
@using Nop.Plugin.Api.Infrastructure
@model Nop.Plugin.Api.Areas.Admin.Models.ConfigurationModel

@{
Layout = ViewNames.AdminLayout;
@{
Layout = Constants.ViewNames.AdminLayout;

//page title
ViewBag.Title = T("Plugins.Api.Admin.Page.Settings.Title").Text;

//active menu item (system name)
Html.SetActiveMenuItemSystemName("Api-Settings-Menu");
Html.SetActiveMenuItemSystemName("Api-Settings-Menu");
}

<form asp-controller="ApiAdmin" asp-action="Settings" method="post">
Expand All @@ -28,7 +29,6 @@
<div class="content">
<div class="form-horizontal">
@await Component.InvokeAsync("StoreScopeConfiguration")
@await Component.InvokeAsync("SettingMode")
@Html.ValidationSummary(false)
<div class="panel-group">

Expand All @@ -44,26 +44,6 @@
<span asp-validation-for="EnableApi"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<nop-override-store-checkbox asp-for="AllowRequestsFromSwagger_OverrideForStore" asp-input="AllowRequestsFromSwagger" asp-store-scope="@Model.ActiveStoreScopeConfiguration" />
<nop-label asp-for="AllowRequestsFromSwagger" />
</div>
<div class="col-md-9">
<nop-editor asp-for="AllowRequestsFromSwagger" />
<span asp-validation-for="AllowRequestsFromSwagger"></span>
</div>
</div>
<div class="form-group advanced-setting">
<div class="col-md-3">
<nop-override-store-checkbox asp-for="EnableLogging_OverrideForStore" asp-input="EnableLogging" asp-store-scope="@Model.ActiveStoreScopeConfiguration" />
<nop-label asp-for="EnableLogging" />
</div>
<div class="col-md-9">
<nop-editor asp-for="EnableLogging" />
<span asp-validation-for="EnableLogging"></span>
</div>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Nop.Web.Framework

@using Nop.Plugin.Api.Constants
@using Nop.Web.Framework.UI
@using Nop.Plugin.Api.Models;
@using IdentityServer4.Models;
@using Nop.Plugin.Api.Models
42 changes: 42 additions & 0 deletions Attributes/ApiAuthorize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//namespace Nop.Plugin.Api.Attributes
//{
// using Microsoft.AspNetCore.Authorization;
// using Nop.Core.Infrastructure;
// using Nop.Services.Plugins;

// // We need the ApiAuthorize attribute because when the api plugin assembly is loaded in memory by PluginManager
// // all of its attributes are being initialized by the .NetFramework.
// // The authorize attribute of the api plugin is marked with the Bearer authentication scheme, but the scheme is registered in the ApiStartup class,
// // which is called on plugin install.
// // If the plugin is not installed the authorize attribute will still be initialized when the assembly is loaded in memory, but the scheme won't be registered,
// // which will cause an exception.
// // That is why we need to make sure that the plugin is installed before setting the scheme.
// public class ApiAuthorize : AuthorizeAttribute
// {

// public new string Policy
// {
// get => base.AuthenticationSchemes;
// set => base.AuthenticationSchemes = GetAuthenticationSchemeName(value);
// }

// public new string AuthenticationSchemes
// {
// get => base.AuthenticationSchemes;
// set => base.AuthenticationSchemes = GetAuthenticationSchemeName(value);
// }

// private string GetAuthenticationSchemeName(string value)
// {
// var pluginService = EngineContext.Current.Resolve<IPluginService>();
// var pluginInstalled = pluginService.FindPluginByTypeInAssembly(typeof(ApiStartup))?.PluginDescriptor.Installed ?? false;

// if (pluginInstalled)
// {
// return value;
// }

// return default(string);
// }
// }
//}
File renamed without changes.
Loading