-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathPricingSamplesCustomerOrderDataProtectionService.cs
More file actions
52 lines (43 loc) · 1.88 KB
/
PricingSamplesCustomerOrderDataProtectionService.cs
File metadata and controls
52 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Services;
using VirtoCommerce.OrdersModule.Data.Services;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Security;
using VirtoCommerce.StoreModule.Core.Model;
using VirtoCommerce.StoreModule.Core.Services;
namespace VirtoCommerce.OrdersModule2.Web.Services;
public sealed class PricingSamplesCustomerOrderDataProtectionService(
ICustomerOrderService crudService,
ICustomerOrderSearchService searchService,
IUserNameResolver userNameResolver,
SignInManager<ApplicationUser> signInManager,
IStoreService storeService,
IOptions<MvcNewtonsoftJsonOptions> jsonOptions)
: CustomerOrderDataProtectionService(crudService, searchService, userNameResolver, signInManager)
{
private readonly MvcNewtonsoftJsonOptions _jsonOptions = jsonOptions.Value;
protected override async Task<bool> CanReadPrices(ClaimsPrincipal user, CustomerOrder order)
{
var canReadPrices = await base.CanReadPrices(user, order);
if (!canReadPrices)
{
var store = await storeService.GetByIdAsync(order.StoreId);
canReadPrices = store != null && CanReadPricesForStore(user, store);
}
return canReadPrices;
}
private bool CanReadPricesForStore(ClaimsPrincipal user, Store store)
{
var isDirectDistributor = store.Name.ContainsIgnoreCase("Direct");
var permissionName = isDirectDistributor
? ModuleConstants.Permissions.ReadPricesDirect
: ModuleConstants.Permissions.ReadPricesIndirect;
var permission = user.FindPermission(permissionName, _jsonOptions.SerializerSettings);
return permission != null;
}
}