Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,20 @@ public virtual async Task<IPagedList<MerchandiseReturn>> SearchMerchandiseReturn
/// <summary>
/// Gets all merchandise return actions
/// </summary>
/// <param name="storeId">Store identifier; empty to load all entries</param>
/// <returns>Merchandise return actions</returns>
public virtual async Task<IList<MerchandiseReturnAction>> GetAllMerchandiseReturnActions()
public virtual async Task<IList<MerchandiseReturnAction>> GetAllMerchandiseReturnActions(string storeId = "")
{
return await _cacheBase.GetAsync(CacheKey.MERCHANDISE_RETURN_ACTIONS_ALL_KEY, async () =>
var key = string.Format(CacheKey.MERCHANDISE_RETURN_ACTIONS_ALL_KEY, storeId);
return await _cacheBase.GetAsync(key, async () =>
{
var query = from rra in _merchandiseReturnActionRepository.Table
orderby rra.DisplayOrder
select rra;
return await Task.FromResult(query.ToList());
var actions = query.ToList();
if (!string.IsNullOrEmpty(storeId))
actions = actions.Where(x => !x.LimitedToStores || x.Stores.Contains(storeId)).ToList();
return await Task.FromResult(actions);
});
}

Expand Down Expand Up @@ -203,7 +208,7 @@ public virtual async Task InsertMerchandiseReturnAction(MerchandiseReturnAction
await _mediator.EntityInserted(merchandiseReturnAction);

//clear cache
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_ACTIONS_ALL_KEY);
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_ACTIONS_PATTERN_KEY);
}

/// <summary>
Expand All @@ -220,7 +225,7 @@ public virtual async Task UpdateMerchandiseReturnAction(MerchandiseReturnAction
await _mediator.EntityUpdated(merchandiseReturnAction);

//clear cache
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_ACTIONS_ALL_KEY);
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_ACTIONS_PATTERN_KEY);
}

/// <summary>
Expand Down Expand Up @@ -251,21 +256,26 @@ public virtual async Task DeleteMerchandiseReturnReason(MerchandiseReturnReason
await _mediator.EntityDeleted(merchandiseReturnReason);

//clear cache
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_REASONS_ALL_KEY);
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_REASONS_PATTERN_KEY);
}

/// <summary>
/// Gets all merchandise return reasons
/// </summary>
/// <param name="storeId">Store identifier; empty to load all entries</param>
/// <returns>Merchandise return reasons</returns>
public virtual async Task<IList<MerchandiseReturnReason>> GetAllMerchandiseReturnReasons()
public virtual async Task<IList<MerchandiseReturnReason>> GetAllMerchandiseReturnReasons(string storeId = "")
{
return await _cacheBase.GetAsync(CacheKey.MERCHANDISE_RETURN_REASONS_ALL_KEY, async () =>
var key = string.Format(CacheKey.MERCHANDISE_RETURN_REASONS_ALL_KEY, storeId);
return await _cacheBase.GetAsync(key, async () =>
{
var query = from rra in _merchandiseReturnReasonRepository.Table
orderby rra.DisplayOrder
select rra;
return await Task.FromResult(query.ToList());
var reasons = query.ToList();
if (!string.IsNullOrEmpty(storeId))
reasons = reasons.Where(x => !x.LimitedToStores || x.Stores.Contains(storeId)).ToList();
return await Task.FromResult(reasons);
});
}

Expand Down Expand Up @@ -293,7 +303,7 @@ public virtual async Task InsertMerchandiseReturnReason(MerchandiseReturnReason
await _mediator.EntityInserted(merchandiseReturnReason);

//clear cache
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_REASONS_ALL_KEY);
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_REASONS_PATTERN_KEY);
}

/// <summary>
Expand All @@ -310,7 +320,7 @@ public virtual async Task UpdateMerchandiseReturnReason(MerchandiseReturnReason
await _mediator.EntityUpdated(merchandiseReturnReason);

//clear cache
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_REASONS_ALL_KEY);
await _cacheBase.RemoveByPrefix(CacheKey.MERCHANDISE_RETURN_REASONS_PATTERN_KEY);
}

