Unverified Commit 3ca187b4 authored by Jamie's avatar Jamie Committed by GitHub

Merge pull request #3250 from tidusjar/develop

Develop
parents c547777d 93f5f94a
......@@ -246,3 +246,4 @@ _Pvt_Extensions
# Ignore local vscode config
*.vscode
/src/Ombi/database.json
# Changelog
## v3.0.4817 (2019-10-15)
## (unreleased)
### **New Features**
- Update login.component.ts. [Jamie]
- Update CHANGELOG.md. [Jamie]
- Updated SlackNotification.cs. [Tim]
### **Fixes**
- Fixed the issue where we couldn't always pick up stuff on the sync. [tidusjar]
- Removed hangfire completly from Ombi. [tidusjar]
- Fixed the notifications issue. [tidusjar]
- Fixed the issues where the DB was being disposed too early. [tidusjar]
- Fixed an error with the newsletter with the new db structure. [tidusjar]
- Output some useful stuff to the about window regarding the databases. [tidusjar]
- Fixed the migration for combined databases. [tidusjar]
- Fixed the issue where exisitng databases would now fail due to the DB structure changes. [tidusjar]
- Finished it! [tidusjar]
- Got MySql working. [tidusjar]
- Got the new DB structure in place. [tidusjar]
- Fix for #3219. [tidusjar]
- Fixed the error in the newsletter. [tidusjar]
- Fixed #3208. [tidusjar]
- Use tags and autocomplete for excluded keywords. [Taylor Buchanan]
- Add comments to clarify filter decisions. [Taylor Buchanan]
- Fix TS import order. [Taylor Buchanan]
- Add adult movie filtering. [Taylor Buchanan]
- Fix search bar overlap on mobile. [Taylor Buchanan]
- New translations en.json (Slovak) [Jamie]
- New translations en.json (Slovak) [Jamie]
- New translations en.json (Slovak) [Jamie]
- New translations en.json (Slovak) [Jamie]
- New translations en.json (Slovak) [Jamie]
- New translations en.json (Slovak) [Jamie]
- New translations en.json (Slovak) [Jamie]
- Add SK lang. [Jamie Rees]
- Add the migration to the correct database... #3214. [tidusjar]
- Hopefully provide a fix now for #2998 Theory is that the refresh metadata was using stale data and then overriding the availbility that just happened on that media item. [tidusjar]
## v3.0.4817 (2019-10-12)
### **New Features**
......@@ -34,6 +105,8 @@
### **Fixes**
- Gitchangelog. [tidusjar]
- Fixed #3078. [tidusjar]
- Fixes issue #3195 The new string extension method ToHttpsUrl ensures that URLs starting with "https" are no longer turned into "httpss" The commit also replaces all occurances of the error prone .Replace("http", "https") in the whole solution. [msdeibel]
......
......@@ -93,24 +93,7 @@ namespace Ombi.Api
public void AddQueryString(string key, string value)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;
var builder = new UriBuilder(FullUri);
var startingTag = string.Empty;
var hasQuery = false;
if (string.IsNullOrEmpty(builder.Query))
{
startingTag = "?";
}
else
{
hasQuery = true;
startingTag = builder.Query.Contains("?") ? "&" : "?";
}
builder.Query = hasQuery
? $"{builder.Query}{startingTag}{key}={value}"
: $"{startingTag}{key}={value}";
_modified = builder.Uri;
_modified = FullUri.AddQueryParameter(key, value);
}
public void AddJsonBody(object obj)
......
......@@ -188,11 +188,7 @@ namespace Ombi.Core.Engine
var requests = await (OrderMovies(allRequests, orderFilter.OrderType)).Skip(position).Take(count)
.ToListAsync();
requests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
await CheckForSubscription(shouldHide, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
......@@ -251,26 +247,30 @@ namespace Ombi.Core.Engine
allRequests = await MovieRepository.GetWithUser().ToListAsync();
}
allRequests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
await CheckForSubscription(shouldHide, allRequests);
return allRequests;
}
private async Task CheckForSubscription(HideResult shouldHide, MovieRequests x)
private async Task CheckForSubscription(HideResult shouldHide, List<MovieRequests> movieRequests)
{
if (shouldHide.UserId == x.RequestedUserId)
{
x.ShowSubscribe = false;
}
else
var requestIds = movieRequests.Select(x => x.Id);
var sub = await _subscriptionRepository.GetAll().Where(s =>
s.UserId == shouldHide.UserId && requestIds.Contains(s.RequestId) && s.RequestType == RequestType.Movie)
.ToListAsync();
foreach (var x in movieRequests)
{
x.ShowSubscribe = true;
var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s =>
s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie);
x.Subscribed = sub != null;
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
if (shouldHide.UserId == x.RequestedUserId)
{
x.ShowSubscribe = false;
}
else
{
x.ShowSubscribe = true;
var hasSub = sub.FirstOrDefault(r => r.RequestId == x.Id);
x.Subscribed = hasSub != null;
}
}
}
......@@ -293,11 +293,8 @@ namespace Ombi.Core.Engine
}
var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList();
results.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
await CheckForSubscription(shouldHide, results);
return results;
}
......@@ -321,7 +318,7 @@ namespace Ombi.Core.Engine
request.Denied = true;
request.DeniedReason = denyReason;
// We are denying a request
NotificationHelper.Notify(request, NotificationType.RequestDeclined);
await NotificationHelper.Notify(request, NotificationType.RequestDeclined);
await MovieRepository.Update(request);
return new RequestEngineResult
......@@ -349,7 +346,7 @@ namespace Ombi.Core.Engine
var canNotify = await RunSpecificRule(request, SpecificRules.CanSendNotification);
if (canNotify.Success)
{
NotificationHelper.Notify(request, NotificationType.RequestApproved);
await NotificationHelper.Notify(request, NotificationType.RequestApproved);
}
if (request.Approved)
......@@ -465,7 +462,7 @@ namespace Ombi.Core.Engine
request.Available = true;
request.MarkedAsAvailable = DateTime.Now;
NotificationHelper.Notify(request, NotificationType.RequestAvailable);
await NotificationHelper.Notify(request, NotificationType.RequestAvailable);
await MovieRepository.Update(request);
return new RequestEngineResult
......@@ -481,8 +478,8 @@ namespace Ombi.Core.Engine
var result = await RunSpecificRule(model, SpecificRules.CanSendNotification);
if (result.Success)
{
NotificationHelper.NewRequest(model);
{
await NotificationHelper.NewRequest(model);
}
await _requestLog.Add(new RequestLog
......@@ -493,7 +490,7 @@ namespace Ombi.Core.Engine
RequestType = RequestType.Movie,
});
return new RequestEngineResult {Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id};
return new RequestEngineResult { Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id };
}
public async Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user)
......@@ -533,7 +530,7 @@ namespace Ombi.Core.Engine
return new RequestQuotaCountModel()
{
HasLimit = true,
HasLimit = true,
Limit = limit,
Remaining = count,
NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc),
......
......@@ -314,7 +314,7 @@ namespace Ombi.Core.Engine
request.Denied = true;
request.DeniedReason = reason;
// We are denying a request
NotificationHelper.Notify(request, NotificationType.RequestDeclined);
await NotificationHelper.Notify(request, NotificationType.RequestDeclined);
await MusicRepository.Update(request);
return new RequestEngineResult
......@@ -342,7 +342,7 @@ namespace Ombi.Core.Engine
var canNotify = await RunSpecificRule(request, SpecificRules.CanSendNotification);
if (canNotify.Success)
{
NotificationHelper.Notify(request, NotificationType.RequestApproved);
await NotificationHelper.Notify(request, NotificationType.RequestApproved);
}
if (request.Approved)
......@@ -469,7 +469,7 @@ namespace Ombi.Core.Engine
request.Available = true;
request.MarkedAsAvailable = DateTime.Now;
NotificationHelper.Notify(request, NotificationType.RequestAvailable);
await NotificationHelper.Notify(request, NotificationType.RequestAvailable);
await MusicRepository.Update(request);
return new RequestEngineResult
......@@ -486,7 +486,7 @@ namespace Ombi.Core.Engine
var result = await RunSpecificRule(model, SpecificRules.CanSendNotification);
if (result.Success)
{
NotificationHelper.NewRequest(model);
await NotificationHelper.NewRequest(model);
}
await _requestLog.Add(new RequestLog
......
......@@ -156,10 +156,9 @@ namespace Ombi.Core.Engine
.ThenInclude(x => x.Episodes)
.OrderByDescending(x => x.ChildRequests.Select(y => y.RequestedDate).FirstOrDefault())
.Skip(position).Take(count).ToListAsync();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
}
await CheckForSubscription(shouldHide, allRequests);
return new RequestsViewModel<TvRequests>
{
......@@ -194,7 +193,8 @@ namespace Ombi.Core.Engine
{
return new RequestsViewModel<TvRequests>();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
await CheckForSubscription(shouldHide, allRequests);
return new RequestsViewModel<TvRequests>
{
......@@ -216,7 +216,7 @@ namespace Ombi.Core.Engine
allRequests = await TvRepository.Get().ToListAsync();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
await CheckForSubscription(shouldHide, allRequests);
return allRequests;
}
......@@ -236,7 +236,7 @@ namespace Ombi.Core.Engine
allRequests = await TvRepository.GetLite().ToListAsync();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
await CheckForSubscription(shouldHide, allRequests);
return allRequests;
}
......@@ -255,7 +255,7 @@ namespace Ombi.Core.Engine
request = await TvRepository.Get().Where(x => x.Id == requestId).FirstOrDefaultAsync();
}
await CheckForSubscription(shouldHide, request);
await CheckForSubscription(shouldHide, new List<TvRequests>{request});
return request;
}
......@@ -304,7 +304,7 @@ namespace Ombi.Core.Engine
allRequests = await TvRepository.GetChild().Include(x => x.SeasonRequests).Where(x => x.ParentRequestId == tvId).ToListAsync();
}
allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
await CheckForSubscription(shouldHide, allRequests);
return allRequests;
}
......@@ -323,7 +323,7 @@ namespace Ombi.Core.Engine
}
var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync();
results.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
await CheckForSubscription(shouldHide, results);
return results;
}
......@@ -388,7 +388,7 @@ namespace Ombi.Core.Engine
if (request.Approved)
{
NotificationHelper.Notify(request, NotificationType.RequestApproved);
await NotificationHelper.Notify(request, NotificationType.RequestApproved);
// Autosend
await TvSender.Send(request);
}
......@@ -411,7 +411,7 @@ namespace Ombi.Core.Engine
request.Denied = true;
request.DeniedReason = reason;
await TvRepository.UpdateChild(request);
NotificationHelper.Notify(request, NotificationType.RequestDeclined);
await NotificationHelper.Notify(request, NotificationType.RequestDeclined);
return new RequestEngineResult
{
Result = true
......@@ -420,7 +420,7 @@ namespace Ombi.Core.Engine
public async Task<ChildRequests> UpdateChildRequest(ChildRequests request)
{
await TvRepository.UpdateChild(request);
await TvRepository.UpdateChild(request);
return request;
}
......@@ -438,14 +438,14 @@ namespace Ombi.Core.Engine
// Delete the parent
TvRepository.Db.TvRequests.Remove(parent);
}
await TvRepository.Db.SaveChangesAsync();
}
public async Task RemoveTvRequest(int requestId)
{
var request = await TvRepository.Get().FirstOrDefaultAsync(x => x.Id == requestId);
await TvRepository.Delete(request);
await TvRepository.Delete(request);
}
public async Task<bool> UserHasRequest(string userId)
......@@ -499,7 +499,7 @@ namespace Ombi.Core.Engine
}
}
await TvRepository.UpdateChild(request);
NotificationHelper.Notify(request, NotificationType.RequestAvailable);
await NotificationHelper.Notify(request, NotificationType.RequestAvailable);
return new RequestEngineResult
{
Result = true,
......@@ -520,26 +520,32 @@ namespace Ombi.Core.Engine
}
}
private async Task CheckForSubscription(HideResult shouldHide, TvRequests x)
private async Task CheckForSubscription(HideResult shouldHide, List<TvRequests> x)
{
foreach (var tv in x.ChildRequests)
foreach (var tvRequest in x)
{
await CheckForSubscription(shouldHide, tv);
await CheckForSubscription(shouldHide, tvRequest.ChildRequests);
}
}
private async Task CheckForSubscription(HideResult shouldHide, ChildRequests x)
private async Task CheckForSubscription(HideResult shouldHide, List<ChildRequests> childRequests)
{
if (shouldHide.UserId == x.RequestedUserId)
var sub = _subscriptionRepository.GetAll();
var childIds = childRequests.Select(x => x.Id);
var relevantSubs = await sub.Where(s =>
s.UserId == shouldHide.UserId && childIds.Contains(s.Id) && s.RequestType == RequestType.TvShow).ToListAsync();
foreach (var x in childRequests)
{
x.ShowSubscribe = false;
}
else
{
x.ShowSubscribe = true;
var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s =>
s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.TvShow);
x.Subscribed = sub != null;
if (shouldHide.UserId == x.RequestedUserId)
{
x.ShowSubscribe = false;
}
else
{
x.ShowSubscribe = true;
var result = relevantSubs.FirstOrDefault(s => s.RequestId == x.Id);
x.Subscribed = result != null;
}
}
}
......@@ -560,7 +566,7 @@ namespace Ombi.Core.Engine
return await AfterRequest(model.ChildRequests.FirstOrDefault());
}
private static List<ChildRequests> SortEpisodes(List<ChildRequests> items)
private static List<ChildRequests> SortEpisodes(List<ChildRequests> items)
{
foreach (var value in items)
{
......@@ -578,7 +584,7 @@ namespace Ombi.Core.Engine
var sendRuleResult = await RunSpecificRule(model, SpecificRules.CanSendNotification);
if (sendRuleResult.Success)
{
NotificationHelper.NewRequest(model);
await NotificationHelper.NewRequest(model);
}
await _requestLog.Add(new RequestLog
......@@ -593,11 +599,11 @@ namespace Ombi.Core.Engine
if (model.Approved)
{
// Autosend
NotificationHelper.Notify(model, NotificationType.RequestApproved);
await NotificationHelper.Notify(model, NotificationType.RequestApproved);
var result = await TvSender.Send(model);
if (result.Success)
{
return new RequestEngineResult { Result = true, RequestId = model.Id};
return new RequestEngineResult { Result = true, RequestId = model.Id };
}
return new RequestEngineResult
{
......@@ -650,10 +656,10 @@ namespace Ombi.Core.Engine
DateTime oldestRequestedAt = await log.OrderBy(x => x.RequestDate)
.Select(x => x.RequestDate)
.FirstOrDefaultAsync();
return new RequestQuotaCountModel()
{
HasLimit = true,
HasLimit = true,
Limit = limit,
Remaining = count,
NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc),
......
using System;
using Hangfire;
using System.Collections.Generic;
using System.Threading.Tasks;
using Ombi.Core.Notifications;
using Ombi.Helpers;
using Ombi.Notifications.Models;
......@@ -9,13 +10,7 @@ namespace Ombi.Core
{
public class NotificationHelper : INotificationHelper
{
public NotificationHelper(INotificationService service)
{
NotificationService = service;
}
private INotificationService NotificationService { get; }
public void NewRequest(FullBaseRequest model)
public async Task NewRequest(FullBaseRequest model)
{
var notificationModel = new NotificationOptions
{
......@@ -24,11 +19,13 @@ namespace Ombi.Core
NotificationType = NotificationType.NewRequest,
RequestType = model.RequestType
};
BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel));
await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary<string, object>
{
{JobDataKeys.NotificationOptions, notificationModel}
});
}
public void NewRequest(ChildRequests model)
public async Task NewRequest(ChildRequests model)
{
var notificationModel = new NotificationOptions
{
......@@ -36,11 +33,14 @@ namespace Ombi.Core
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest,
RequestType = model.RequestType
};
BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel));
};
await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary<string, object>
{
{JobDataKeys.NotificationOptions, notificationModel}
});
}
public void NewRequest(AlbumRequest model)
public async Task NewRequest(AlbumRequest model)
{
var notificationModel = new NotificationOptions
{
......@@ -48,12 +48,15 @@ namespace Ombi.Core
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest,
RequestType = model.RequestType
};
BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel));
};
await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary<string, object>
{
{JobDataKeys.NotificationOptions, notificationModel}
});
}
public void Notify(MovieRequests model, NotificationType type)
public async Task Notify(MovieRequests model, NotificationType type)
{
var notificationModel = new NotificationOptions
{
......@@ -63,10 +66,13 @@ namespace Ombi.Core
RequestType = model.RequestType,
Recipient = model.RequestedUser?.Email ?? string.Empty
};
BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel));
await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary<string, object>
{
{JobDataKeys.NotificationOptions, notificationModel}
});
}
public void Notify(ChildRequests model, NotificationType type)
public async Task Notify(ChildRequests model, NotificationType type)
{
var notificationModel = new NotificationOptions
{
......@@ -76,10 +82,13 @@ namespace Ombi.Core
RequestType = model.RequestType,
Recipient = model.RequestedUser?.Email ?? string.Empty
};
BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel));
await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary<string, object>
{
{JobDataKeys.NotificationOptions, notificationModel}
});
}
public void Notify(AlbumRequest model, NotificationType type)
public async Task Notify(AlbumRequest model, NotificationType type)
{
var notificationModel = new NotificationOptions
{
......@@ -90,7 +99,18 @@ namespace Ombi.Core
Recipient = model.RequestedUser?.Email ?? string.Empty
};
BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel));
await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary<string, object>
{
{JobDataKeys.NotificationOptions, notificationModel}
});
}
public async Task Notify(NotificationOptions model)
{
await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary<string, object>
{
{JobDataKeys.NotificationOptions, model}
});
}
}
}
\ No newline at end of file
......@@ -11,7 +11,6 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="6.1.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="3.2.0" />
<PackageReference Include="Hangfire" Version="1.6.22" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.2" />
<PackageReference Include="MiniProfiler.AspNetCore" Version="4.0.0-alpha6-79" />
......
......@@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore;
using Ombi.Core.Authentication;
using Ombi.Core.Rule.Interfaces;
using Ombi.Helpers;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
namespace Ombi.Core.Rule.Rules.Request
......
......@@ -7,12 +7,12 @@ namespace Ombi.Core.Rule.Rules.Request
{
public class SonarrCacheRequestRule : BaseRequestRule, IRules<BaseRequest>
{
public SonarrCacheRequestRule(IExternalContext ctx)
public SonarrCacheRequestRule(ExternalContext ctx)
{
_ctx = ctx;