Added the test button for mobile notifications

This commit is contained in:
Jamie Rees 2018-05-17 09:00:35 +01:00
commit 1935d70cf7
9 changed files with 74 additions and 5 deletions

View file

@ -152,6 +152,7 @@ namespace Ombi.DependencyInjection
services.AddTransient<IMattermostNotification, MattermostNotification>(); services.AddTransient<IMattermostNotification, MattermostNotification>();
services.AddTransient<IPushoverNotification, PushoverNotification>(); services.AddTransient<IPushoverNotification, PushoverNotification>();
services.AddTransient<ITelegramNotification, TelegramNotification>(); services.AddTransient<ITelegramNotification, TelegramNotification>();
services.AddTransient<IMobileNotification, MobileNotification>();
services.AddTransient<IChangeLogProcessor, ChangeLogProcessor>(); services.AddTransient<IChangeLogProcessor, ChangeLogProcessor>();
} }

View file

@ -0,0 +1,6 @@
namespace Ombi.Notifications.Agents
{
public interface IMobileNotification : INotification
{
}
}

View file

@ -18,7 +18,7 @@ using Ombi.Store.Repository.Requests;
namespace Ombi.Notifications.Agents namespace Ombi.Notifications.Agents
{ {
public class MobileNotification : BaseNotification<MobileNotificationSettings> public class MobileNotification : BaseNotification<MobileNotificationSettings>, IMobileNotification
{ {
public MobileNotification(IOneSignalApi api, ISettingsService<MobileNotificationSettings> sn, ILogger<MobileNotification> log, INotificationTemplatesRepository r, public MobileNotification(IOneSignalApi api, ISettingsService<MobileNotificationSettings> sn, ILogger<MobileNotification> log, INotificationTemplatesRepository r,
IMovieRequestRepository m, ITvRequestRepository t, ISettingsService<CustomizationSettings> s, IRepository<NotificationUserId> notification, IMovieRequestRepository m, ITvRequestRepository t, ISettingsService<CustomizationSettings> s, IRepository<NotificationUserId> notification,
@ -232,7 +232,13 @@ namespace Ombi.Notifications.Agents
Message = message, Message = message,
}; };
// Send to user // Send to user
var playerIds = await GetAdmins(NotificationType.RequestAvailable); var user = await _userManager.Users.Include(x => x.NotificationUserIds).FirstOrDefaultAsync(x => x.Id.Equals(model.UserId));
if (user == null)
{
return;
}
var playerIds = user.NotificationUserIds.Select(x => x.PlayerId).ToList();
await Send(playerIds, notification, settings); await Send(playerIds, notification, settings);
} }

View file

@ -101,3 +101,8 @@ export interface IMattermostNotifcationSettings extends INotificationSettings {
export interface IMobileNotifcationSettings extends INotificationSettings { export interface IMobileNotifcationSettings extends INotificationSettings {
notificationTemplates: INotificationTemplates[]; notificationTemplates: INotificationTemplates[];
} }
export interface IMobileNotificationTestSettings {
settings: IMobileNotifcationSettings;
userId: string;
}

View file

@ -12,6 +12,7 @@ import {
IEmailNotificationSettings, IEmailNotificationSettings,
IEmbyServer, IEmbyServer,
IMattermostNotifcationSettings, IMattermostNotifcationSettings,
IMobileNotificationTestSettings,
INewsletterNotificationSettings, INewsletterNotificationSettings,
IPlexServer, IPlexServer,
IPushbulletNotificationSettings, IPushbulletNotificationSettings,
@ -82,4 +83,7 @@ export class TesterService extends ServiceHelpers {
public newsletterTest(settings: INewsletterNotificationSettings): Observable<boolean> { public newsletterTest(settings: INewsletterNotificationSettings): Observable<boolean> {
return this.http.post<boolean>(`${this.url}newsletter`, JSON.stringify(settings), {headers: this.headers}); return this.http.post<boolean>(`${this.url}newsletter`, JSON.stringify(settings), {headers: this.headers});
} }
public mobileNotificationTest(settings: IMobileNotificationTestSettings): Observable<boolean> {
return this.http.post<boolean>(`${this.url}mobile`, JSON.stringify(settings), {headers: this.headers});
}
} }

View file

@ -34,8 +34,21 @@
</div> </div>
<div class="row"> <div class="row">
<div class="form-group">
<label for="select" class="control-label">User to send test notification to</label>
<div>
<select class="form-control form-control-custom" id="select" [(ngModel)]="testUserId" [ngModelOptions]="{standalone: true}">
<option value="">Please select</option>
<option *ngFor="let x of userList" [value]="x.id">{{x.username}}</option>
</select>
</div>
</div>
<div class="form-group">
<div>
<button [disabled]="form.invalid" type="button" (click)="test(form)" class="btn btn-danger-outline">Test</button>
</div>
</div>
<div class="form-group"> <div class="form-group">

View file

@ -15,6 +15,7 @@ export class MobileComponent implements OnInit {
public templates: INotificationTemplates[]; public templates: INotificationTemplates[];
public form: FormGroup; public form: FormGroup;
public userList: IMobileUsersViewModel[]; public userList: IMobileUsersViewModel[];
public testUserId: string = "d164439a-6f23-43c6-bc12-6a8d3d89dbf5";
constructor(private settingsService: SettingsService, constructor(private settingsService: SettingsService,
private notificationService: NotificationService, private notificationService: NotificationService,
@ -64,8 +65,12 @@ export class MobileComponent implements OnInit {
this.notificationService.error("Please check your entered values"); this.notificationService.error("Please check your entered values");
return; return;
} }
if(!this.testUserId) {
this.notificationService.warning("Warning","Please select a user to send the test notification");
return;
}
this.testerService.discordTest(form.value).subscribe(x => { this.testerService.mobileNotificationTest({settings: form.value, userId: this.testUserId}).subscribe(x => {
if (x) { if (x) {
this.notificationService.success("Successfully sent a Mobile message, please check the admin mobile device"); this.notificationService.success("Successfully sent a Mobile message, please check the admin mobile device");
} else { } else {

View file

@ -14,6 +14,7 @@ using Ombi.Core.Models.UI;
using Ombi.Core.Notifications; using Ombi.Core.Notifications;
using Ombi.Core.Settings.Models.External; using Ombi.Core.Settings.Models.External;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Models;
using Ombi.Notifications; using Ombi.Notifications;
using Ombi.Notifications.Agents; using Ombi.Notifications.Agents;
using Ombi.Notifications.Models; using Ombi.Notifications.Models;
@ -37,7 +38,7 @@ namespace Ombi.Controllers.External
public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN, public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN,
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm, IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider, IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider,
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter) ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter, IMobileNotification mobileNotification)
{ {
Service = service; Service = service;
DiscordNotification = notification; DiscordNotification = notification;
@ -56,6 +57,7 @@ namespace Ombi.Controllers.External
TelegramNotification = telegram; TelegramNotification = telegram;
SickRageApi = srApi; SickRageApi = srApi;
Newsletter = newsletter; Newsletter = newsletter;
MobileNotification = mobileNotification;
} }
private INotificationService Service { get; } private INotificationService Service { get; }
@ -75,6 +77,7 @@ namespace Ombi.Controllers.External
private ITelegramNotification TelegramNotification { get; } private ITelegramNotification TelegramNotification { get; }
private ISickRageApi SickRageApi { get; } private ISickRageApi SickRageApi { get; }
private INewsletterJob Newsletter { get; } private INewsletterJob Newsletter { get; }
private IMobileNotification MobileNotification { get; }
/// <summary> /// <summary>
@ -388,5 +391,21 @@ namespace Ombi.Controllers.External
return false; return false;
} }
} }
[HttpPost("mobile")]
public async Task<bool> MobileNotificationTest([FromBody] MobileNotificationTestViewModel settings)
{
try
{
await MobileNotification.NotifyAsync(new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1, UserId = settings.UserId}, settings.Settings);
return true;
}
catch (Exception e)
{
Log.LogError(LoggingEvents.Api, e, "Could not test Mobile Notifications");
return false;
}
}
} }
} }

View file

@ -0,0 +1,10 @@
using Ombi.Settings.Settings.Models.Notifications;
namespace Ombi.Models
{
public class MobileNotificationTestViewModel
{
public string UserId { get; set; }
public MobileNotificationSettings Settings { get; set; }
}
}