Migrate ActivityLogEntryPoint.OnUserLockedOut to IEventConsumer

This commit is contained in:
Patrick Barron 2020-08-13 21:11:38 -04:00
parent a1ecafb40d
commit 8a4bdaed6b
3 changed files with 66 additions and 24 deletions

View File

@ -6,7 +6,6 @@ using Jellyfin.Data.Events;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Updates; using MediaBrowser.Common.Updates;
using MediaBrowser.Controller.Authentication; using MediaBrowser.Controller.Authentication;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Activity; using MediaBrowser.Model.Activity;
@ -26,7 +25,6 @@ namespace Emby.Server.Implementations.Activity
private readonly ISessionManager _sessionManager; private readonly ISessionManager _sessionManager;
private readonly IActivityManager _activityManager; private readonly IActivityManager _activityManager;
private readonly ILocalizationManager _localization; private readonly ILocalizationManager _localization;
private readonly IUserManager _userManager;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ActivityLogEntryPoint"/> class. /// Initializes a new instance of the <see cref="ActivityLogEntryPoint"/> class.
@ -35,19 +33,16 @@ namespace Emby.Server.Implementations.Activity
/// <param name="activityManager">The activity manager.</param> /// <param name="activityManager">The activity manager.</param>
/// <param name="localization">The localization manager.</param> /// <param name="localization">The localization manager.</param>
/// <param name="installationManager">The installation manager.</param> /// <param name="installationManager">The installation manager.</param>
/// <param name="userManager">The user manager.</param>
public ActivityLogEntryPoint( public ActivityLogEntryPoint(
ISessionManager sessionManager, ISessionManager sessionManager,
IActivityManager activityManager, IActivityManager activityManager,
ILocalizationManager localization, ILocalizationManager localization,
IInstallationManager installationManager, IInstallationManager installationManager)
IUserManager userManager)
{ {
_sessionManager = sessionManager; _sessionManager = sessionManager;
_activityManager = activityManager; _activityManager = activityManager;
_localization = localization; _localization = localization;
_installationManager = installationManager; _installationManager = installationManager;
_userManager = userManager;
} }
/// <inheritdoc /> /// <inheritdoc />
@ -63,25 +58,9 @@ namespace Emby.Server.Implementations.Activity
_sessionManager.AuthenticationSucceeded += OnAuthenticationSucceeded; _sessionManager.AuthenticationSucceeded += OnAuthenticationSucceeded;
_sessionManager.SessionEnded += OnSessionEnded; _sessionManager.SessionEnded += OnSessionEnded;
_userManager.OnUserLockedOut += OnUserLockedOut;
return Task.CompletedTask; return Task.CompletedTask;
} }
private async void OnUserLockedOut(object sender, GenericEventArgs<User> e)
{
await CreateLogEntry(new ActivityLog(
string.Format(
CultureInfo.InvariantCulture,
_localization.GetLocalizedString("UserLockedOutWithName"),
e.Argument.Username),
NotificationType.UserLockedOut.ToString(),
e.Argument.Id)
{
LogSeverity = LogLevel.Error
}).ConfigureAwait(false);
}
private async void OnSessionEnded(object sender, SessionEventArgs e) private async void OnSessionEnded(object sender, SessionEventArgs e)
{ {
var session = e.SessionInfo; var session = e.SessionInfo;
@ -251,8 +230,6 @@ namespace Emby.Server.Implementations.Activity
_sessionManager.AuthenticationFailed -= OnAuthenticationFailed; _sessionManager.AuthenticationFailed -= OnAuthenticationFailed;
_sessionManager.AuthenticationSucceeded -= OnAuthenticationSucceeded; _sessionManager.AuthenticationSucceeded -= OnAuthenticationSucceeded;
_sessionManager.SessionEnded -= OnSessionEnded; _sessionManager.SessionEnded -= OnSessionEnded;
_userManager.OnUserLockedOut -= OnUserLockedOut;
} }
} }
} }

View File

@ -0,0 +1,18 @@
using Jellyfin.Data.Entities;
namespace Jellyfin.Data.Events.Users
{
/// <summary>
/// An event that occurs when a user is locked out.
/// </summary>
public class UserLockedOutEventArgs : GenericEventArgs<User>
{
/// <summary>
/// Initializes a new instance of the <see cref="UserLockedOutEventArgs"/> class.
/// </summary>
/// <param name="arg">The user.</param>
public UserLockedOutEventArgs(User arg) : base(arg)
{
}
}
}

View File

@ -0,0 +1,47 @@
using System.Globalization;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Events.Users;
using MediaBrowser.Controller.Events;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Notifications;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Server.Implementations.Events.Consumers.Users
{
/// <summary>
/// Creates an entry in the activity log when a user is locked out.
/// </summary>
public class UserLockedOutLogger : IEventConsumer<UserLockedOutEventArgs>
{
private readonly ILocalizationManager _localizationManager;
private readonly IActivityManager _activityManager;
/// <summary>
/// Initializes a new instance of the <see cref="UserLockedOutLogger"/> class.
/// </summary>
/// <param name="localizationManager">The localization manager.</param>
/// <param name="activityManager">The activity manager.</param>
public UserLockedOutLogger(ILocalizationManager localizationManager, IActivityManager activityManager)
{
_localizationManager = localizationManager;
_activityManager = activityManager;
}
/// <inheritdoc />
public async Task OnEvent(UserLockedOutEventArgs eventArgs)
{
await _activityManager.CreateAsync(new ActivityLog(
string.Format(
CultureInfo.InvariantCulture,
_localizationManager.GetLocalizedString("UserLockedOutWithName"),
eventArgs.Argument.Username),
NotificationType.UserLockedOut.ToString(),
eventArgs.Argument.Id)
{
LogSeverity = LogLevel.Error
}).ConfigureAwait(false);
}
}
}