Added the test button and done a bunch of testing. Almost ready !wip

pull/2090/head
tidusjar 7 years ago
parent 6005db374a
commit 11442e2ea7

@ -69,7 +69,8 @@ namespace Ombi.Core.Engine
{
AddedAt = DateTime.Now,
Type = RecentlyAddedType.Plex,
ContentId = p.Id
ContentId = p.Id,
ContentType = ContentType.Parent
});
}
else
@ -81,7 +82,8 @@ namespace Ombi.Core.Engine
{
AddedAt = DateTime.Now,
Type = RecentlyAddedType.Plex,
ContentId = ep.Id
ContentId = ep.Id,
ContentType = ContentType.Episode
});
}
}
@ -95,7 +97,8 @@ namespace Ombi.Core.Engine
{
AddedAt = DateTime.Now,
Type = RecentlyAddedType.Emby,
ContentId = e.Id
ContentId = e.Id,
ContentType = ContentType.Parent
});
}
else
@ -106,8 +109,9 @@ namespace Ombi.Core.Engine
recentlyAddedLog.Add(new RecentlyAddedLog
{
AddedAt = DateTime.Now,
Type = RecentlyAddedType.Plex,
ContentId = ep.Id
Type = RecentlyAddedType.Emby,
ContentId = ep.Id,
ContentType = ContentType.Episode
});
}
}

@ -1,9 +1,11 @@
using System.Threading.Tasks;
using Ombi.Settings.Settings.Models.Notifications;
namespace Ombi.Schedule.Jobs.Ombi
{
public interface INewsletterJob : IBaseJob
{
Task Start();
Task Start(NewsletterSettings settings, bool test);
}
}

