diff --git a/Ombi.Api.Interfaces/IWatcherApi.cs b/Ombi.Api.Interfaces/IWatcherApi.cs new file mode 100644 index 000000000..2aa90b4d5 --- /dev/null +++ b/Ombi.Api.Interfaces/IWatcherApi.cs @@ -0,0 +1,40 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: IWatcherApi.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; +using System.Collections.Generic; +using Ombi.Api.Models.Watcher; + +namespace Ombi.Api.Interfaces +{ + public interface IWatcherApi + { + WatcherAddMovieResult AddMovie(string imdbId, string apiKey, Uri baseUrl); + List ListMovies(string apiKey, Uri baseUrl); + List ListMovies(string apiKey, Uri baseUrl, string imdbId); + } +} \ No newline at end of file diff --git a/Ombi.Api.Interfaces/Ombi.Api.Interfaces.csproj b/Ombi.Api.Interfaces/Ombi.Api.Interfaces.csproj index 859c3cecc..c33bbf0c2 100644 --- a/Ombi.Api.Interfaces/Ombi.Api.Interfaces.csproj +++ b/Ombi.Api.Interfaces/Ombi.Api.Interfaces.csproj @@ -55,6 +55,7 @@ + diff --git a/Ombi.Api.Models/Ombi.Api.Models.csproj b/Ombi.Api.Models/Ombi.Api.Models.csproj index 81e440075..c44e89bf8 100644 --- a/Ombi.Api.Models/Ombi.Api.Models.csproj +++ b/Ombi.Api.Models/Ombi.Api.Models.csproj @@ -35,6 +35,10 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True + + ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll + True + @@ -102,6 +106,8 @@ + + diff --git a/Ombi.Api.Models/Watcher/WatcherAddMovieResult.cs b/Ombi.Api.Models/Watcher/WatcherAddMovieResult.cs new file mode 100644 index 000000000..dd546ac51 --- /dev/null +++ b/Ombi.Api.Models/Watcher/WatcherAddMovieResult.cs @@ -0,0 +1,34 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: WatcherAddMovieResult.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 +namespace Ombi.Api.Models.Watcher +{ + public class WatcherAddMovieResult + { + public string status { get; set; } + public string message { get; set; } + } +} \ No newline at end of file diff --git a/Ombi.Api.Models/Watcher/WatcherListStatusResult.cs b/Ombi.Api.Models/Watcher/WatcherListStatusResult.cs new file mode 100644 index 000000000..4d4d043a4 --- /dev/null +++ b/Ombi.Api.Models/Watcher/WatcherListStatusResult.cs @@ -0,0 +1,77 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: WatcherListStatusResult.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 Newtonsoft.Json; +using RestSharp.Deserializers; + +namespace Ombi.Api.Models.Watcher +{ + public class Quality2 + { + [DeserializeAs(Name = "720P")] + public List Q720P { get; set; } + [DeserializeAs(Name = "1080P")] + public List Q1080P { get; set; } + [DeserializeAs( Name = "4K")] + public List Q4K { get; set; } + public List SD { get; set; } + } + + public class Filters + { + public string preferredwords { get; set; } + public string ignoredwords { get; set; } + public string requiredwords { get; set; } + } + + public class Quality + { + [DeserializeAs(Name = "Quality")] + public Quality2 quality { get; set; } + public Filters Filters { get; set; } + } + + public class WatcherListStatusResult + { + public string status { get; set; } + public string plot { get; set; } + public string rated { get; set; } + public string title { get; set; } + public object finishedscore { get; set; } + public string predb { get; set; } + public string year { get; set; } + public string poster { get; set; } + public string tomatourl { get; set; } + public string released { get; set; } + public object finisheddate { get; set; } + public string dvd { get; set; } + public string tomatorating { get; set; } + public string imdbid { get; set; } + public Quality quality { get; set; } + } +} \ No newline at end of file diff --git a/Ombi.Api.Models/packages.config b/Ombi.Api.Models/packages.config index e1fae9c6a..7b2a57310 100644 --- a/Ombi.Api.Models/packages.config +++ b/Ombi.Api.Models/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/Ombi.Api/Ombi.Api.csproj b/Ombi.Api/Ombi.Api.csproj index a1510eb9d..615f5ac3a 100644 --- a/Ombi.Api/Ombi.Api.csproj +++ b/Ombi.Api/Ombi.Api.csproj @@ -69,6 +69,7 @@ + diff --git a/Ombi.Api/WatcherApi.cs b/Ombi.Api/WatcherApi.cs new file mode 100644 index 000000000..769ff58eb --- /dev/null +++ b/Ombi.Api/WatcherApi.cs @@ -0,0 +1,83 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoApi.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; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; +using NLog; +using Ombi.Api.Interfaces; +using Ombi.Api.Models.Movie; +using Ombi.Api.Models.Watcher; +using Ombi.Helpers; +using RestSharp; + +namespace Ombi.Api +{ + public class WatcherApi : IWatcherApi + { + public WatcherApi() + { + Api = new ApiRequest(); + } + + private ApiRequest Api { get; set; } + private static Logger Log = LogManager.GetCurrentClassLogger(); + + public WatcherAddMovieResult AddMovie(string imdbId, string apiKey, Uri baseUrl) + { + return Send("addmovie", apiKey, baseUrl, imdbId); + } + + public List ListMovies(string apiKey, Uri baseUrl) + { + return Send>("liststatus", apiKey, baseUrl); + } + + public List ListMovies(string apiKey, Uri baseUrl, string imdbId) + { + return Send>("liststatus", apiKey, baseUrl, imdbId); + } + + + private T Send(string mode, string apiKey, Uri baseUrl, string imdbid = "") where T : new() + { + RestRequest request; + request = new RestRequest + { + Resource = "/api" + }; + + request.AddUrlSegment("apikey", apiKey); + if(!string.IsNullOrEmpty(imdbid)) + { request.AddUrlSegment("imdbid", imdbid);} + request.AddUrlSegment("mode", mode); + + return Api.Execute(request, baseUrl); + } + } + +} \ No newline at end of file diff --git a/Ombi.Helpers/SerializerSettings.cs b/Ombi.Helpers/SerializerSettings.cs index 7dd604df5..f474417b4 100644 --- a/Ombi.Helpers/SerializerSettings.cs +++ b/Ombi.Helpers/SerializerSettings.cs @@ -36,8 +36,8 @@ namespace Ombi.Helpers public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings { Formatting = Formatting.None, - TypeNameHandling = TypeNameHandling.Objects, - TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple, + //TypeNameHandling = TypeNameHandling.Objects, + //TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple, NullValueHandling = NullValueHandling.Ignore }; diff --git a/Ombi.Services/Jobs/PlexUserChecker.cs b/Ombi.Services/Jobs/PlexUserChecker.cs index cd1d26bb3..d09bba28c 100644 --- a/Ombi.Services/Jobs/PlexUserChecker.cs +++ b/Ombi.Services/Jobs/PlexUserChecker.cs @@ -34,6 +34,7 @@ using Ombi.Api.Interfaces; using Ombi.Core; using Ombi.Core.SettingModels; using Ombi.Core.Users; +using Ombi.Helpers.Permissions; using Ombi.Services.Interfaces; using Ombi.Store.Models; using Ombi.Store.Repository; @@ -80,10 +81,13 @@ namespace Ombi.Services.Jobs } var plexUsers = PlexApi.GetUsers(settings.PlexAuthToken); var userManagementSettings = UserManagementSettings.GetSettings(); + var mainPlexAccount = PlexApi.GetAccount(settings.PlexAuthToken); var requests = RequestService.GetAll().ToList(); var dbUsers = Repo.GetAll().ToList(); var localUsers = LocalUserRepository.GetAll().ToList(); + + // Regular users foreach (var user in plexUsers.User) { var dbUser = dbUsers.FirstOrDefault(x => x.PlexUserId == user.Id); @@ -144,7 +148,7 @@ namespace Ombi.Services.Jobs continue; } - + // Looks like it's a new user! var m = new PlexUsers { @@ -160,6 +164,33 @@ namespace Ombi.Services.Jobs Repo.Insert(m); } + // Main Plex user + var dbMainAcc = dbUsers.FirstOrDefault(x => x.Username.Equals(mainPlexAccount.Username, StringComparison.CurrentCulture)); + var localMainAcc = localUsers.FirstOrDefault(x => x.UserName.Equals(mainPlexAccount.Username, StringComparison.CurrentCulture)); + + // TODO if admin acc does exist, check if we need to update it + + + // Create the local admin account if it doesn't already exist + if (dbMainAcc == null && localMainAcc == null) + { + var a = new PlexUsers + { + PlexUserId = mainPlexAccount.Id, + Permissions = UserManagementHelper.GetPermissions(userManagementSettings), + Features = UserManagementHelper.GetFeatures(userManagementSettings), + UserAlias = string.Empty, + EmailAddress = mainPlexAccount.Email, + Username = mainPlexAccount.Username, + LoginId = Guid.NewGuid().ToString() + }; + + a.Permissions += (int) Permissions.Administrator; // Make admin + + Repo.Insert(a); + } + + } catch (Exception e) { diff --git a/Ombi.UI/Jobs/Scheduler.cs b/Ombi.UI/Jobs/Scheduler.cs index 6dd12321f..9f01ac625 100644 --- a/Ombi.UI/Jobs/Scheduler.cs +++ b/Ombi.UI/Jobs/Scheduler.cs @@ -183,7 +183,7 @@ namespace Ombi.UI.Jobs var plexUserChecker = TriggerBuilder.Create() .WithIdentity("PlexUserChecker", "Plex") - .StartAt(DateBuilder.FutureDate(30, IntervalUnit.Minute)) + .StartAt(DateBuilder.FutureDate(1, IntervalUnit.Minute)) .WithSimpleSchedule(x => x.WithIntervalInMinutes(s.PlexUserChecker).RepeatForever()) .Build(); diff --git a/Ombi.UI/Modules/Admin/AdminModule.cs b/Ombi.UI/Modules/Admin/AdminModule.cs index 15dbd81d3..2b3601924 100644 --- a/Ombi.UI/Modules/Admin/AdminModule.cs +++ b/Ombi.UI/Modules/Admin/AdminModule.cs @@ -672,7 +672,7 @@ namespace Ombi.UI.Modules.Admin NotificationType = NotificationType.Test, DateTime = DateTime.Now }; - var currentSettings = await PushbulletService.GetSettingsAsync(); + var currentSettings = await PushoverService.GetSettingsAsync(); try { NotificationService.Subscribe(new PushoverNotification(PushoverApi, PushoverService)); diff --git a/Ombi.UI/Modules/UserManagementModule.cs b/Ombi.UI/Modules/UserManagementModule.cs index 5b853f70d..1a2581d40 100644 --- a/Ombi.UI/Modules/UserManagementModule.cs +++ b/Ombi.UI/Modules/UserManagementModule.cs @@ -406,8 +406,10 @@ namespace Ombi.UI.Modules private UserManagementUsersViewModel MapPlexUser(UserFriends plexInfo, PlexUsers dbUser, DateTime lastLoggedIn) { + var newUser = false; if (dbUser == null) { + newUser = true; dbUser = new PlexUsers(); } var features = (Features)dbUser?.Features; @@ -416,8 +418,8 @@ namespace Ombi.UI.Modules var m = new UserManagementUsersViewModel { Id = plexInfo.Id, - PermissionsFormattedString = permissions == 0 ? "None" : permissions.ToString(), - FeaturesFormattedString = features.ToString(), + PermissionsFormattedString = newUser ? "Processing..." :( permissions == 0 ? "None" : permissions.ToString()), + FeaturesFormattedString = newUser ? "Processing..." : features.ToString(), Username = plexInfo.Username, Type = UserType.PlexUser, EmailAddress = plexInfo.Email, @@ -437,8 +439,10 @@ namespace Ombi.UI.Modules private UserManagementUsersViewModel MapPlexAdmin(PlexAccount plexInfo, PlexUsers dbUser, DateTime lastLoggedIn) { + var newUser = false; if (dbUser == null) { + newUser = true; dbUser = new PlexUsers(); } var features = (Features)dbUser?.Features; @@ -447,8 +451,8 @@ namespace Ombi.UI.Modules var m = new UserManagementUsersViewModel { Id = plexInfo.Id, - PermissionsFormattedString = permissions == 0 ? "None" : permissions.ToString(), - FeaturesFormattedString = features.ToString(), + PermissionsFormattedString = newUser ? "Processing..." : (permissions == 0 ? "None" : permissions.ToString()), + FeaturesFormattedString = newUser ? "Processing..." : features.ToString(), Username = plexInfo.Username, Type = UserType.PlexUser, EmailAddress = plexInfo.Email, diff --git a/Ombi.UI/NinjectModules/ApiModule.cs b/Ombi.UI/NinjectModules/ApiModule.cs index 891655450..4dd37a8db 100644 --- a/Ombi.UI/NinjectModules/ApiModule.cs +++ b/Ombi.UI/NinjectModules/ApiModule.cs @@ -45,6 +45,7 @@ namespace Ombi.UI.NinjectModules Bind().To(); Bind().To(); Bind().To(); + Bind().To(); } } } \ No newline at end of file diff --git a/Ombi.UI/Views/Admin/PushoverNotifications.cshtml b/Ombi.UI/Views/Admin/PushoverNotifications.cshtml index b5df6bdc5..efc5ddb1d 100644 --- a/Ombi.UI/Views/Admin/PushoverNotifications.cshtml +++ b/Ombi.UI/Views/Admin/PushoverNotifications.cshtml @@ -1,25 +1,14 @@ @using Ombi.UI.Helpers +@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase @Html.Partial("Shared/Partial/_Sidebar")
Pushover Notifications + -
-
- - @if (Model.Enabled) - { - - } - else - { - - } - -
-
+ @Html.Checkbox(Model.Enabled, "Enabled", "Enabled")
diff --git a/Ombi.UI/Views/Shared/Partial/_Navbar.cshtml b/Ombi.UI/Views/Shared/Partial/_Navbar.cshtml index 95b356746..3107c5866 100644 --- a/Ombi.UI/Views/Shared/Partial/_Navbar.cshtml +++ b/Ombi.UI/Views/Shared/Partial/_Navbar.cshtml @@ -52,10 +52,6 @@