Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Changes in GetTranslationPermissionName
KrzysztofPajakbaa3800dde83
diff --git a/src/Business/Grand.Business.Core/Extensions/TranslateExtensions.cs b/src/Business/Grand.Business.Core/Extensions/TranslateExtensions.csindex eddab5851..968a1f128 100644--- a/src/Business/Grand.Business.Core/Extensions/TranslateExtensions.cs+++ b/src/Business/Grand.Business.Core/Extensions/TranslateExtensions.cs@@ -108,40 +108,10 @@ public static class TranslateExtensions/// We don't have UI to manage permission localizable name. That's why we're using this extension method/// </summary>/// <param name="permissionRecord">Permission record</param>- /// <param name="translationService">Translation service</param>- /// <param name="workContext">Work context</param>/// <returns>Translation value</returns>- public static string GetTranslationPermissionName(this Permission permissionRecord,- ITranslationService translationService, IWorkContext workContext)+ public static string GetTranslationPermissionName(this Permission permissionRecord){- ArgumentNullException.ThrowIfNull(workContext);-- return GetTranslationPermissionName(permissionRecord, translationService, workContext.WorkingLanguage.Id);- }-- /// <summary>- /// Get translation value of enum- /// We don't have UI to manage permission translation name. That's why we're using this extension method- /// </summary>- /// <param name="permissionRecord">Permission record</param>- /// <param name="translationService">Translation service</param>- /// <param name="languageId">Language identifier</param>- /// <returns>Translation value</returns>- public static string GetTranslationPermissionName(this Permission permissionRecord,- ITranslationService translationService, string languageId)- {- ArgumentNullException.ThrowIfNull(permissionRecord);- ArgumentNullException.ThrowIfNull(translationService);-- //Translation value- var name = $"Permission.{permissionRecord.SystemName}";- var result = translationService.GetResource(name, languageId, "", true);-- //set default value if required- if (string.IsNullOrEmpty(result))- result = permissionRecord.Name;-- return result;+ return $"Permission.{permissionRecord.SystemName}";}/// <summary>diff --git a/src/Tests/Grand.Business.Common.Tests/Extensions/TranslateExtensionsTests.cs b/src/Tests/Grand.Business.Common.Tests/Extensions/TranslateExtensionsTests.csindex c10c5cb96..77414435a 100644--- a/src/Tests/Grand.Business.Common.Tests/Extensions/TranslateExtensionsTests.cs+++ b/src/Tests/Grand.Business.Common.Tests/Extensions/TranslateExtensionsTests.cs@@ -63,34 +63,6 @@ public class TranslateExtensionsTestsvar fake = new FakeStruct();Assert.ThrowsException<ArgumentException>(() => fake.GetTranslationEnum(translationServiceMock.Object, "PL"));}-- [TestMethod]- public void GetTranslationPermissionName_ReturnExpectedValue()- {- var expectedValue = "PLpermision";- var translationServiceMock = new Mock<ITranslationService>();- translationServiceMock- .Setup(c => c.GetResource(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))- .Returns(expectedValue);- var record = new Permission {- SystemName = "sysname"- };- var result = record.GetTranslationPermissionName(translationServiceMock.Object, "PL");- Assert.AreEqual(result, expectedValue);- }-- [TestMethod]- public void GetTranslationPermissionName_NullArgument_ThrowException()- {- var expectedValue = "PLpermision";- var translationServiceMock = new Mock<ITranslationService>();- translationServiceMock- .Setup(c => c.GetResource(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))- .Returns(expectedValue);- Permission record = null;- Assert.ThrowsException<ArgumentNullException>(() =>- record.GetTranslationPermissionName(translationServiceMock.Object, "PL"));- }-+private struct FakeStruct;}\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Controllers/CustomerGroupController.cs b/src/Web/Grand.Web.Admin/Controllers/CustomerGroupController.csindex 15ecca5b5..ed99f4e43 100644--- a/src/Web/Grand.Web.Admin/Controllers/CustomerGroupController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/CustomerGroupController.cs@@ -263,7 +263,7 @@ public class CustomerGroupController : BaseAdminControllerforeach (var pr in permissionRecords)model.Add(new CustomerGroupPermissionModel {Id = pr.Id,- Name = pr.GetTranslationPermissionName(_translationService, _workContext),+ Name = _translationService.GetResource(pr.GetTranslationPermissionName(), _workContext.WorkingLanguage.Id),SystemName = pr.SystemName,Actions = pr.Actions.ToList(),Access = pr.CustomerGroups.Contains(customerGroupId)diff --git a/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs b/src/Web/Grand.Web.Admin/Controllers/PermissionController.csindex c231d0b28..3aff73df0 100644--- a/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs@@ -1,4 +1,5 @@-using Grand.Business.Core.Extensions;+using DotLiquid.Util;+using Grand.Business.Core.Extensions;using Grand.Business.Core.Interfaces.Common.Directory;using Grand.Business.Core.Interfaces.Common.Localization;using Grand.Business.Core.Interfaces.Common.Security;@@ -50,7 +51,7 @@ public class PermissionController : BaseAdminControllervar customerGroups = await _groupService.GetAllCustomerGroups(showHidden: true);foreach (var pr in permissionRecords.OrderBy(x => x.Category))model.AvailablePermissions.Add(new PermissionRecordModel {- Name = pr.GetTranslationPermissionName(_translationService, _workContext),+ Name =_translationService.GetResource(pr.GetTranslationPermissionName(), _workContext.WorkingLanguage.Id),SystemName = pr.SystemName,Area = pr.Area,Category = pr.Category,@@ -169,7 +170,7 @@ public class PermissionController : BaseAdminControllerif (permissionRecord != null){model.AvailableActions = permissionRecord.Actions.ToList();- model.PermissionName = permissionRecord.GetTranslationPermissionName(_translationService, _workContext);+ model.PermissionName = _translationService.GetResource(permissionRecord.GetTranslationPermissionName(), _workContext.WorkingLanguage.Id);}else{