#region Merchandise return notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ Task<IPagedList<MerchandiseReturn>> SearchMerchandiseReturns(string storeId = ""
/// <summary>
/// Gets all merchandise return actions
/// </summary>
/// <param name="storeId">Store identifier; empty to load all entries</param>
/// <returns>Merchandise return actions</returns>
Task<IList<MerchandiseReturnAction>> GetAllMerchandiseReturnActions();
Task<IList<MerchandiseReturnAction>> GetAllMerchandiseReturnActions(string storeId = "");

/// <summary>
/// Gets a merchandise return action
Expand Down Expand Up @@ -93,8 +94,9 @@ Task<IPagedList<MerchandiseReturn>> SearchMerchandiseReturns(string storeId = ""
/// <summary>
/// Gets all merchandise return reasons
/// </summary>
/// <param name="storeId">Store identifier; empty to load all entries</param>
/// <returns>Merchandise return reasons</returns>
Task<IList<MerchandiseReturnReason>> GetAllMerchandiseReturnReasons();
Task<IList<MerchandiseReturnReason>> GetAllMerchandiseReturnReasons(string storeId = "");

/// <summary>
/// Gets a merchandise return reasons
Expand Down
13 changes: 12 additions & 1 deletion src/Core/Grand.Domain/Orders/MerchandiseReturnAction.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Grand.Domain.Localization;
using Grand.Domain.Stores;

namespace Grand.Domain.Orders;

/// <summary>
/// Represents a merchandise return action
/// </summary>
public class MerchandiseReturnAction : BaseEntity, ITranslationEntity
public class MerchandiseReturnAction : BaseEntity, ITranslationEntity, IStoreLinkEntity
{
/// <summary>
/// Gets or sets the name
Expand All @@ -21,4 +22,14 @@ public class MerchandiseReturnAction : BaseEntity, ITranslationEntity
/// Gets or sets the collection of locales
/// </summary>
public IList<TranslationEntity> Locales { get; set; } = new List<TranslationEntity>();

/// <summary>
/// Gets or sets a value indicating whether the entity is limited/restricted to certain stores
/// </summary>
public bool LimitedToStores { get; set; }

/// <summary>
/// Gets or sets the stores
/// </summary>
public IList<string> Stores { get; set; } = new List<string>();
}
13 changes: 12 additions & 1 deletion src/Core/Grand.Domain/Orders/MerchandiseReturnReason.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Grand.Domain.Localization;
using Grand.Domain.Stores;

namespace Grand.Domain.Orders;

/// <summary>
/// Represents a merchandise return reason
/// </summary>
public class MerchandiseReturnReason : BaseEntity, ITranslationEntity
public class MerchandiseReturnReason : BaseEntity, ITranslationEntity, IStoreLinkEntity
{
/// <summary>
/// Gets or sets the name
Expand All @@ -21,4 +22,14 @@ public class MerchandiseReturnReason : BaseEntity, ITranslationEntity
/// Gets or sets the collection of locales
/// </summary>
public IList<TranslationEntity> Locales { get; set; } = new List<TranslationEntity>();

/// <summary>
/// Gets or sets a value indicating whether the entity is limited/restricted to certain stores
/// </summary>
public bool LimitedToStores { get; set; }

/// <summary>
/// Gets or sets the stores
/// </summary>
public IList<string> Stores { get; set; } = new List<string>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
public static partial class CacheKey
{
/// <summary>
/// Key for all merchandise return reason
/// Key for all merchandise return reasons. {0} - store ID
/// </summary>
public static string MERCHANDISE_RETURN_REASONS_ALL_KEY => "Grand.merchandisereturn.reasons.all";
public static string MERCHANDISE_RETURN_REASONS_ALL_KEY => "Grand.merchandisereturn.reasons.all-{0}";

/// <summary>
/// Key for all merchandise return actions
/// Key pattern to clear merchandise return reasons cache
/// </summary>
public static string MERCHANDISE_RETURN_ACTIONS_ALL_KEY => "Grand.merchandisereturn.actions.all";
public static string MERCHANDISE_RETURN_REASONS_PATTERN_KEY => "Grand.merchandisereturn.reasons";

/// <summary>
/// Key for all merchandise return actions. {0} - store ID
/// </summary>
public static string MERCHANDISE_RETURN_ACTIONS_ALL_KEY => "Grand.merchandisereturn.actions.all-{0}";

/// <summary>
/// Key pattern to clear merchandise return actions cache
/// </summary>
public static string MERCHANDISE_RETURN_ACTIONS_PATTERN_KEY => "Grand.merchandisereturn.actions";
}
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ public static class StandardAdminSiteMap
new() {
SystemName = "Push notifications settings",
ResourceName = "Admin.Settings.PushNotifications",
PermissionNames = new List<string> { PermissionSystemName.System },
ControllerName = "Setting",
ActionName = "PushNotifications",
DisplayOrder = 7,
Expand All @@ -983,6 +984,7 @@ public static class StandardAdminSiteMap
new() {
SystemName = "Admin search settings",
ResourceName = "Admin.Settings.AdminSearch",
PermissionNames = new List<string> { PermissionSystemName.System },
ControllerName = "Setting",
ActionName = "AdminSearch",
DisplayOrder = 8,
Expand All @@ -991,6 +993,7 @@ public static class StandardAdminSiteMap
new() {
SystemName = "System settings",
ResourceName = "Admin.Settings.System",
PermissionNames = new List<string> { PermissionSystemName.System },
ControllerName = "Setting",
ActionName = "SystemSetting",
DisplayOrder = 9,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Grand.Data;
using Grand.Domain.Admin;
using Grand.Domain.Permissions;
using Grand.Infrastructure.Migrations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Grand.Module.Migration.Migrations._2._4;

public class MigrationUpdateAdminSiteMap : IMigration
{
public int Priority => 1;
public DbVersion Version => new(2, 4);
public Guid Identity => new("B7C3D8E2-F1A4-4B9E-8C62-197E3F5A4D21");
public string Name => "Update standard admin site map - restrict Push notifications, Admin search, System settings to System permission";

/// <summary>
/// Upgrade process
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
public bool UpgradeProcess(IServiceProvider serviceProvider)
{
var repository = serviceProvider.GetRequiredService<IRepository<AdminSiteMap>>();
var logService = serviceProvider.GetRequiredService<ILogger<MigrationUpdateAdminSiteMap>>();

try
{
var sitemapSettings = repository.Table.FirstOrDefault(x => x.SystemName == "Settings");
if (sitemapSettings == null) return true;

var adminOnlyItems = new[] {
"Push notifications settings",
"Admin search settings",
"System settings"
};

foreach (var itemName in adminOnlyItems)
{
var item = sitemapSettings.ChildNodes.FirstOrDefault(x => x.SystemName == itemName);
if (item != null && !item.PermissionNames.Contains(PermissionSystemName.System))
item.PermissionNames.Add(PermissionSystemName.System);
}

repository.Update(sitemapSettings);
}
catch (InvalidOperationException ex)
{
logService.LogError(ex, "UpgradeProcess - UpdateAdminSiteMap (2.4)");
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ public class MerchandiseReturnActionProfile : Profile, IAutoMapperProfile
public MerchandiseReturnActionProfile()
{
CreateMap<MerchandiseReturnAction, MerchandiseReturnActionModel>()
.ForMember(dest => dest.Locales, mo => mo.Ignore());
.ForMember(dest => dest.Locales, mo => mo.Ignore())
.ForMember(dest => dest.Stores, mo => mo.MapFrom(src => src.Stores.ToArray()));
CreateMap<MerchandiseReturnActionModel, MerchandiseReturnAction>()
.ForMember(dest => dest.Locales, mo => mo.MapFrom(x => x.Locales.ToTranslationProperty()))
.ForMember(dest => dest.Id, mo => mo.Ignore());
.ForMember(dest => dest.Id, mo => mo.Ignore())
.ForMember(dest => dest.LimitedToStores, mo => mo.MapFrom(x => x.Stores != null && x.Stores.Any()))
.ForMember(dest => dest.Stores, mo => mo.MapFrom(x => x.Stores != null ? x.Stores.ToList() : new List<string>()));
}

public int Order => 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ public class MerchandiseReturnReasonProfile : Profile, IAutoMapperProfile
public MerchandiseReturnReasonProfile()
{
CreateMap<MerchandiseReturnReason, MerchandiseReturnReasonModel>()
.ForMember(dest => dest.Locales, mo => mo.Ignore());
.ForMember(dest => dest.Locales, mo => mo.Ignore())
.ForMember(dest => dest.Stores, mo => mo.MapFrom(src => src.Stores.ToArray()));
CreateMap<MerchandiseReturnReasonModel, MerchandiseReturnReason>()
.ForMember(dest => dest.Locales, mo => mo.MapFrom(x => x.Locales.ToTranslationProperty()))
.ForMember(dest => dest.Id, mo => mo.Ignore());
.ForMember(dest => dest.Id, mo => mo.Ignore())
.ForMember(dest => dest.LimitedToStores, mo => mo.MapFrom(x => x.Stores != null && x.Stores.Any()))
.ForMember(dest => dest.Stores, mo => mo.MapFrom(x => x.Stores != null ? x.Stores.ToList() : new List<string>()));
}

public int Order => 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
using Grand.Web.Common.Link;
using Grand.Web.Common.Models;
using System.ComponentModel.DataAnnotations;

namespace Grand.Web.AdminShared.Models.Settings;

public class MerchandiseReturnActionModel : BaseEntityModel, ILocalizedModel<MerchandiseReturnActionLocalizedModel>
public class MerchandiseReturnActionModel : BaseEntityModel, ILocalizedModel<MerchandiseReturnActionLocalizedModel>,
IStoreLinkModel
{
[GrandResourceDisplayName("Admin.Settings.Order.MerchandiseReturnActions.Name")]

Expand All @@ -15,6 +18,10 @@ public class MerchandiseReturnActionModel : BaseEntityModel, ILocalizedModel<Mer

public IList<MerchandiseReturnActionLocalizedModel> Locales { get; set; } =
new List<MerchandiseReturnActionLocalizedModel>();

[GrandResourceDisplayName("Admin.Settings.Order.MerchandiseReturnActions.LimitedToStores")]
[UIHint("Stores")]
public string[] Stores { get; set; }
}

public class MerchandiseReturnActionLocalizedModel : ILocalizedModelLocal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
using Grand.Web.Common.Link;
using Grand.Web.Common.Models;
using System.ComponentModel.DataAnnotations;

namespace Grand.Web.AdminShared.Models.Settings;

public class MerchandiseReturnReasonModel : BaseEntityModel, ILocalizedModel<MerchandiseReturnReasonLocalizedModel>
public class MerchandiseReturnReasonModel : BaseEntityModel, ILocalizedModel<MerchandiseReturnReasonLocalizedModel>,
IStoreLinkModel
{
[GrandResourceDisplayName("Admin.Settings.Order.MerchandiseReturnReasons.Name")]

Expand All @@ -15,6 +18,10 @@ public class MerchandiseReturnReasonModel : BaseEntityModel, ILocalizedModel<Mer

public IList<MerchandiseReturnReasonLocalizedModel> Locales { get; set; } =
new List<MerchandiseReturnReasonLocalizedModel>();

[GrandResourceDisplayName("Admin.Settings.Order.MerchandiseReturnReasons.LimitedToStores")]
[UIHint("Stores")]
public string[] Stores { get; set; }
}

public class MerchandiseReturnReasonLocalizedModel : ILocalizedModelLocal
Expand Down
Loading
Loading