2019-03-27 20:40:26 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-04-16 12:32:42 -04:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
using SharedLibraryCore.Dtos.Meta.Responses;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.QueryHelper;
|
2019-03-29 22:56:56 -04:00
|
|
|
|
using System;
|
2019-04-16 12:32:42 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Claims;
|
2019-03-27 20:40:26 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.ViewComponents
|
|
|
|
|
{
|
|
|
|
|
public class ProfileMetaListViewComponent : ViewComponent
|
|
|
|
|
{
|
2022-03-23 09:43:57 -04:00
|
|
|
|
private readonly IMetaServiceV2 _metaService;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
public ProfileMetaListViewComponent(IMetaServiceV2 metaService)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
_metaService = metaService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IViewComponentResult> InvokeAsync(int clientId, int count, int offset, DateTime? startAt, MetaType? metaType)
|
2019-03-27 20:40:26 -04:00
|
|
|
|
{
|
2019-04-16 12:32:42 -04:00
|
|
|
|
var level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), UserClaimsPrincipal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Role)?.Value ?? "User");
|
|
|
|
|
|
2020-08-17 22:21:11 -04:00
|
|
|
|
var request = new ClientPaginationRequest
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId,
|
|
|
|
|
Count = count,
|
|
|
|
|
Offset = offset,
|
|
|
|
|
Before = startAt,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var meta = await GetClientMeta(_metaService, metaType, level, request);
|
|
|
|
|
ViewBag.Localization = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex;
|
|
|
|
|
|
|
|
|
|
return View("_List", meta);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
public static async Task<IEnumerable<IClientMeta>> GetClientMeta(IMetaServiceV2 metaService, MetaType? metaType,
|
2022-02-25 22:09:57 -05:00
|
|
|
|
EFClient.Permission level, ClientPaginationRequest request)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
IEnumerable<IClientMeta> meta = null;
|
|
|
|
|
|
2022-02-25 22:09:57 -05:00
|
|
|
|
if (metaType is null or MetaType.All)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
meta = await metaService.GetRuntimeMeta(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch (metaType)
|
|
|
|
|
{
|
|
|
|
|
case MetaType.Information:
|
|
|
|
|
meta = await metaService.GetRuntimeMeta<InformationResponse>(request, metaType.Value);
|
|
|
|
|
break;
|
|
|
|
|
case MetaType.AliasUpdate:
|
|
|
|
|
meta = await metaService.GetRuntimeMeta<UpdatedAliasResponse>(request, metaType.Value);
|
|
|
|
|
break;
|
|
|
|
|
case MetaType.ChatMessage:
|
|
|
|
|
meta = await metaService.GetRuntimeMeta<MessageResponse>(request, metaType.Value);
|
|
|
|
|
break;
|
|
|
|
|
case MetaType.Penalized:
|
|
|
|
|
meta = await metaService.GetRuntimeMeta<AdministeredPenaltyResponse>(request, metaType.Value);
|
|
|
|
|
break;
|
|
|
|
|
case MetaType.ReceivedPenalty:
|
|
|
|
|
meta = await metaService.GetRuntimeMeta<ReceivedPenaltyResponse>(request, metaType.Value);
|
|
|
|
|
break;
|
2021-08-31 19:21:40 -04:00
|
|
|
|
case MetaType.ConnectionHistory:
|
|
|
|
|
meta = await metaService.GetRuntimeMeta<ConnectionHistoryResponse>(request, metaType.Value);
|
2020-08-17 22:21:11 -04:00
|
|
|
|
break;
|
2022-02-23 13:47:00 -05:00
|
|
|
|
case MetaType.PermissionLevel:
|
|
|
|
|
meta = await metaService.GetRuntimeMeta<PermissionLevelChangedResponse>(request,
|
|
|
|
|
metaType.Value);
|
|
|
|
|
break;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-16 12:32:42 -04:00
|
|
|
|
|
|
|
|
|
if (level < EFClient.Permission.Trusted)
|
|
|
|
|
{
|
2020-08-17 22:21:11 -04:00
|
|
|
|
meta = meta.Where(_meta => !_meta.IsSensitive);
|
2019-04-16 12:32:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-17 22:21:11 -04:00
|
|
|
|
return meta;
|
2019-03-27 20:40:26 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|