Initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
namespace SharepointToolbox.Web.Core.Models;
|
||||
|
||||
public record PermissionSummary(
|
||||
string Label,
|
||||
RiskLevel RiskLevel,
|
||||
int Count,
|
||||
int DistinctUsers
|
||||
);
|
||||
|
||||
public static class PermissionSummaryBuilder
|
||||
{
|
||||
private static readonly Dictionary<RiskLevel, string> Labels = new()
|
||||
{
|
||||
[RiskLevel.High] = "High Risk",
|
||||
[RiskLevel.Medium] = "Medium Risk",
|
||||
[RiskLevel.Low] = "Low Risk",
|
||||
[RiskLevel.ReadOnly] = "Read Only",
|
||||
};
|
||||
|
||||
public static IReadOnlyList<PermissionSummary> Build(IEnumerable<SimplifiedPermissionEntry> entries)
|
||||
{
|
||||
var grouped = entries.GroupBy(e => e.RiskLevel).ToDictionary(g => g.Key, g => g.ToList());
|
||||
return Enum.GetValues<RiskLevel>().Select(level =>
|
||||
{
|
||||
var items = grouped.GetValueOrDefault(level, new List<SimplifiedPermissionEntry>());
|
||||
var distinctUsers = items
|
||||
.SelectMany(e => e.UserLogins.Split(';', StringSplitOptions.RemoveEmptyEntries))
|
||||
.Select(u => u.Trim()).Where(u => u.Length > 0)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase).Count();
|
||||
return new PermissionSummary(Labels[level], level, items.Count, distinctUsers);
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user