mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 23:31:13 -05:00
initial permissions based webfront access implementation
This commit is contained in:
@ -10,6 +10,7 @@ using SharedLibraryCore;
|
||||
using SharedLibraryCore.Commands;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using WebfrontCore.Permissions;
|
||||
using WebfrontCore.ViewModels;
|
||||
|
||||
namespace WebfrontCore.Controllers
|
||||
@ -314,6 +315,14 @@ namespace WebfrontCore.Controllers
|
||||
public async Task<IActionResult> RecentClientsForm()
|
||||
{
|
||||
var clients = await Manager.GetClientService().GetRecentClients();
|
||||
foreach (var client in clients)
|
||||
{
|
||||
client.IPAddress =
|
||||
_appConfig.HasPermission(Client.Level, WebfrontEntity.IPAddress, WebfrontPermission.Read)
|
||||
? client.IPAddress
|
||||
: null;
|
||||
}
|
||||
|
||||
return View("~/Views/Shared/Components/Client/_RecentClients.cshtml", clients);
|
||||
}
|
||||
|
||||
@ -453,4 +462,4 @@ namespace WebfrontCore.Controllers
|
||||
})
|
||||
.ToDictionary(item => item.Value, item => item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,13 @@ using SharedLibraryCore.Interfaces;
|
||||
using SharedLibraryCore.QueryHelper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Models;
|
||||
using Stats.Config;
|
||||
using WebfrontCore.Permissions;
|
||||
using WebfrontCore.ViewComponents;
|
||||
|
||||
namespace WebfrontCore.Controllers
|
||||
@ -79,7 +81,7 @@ namespace WebfrontCore.Controllers
|
||||
Level = displayLevel,
|
||||
LevelInt = displayLevelInt,
|
||||
ClientId = client.ClientId,
|
||||
IPAddress = client.IPAddressString,
|
||||
IPAddress = PermissionsSet.HasPermission(WebfrontEntity.IPAddress, WebfrontPermission.Read) ? client.IPAddressString : null,
|
||||
NetworkId = client.NetworkId,
|
||||
Meta = new List<InformationResponse>(),
|
||||
Aliases = client.AliasLink.Children
|
||||
@ -90,13 +92,13 @@ namespace WebfrontCore.Controllers
|
||||
.Distinct()
|
||||
.OrderBy(a => a)
|
||||
.ToList(),
|
||||
IPs = client.AliasLink.Children
|
||||
IPs = PermissionsSet.HasPermission(WebfrontEntity.IPAddress, WebfrontPermission.Read) ? client.AliasLink.Children
|
||||
.Where(i => i.IPAddress != null)
|
||||
.OrderByDescending(i => i.DateAdded)
|
||||
.Select(i => i.IPAddress.ConvertIPtoString())
|
||||
.Prepend(client.CurrentAlias.IPAddress.ConvertIPtoString())
|
||||
.Distinct()
|
||||
.ToList(),
|
||||
.ToList() : new List<string>(),
|
||||
HasActivePenalty = activePenalties.Any(_penalty => _penalty.Type != EFPenalty.PenaltyType.Flag),
|
||||
Online = Manager.GetActiveClients().FirstOrDefault(c => c.ClientId == client.ClientId) != null,
|
||||
TimeOnline = (DateTime.UtcNow - client.LastConnection).HumanizeForCurrentCulture(),
|
||||
@ -191,7 +193,7 @@ namespace WebfrontCore.Controllers
|
||||
return View("Find/Index", clientsDto);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Meta(int id, int count, int offset, long? startAt, MetaType? metaFilterType, CancellationToken token)
|
||||
public IActionResult Meta(int id, int count, int offset, long? startAt, MetaType? metaFilterType, CancellationToken token)
|
||||
{
|
||||
var request = new ClientPaginationRequest
|
||||
{
|
||||
@ -201,14 +203,15 @@ namespace WebfrontCore.Controllers
|
||||
Before = DateTime.FromFileTimeUtc(startAt ?? DateTime.UtcNow.ToFileTimeUtc())
|
||||
};
|
||||
|
||||
var meta = await ProfileMetaListViewComponent.GetClientMeta(_metaService, metaFilterType, Client.Level, request, token);
|
||||
|
||||
if (!meta.Any())
|
||||
return ViewComponent(typeof(ProfileMetaListViewComponent), new
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return View("Components/ProfileMetaList/_List", meta);
|
||||
clientId = request.ClientId,
|
||||
count = request.Count,
|
||||
offset = request.Offset,
|
||||
startAt = request.Before,
|
||||
metaType = metaFilterType,
|
||||
token
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
WebfrontCore/Permissions/WebfrontEntity.cs
Normal file
15
WebfrontCore/Permissions/WebfrontEntity.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace WebfrontCore.Permissions;
|
||||
|
||||
public enum WebfrontEntity
|
||||
{
|
||||
IPAddress,
|
||||
MetaAliasUpdate
|
||||
}
|
||||
|
||||
public enum WebfrontPermission
|
||||
{
|
||||
Read,
|
||||
Create,
|
||||
Update,
|
||||
Delete
|
||||
}
|
@ -9,16 +9,21 @@ using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using WebfrontCore.Permissions;
|
||||
|
||||
namespace WebfrontCore.ViewComponents
|
||||
{
|
||||
public class ProfileMetaListViewComponent : ViewComponent
|
||||
{
|
||||
private readonly IMetaServiceV2 _metaService;
|
||||
private readonly ApplicationConfiguration _appConfig;
|
||||
|
||||
public ProfileMetaListViewComponent(IMetaServiceV2 metaService)
|
||||
public ProfileMetaListViewComponent(IMetaServiceV2 metaService, ApplicationConfiguration appConfig)
|
||||
{
|
||||
_metaService = metaService;
|
||||
_appConfig = appConfig;
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync(int clientId, int count, int offset, DateTime? startAt, MetaType? metaType, CancellationToken token)
|
||||
@ -39,11 +44,16 @@ namespace WebfrontCore.ViewComponents
|
||||
return View("_List", meta);
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<IClientMeta>> GetClientMeta(IMetaServiceV2 metaService, MetaType? metaType,
|
||||
private async Task<IEnumerable<IClientMeta>> GetClientMeta(IMetaServiceV2 metaService, MetaType? metaType,
|
||||
EFClient.Permission level, ClientPaginationRequest request, CancellationToken token)
|
||||
{
|
||||
IEnumerable<IClientMeta> meta = null;
|
||||
|
||||
if (!_appConfig.PermissionSets.TryGetValue(level.ToString(), out var permissionSet))
|
||||
{
|
||||
permissionSet = new List<string>();
|
||||
}
|
||||
|
||||
if (metaType is null or MetaType.All)
|
||||
{
|
||||
meta = await metaService.GetRuntimeMeta(request, token);
|
||||
@ -51,30 +61,24 @@ namespace WebfrontCore.ViewComponents
|
||||
|
||||
else
|
||||
{
|
||||
switch (metaType)
|
||||
meta = metaType switch
|
||||
{
|
||||
case MetaType.Information:
|
||||
meta = await metaService.GetRuntimeMeta<InformationResponse>(request, metaType.Value, token);
|
||||
break;
|
||||
case MetaType.AliasUpdate:
|
||||
meta = await metaService.GetRuntimeMeta<UpdatedAliasResponse>(request, metaType.Value, token);
|
||||
break;
|
||||
case MetaType.ChatMessage:
|
||||
meta = await metaService.GetRuntimeMeta<MessageResponse>(request, metaType.Value, token);
|
||||
break;
|
||||
case MetaType.Penalized:
|
||||
meta = await metaService.GetRuntimeMeta<AdministeredPenaltyResponse>(request, metaType.Value, token);
|
||||
break;
|
||||
case MetaType.ReceivedPenalty:
|
||||
meta = await metaService.GetRuntimeMeta<ReceivedPenaltyResponse>(request, metaType.Value, token);
|
||||
break;
|
||||
case MetaType.ConnectionHistory:
|
||||
meta = await metaService.GetRuntimeMeta<ConnectionHistoryResponse>(request, metaType.Value, token);
|
||||
break;
|
||||
case MetaType.PermissionLevel:
|
||||
meta = await metaService.GetRuntimeMeta<PermissionLevelChangedResponse>(request, metaType.Value, token);
|
||||
break;
|
||||
}
|
||||
MetaType.Information => await metaService.GetRuntimeMeta<InformationResponse>(request,
|
||||
metaType.Value, token),
|
||||
MetaType.AliasUpdate => permissionSet.HasPermission(WebfrontEntity.MetaAliasUpdate, WebfrontPermission.Read) ? await metaService.GetRuntimeMeta<UpdatedAliasResponse>(request,
|
||||
metaType.Value, token) : new List<IClientMeta>(),
|
||||
MetaType.ChatMessage => await metaService.GetRuntimeMeta<MessageResponse>(request, metaType.Value,
|
||||
token),
|
||||
MetaType.Penalized => await metaService.GetRuntimeMeta<AdministeredPenaltyResponse>(request,
|
||||
metaType.Value, token),
|
||||
MetaType.ReceivedPenalty => await metaService.GetRuntimeMeta<ReceivedPenaltyResponse>(request,
|
||||
metaType.Value, token),
|
||||
MetaType.ConnectionHistory => await metaService.GetRuntimeMeta<ConnectionHistoryResponse>(request,
|
||||
metaType.Value, token),
|
||||
MetaType.PermissionLevel => await metaService.GetRuntimeMeta<PermissionLevelChangedResponse>(
|
||||
request, metaType.Value, token),
|
||||
_ => meta
|
||||
};
|
||||
}
|
||||
|
||||
if (level < EFClient.Permission.Trusted)
|
||||
|
@ -1,5 +1,4 @@
|
||||
@using SharedLibraryCore.Dtos.Meta.Responses
|
||||
@using SharedLibraryCore
|
||||
@model UpdatedAliasResponse
|
||||
|
||||
@foreach (var token in Utilities.SplitTranslationTokens("WEBFRONT_PROFILE_META_CONNECT_ALIAS"))
|
||||
|
Reference in New Issue
Block a user