diff --git a/src/CIS.Service.Client.Tests/Tests/ImpersonatingMetaSystemProviderTests.cs b/src/CIS.Service.Client.Tests/Tests/ImpersonatingMetaSystemProviderTests.cs index 3a20b45..80e4414 100644 --- a/src/CIS.Service.Client.Tests/Tests/ImpersonatingMetaSystemProviderTests.cs +++ b/src/CIS.Service.Client.Tests/Tests/ImpersonatingMetaSystemProviderTests.cs @@ -63,6 +63,22 @@ public async Task LoadAttributesForMaterialNameWithContext() }); } + [Test] + public async Task LoadAttributesForMaterialNameWithDictionaryContext() + { + // Arrange + var provider = ServiceProvider.GetService(); + + // Act + var attributeList = await provider.LoadAttributesAsync(_user, nameof(MaterialName), new() { { "_identity", Guid.NewGuid() }, { nameof(MaterialName.Name), "test" } }); + + // Assert + Assert.Multiple(() => + { + Assert.That(attributeList, Is.Not.Null); + }); + } + [Test] public async Task LoadAttributesForEmployee() { @@ -303,6 +319,22 @@ public async Task LoadMetaClassForOrderDisplayWithContext() }); } + [Test] + public async Task LoadMetaClassForOrderDisplayWithDictionaryContext() + { + // Arrange + var provider = ServiceProvider.GetService(); + + // Act + var metaClass = await provider.LoadMetaClassAsync(_user, nameof(OrderDisplay), new() { { "_identity", Guid.NewGuid() }, { nameof(OrderDisplay.Name), "Заказ тестовый" } }); + + // Assert + Assert.Multiple(() => + { + Assert.That(metaClass, Is.Not.Null); + }); + } + [Test] public async Task LoadMetaClassList() { diff --git a/src/CIS.Service.Client/Models/ImpersonatingDictionaryObject.cs b/src/CIS.Service.Client/Models/ImpersonatingDictionaryObject.cs new file mode 100644 index 0000000..3e0dd98 --- /dev/null +++ b/src/CIS.Service.Client/Models/ImpersonatingDictionaryObject.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace CIS.Service.Client.Models +{ + /// + /// The persistent object with user impersonating feature. + /// + public class ImpersonatingDictionaryObject + { + /// + /// Gets or sets the user. + /// + public ImpersonatingUser User { get; set; } + + /// + /// Gets or sets the object. + /// + public Dictionary Object { get; set; } + } +} diff --git a/src/CIS.Service.Client/Services/IImpersonatingMetaSystemProvider.cs b/src/CIS.Service.Client/Services/IImpersonatingMetaSystemProvider.cs index 711fa53..5335c88 100644 --- a/src/CIS.Service.Client/Services/IImpersonatingMetaSystemProvider.cs +++ b/src/CIS.Service.Client/Services/IImpersonatingMetaSystemProvider.cs @@ -26,6 +26,11 @@ public interface IImpersonatingMetaSystemProvider /// Task> LoadAttributesAsync(ImpersonatingUser user, T contextObject) where T : IdentityObject; + /// + /// Async loads the available attribute list for the context object and specified user. + /// + Task> LoadAttributesAsync(ImpersonatingUser user, string objectClassName, Dictionary contextObject); + /// /// Async loads the accessible meta-system info for the specified user. /// @@ -41,6 +46,11 @@ public interface IImpersonatingMetaSystemProvider /// Task LoadMetaClassAsync(ImpersonatingUser user, T contextObject) where T : IdentityObject; + /// + /// Async loads the accessible meta-system info for the context object and specified user. + /// + Task LoadMetaClassAsync(ImpersonatingUser user, string objectClassName, Dictionary contextObject); + /// /// Async loads the accessible meta-system info list for the specified user. /// diff --git a/src/CIS.Service.Client/Services/PersistentCisServiceProvider.MetaSystem.cs b/src/CIS.Service.Client/Services/PersistentCisServiceProvider.MetaSystem.cs index b8d4dd9..a5bde87 100644 --- a/src/CIS.Service.Client/Services/PersistentCisServiceProvider.MetaSystem.cs +++ b/src/CIS.Service.Client/Services/PersistentCisServiceProvider.MetaSystem.cs @@ -52,6 +52,30 @@ public async Task> LoadAttributesAsync(ImpersonatingUser return attributeList; } + public async Task> LoadAttributesAsync(ImpersonatingUser user, string objectClassName, Dictionary contextObject) + { + if (user == null) + throw new ArgumentNullException(nameof(user)); + + if (contextObject == null) + throw new ArgumentNullException(nameof(contextObject)); + + + var uri = new Uri(new Uri(Settings.WebAPIEndpointAddress), $"{_impersonatingControllerName}{objectClassName}/LoadAttributesByContext"); + + var impersonatingContextObject = new ImpersonatingDictionaryObject + { + User = user, + Object = contextObject + }; + + var jsonModel = JsonHelper.ToJson(impersonatingContextObject); + + var attributeList = await InvokeAsync>(Settings, uri, HttpMethod.Post, jsonModel); + + return attributeList; + } + public Task LoadMetaClassAsync(ImpersonatingUser user) where T : IdentityObject => LoadMetaClassAsync(user, typeof(T).Name); @@ -92,6 +116,29 @@ public async Task LoadMetaClassAsync(ImpersonatingUser user, T con return metaClass; } + public async Task LoadMetaClassAsync(ImpersonatingUser user, string objectClassName, Dictionary contextObject) + { + if (user == null) + throw new ArgumentNullException(nameof(user)); + + if (contextObject == null) + throw new ArgumentNullException(nameof(contextObject)); + + var uri = new Uri(new Uri(Settings.WebAPIEndpointAddress), $"{_impersonatingControllerName}{objectClassName}/LoadMetaClassByContext"); + + var impersonatingContextObject = new ImpersonatingDictionaryObject + { + User = user, + Object = contextObject + }; + + var jsonModel = JsonHelper.ToJson(impersonatingContextObject); + + var metaClass = await InvokeAsync(Settings, uri, HttpMethod.Post, jsonModel); + + return metaClass; + } + public async Task> LoadMetaClassListAsync(ImpersonatingUser user, List objectClassNames, bool withAttributes = false) { if (user == null)