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

Adding Access orders to the Access control list for customers #1034

Open
wants to merge 4 commits into
base: main
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Smartstore.Core/Checkout/Permissions.Checkout.cs
Expand Up @@ -83,6 +83,7 @@ public static class Cart
{
public const string Self = "cart";
public const string Read = "cart.read";
public const string AccessOrders = "cart.accessorders";
public const string AccessShoppingCart = "cart.accessshoppingcart";
public const string AccessWishlist = "cart.accesswishlist";

Expand Down
211 changes: 0 additions & 211 deletions src/Smartstore.Core/Migrations/SmartDbContextDataSeeder.cs

This file was deleted.

Expand Up @@ -41,6 +41,7 @@ public virtual IEnumerable<DefaultPermissionRecord> GetDefaultPermissions()
PermissionRecords = new[]
{
new PermissionRecord { SystemName = Permissions.Catalog.DisplayPrice },
new PermissionRecord { SystemName = Permissions.Cart.AccessOrders },
new PermissionRecord { SystemName = Permissions.Cart.AccessShoppingCart },
new PermissionRecord { SystemName = Permissions.Cart.AccessWishlist },
new PermissionRecord { SystemName = Permissions.System.AccessShop }
Expand All @@ -52,6 +53,7 @@ public virtual IEnumerable<DefaultPermissionRecord> GetDefaultPermissions()
PermissionRecords = new[]
{
new PermissionRecord { SystemName = Permissions.Catalog.DisplayPrice },
new PermissionRecord { SystemName = Permissions.Cart.AccessOrders },
new PermissionRecord { SystemName = Permissions.Cart.AccessShoppingCart },
new PermissionRecord { SystemName = Permissions.Cart.AccessWishlist },
new PermissionRecord { SystemName = Permissions.System.AccessShop }
Expand All @@ -63,6 +65,7 @@ public virtual IEnumerable<DefaultPermissionRecord> GetDefaultPermissions()
PermissionRecords = new[]
{
new PermissionRecord { SystemName = Permissions.Catalog.DisplayPrice },
new PermissionRecord { SystemName = Permissions.Cart.AccessOrders },
new PermissionRecord { SystemName = Permissions.Cart.AccessShoppingCart },
new PermissionRecord { SystemName = Permissions.Cart.AccessWishlist },
new PermissionRecord { SystemName = Permissions.System.AccessShop }
Expand Down
16 changes: 10 additions & 6 deletions src/Smartstore.Web/Components/AccountDropdownViewComponent.cs
Expand Up @@ -18,6 +18,7 @@ public async Task<IViewComponentResult> InvokeAsync()
DisplayAdminLink = await Services.Permissions.AuthorizeAsync(Permissions.System.AccessBackend),
ShoppingCartEnabled = await Services.Permissions.AuthorizeAsync(Permissions.Cart.AccessShoppingCart),
WishlistEnabled = await Services.Permissions.AuthorizeAsync(Permissions.Cart.AccessWishlist),
OrdersEnabled = await Services.Permissions.AuthorizeAsync(Permissions.Cart.AccessOrders),
//ShoppingCartItems = await Services.DbContext.ShoppingCartItems.CountCartItemsAsync(customer, ShoppingCartType.ShoppingCart, Services.StoreContext.CurrentStore.Id),
//WishlistItems = await Services.DbContext.ShoppingCartItems.CountCartItemsAsync(customer, ShoppingCartType.Wishlist, Services.StoreContext.CurrentStore.Id)
};
Expand All @@ -29,12 +30,15 @@ public async Task<IViewComponentResult> InvokeAsync()
.Text(T("Account.MyAccount"))
.AsItem());

model.MenuItems.Add(new MenuItem().ToBuilder()
.Action("Orders", "Customer")
.LinkHtmlAttributes(new { @class = "dropdown-item", rel = "nofollow" })
.Icon("fal fa-file-lines fa-fw")
.Text(T("Account.MyOrders"))
.AsItem());
if (model.OrdersEnabled)
{
model.MenuItems.Add(new MenuItem().ToBuilder()
.Action("Orders", "Customer")
.LinkHtmlAttributes(new { @class = "dropdown-item", rel = "nofollow" })
.Icon("fal fa-file-lines fa-fw")
.Text(T("Account.MyOrders"))
.AsItem());
}

if (model.DisplayAdminLink)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Smartstore.Web/Controllers/CustomerController.cs
Expand Up @@ -494,6 +494,11 @@ public async Task<IActionResult> Orders(int? page, int? recurringPaymentsPage)
return ChallengeOrForbid();
}

if (!await Services.Permissions.AuthorizeAsync(Permissions.Cart.AccessOrders))
{
return RedirectToRoute("Homepage");
}

var ordersPageIndex = Math.Max((page ?? 0) - 1, 0);
var rpPageIndex = Math.Max((recurringPaymentsPage ?? 0) - 1, 0);

Expand Down
13 changes: 9 additions & 4 deletions src/Smartstore.Web/Infrastructure/Menus/MyAccountMenu.cs
Expand Up @@ -3,6 +3,7 @@
using Smartstore.Core.Content.Menus;
using Smartstore.Core.Identity;
using Smartstore.Core.Localization;
using Smartstore.Core.Security;

namespace Smartstore.Web.Infrastructure
{
Expand Down Expand Up @@ -110,16 +111,20 @@ protected virtual async Task<TreeNode<MenuItem>> BuildAsync()
Icon = "fal fa-address-book",
ActionName = "Addresses",
ControllerName = "Customer"
},
new MenuItem
}
});

if (await _services.Permissions.AuthorizeAsync(Permissions.Cart.AccessOrders))
{
root.Append(new MenuItem
{
Id = "orders",
Text = T("Account.CustomerOrders"),
Icon = "fal fa-file-lines",
ActionName = "Orders",
ControllerName = "Customer"
}
});
});
}

if (_orderSettings.ReturnRequestsEnabled)
{
Expand Down
1 change: 1 addition & 0 deletions src/Smartstore.Web/Models/Common/AccountDropdownModel.cs
Expand Up @@ -10,6 +10,7 @@ public partial class AccountDropdownModel : EntityModelBase
public bool ShoppingCartEnabled { get; set; }
public int ShoppingCartItems { get; set; }
public bool WishlistEnabled { get; set; }
public bool OrdersEnabled { get; set; }
public int WishlistItems { get; set; }

public List<MenuItem> MenuItems { get; } = new();
Expand Down