@ -38,6 +38,9 @@ namespace Ombi.Schedule.Jobs.Ombi
_emailSettings = emailSettings;
_newsletterSettings = newsletter;
_userManager = um;
_emailSettings.ClearCache();
_customizationSettings.ClearCache();
_newsletterSettings.ClearCache();
}
private readonly IPlexContentRepository _plex;
@ -52,10 +55,9 @@ namespace Ombi.Schedule.Jobs.Ombi
private readonly ISettingsService<NewsletterSettings> _newsletterSettings;
private readonly UserManager<OmbiUser> _userManager;
public async Task Start()
public async Task Start(NewsletterSettings settings, bool test)
{
var newsletterSettings = await _newsletterSettings.GetSettingsAsync();
if (!newsletterSettings.Enabled)
if (!settings.Enabled)
{
return;
}
@ -85,17 +87,33 @@ namespace Ombi.Schedule.Jobs.Ombi
var addedEmbyEpisodesLogIds = addedLog.Where(x => x.Type == RecentlyAddedType.Emby && x.ContentType == ContentType.Episode).Select(x => x.ContentId);
// Filter out the ones that we haven't sent yet
var plexContentMoviesToSend = plexContent.Where(x => !addedPlexMovieLogIds.Contains(x.Id));
var embyContentMoviesToSend = embyContent.Where(x => !addedEmbyMoviesLogIds.Contains(x.Id));
var plexContentMoviesToSend = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Movie && !addedPlexMovieLogIds.Contains(x.Id));
var embyContentMoviesToSend = embyContent.Where(x => x.Type == EmbyMediaType.Movie && !addedEmbyMoviesLogIds.Contains(x.Id));
var plexContentTvToSend = plexContent.Where(x => x.Episodes.Any(e => !addedPlexEpisodesLogIds.Contains(e.Id)));
var embyContentTvToSend = embyContent.Where(x => x.Episodes.Any(e => !addedEmbyEpisodesLogIds.Contains(e.Id)));
var plexContentTvToSend = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Show && x.Episodes.Any(e => !addedPlexEpisodesLogIds.Contains(e.Id)));
var embyContentTvToSend = embyContent.Where(x => x.Type == EmbyMediaType.Series && x.Episodes.Any(e => !addedEmbyEpisodesLogIds.Contains(e.Id)));
var plexContentToSend = plexContentMoviesToSend.Union(plexContentTvToSend);
var embyContentToSend = embyContentMoviesToSend.Union(embyContentTvToSend);
var body = string.Empty;
if (test)
{
var plexm = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Movie).OrderByDescending(x => x.AddedAt).Take(10);
var embym = embyContent.Where(x => x.Type == EmbyMediaType.Movie).OrderByDescending(x => x.AddedAt).Take(10);
var plext = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Show).OrderByDescending(x => x.AddedAt).Take(10);
var embyt = embyContent.Where(x => x.Type == EmbyMediaType.Series).OrderByDescending(x => x.AddedAt).Take(10);
body = await BuildHtml(plexm.Union(plext), embym.Union(embyt));
}
else
{
body = await BuildHtml(plexContentToSend, embyContentToSend);
if (body.IsNullOrEmpty())
{
return;
}
var body = await BuildHtml(plexContentToSend, embyContentToSend);
}
// Get the users to send it to
var users = await _userManager.GetUsersInRoleAsync(OmbiRoles.RecievesNewsletter);
@ -174,6 +192,12 @@ namespace Ombi.Schedule.Jobs.Ombi
await Task.WhenAll(emailTasks.ToArray());
}
public async Task Start()
{
var newsletterSettings = await _newsletterSettings.GetSettingsAsync();
await Start(newsletterSettings, false);
}
private string LoadTemplate(string body, NotificationTemplates template, CustomizationSettings settings, string username)
{
var email = new NewsletterTemplate();

@ -14,7 +14,7 @@ using System;
namespace Ombi.Store.Migrations
{
[DbContext(typeof(OmbiContext))]
[Migration("20180322085345_RecentlyAddedLog")]
[Migration("20180322204610_RecentlyAddedLog")]
partial class RecentlyAddedLog
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -440,6 +440,8 @@ namespace Ombi.Store.Migrations
b.Property<int>("ContentId");
b.Property<int>("ContentType");
b.Property<int>("Type");
b.HasKey("Id");

@ -16,6 +16,7 @@ namespace Ombi.Store.Migrations
.Annotation("Sqlite:Autoincrement", true),
AddedAt = table.Column<DateTime>(nullable: false),
ContentId = table.Column<int>(nullable: false),
ContentType = table.Column<int>(nullable: false),
Type = table.Column<int>(nullable: false)
},
constraints: table =>

@ -439,6 +439,8 @@ namespace Ombi.Store.Migrations
b.Property<int>("ContentId");
b.Property<int>("ContentType");
b.Property<int>("Type");
b.HasKey("Id");

@ -40,6 +40,11 @@ namespace Ombi.Store.Repository
public async Task Update(NotificationTemplates template)
{
if (Db.Entry(template).State == EntityState.Detached)
{
Db.Attach(template);
Db.Entry(template).State = EntityState.Modified;
}
await Db.SaveChangesAsync();
}

@ -40,7 +40,7 @@ export class RecentlyAddedComponent implements OnInit {
public tv: IRecentlyAddedTvShows[];
public range: Date[];
public groupTv: boolean;
public groupTv: boolean = false;
// https://github.com/sheikalthaf/ngu-carousel
public carouselTile: NguCarousel;
@ -76,7 +76,7 @@ export class RecentlyAddedComponent implements OnInit {
}
this.getMovies();
}
public change() {
this.getShows();
}

@ -12,6 +12,7 @@ import {
IEmailNotificationSettings,
IEmbyServer,
IMattermostNotifcationSettings,
INewsletterNotificationSettings,
IPlexServer,
IPushbulletNotificationSettings,
IPushoverNotificationSettings,
@ -77,5 +78,8 @@ export class TesterService extends ServiceHelpers {
public sickrageTest(settings: ISickRageSettings): Observable<boolean> {
return this.http.post<boolean>(`${this.url}sickrage`, JSON.stringify(settings), {headers: this.headers});
}
public newsletterTest(settings: INewsletterNotificationSettings): Observable<boolean> {
return this.http.post<boolean>(`${this.url}newsletter`, JSON.stringify(settings), {headers: this.headers});
}
}

@ -1,47 +1,37 @@
<settings-menu></settings-menu>
<div *ngIf="form">
<div *ngIf="settings">
<fieldset>
<legend>Newsletter</legend>
<div class="col-md-6">
<form novalidate [formGroup]="form" (ngSubmit)="onSubmit(form)">
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="enable" formControlName="enabled">
<label for="enable">Enabled</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="enabled" [(ngModel)]="template.enabled" ng-checked="template.enabled">
<label for="enabled">Enable</label>
<input type="checkbox" id="enabled" [(ngModel)]="settings.enabled" ng-checked="settings.enabled"><label for="enabled">Enable</label>
</div>
</div>
<div class="form-group" *ngIf="showSubject">
<div class="form-group">
<label class="control-label">Subject</label>
<div>
<input type="text" class="form-control form-control-custom" [(ngModel)]="template.subject" value="{{template.subject}}">
<input type="text" class="form-control form-control-custom" [(ngModel)]="settings.notificationTemplate.subject" value="{{settings.notificationTemplate.subject}}">
</div>
</div>
<div class="form-group">
<label class="control-label">Message</label>
<div>
<textarea type="text" class="form-control form-control-custom" [(ngModel)]="template.message" value="{{template.message}}"></textarea>
<textarea type="text" class="form-control form-control-custom" [(ngModel)]="settings.notificationTemplate.message" value="{{settings.notificationTemplate.message}}"></textarea>
</div>
</div>
<div class="form-group">
<div>
<button [disabled]="form.invalid" type="submit" id="save" class="btn btn-primary-outline">Submit</button>
<button [disabled]="form.invalid" type="button" (click)="updateDatabase()" class="btn btn-info-outline" tooltipPosition="top" pTooltip="I reccomend running this with a fresh Ombi install, this will set all the current *found* content to have been sent via Newsletter,
if you do not do this then eventhing that Ombi has found in your libraries will go out on the first email!">Update Database</button>
<button type="submit" id="save" (click)="onSubmit()" class="btn btn-primary-outline">Submit</button>
<button type="button" (click)="test()" class="btn btn-danger-outline">Test</button>
<button type="button" (click)="updateDatabase()" class="btn btn-info-outline" tooltipPosition="top" pTooltip="I recommend running this with a fresh Ombi install, this will set all the current *found* content to have been sent via Newsletter,
if you do not do this then everything that Ombi has found in your libraries will go out on the first email!">Update Database</button>
</div>
</div>
</form>
</div>

@ -1,8 +1,7 @@
import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup } from "@angular/forms";
import { TesterService } from './../../services/applications/tester.service';
import { Component, OnInit } from "@angular/core";
import { INewsletterNotificationSettings, INotificationTemplates, NotificationType } from "../../interfaces";
import { TesterService } from "../../services";
import { INewsletterNotificationSettings, NotificationType } from "../../interfaces";
import { NotificationService } from "../../services";
import { SettingsService } from "../../services";
@ -12,21 +11,15 @@ import { SettingsService } from "../../services";
export class NewsletterComponent implements OnInit {
public NotificationType = NotificationType;
public template: INotificationTemplates;
public form: FormGroup;
public settings: INewsletterNotificationSettings;
constructor(private settingsService: SettingsService,
private notificationService: NotificationService,
private fb: FormBuilder,
private testerService: TesterService) { }
private testService: TesterService) { }
public ngOnInit() {
this.settingsService.getNewsletterSettings().subscribe(x => {
this.template = x.notificationTemplate;
this.form = this.fb.group({
enabled: [x.enabled],
});
this.settings = x;
});
}
@ -34,16 +27,12 @@ export class NewsletterComponent implements OnInit {
this.settingsService.updateNewsletterDatabase().subscribe();
}
public onSubmit(form: FormGroup) {
if (form.invalid) {
this.notificationService.error("Please check your entered values");
return;
}
const settings = <INewsletterNotificationSettings>form.value;
settings.notificationTemplate = this.template;
public test() {
this.testService.testNewsletter(this.settings).subscribe();
}
this.settingsService.saveNewsletterSettings(settings).subscribe(x => {
public onSubmit() {
this.settingsService.saveNewsletterSettings(this.settings).subscribe(x => {
if (x) {
this.notificationService.success("Successfully saved the Newsletter settings");
} else {
@ -52,20 +41,4 @@ export class NewsletterComponent implements OnInit {
});
}
public test(form: FormGroup) {
if (form.invalid) {
this.notificationService.error("Please check your entered values");
return;
}
this.testerService.discordTest(form.value).subscribe(x => {
if (x) {
this.notificationService.success("Successfully sent a Discord message, please check the discord channel");
} else {
this.notificationService.error("There was an error when sending the Discord message. Please check your settings");
}
});
}
}

@ -10,12 +10,14 @@ using Ombi.Api.Radarr;
using Ombi.Api.SickRage;
using Ombi.Api.Sonarr;
using Ombi.Attributes;
using Ombi.Core.Models.UI;
using Ombi.Core.Notifications;
using Ombi.Core.Settings.Models.External;
using Ombi.Helpers;
using Ombi.Notifications;
using Ombi.Notifications.Agents;
using Ombi.Notifications.Models;
using Ombi.Schedule.Jobs.Ombi;
using Ombi.Settings.Settings.Models.External;
using Ombi.Settings.Settings.Models.Notifications;
@ -35,7 +37,7 @@ namespace Ombi.Controllers.External
public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN,
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider,
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi)
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter)
{
Service = service;
DiscordNotification = notification;
@ -53,6 +55,7 @@ namespace Ombi.Controllers.External
CouchPotatoApi = cpApi;
TelegramNotification = telegram;
SickRageApi = srApi;
Newsletter = newsletter;
}
private INotificationService Service { get; }
@ -71,6 +74,7 @@ namespace Ombi.Controllers.External
private IEmailProvider EmailProvider { get; }
private ITelegramNotification TelegramNotification { get; }
private ISickRageApi SickRageApi { get; }
private INewsletterJob Newsletter { get; }
/// <summary>
@ -368,5 +372,21 @@ namespace Ombi.Controllers.External
return false;
}
}
[HttpPost("newsletter")]
public async Task<bool> NewsletterTest([FromBody] NewsletterNotificationViewModel settings)
{
try
{
settings.Enabled = true;
await Newsletter.Start(settings, true);
return true;
}
catch (Exception e)
{
Log.LogError(LoggingEvents.Api, e, "Could not test Newsletter");
return false;
}
}
}
}

@ -71,6 +71,7 @@ namespace Ombi.Controllers
_radarrSync = radarrSync;
_cache = memCache;
_githubApi = githubApi;
_recentlyAdded = engine;
}
private ISettingsResolver SettingsResolver { get; }

Loading…
Cancel
Save