aktueller Status
This commit is contained in:
@@ -285,6 +285,16 @@ namespace C4IT.F4SD
|
||||
public Dictionary<string, int> Counts { get; set; } = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public class TicketOverviewCountsByRoleResult
|
||||
{
|
||||
[JsonProperty("generatedAtUtc")]
|
||||
public DateTime GeneratedAtUtc { get; set; } = DateTime.UtcNow;
|
||||
|
||||
[JsonProperty("countsByRole")]
|
||||
public Dictionary<string, Dictionary<string, int>> CountsByRole { get; set; }
|
||||
= new Dictionary<string, Dictionary<string, int>>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public class TicketOverviewRelationDto
|
||||
{
|
||||
public enumF4sdSearchResultClass Type { get; set; }
|
||||
@@ -354,6 +364,64 @@ namespace C4IT.F4SD
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task<TicketOverviewCountsByRoleResult> getTicketOverviewCountsByRoles(string sid, IEnumerable<Guid> roleGuids, IEnumerable<string> keys)
|
||||
{
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
var normalizedKeys = (keys ?? Array.Empty<string>())
|
||||
.Where(k => !string.IsNullOrWhiteSpace(k))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
if (normalizedKeys.Count == 0)
|
||||
{
|
||||
normalizedKeys.AddRange(TicketOverviewKeys);
|
||||
}
|
||||
|
||||
var roleIds = await ResolveTicketOverviewRoleIdsAsync(sid, roleGuids);
|
||||
if (roleIds.Count == 0)
|
||||
return new TicketOverviewCountsByRoleResult();
|
||||
|
||||
var entries = await LoadTicketOverviewEntriesByRoleIds(roleIds);
|
||||
var entriesByRole = entries
|
||||
.GroupBy(entry => entry.RecipientRoleId)
|
||||
.ToDictionary(group => group.Key, group => group.ToList());
|
||||
|
||||
var countsByRole = new Dictionary<string, Dictionary<string, int>>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var roleId in roleIds)
|
||||
{
|
||||
var roleEntries = entriesByRole.TryGetValue(roleId, out var list)
|
||||
? list
|
||||
: new List<TicketOverviewEntry>();
|
||||
|
||||
var counts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var key in normalizedKeys)
|
||||
{
|
||||
counts[key] = roleEntries.Count(entry => MatchesTicketOverviewKey(entry, key));
|
||||
}
|
||||
|
||||
countsByRole[roleId.ToString()] = counts;
|
||||
}
|
||||
|
||||
return new TicketOverviewCountsByRoleResult
|
||||
{
|
||||
GeneratedAtUtc = DateTime.UtcNow,
|
||||
CountsByRole = countsByRole
|
||||
};
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
return new TicketOverviewCountsByRoleResult();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task<List<TicketOverviewRelationDto>> getTicketOverviewRelations(string sid, string scope, string key, int count)
|
||||
{
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
@@ -430,6 +498,49 @@ namespace C4IT.F4SD
|
||||
return new List<TicketOverviewEntry>();
|
||||
|
||||
var filter = await BuildTicketOverviewFilterAsync(sid, useRoleScope);
|
||||
return await LoadTicketOverviewEntriesByFilter(filter);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
return new List<TicketOverviewEntry>();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<List<TicketOverviewEntry>> LoadTicketOverviewEntriesByRoleIds(IEnumerable<Guid> roleIds)
|
||||
{
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
await Task.Delay(0);
|
||||
|
||||
var filter = BuildTicketOverviewFilterForRoleIds(roleIds);
|
||||
return await LoadTicketOverviewEntriesByFilter(filter);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
return new List<TicketOverviewEntry>();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<List<TicketOverviewEntry>> LoadTicketOverviewEntriesByFilter(string filter)
|
||||
{
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
await Task.Delay(0);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(filter))
|
||||
return new List<TicketOverviewEntry>();
|
||||
|
||||
@@ -443,7 +554,7 @@ namespace C4IT.F4SD
|
||||
", Initiator.PrimaryAccount.T(SPSAccountClassAD).Domain.NT4Name as InitiatorDomain" +
|
||||
", Initiator.PrimaryAccount.T(SPSAccountClassAD).Sid as InitiatorSid" +
|
||||
", Recipient as RecipientId" +
|
||||
", RecipientRole as RecipientRoleId" +
|
||||
", RecipientRole.T(SPSSecurityClassRole).ID as RecipientRoleId" +
|
||||
", T(SPSCommonClassBase).State as State" +
|
||||
", CreatedDate" +
|
||||
", NewInformationReceived" +
|
||||
@@ -497,6 +608,20 @@ namespace C4IT.F4SD
|
||||
}
|
||||
|
||||
private async Task<string> BuildTicketOverviewFilterAsync(string sid, bool useRoleScope)
|
||||
{
|
||||
var filter = BuildTicketOverviewBaseFilter();
|
||||
|
||||
if (!useRoleScope)
|
||||
{
|
||||
filter += $" AND Initiator.Accounts.T(SPSAccountClassAd).Sid = '{Escape(sid)}'";
|
||||
return filter;
|
||||
}
|
||||
|
||||
var roleIds = await ResolveTicketOverviewRoleIdsAsync(sid, null);
|
||||
return BuildTicketOverviewFilterForRoleIds(roleIds, filter);
|
||||
}
|
||||
|
||||
private string BuildTicketOverviewBaseFilter()
|
||||
{
|
||||
var filter = "T(SPSCommonClassBase).State <> 204";
|
||||
|
||||
@@ -511,31 +636,49 @@ namespace C4IT.F4SD
|
||||
filter += " AND (UsedInTypeSPSActivityTypeIncident IS NOT NULL)";
|
||||
}
|
||||
|
||||
if (!useRoleScope)
|
||||
{
|
||||
filter += $" AND Initiator.Accounts.T(SPSAccountClassAd).Sid = '{Escape(sid)}'";
|
||||
return filter;
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
private string BuildTicketOverviewFilterForRoleIds(IEnumerable<Guid> roleIds, string baseFilter = null)
|
||||
{
|
||||
var filter = string.IsNullOrWhiteSpace(baseFilter) ? BuildTicketOverviewBaseFilter() : baseFilter;
|
||||
|
||||
var roleIdList = (roleIds ?? Enumerable.Empty<Guid>())
|
||||
.Where(id => id != Guid.Empty)
|
||||
.Distinct()
|
||||
.Select(id => $"'{id}'")
|
||||
.ToList();
|
||||
|
||||
if (roleIdList.Count == 0)
|
||||
return null;
|
||||
|
||||
filter += $" AND RecipientRole.T(SPSSecurityClassRole).ID IN ({string.Join(", ", roleIdList)})";
|
||||
return filter;
|
||||
}
|
||||
|
||||
private async Task<List<Guid>> ResolveTicketOverviewRoleIdsAsync(string sid, IEnumerable<Guid> roleGuids)
|
||||
{
|
||||
var roleIds = (roleGuids ?? Enumerable.Empty<Guid>())
|
||||
.Where(id => id != Guid.Empty)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
if (roleIds.Count > 0)
|
||||
return roleIds;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sid))
|
||||
return new List<Guid>();
|
||||
|
||||
var userId = getUserBySid(sid);
|
||||
if (userId == Guid.Empty)
|
||||
return null;
|
||||
return new List<Guid>();
|
||||
|
||||
var roles = await getRoleMembershipById(userId) ?? new List<M42Role>();
|
||||
if (roles.Count == 0)
|
||||
return null;
|
||||
|
||||
var roleIDs = roles
|
||||
.Select(role => role?.Id)
|
||||
.Where(Id => !Guid.Empty.Equals(Id))
|
||||
.Select(Id => $"'{(Id)}'")
|
||||
return roles
|
||||
.Where(role => role != null && role.Id != Guid.Empty)
|
||||
.Select(role => role.Id)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
if (roleIDs.Count == 0)
|
||||
return null;
|
||||
|
||||
filter += $" AND RecipientRole.T(SPSSecurityClassRole).ID IN ({string.Join(", ", roleIDs)})";
|
||||
return filter;
|
||||
}
|
||||
|
||||
private static bool MatchesTicketOverviewKey(TicketOverviewEntry entry, string key)
|
||||
|
||||
@@ -162,6 +162,23 @@ namespace C4IT.F4SD
|
||||
return await _f4stHelperService.getTicketOverviewCounts(sid, scope, parsedKeys);
|
||||
}
|
||||
|
||||
[Route("getTicketOverviewCountsByRoles"), HttpPost]
|
||||
public async Task<F4SDHelperService.TicketOverviewCountsByRoleResult> getTicketOverviewCountsByRoles([FromBody] TicketOverviewCountsByRolesRequest request)
|
||||
{
|
||||
var parsedKeys = (request?.Keys ?? new List<string>())
|
||||
.Where(key => !string.IsNullOrWhiteSpace(key))
|
||||
.Select(key => key.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var roleGuids = (request?.RoleGuids ?? new List<Guid>())
|
||||
.Where(roleId => roleId != Guid.Empty)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
return await _f4stHelperService.getTicketOverviewCountsByRoles(request?.Sid, roleGuids, parsedKeys);
|
||||
}
|
||||
|
||||
[Route("getTicketOverviewRelations"), HttpGet]
|
||||
public async Task<List<F4SDHelperService.TicketOverviewRelationDto>> getTicketOverviewRelations(string sid, string scope = "personal", string key = "", int count = 0)
|
||||
{
|
||||
@@ -249,6 +266,13 @@ namespace C4IT.F4SD
|
||||
public GetRoleMembershipsRequest() { }
|
||||
}
|
||||
|
||||
public class TicketOverviewCountsByRolesRequest
|
||||
{
|
||||
public string Sid { get; set; }
|
||||
public List<Guid> RoleGuids { get; set; } = new List<Guid>();
|
||||
public List<string> Keys { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
[Route("isAlive"), HttpGet]
|
||||
public HttpResponseMessage isAlive()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user