prevent flag icon from showing on banned profiles

implement automated penalty info for profanity determent issue #75
This commit is contained in:
RaidMax 2019-08-06 13:36:37 -05:00
parent d11a5f862b
commit b8a310bb07
5 changed files with 57 additions and 25 deletions

View File

@ -1,9 +1,11 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Plugins.ProfanityDeterment
@ -41,7 +43,15 @@ namespace IW4MAdmin.Plugins.ProfanityDeterment
if (containsObjectionalWord)
{
E.Origin.Kick(Settings.Configuration().ProfanityKickMessage, Utilities.IW4MAdminClient(E.Owner));
var sender = Utilities.IW4MAdminClient(E.Owner);
sender.AdministeredPenalties = new List<EFPenalty>()
{
new EFPenalty()
{
AutomatedOffense = E.Origin.Name
}
};
E.Origin.Kick(Settings.Configuration().ProfanityKickMessage, sender);
};
}
@ -78,7 +88,16 @@ namespace IW4MAdmin.Plugins.ProfanityDeterment
else if (profanityInfringments < Settings.Configuration().KickAfterInfringementCount)
{
E.Origin.SetAdditionalProperty("_profanityInfringements", profanityInfringments + 1);
E.Origin.Warn(Settings.Configuration().ProfanityWarningMessage, Utilities.IW4MAdminClient(E.Owner));
var sender = Utilities.IW4MAdminClient(E.Owner);
sender.AdministeredPenalties = new List<EFPenalty>()
{
new EFPenalty()
{
AutomatedOffense = E.Data
}
};
E.Origin.Warn(Settings.Configuration().ProfanityWarningMessage, sender);
}
}
}

View File

@ -102,21 +102,16 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers
[HttpGet]
[Authorize]
public async Task<IActionResult> GetAutomatedPenaltyInfoAsync(int clientId)
public async Task<IActionResult> GetAutomatedPenaltyInfoAsync(int penaltyId)
{
using (var ctx = new SharedLibraryCore.Database.DatabaseContext(true))
{
int linkId = await ctx.Clients
.Where(_client => _client.ClientId == clientId)
.Select(_client => _client.AliasLinkId)
.FirstOrDefaultAsync();
var penalty = await ctx.Penalties
.Select(_penalty => new { _penalty.OffenderId, _penalty.PenaltyId, _penalty.When, _penalty.AutomatedOffense })
.FirstOrDefaultAsync(_penalty => _penalty.PenaltyId == penaltyId);
var clientIds = await ctx.Clients.Where(_client => _client.AliasLinkId == linkId)
.Select(_client => _client.ClientId)
.ToListAsync();
var iqPenaltyInfo = ctx.Set<Models.EFACSnapshot>()
.Where(s => clientIds.Contains(s.ClientId))
var iqSnapshotInfo = ctx.Set<Models.EFACSnapshot>()
.Where(s => s.ClientId == penalty.OffenderId)
.Include(s => s.LastStrainAngle)
.Include(s => s.HitOrigin)
.Include(s => s.HitDestination)
@ -126,12 +121,28 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers
.ThenBy(s => s.Hits);
#if DEBUG == true
var sql = iqPenaltyInfo.ToSql();
var sql = iqSnapshotInfo.ToSql();
#endif
var penaltyInfo = await iqSnapshotInfo.ToListAsync();
var penaltyInfo = await iqPenaltyInfo.ToListAsync();
if (penaltyInfo.Count > 0)
{
return View("_PenaltyInfo", penaltyInfo);
}
return View("_PenaltyInfo", penaltyInfo);
// we want to show anything related to the automated offense
else
{
return View("_MessageContext", new[]
{
new ChatInfo()
{
ClientId = penalty.OffenderId,
Message = penalty.AutomatedOffense,
Time = penalty.When
}
});
}
}
}
}

View File

@ -6,13 +6,12 @@
string gravatarUrl = Model.Meta.FirstOrDefault(m => m.Key == "GravatarEmail")?.Value;
bool isTempBanned = Model.ActivePenaltyType == "TempBan";
bool isFlagged = Model.LevelInt == (int)SharedLibraryCore.Database.Models.EFClient.Permission.Flagged;
bool isPermBanned = Model.LevelInt == (int)SharedLibraryCore.Database.Models.EFClient.Permission.Banned;
var informationMeta = Model.Meta
.Where(_meta => _meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Information)
.OrderBy(_meta => _meta.Order)
.GroupBy(_meta => _meta.Column)
.OrderBy(_grouping => _grouping.Key);
}
<div id="profile_wrapper" class="pb-3 row d-flex flex-column flex-lg-row">
@ -57,7 +56,10 @@
@if (ViewBag.Authorized)
{
<div class="pr-lg-0 text-center text-lg-right">
<div class="profile-action oi oi-flag h3 ml-2 @(isFlagged ? "text-secondary" : "text-success")" data-action="@(isFlagged ? "unflag" : "flag")" aria-hidden="true"></div>
@if (!isPermBanned)
{
<div class="profile-action oi oi-flag h3 ml-2 @(isFlagged ? "text-secondary" : "text-success")" data-action="@(isFlagged ? "unflag" : "flag")" aria-hidden="true"></div>
}
@if (Model.LevelInt < (int)ViewBag.User.Level && !Model.HasActivePenalty)
{

View File

@ -21,12 +21,12 @@
return meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized ?
string.Format(localizationMessage,
$"<span class='text-highlight'><a class='link-inverse' href='{penalty.OffenderId}'>{penalty.OffenderName}</a></span>",
$"<span class='{(ViewBag.Authorized ? "automated-penalty-info-detailed" : "")} text-white' data-clientid='{penalty.OffenderId}'>{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}</span>")
$"<span class='{(ViewBag.Authorized ? "automated-penalty-info-detailed" : "")} text-white' data-penalty-id='{penalty.Id}'>{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}</span>")
.Replace("{", "")
.Replace("}", "") :
string.Format(localizationMessage,
$"<span class='text-highlight'><a class='link-inverse' href='{penalty.PunisherId}'>{penalty.PunisherName}</a></span>",
$"<span class='{(ViewBag.Authorized ? "automated-penalty-info-detailed" : "")} text-white' data-clientid='{penalty.OffenderId}'>{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}</span>",
$"<span class='{(ViewBag.Authorized ? "automated-penalty-info-detailed" : "")} text-white' data-penalty-id='{penalty.Id}'>{penalty.Offense} {(ViewBag.Authorized ? penalty.AdditionalPenaltyInformation : "")}</span>",
penalty.Offense)
.Replace("{", "")
.Replace("}", "");

View File

@ -35,14 +35,14 @@
});
/*
* load info on ban/flag
*/
* load info on ban/flag
*/
$(document).off('click', '.automated-penalty-info-detailed');
$(document).on('click', '.automated-penalty-info-detailed', function (e) {
showLoader();
const location = $(this).parent();
$.get('/Stats/GetAutomatedPenaltyInfoAsync', {
'clientId': $(this).data('clientid')
'penaltyId': $(this).data('penalty-id')
})
.done(function (response) {
$('.penalty-info-context').remove();