From 39a1066c743c6339140da0b88bb088203308d77f Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 23 Feb 2022 12:47:00 -0600 Subject: [PATCH] add permission level changed meta --- Application/Main.cs | 1 + Application/Meta/MetaRegistration.cs | 18 +++++- ...rmissionLevelChangedResourceQueryHelper.cs | 50 +++++++++++++++ .../PermissionLevelChangedResponse.cs | 20 ++++++ SharedLibraryCore/Interfaces/IClientMeta.cs | 5 +- .../ProfileMetaListViewComponent.cs | 4 ++ .../Views/Client/Profile/Index.cshtml | 63 ++++++++++++------- .../_PermissionLevelChangedResponse.cshtml | 29 +++++++++ WebfrontCore/wwwroot/js/profile.js | 12 ++-- 9 files changed, 170 insertions(+), 32 deletions(-) create mode 100644 Application/Meta/PermissionLevelChangedResourceQueryHelper.cs create mode 100644 SharedLibraryCore/Dtos/Meta/Responses/PermissionLevelChangedResponse.cs create mode 100644 WebfrontCore/Views/Client/Profile/Meta/_PermissionLevelChangedResponse.cshtml diff --git a/Application/Main.cs b/Application/Main.cs index 441389ec7..88cd1b1ea 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -417,6 +417,7 @@ namespace IW4MAdmin.Application UpdatedAliasResourceQueryHelper>() .AddSingleton, ChatResourceQueryHelper>() .AddSingleton, ConnectionsResourceQueryHelper>() + .AddSingleton, PermissionLevelChangedResourceQueryHelper>() .AddTransient() .AddSingleton() .AddSingleton() diff --git a/Application/Meta/MetaRegistration.cs b/Application/Meta/MetaRegistration.cs index 64a5a11ba..186299f6d 100644 --- a/Application/Meta/MetaRegistration.cs +++ b/Application/Meta/MetaRegistration.cs @@ -22,12 +22,16 @@ namespace IW4MAdmin.Application.Meta private readonly IResourceQueryHelper _updatedAliasHelper; private readonly IResourceQueryHelper _connectionHistoryHelper; + private readonly IResourceQueryHelper + _permissionLevelHelper; - public MetaRegistration(ILogger logger, IMetaService metaService, ITranslationLookup transLookup, IEntityService clientEntityService, + public MetaRegistration(ILogger logger, IMetaService metaService, + ITranslationLookup transLookup, IEntityService clientEntityService, IResourceQueryHelper receivedPenaltyHelper, IResourceQueryHelper administeredPenaltyHelper, IResourceQueryHelper updatedAliasHelper, - IResourceQueryHelper connectionHistoryHelper) + IResourceQueryHelper connectionHistoryHelper, + IResourceQueryHelper permissionLevelHelper) { _logger = logger; _transLookup = transLookup; @@ -37,6 +41,7 @@ namespace IW4MAdmin.Application.Meta _administeredPenaltyHelper = administeredPenaltyHelper; _updatedAliasHelper = updatedAliasHelper; _connectionHistoryHelper = connectionHistoryHelper; + _permissionLevelHelper = permissionLevelHelper; } public void Register() @@ -46,6 +51,8 @@ namespace IW4MAdmin.Application.Meta _metaService.AddRuntimeMeta(MetaType.Penalized, GetAdministeredPenaltiesMeta); _metaService.AddRuntimeMeta(MetaType.AliasUpdate, GetUpdatedAliasMeta); _metaService.AddRuntimeMeta(MetaType.ConnectionHistory, GetConnectionHistoryMeta); + _metaService.AddRuntimeMeta( + MetaType.PermissionLevel, GetPermissionLevelMeta); } private async Task> GetProfileMeta(ClientPaginationRequest request) @@ -174,5 +181,12 @@ namespace IW4MAdmin.Application.Meta var connections = await _connectionHistoryHelper.QueryResource(request); return connections.Results; } + + private async Task> GetPermissionLevelMeta( + ClientPaginationRequest request) + { + var permissionChanges = await _permissionLevelHelper.QueryResource(request); + return permissionChanges.Results; + } } } diff --git a/Application/Meta/PermissionLevelChangedResourceQueryHelper.cs b/Application/Meta/PermissionLevelChangedResourceQueryHelper.cs new file mode 100644 index 000000000..9505bbc43 --- /dev/null +++ b/Application/Meta/PermissionLevelChangedResourceQueryHelper.cs @@ -0,0 +1,50 @@ +using System.Linq; +using System.Threading.Tasks; +using Data.Abstractions; +using Data.Models; +using Microsoft.EntityFrameworkCore; +using SharedLibraryCore.Dtos.Meta.Responses; +using SharedLibraryCore.Helpers; +using SharedLibraryCore.Interfaces; +using SharedLibraryCore.QueryHelper; + +namespace IW4MAdmin.Application.Meta; + +public class + PermissionLevelChangedResourceQueryHelper : IResourceQueryHelper +{ + private readonly IDatabaseContextFactory _contextFactory; + + public PermissionLevelChangedResourceQueryHelper(IDatabaseContextFactory contextFactory) + { + _contextFactory = contextFactory; + } + + public async Task> QueryResource( + ClientPaginationRequest query) + { + await using var context = _contextFactory.CreateContext(); + + var auditEntries = context.EFChangeHistory.Where(change => change.TargetEntityId == query.ClientId) + .Where(change => change.TypeOfChange == EFChangeHistory.ChangeType.Permission); + + var audits = from change in auditEntries + join client in context.Clients + on change.OriginEntityId equals client.ClientId + select new PermissionLevelChangedResponse + { + ChangedById = change.OriginEntityId, + ChangedByName = client.CurrentAlias.Name, + PreviousPermissionLevelValue = change.PreviousValue, + CurrentPermissionLevelValue = change.CurrentValue, + When = change.TimeChanged, + ClientId = change.TargetEntityId + }; + + return new ResourceQueryHelperResult + { + Results = await audits.Skip(query.Offset).Take(query.Count).ToListAsync() + }; + } +} diff --git a/SharedLibraryCore/Dtos/Meta/Responses/PermissionLevelChangedResponse.cs b/SharedLibraryCore/Dtos/Meta/Responses/PermissionLevelChangedResponse.cs new file mode 100644 index 000000000..7733ab803 --- /dev/null +++ b/SharedLibraryCore/Dtos/Meta/Responses/PermissionLevelChangedResponse.cs @@ -0,0 +1,20 @@ +using System; +using Data.Models.Client; + +namespace SharedLibraryCore.Dtos.Meta.Responses; + +public class PermissionLevelChangedResponse : BaseMetaResponse +{ + public EFClient.Permission PreviousPermissionLevel => + (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), + PreviousPermissionLevelValue ?? EFClient.Permission.User.ToString()); + + public string PreviousPermissionLevelValue { get; set; } + + public EFClient.Permission CurrentPermissionLevel => (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), + CurrentPermissionLevelValue ?? EFClient.Permission.User.ToString()); + + public string CurrentPermissionLevelValue { get; set; } + public int ChangedById { get; set; } + public string ChangedByName { get; set; } +} diff --git a/SharedLibraryCore/Interfaces/IClientMeta.cs b/SharedLibraryCore/Interfaces/IClientMeta.cs index 413c5d35a..1b3ed0a41 100644 --- a/SharedLibraryCore/Interfaces/IClientMeta.cs +++ b/SharedLibraryCore/Interfaces/IClientMeta.cs @@ -27,6 +27,7 @@ namespace SharedLibraryCore.Interfaces Penalized, ReceivedPenalty, QuickMessage, - ConnectionHistory + ConnectionHistory, + PermissionLevel, } -} \ No newline at end of file +} diff --git a/WebfrontCore/ViewComponents/ProfileMetaListViewComponent.cs b/WebfrontCore/ViewComponents/ProfileMetaListViewComponent.cs index 4de5be092..db7fc7c7d 100644 --- a/WebfrontCore/ViewComponents/ProfileMetaListViewComponent.cs +++ b/WebfrontCore/ViewComponents/ProfileMetaListViewComponent.cs @@ -69,6 +69,10 @@ namespace WebfrontCore.ViewComponents case MetaType.ConnectionHistory: meta = await metaService.GetRuntimeMeta(request, metaType.Value); break; + case MetaType.PermissionLevel: + meta = await metaService.GetRuntimeMeta(request, + metaType.Value); + break; } } diff --git a/WebfrontCore/Views/Client/Profile/Index.cshtml b/WebfrontCore/Views/Client/Profile/Index.cshtml index 450ced47a..2ff9a20dd 100644 --- a/WebfrontCore/Views/Client/Profile/Index.cshtml +++ b/WebfrontCore/Views/Client/Profile/Index.cshtml @@ -6,11 +6,11 @@ var match = System.Text.RegularExpressions.Regex.Match(Model.Name.ToUpper(), "[A-Z]").Value; var shortCode = match == string.Empty ? "?" : match; var gravatarUrl = Model.Meta.FirstOrDefault(m => m.Key == "GravatarEmail")?.Value; - var isFlagged = Model.LevelInt == (int) EFClient.Permission.Flagged; - var isPermBanned = Model.LevelInt == (int) EFClient.Permission.Banned; + var isFlagged = Model.LevelInt == (int)EFClient.Permission.Flagged; + var isPermBanned = Model.LevelInt == (int)EFClient.Permission.Banned; var isTempBanned = Model.ActivePenalty?.Type == EFPenalty.PenaltyType.TempBan; var translationKey = $"WEBFRONT_PROFILE_{Model.ActivePenalty?.Type.ToString().ToUpper()}_INFO"; - var ignoredMetaTypes = new[] {MetaType.Information, MetaType.Other, MetaType.QuickMessage}; + var ignoredMetaTypes = new[] { MetaType.Information, MetaType.Other, MetaType.QuickMessage }; }
@@ -44,7 +44,7 @@ @foreach (var linked in Model.LinkedAccounts) {
- @Html.ActionLink(linked.Value.ToString("X"), "ProfileAsync", "Client", new {id = linked.Key}, new {@class = "link-inverse"}) + @Html.ActionLink(linked.Value.ToString("X"), "ProfileAsync", "Client", new { id = linked.Key }, new { @class = "link-inverse" })
} @foreach (var alias in Model.Aliases) @@ -110,12 +110,12 @@ } - @if (Model.LevelInt < (int) ViewBag.User.Level && !Model.HasActivePenalty) + @if (Model.LevelInt < (int)ViewBag.User.Level && !Model.HasActivePenalty) { } - @if (Model.LevelInt < (int) ViewBag.User.Level && Model.HasActivePenalty) + @if (Model.LevelInt < (int)ViewBag.User.Level && Model.HasActivePenalty) { @if (isTempBanned) { @@ -145,31 +145,46 @@
-
- -
- - @ViewBag.Localization["META_TYPE_ALL_NAME"] - - - @foreach (MetaType type in Enum.GetValues(typeof(MetaType))) - { - if (!ignoredMetaTypes.Contains(type)) +
+
+ +
+ + @ViewBag.Localization["META_TYPE_ALL_NAME"] + + @{ var metaTypes = Enum.GetValues(typeof(MetaType)) + .Cast() + .Where(type => !ignoredMetaTypes.Contains(type)) + .ToList(); } + @foreach (var type in metaTypes.Take(4)) { @type.ToTranslatedName() } - } + ... +
+ @foreach (var type in metaTypes.Skip(4)) + { + + @type.ToTranslatedName() + + } +
+
@@ -177,7 +192,7 @@ {
- @await Component.InvokeAsync("ProfileMetaList", new {clientId = Model.ClientId, count = 30, offset = 0, startAt = DateTime.UtcNow, metaType = Model.MetaFilterType}) + @await Component.InvokeAsync("ProfileMetaList", new { clientId = Model.ClientId, count = 30, offset = 0, startAt = DateTime.UtcNow, metaType = Model.MetaFilterType })
} diff --git a/WebfrontCore/Views/Client/Profile/Meta/_PermissionLevelChangedResponse.cshtml b/WebfrontCore/Views/Client/Profile/Meta/_PermissionLevelChangedResponse.cshtml new file mode 100644 index 000000000..f2c191f44 --- /dev/null +++ b/WebfrontCore/Views/Client/Profile/Meta/_PermissionLevelChangedResponse.cshtml @@ -0,0 +1,29 @@ +@model SharedLibraryCore.Dtos.Meta.Responses.PermissionLevelChangedResponse + +@foreach (var token in Utilities.SplitTranslationTokens("WEBFRONT_CLIENT_META_PERMISSION_CHANGED")) +{ + if (token.IsInterpolation) + { + switch (token.MatchValue) + { + case "permission": + @Model.CurrentPermissionLevel.ToLocalizedLevelName() + break; + case "originClient": + + + + + + break; + case "type": + @token.TranslationValue + break; + } + } + + else + { + @token.MatchValue + } +} diff --git a/WebfrontCore/wwwroot/js/profile.js b/WebfrontCore/wwwroot/js/profile.js index 54b262773..c60d13a87 100644 --- a/WebfrontCore/wwwroot/js/profile.js +++ b/WebfrontCore/wwwroot/js/profile.js @@ -35,11 +35,15 @@ startAt = $('.loader-data-time').last().data('time'); $('#filter_meta_container_button').click(function () { - $('#filter_meta_container').hide(); - $('#filter_meta_container').removeClass('d-none'); - $('#filter_meta_container').addClass('d-block'); - $('#filter_meta_container').slideDown(); + $('#filter_meta_container').hide().removeClass('d-none').addClass('d-block').slideDown(); + $('#additional-meta-filter').removeClass('d-md-none').addClass('d-flex').slideDown(); + $('#expand-meta-filters').removeClass('d-md-block'); }); + + $('#expand-meta-filters').click(function () { + $('#additional-meta-filter').removeClass('d-md-none').addClass('d-flex').slideDown(); + $('#expand-meta-filters').removeClass('d-md-block'); + }) /* * load context of chat