mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
Implimented the features #218
This commit is contained in:
parent
4cf01fb9c4
commit
00cd6969e0
11 changed files with 277 additions and 150 deletions
|
@ -32,6 +32,7 @@ using NLog;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
|
using PlexRequests.Core.Users;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
using PlexRequests.Helpers.Permissions;
|
using PlexRequests.Helpers.Permissions;
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
|
@ -43,8 +44,9 @@ namespace PlexRequests.Core.Migration.Migrations
|
||||||
[Migration(11000, "v1.10.0.0")]
|
[Migration(11000, "v1.10.0.0")]
|
||||||
public class Version1100 : BaseMigration, IMigration
|
public class Version1100 : BaseMigration, IMigration
|
||||||
{
|
{
|
||||||
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log, IPlexApi plexApi, ISettingsService<PlexSettings> plexService, IPlexUserRepository plexusers,
|
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log, IPlexApi plexApi, ISettingsService<PlexSettings> plexService,
|
||||||
ISettingsService<PlexRequestSettings> prSettings, ISettingsService<UserManagementSettings> umSettings, ISettingsService<ScheduledJobsSettings> sjs)
|
IPlexUserRepository plexusers, ISettingsService<PlexRequestSettings> prSettings, ISettingsService<UserManagementSettings> umSettings,
|
||||||
|
ISettingsService<ScheduledJobsSettings> sjs, IRepository<UsersToNotify> usersToNotify)
|
||||||
{
|
{
|
||||||
UserRepo = userRepo;
|
UserRepo = userRepo;
|
||||||
RequestService = requestService;
|
RequestService = requestService;
|
||||||
|
@ -55,6 +57,7 @@ namespace PlexRequests.Core.Migration.Migrations
|
||||||
PlexRequestSettings = prSettings;
|
PlexRequestSettings = prSettings;
|
||||||
UserManagementSettings = umSettings;
|
UserManagementSettings = umSettings;
|
||||||
ScheduledJobSettings = sjs;
|
ScheduledJobSettings = sjs;
|
||||||
|
UserNotifyRepo = usersToNotify;
|
||||||
}
|
}
|
||||||
public int Version => 11000;
|
public int Version => 11000;
|
||||||
private IUserRepository UserRepo { get; }
|
private IUserRepository UserRepo { get; }
|
||||||
|
@ -66,6 +69,7 @@ namespace PlexRequests.Core.Migration.Migrations
|
||||||
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
|
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
|
||||||
private ISettingsService<UserManagementSettings> UserManagementSettings { get; }
|
private ISettingsService<UserManagementSettings> UserManagementSettings { get; }
|
||||||
private ISettingsService<ScheduledJobsSettings> ScheduledJobSettings { get; }
|
private ISettingsService<ScheduledJobsSettings> ScheduledJobSettings { get; }
|
||||||
|
private IRepository<UsersToNotify> UserNotifyRepo { get; }
|
||||||
|
|
||||||
public void Start(IDbConnection con)
|
public void Start(IDbConnection con)
|
||||||
{
|
{
|
||||||
|
@ -77,10 +81,36 @@ namespace PlexRequests.Core.Migration.Migrations
|
||||||
UpdatePlexUsers();
|
UpdatePlexUsers();
|
||||||
PopulateDefaultUserManagementSettings();
|
PopulateDefaultUserManagementSettings();
|
||||||
UpdateScheduledJobs();
|
UpdateScheduledJobs();
|
||||||
|
MigrateUserNotifications();
|
||||||
|
|
||||||
UpdateSchema(con, Version);
|
UpdateSchema(con, Version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MigrateUserNotifications()
|
||||||
|
{
|
||||||
|
var usersToNotify = UserNotifyRepo.GetAll();
|
||||||
|
var plexUsers = PlexUsers.GetAll().ToList();
|
||||||
|
var users = UserRepo.GetAll().ToList();
|
||||||
|
foreach (var u in usersToNotify)
|
||||||
|
{
|
||||||
|
var selectedPlexUser = plexUsers.FirstOrDefault(x => x.Username.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
if (selectedPlexUser != null)
|
||||||
|
{
|
||||||
|
selectedPlexUser.Features += (int)Features.RequestAddedNotification;
|
||||||
|
PlexUsers.Update(selectedPlexUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedLocalUser =
|
||||||
|
users.FirstOrDefault(x => x.UserName.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
if (selectedLocalUser != null)
|
||||||
|
{
|
||||||
|
selectedLocalUser.Features += (int) Features.RequestAddedNotification;
|
||||||
|
UserRepo.Update(selectedLocalUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateScheduledJobs()
|
private void UpdateScheduledJobs()
|
||||||
{
|
{
|
||||||
var settings = ScheduledJobSettings.GetSettings();
|
var settings = ScheduledJobSettings.GetSettings();
|
||||||
|
|
|
@ -147,9 +147,12 @@
|
||||||
<Compile Include="StatusChecker\AppveyorBranchResult.cs" />
|
<Compile Include="StatusChecker\AppveyorBranchResult.cs" />
|
||||||
<Compile Include="TvSender.cs" />
|
<Compile Include="TvSender.cs" />
|
||||||
<Compile Include="TvSenderOld.cs" />
|
<Compile Include="TvSenderOld.cs" />
|
||||||
|
<Compile Include="Users\IUserHelper.cs" />
|
||||||
|
<Compile Include="Users\UserHelper.cs" />
|
||||||
<Compile Include="UserIdentity.cs" />
|
<Compile Include="UserIdentity.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="UserMapper.cs" />
|
<Compile Include="UserMapper.cs" />
|
||||||
|
<Compile Include="Users\UserHelperModel.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
|
|
12
PlexRequests.Core/Users/IUserHelper.cs
Normal file
12
PlexRequests.Core/Users/IUserHelper.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using PlexRequests.Helpers.Permissions;
|
||||||
|
|
||||||
|
namespace PlexRequests.Core.Users
|
||||||
|
{
|
||||||
|
public interface IUserHelper
|
||||||
|
{
|
||||||
|
IEnumerable<UserHelperModel> GetUsers();
|
||||||
|
IEnumerable<UserHelperModel> GetUsersWithPermission(Permissions permission);
|
||||||
|
IEnumerable<UserHelperModel> GetUsersWithFeature(Features feature);
|
||||||
|
}
|
||||||
|
}
|
159
PlexRequests.Core/Users/UserHelper.cs
Normal file
159
PlexRequests.Core/Users/UserHelper.cs
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: UserHelper.cs
|
||||||
|
// Created By: Jamie Rees
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
// a copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
// the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
|
using PlexRequests.Helpers;
|
||||||
|
using PlexRequests.Helpers.Permissions;
|
||||||
|
using PlexRequests.Store.Repository;
|
||||||
|
|
||||||
|
namespace PlexRequests.Core.Users
|
||||||
|
{
|
||||||
|
public class UserHelper : IUserHelper
|
||||||
|
{
|
||||||
|
public UserHelper(IUserRepository userRepository, IPlexUserRepository plexUsers, ISecurityExtensions security)
|
||||||
|
{
|
||||||
|
LocalUserRepository = userRepository;
|
||||||
|
PlexUserRepository = plexUsers;
|
||||||
|
Security = security;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IUserRepository LocalUserRepository { get; }
|
||||||
|
private IPlexUserRepository PlexUserRepository { get; }
|
||||||
|
private ISecurityExtensions Security { get; }
|
||||||
|
|
||||||
|
|
||||||
|
public IEnumerable<UserHelperModel> GetUsers()
|
||||||
|
{
|
||||||
|
var model = new List<UserHelperModel>();
|
||||||
|
|
||||||
|
var localUsers = LocalUserRepository.GetAll();
|
||||||
|
var plexUsers = PlexUserRepository.GetAll();
|
||||||
|
|
||||||
|
foreach (var user in localUsers)
|
||||||
|
{
|
||||||
|
var props = ByteConverterHelper.ReturnObject<UserProperties>(user.UserProperties);
|
||||||
|
model.Add(new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.LocalUser,
|
||||||
|
Username = user.UserName,
|
||||||
|
UserAlias = props.UserAlias,
|
||||||
|
EmailAddress = props.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
model.AddRange(plexUsers.Select(user => new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.LocalUser,
|
||||||
|
Username = user.Username,
|
||||||
|
UserAlias = user.UserAlias,
|
||||||
|
EmailAddress = user.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions
|
||||||
|
}));
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<UserHelperModel> GetUsersWithPermission(Permissions permission)
|
||||||
|
{
|
||||||
|
var model = new List<UserHelperModel>();
|
||||||
|
|
||||||
|
var localUsers = LocalUserRepository.GetAll().ToList();
|
||||||
|
var plexUsers = PlexUserRepository.GetAll().ToList();
|
||||||
|
|
||||||
|
var filteredLocal = localUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
|
||||||
|
var filteredPlex = plexUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var user in filteredLocal)
|
||||||
|
{
|
||||||
|
var props = ByteConverterHelper.ReturnObject<UserProperties>(user.UserProperties);
|
||||||
|
model.Add(new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.LocalUser,
|
||||||
|
Username = user.UserName,
|
||||||
|
UserAlias = props.UserAlias,
|
||||||
|
EmailAddress = props.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions,
|
||||||
|
Features = (Features)user.Features
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
model.AddRange(filteredPlex.Select(user => new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.LocalUser,
|
||||||
|
Username = user.Username,
|
||||||
|
UserAlias = user.UserAlias,
|
||||||
|
EmailAddress = user.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions,
|
||||||
|
Features = (Features)user.Features
|
||||||
|
}));
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<UserHelperModel> GetUsersWithFeatures(Features features)
|
||||||
|
{
|
||||||
|
var model = new List<UserHelperModel>();
|
||||||
|
|
||||||
|
var localUsers = LocalUserRepository.GetAll().ToList();
|
||||||
|
var plexUsers = PlexUserRepository.GetAll().ToList();
|
||||||
|
|
||||||
|
var filteredLocal = localUsers.Where(x => ((Features)x.Features).HasFlag(features));
|
||||||
|
var filteredPlex = plexUsers.Where(x => ((Features)x.Features).HasFlag(features));
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var user in filteredLocal)
|
||||||
|
{
|
||||||
|
var props = ByteConverterHelper.ReturnObject<UserProperties>(user.UserProperties);
|
||||||
|
model.Add(new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.LocalUser,
|
||||||
|
Username = user.UserName,
|
||||||
|
UserAlias = props.UserAlias,
|
||||||
|
EmailAddress = props.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions,
|
||||||
|
Features = (Features)user.Features
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
model.AddRange(filteredPlex.Select(user => new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.LocalUser,
|
||||||
|
Username = user.Username,
|
||||||
|
UserAlias = user.UserAlias,
|
||||||
|
EmailAddress = user.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions,
|
||||||
|
Features = (Features)user.Features
|
||||||
|
}));
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
PlexRequests.Core/Users/UserHelperModel.cs
Normal file
42
PlexRequests.Core/Users/UserHelperModel.cs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: UserHelperModel.cs
|
||||||
|
// Created By: Jamie Rees
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
// a copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
// the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
// ************************************************************************/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using PlexRequests.Helpers;
|
||||||
|
using PlexRequests.Helpers.Permissions;
|
||||||
|
|
||||||
|
namespace PlexRequests.Core.Users
|
||||||
|
{
|
||||||
|
public class UserHelperModel
|
||||||
|
{
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string UserAlias { get; set; }
|
||||||
|
public Permissions Permissions { get; set; }
|
||||||
|
public Features Features { get; set; }
|
||||||
|
public string EmailAddress { get; set; }
|
||||||
|
public UserType Type { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,8 +35,8 @@ namespace PlexRequests.Helpers.Permissions
|
||||||
{
|
{
|
||||||
[Display(Name = "Newsletter")]
|
[Display(Name = "Newsletter")]
|
||||||
Newsletter = 1,
|
Newsletter = 1,
|
||||||
[Display(Name = "Recently Added Notification")]
|
[Display(Name = "Request Added Notification")]
|
||||||
RecentlyAddedNotification = 2,
|
RequestAddedNotification = 2,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -39,7 +39,9 @@ using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Api.Models.Plex;
|
using PlexRequests.Api.Models.Plex;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
|
using PlexRequests.Core.Users;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
|
using PlexRequests.Helpers.Permissions;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
using PlexRequests.Services.Jobs.Templates;
|
using PlexRequests.Services.Jobs.Templates;
|
||||||
using PlexRequests.Store.Models.Plex;
|
using PlexRequests.Store.Models.Plex;
|
||||||
|
@ -52,8 +54,8 @@ namespace PlexRequests.Services.Jobs
|
||||||
{
|
{
|
||||||
public RecentlyAdded(IPlexApi api, ISettingsService<PlexSettings> plexSettings,
|
public RecentlyAdded(IPlexApi api, ISettingsService<PlexSettings> plexSettings,
|
||||||
ISettingsService<EmailNotificationSettings> email, IJobRecord rec,
|
ISettingsService<EmailNotificationSettings> email, IJobRecord rec,
|
||||||
ISettingsService<NewletterSettings> newsletter,
|
ISettingsService<NewletterSettings> newsletter,
|
||||||
IPlexReadOnlyDatabase db)
|
IPlexReadOnlyDatabase db, IUserHelper userHelper)
|
||||||
{
|
{
|
||||||
JobRecord = rec;
|
JobRecord = rec;
|
||||||
Api = api;
|
Api = api;
|
||||||
|
@ -61,6 +63,7 @@ namespace PlexRequests.Services.Jobs
|
||||||
EmailSettings = email;
|
EmailSettings = email;
|
||||||
NewsletterSettings = newsletter;
|
NewsletterSettings = newsletter;
|
||||||
PlexDb = db;
|
PlexDb = db;
|
||||||
|
UserHelper = userHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IPlexApi Api { get; }
|
private IPlexApi Api { get; }
|
||||||
|
@ -73,6 +76,7 @@ namespace PlexRequests.Services.Jobs
|
||||||
private ISettingsService<NewletterSettings> NewsletterSettings { get; }
|
private ISettingsService<NewletterSettings> NewsletterSettings { get; }
|
||||||
private IJobRecord JobRecord { get; }
|
private IJobRecord JobRecord { get; }
|
||||||
private IPlexReadOnlyDatabase PlexDb { get; }
|
private IPlexReadOnlyDatabase PlexDb { get; }
|
||||||
|
private IUserHelper UserHelper { get; }
|
||||||
|
|
||||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
@ -255,18 +259,21 @@ namespace PlexRequests.Services.Jobs
|
||||||
|
|
||||||
if (!testEmail)
|
if (!testEmail)
|
||||||
{
|
{
|
||||||
if (newletterSettings.SendToPlexUsers)
|
//if (newletterSettings.SendToPlexUsers)
|
||||||
|
//{
|
||||||
|
|
||||||
|
var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification);
|
||||||
|
if (users != null)
|
||||||
{
|
{
|
||||||
var users = Api.GetUsers(plexSettings.PlexAuthToken);
|
foreach (var user in users)
|
||||||
if (users != null)
|
|
||||||
{
|
{
|
||||||
foreach (var user in users.User)
|
if (!string.IsNullOrEmpty(user.EmailAddress))
|
||||||
{
|
{
|
||||||
if (user.Email != null)
|
message.Bcc.Add(new MailboxAddress(user.Username, user.EmailAddress));
|
||||||
message.Bcc.Add(new MailboxAddress(user.Username, user.Email));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
|
|
||||||
if (newletterSettings.CustomUsersEmailAddresses != null
|
if (newletterSettings.CustomUsersEmailAddresses != null
|
||||||
&& newletterSettings.CustomUsersEmailAddresses.Any())
|
&& newletterSettings.CustomUsersEmailAddresses.Any())
|
||||||
|
|
|
@ -34,6 +34,8 @@ using NLog.Fluent;
|
||||||
using PlexRequests.Api;
|
using PlexRequests.Api;
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Core.Models;
|
using PlexRequests.Core.Models;
|
||||||
|
using PlexRequests.Core.Users;
|
||||||
|
using PlexRequests.Helpers.Permissions;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
using PlexRequests.Store.Models;
|
using PlexRequests.Store.Models;
|
||||||
|
@ -43,17 +45,19 @@ namespace PlexRequests.Services.Notification
|
||||||
{
|
{
|
||||||
public class NotificationEngine : INotificationEngine
|
public class NotificationEngine : INotificationEngine
|
||||||
{
|
{
|
||||||
public NotificationEngine(IPlexApi p, IRepository<UsersToNotify> repo, INotificationService service)
|
public NotificationEngine(IPlexApi p, IRepository<UsersToNotify> repo, INotificationService service, IUserHelper userHelper)
|
||||||
{
|
{
|
||||||
PlexApi = p;
|
PlexApi = p;
|
||||||
UserNotifyRepo = repo;
|
UserNotifyRepo = repo;
|
||||||
Notification = service;
|
Notification = service;
|
||||||
|
UserHelper = userHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IPlexApi PlexApi { get; }
|
private IPlexApi PlexApi { get; }
|
||||||
private IRepository<UsersToNotify> UserNotifyRepo { get; }
|
private IRepository<UsersToNotify> UserNotifyRepo { get; }
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
private INotificationService Notification { get; }
|
private INotificationService Notification { get; }
|
||||||
|
private IUserHelper UserHelper { get; }
|
||||||
|
|
||||||
public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, string apiKey, NotificationType type)
|
public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, string apiKey, NotificationType type)
|
||||||
{
|
{
|
||||||
|
@ -64,7 +68,7 @@ namespace PlexRequests.Services.Notification
|
||||||
|
|
||||||
var adminUsername = userAccount.Username ?? string.Empty;
|
var adminUsername = userAccount.Username ?? string.Empty;
|
||||||
|
|
||||||
var users = UserNotifyRepo.GetAll().ToList();
|
var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList();
|
||||||
Log.Debug("Notifying Users Count {0}", users.Count);
|
Log.Debug("Notifying Users Count {0}", users.Count);
|
||||||
foreach (var model in modelChanged)
|
foreach (var model in modelChanged)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +84,7 @@ namespace PlexRequests.Services.Notification
|
||||||
}
|
}
|
||||||
|
|
||||||
var email = plexUser.User.FirstOrDefault(x => x.Username.Equals(user, StringComparison.CurrentCultureIgnoreCase));
|
var email = plexUser.User.FirstOrDefault(x => x.Username.Equals(user, StringComparison.CurrentCultureIgnoreCase));
|
||||||
if (email == null)
|
if (string.IsNullOrEmpty(email?.Email))
|
||||||
{
|
{
|
||||||
Log.Info("There is no email address for this Plex user, cannot send notification");
|
Log.Info("There is no email address for this Plex user, cannot send notification");
|
||||||
// We do not have a plex user that requested this!
|
// We do not have a plex user that requested this!
|
||||||
|
@ -107,7 +111,7 @@ namespace PlexRequests.Services.Notification
|
||||||
|
|
||||||
var adminUsername = userAccount.Username ?? string.Empty;
|
var adminUsername = userAccount.Username ?? string.Empty;
|
||||||
|
|
||||||
var users = UserNotifyRepo.GetAll().ToList();
|
var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList();
|
||||||
Log.Debug("Notifying Users Count {0}", users.Count);
|
Log.Debug("Notifying Users Count {0}", users.Count);
|
||||||
|
|
||||||
var selectedUsers = users.Select(x => x.Username).Intersect(model.RequestedUsers, StringComparer.CurrentCultureIgnoreCase);
|
var selectedUsers = users.Select(x => x.Username).Intersect(model.RequestedUsers, StringComparer.CurrentCultureIgnoreCase);
|
||||||
|
|
41
PlexRequests.UI/Content/search.js
vendored
41
PlexRequests.UI/Content/search.js
vendored
|
@ -51,21 +51,6 @@ $(function () {
|
||||||
});
|
});
|
||||||
focusSearch($('li.active a', '#nav-tabs').first().attr('href'));
|
focusSearch($('li.active a', '#nav-tabs').first().attr('href'));
|
||||||
|
|
||||||
// Get the user notification setting
|
|
||||||
var url = createBaseUrl(base, '/search/notifyuser/');
|
|
||||||
$.ajax({
|
|
||||||
type: "get",
|
|
||||||
url: url,
|
|
||||||
dataType: "json",
|
|
||||||
success: function (response) {
|
|
||||||
$('#notifyUser').prop("checked", response);
|
|
||||||
},
|
|
||||||
error: function (e) {
|
|
||||||
console.log(e);
|
|
||||||
generateNotify("Something went wrong!", "danger");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Type in movie search
|
// Type in movie search
|
||||||
$("#movieSearchContent").on("input", function () {
|
$("#movieSearchContent").on("input", function () {
|
||||||
if (searchTimer) {
|
if (searchTimer) {
|
||||||
|
@ -184,32 +169,6 @@ $(function () {
|
||||||
sendRequestAjax(data, type, url, buttonId);
|
sendRequestAjax(data, type, url, buttonId);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Enable/Disable user notifications
|
|
||||||
$('#saveNotificationSettings')
|
|
||||||
.click(function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
var url = createBaseUrl(base, '/search/notifyuser/');
|
|
||||||
var checked = $('#notifyUser').prop('checked');
|
|
||||||
$.ajax({
|
|
||||||
type: "post",
|
|
||||||
url: url,
|
|
||||||
data: { notify: checked },
|
|
||||||
dataType: "json",
|
|
||||||
success: function (response) {
|
|
||||||
console.log(response);
|
|
||||||
if (response.result === true) {
|
|
||||||
generateNotify(response.message || "Success!", "success");
|
|
||||||
} else {
|
|
||||||
generateNotify(response.message, "warning");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function (e) {
|
|
||||||
console.log(e);
|
|
||||||
generateNotify("Something went wrong!", "danger");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Report Issue
|
// Report Issue
|
||||||
$(document).on("click", ".dropdownIssue", function (e) {
|
$(document).on("click", ".dropdownIssue", function (e) {
|
||||||
var issue = $(this).attr("issue-select");
|
var issue = $(this).attr("issue-select");
|
||||||
|
|
|
@ -133,9 +133,6 @@ namespace PlexRequests.UI.Modules
|
||||||
Post["request/tvEpisodes", true] = async (x, ct) => await RequestTvShow(0, "episode");
|
Post["request/tvEpisodes", true] = async (x, ct) => await RequestTvShow(0, "episode");
|
||||||
Post["request/album", true] = async (x, ct) => await RequestAlbum((string)Request.Form.albumId);
|
Post["request/album", true] = async (x, ct) => await RequestAlbum((string)Request.Form.albumId);
|
||||||
|
|
||||||
Post["/notifyuser", true] = async (x, ct) => await NotifyUser((bool)Request.Form.notify);
|
|
||||||
Get["/notifyuser", true] = async (x, ct) => await GetUserNotificationSettings();
|
|
||||||
|
|
||||||
Get["/seasons"] = x => GetSeasons();
|
Get["/seasons"] = x => GetSeasons();
|
||||||
Get["/episodes", true] = async (x, ct) => await GetEpisodes();
|
Get["/episodes", true] = async (x, ct) => await GetEpisodes();
|
||||||
}
|
}
|
||||||
|
@ -1147,65 +1144,6 @@ namespace PlexRequests.UI.Modules
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Response> NotifyUser(bool notify)
|
|
||||||
{
|
|
||||||
Analytics.TrackEventAsync(Category.Search, Action.Save, "NotifyUser", Username, CookieHelper.GetAnalyticClientId(Cookies), notify ? 1 : 0);
|
|
||||||
var authSettings = await Auth.GetSettingsAsync();
|
|
||||||
var auth = authSettings.UserAuthentication;
|
|
||||||
var emailSettings = await EmailNotificationSettings.GetSettingsAsync();
|
|
||||||
var email = emailSettings.EnableUserEmailNotifications;
|
|
||||||
if (!auth)
|
|
||||||
{
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_ErrorPlexAccountOnly });
|
|
||||||
}
|
|
||||||
if (!email)
|
|
||||||
{
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_ErrorNotEnabled });
|
|
||||||
}
|
|
||||||
var username = Username;
|
|
||||||
var originalList = await UsersToNotifyRepo.GetAllAsync();
|
|
||||||
if (!notify)
|
|
||||||
{
|
|
||||||
if (originalList == null)
|
|
||||||
{
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_NotificationError });
|
|
||||||
}
|
|
||||||
var userToRemove = originalList.FirstOrDefault(x => x.Username == username);
|
|
||||||
if (userToRemove != null)
|
|
||||||
{
|
|
||||||
await UsersToNotifyRepo.DeleteAsync(userToRemove);
|
|
||||||
}
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (originalList == null)
|
|
||||||
{
|
|
||||||
var userModel = new UsersToNotify { Username = username };
|
|
||||||
var insertResult = await UsersToNotifyRepo.InsertAsync(userModel);
|
|
||||||
return Response.AsJson(insertResult != -1 ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = Resources.UI.Common_CouldNotSave });
|
|
||||||
}
|
|
||||||
|
|
||||||
var existingUser = originalList.FirstOrDefault(x => x.Username == username);
|
|
||||||
if (existingUser != null)
|
|
||||||
{
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true }); // It's already enabled
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var userModel = new UsersToNotify { Username = username };
|
|
||||||
var insertResult = await UsersToNotifyRepo.InsertAsync(userModel);
|
|
||||||
return Response.AsJson(insertResult != -1 ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = Resources.UI.Common_CouldNotSave });
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
private async Task<Response> GetUserNotificationSettings()
|
|
||||||
{
|
|
||||||
var all = await UsersToNotifyRepo.GetAllAsync();
|
|
||||||
var retVal = all.FirstOrDefault(x => x.Username == Username);
|
|
||||||
return Response.AsJson(retVal != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Response GetSeasons()
|
private Response GetSeasons()
|
||||||
{
|
{
|
||||||
var seriesId = (int)Request.Query.tvId;
|
var seriesId = (int)Request.Query.tvId;
|
||||||
|
|
|
@ -111,33 +111,6 @@
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
<!-- Notification tab -->
|
|
||||||
<div role="tabpanel" class="tab-pane" id="NotificationsTab">
|
|
||||||
<div class="input-group">
|
|
||||||
<div class="input-group-addon input-group-sm"></div>
|
|
||||||
</div>
|
|
||||||
<br />
|
|
||||||
|
|
||||||
<!-- Notifications content -->
|
|
||||||
<form class="form-horizontal" method="POST" id="notificationsForm">
|
|
||||||
<fieldset>
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="checkbox">
|
|
||||||
<input type="checkbox" id="notifyUser" name="Notify">
|
|
||||||
<label for="notifyUser">@UI.Search_SendNotificationText</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<div>
|
|
||||||
<button id="saveNotificationSettings" class="btn btn-primary-outline">@UI.Common_Save</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Movie and TV Results template -->
|
<!-- Movie and TV Results template -->
|
||||||
<script id="search-template" type="text/x-handlebars-template">
|
<script id="search-template" type="text/x-handlebars-template">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue