Skip to content

Commit

Permalink
LoadMetaClassListAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
o.nadymov committed Oct 17, 2023
1 parent 20ef108 commit 745f57d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,30 @@ public async Task LoadMetaClassForOrderDisplayWithContext()
Assert.That(metaClass, Is.Not.Null);
});
}

[Test]
public async Task LoadMetaClassList()
{
// Arrange
var provider = ServiceProvider.GetService<IImpersonatingMetaSystemProvider>();
var objectClassNameList = new List<string>
{
nameof(OrderDisplay),
nameof(Color),
nameof(Employee),
nameof(OnlineClient),
nameof(LegalPerson)
};

// Act
var metaClassList = await provider.LoadMetaClassListAsync(_user, objectClassNameList);

// Assert
Assert.Multiple(() =>
{
Assert.That(metaClassList, Is.Not.Null);
Assert.That(metaClassList, Has.Count.EqualTo(objectClassNameList.Count));
});
}
}
}
3 changes: 2 additions & 1 deletion src/CIS.Service.Client/MetaSystem/MetaClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class MetaClass : MetaObject
/// Gets or sets the attributes
/// </summary>
[Required]
[JsonRequired]
public List<MetaAttribute> Attributes { get; set; }

/// <summary>
Expand All @@ -29,5 +28,7 @@ public class MetaClass : MetaObject
[Required]
[JsonRequired]
public Dictionary<PermissionType, bool> ClassPermissions { get; set; }

public override string ToString() => Name;
}
}
25 changes: 25 additions & 0 deletions src/CIS.Service.Client/Models/ImpersonatingPersistentClassList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;

namespace CIS.Service.Client.Models
{
/// <summary>
/// The persistent class list with user impersonating feature.
/// </summary>
public class ImpersonatingPersistentClassList
{
/// <summary>
/// Gets or sets the user.
/// </summary>
public ImpersonatingUser User { get; set; }

/// <summary>
/// Gets or sets the object.
/// </summary>
public List<string> ObjectClassNames { get; set; }

/// <summary>
/// Gets or sets the WithAttributes flag.
/// </summary>
public bool WithAttributes { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ public interface IImpersonatingMetaSystemProvider
/// Async loads the accessible meta-system info for the context object and specified user.
/// </summary>
Task<MetaClass> LoadMetaClassAsync<T>(ImpersonatingUser user, T contextObject) where T : IdentityObject;

/// <summary>
/// Async loads the accessible meta-system info list for the specified user.
/// </summary>
Task<List<MetaClass>> LoadMetaClassListAsync(ImpersonatingUser user, List<string> objectClassNames, bool withAttributes = false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public async Task<MetaClass> LoadMetaClassAsync<T>(ImpersonatingUser user, T con
if (contextObject == null)
throw new ArgumentNullException(nameof(contextObject));


var uri = new Uri(new Uri(Settings.WebAPIEndpointAddress), $"{_impersonatingControllerName}{typeof(T).Name}/LoadMetaClassByContext");

var impersonatingContextObject = new ImpersonatingPersistentObject<T>
Expand All @@ -92,5 +91,29 @@ public async Task<MetaClass> LoadMetaClassAsync<T>(ImpersonatingUser user, T con

return metaClass;
}

public async Task<List<MetaClass>> LoadMetaClassListAsync(ImpersonatingUser user, List<string> objectClassNames, bool withAttributes = false)
{
if (user == null)
throw new ArgumentNullException(nameof(user));

if (objectClassNames == null)
throw new ArgumentNullException(nameof(objectClassNames));

var uri = new Uri(new Uri(Settings.WebAPIEndpointAddress), $"{_impersonatingControllerName}PersistentClass/LoadMetaClassList");

var impersonatingPersistentClassList = new ImpersonatingPersistentClassList
{
User = user,
ObjectClassNames = objectClassNames,
WithAttributes = withAttributes
};

var jsonModel = JsonHelper.ToJson(impersonatingPersistentClassList);

var metaClassList = await InvokeAsync<List<MetaClass>>(Settings, uri, HttpMethod.Post, jsonModel);

return metaClassList;
}
}
}

0 comments on commit 745f57d

Please # to comment.