Added the functionality to remove a user from getting notifications to their mobile device #2780

pull/2814/head
tidusjar 6 years ago
parent 42eae458d8
commit 14d8d98979

@ -29,7 +29,6 @@ export class SeriesInformationComponent implements OnInit {
this.searchService.getShowInformation(this.seriesId)
.subscribe(x => {
this.series = x;
debugger;
});
}

@ -15,4 +15,8 @@ export class MobileService extends ServiceHelpers {
public getUserDeviceList(): Observable<IMobileUsersViewModel[]> {
return this.http.get<IMobileUsersViewModel[]>(`${this.url}notification/`, {headers: this.headers});
}
public deleteUser(userId: string): Observable<boolean> {
return this.http.post<boolean>(`${this.url}remove/`, userId, {headers: this.headers});
}
}

@ -35,7 +35,7 @@
<div class="row">
<div class="form-group">
<label for="select" class="control-label">User to send test notification to</label>
<label for="select" class="control-label">Users</label>
<div>
<select class="form-control form-control-custom" id="select" [(ngModel)]="testUserId" [ngModelOptions]="{standalone: true}">
<option value="">Please select</option>
@ -46,7 +46,12 @@
<div class="form-group">
<div>
<button [disabled]="form.invalid" type="button" (click)="test(form)" class="btn btn-danger-outline">Test</button>
<button [disabled]="form.invalid" type="button" (click)="test(form)" class="btn btn-danger-outline">Send Test Notification</button>
</div>
</div>
<div class="form-group">
<div>
<button [disabled]="form.invalid" type="button" (click)="remove(form)" class="btn btn-danger-outline">Remove User</button>
</div>
</div>

@ -79,4 +79,24 @@ export class MobileComponent implements OnInit {
});
}
public remove() {
if (!this.testUserId) {
this.notificationService.warning("Warning", "Please select a user to remove");
return;
}
this.mobileService.deleteUser(this.testUserId).subscribe(x => {
if (x) {
this.notificationService.success("Removed users notification");
const userToRemove = this.userList.filter(u => {
return u.userId === this.testUserId;
})[1];
this.userList.splice(this.userList.indexOf(userToRemove),1);
} else {
this.notificationService.error("There was an error when removing the notification. Please check your logs");
}
});
}
}

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Ombi.Attributes;
using Ombi.Core.Authentication;
using Ombi.Helpers;
@ -20,14 +21,16 @@ namespace Ombi.Controllers
[ApiController]
public class MobileController : ControllerBase
{
public MobileController(IRepository<NotificationUserId> notification, OmbiUserManager user)
public MobileController(IRepository<NotificationUserId> notification, OmbiUserManager user, ILogger<MobileController> log)
{
_notification = notification;
_userManager = user;
_log = log;
}
private readonly IRepository<NotificationUserId> _notification;
private readonly OmbiUserManager _userManager;
private readonly ILogger _log;
[HttpPost("Notification")]
[ApiExplorerSettings(IgnoreApi = true)]
@ -78,5 +81,24 @@ namespace Ombi.Controllers
}
return vm;
}
[HttpPost]
[ApiExplorerSettings(IgnoreApi = true)]
[Admin]
public async Task<bool> RemoveUser([FromBody] string userId)
{
var user = await _userManager.Users.Include(x => x.NotificationUserIds).FirstOrDefaultAsync(x => x.Id.Equals(userId, StringComparison.InvariantCultureIgnoreCase));
try
{
await _notification.DeleteRange(user.NotificationUserIds);
return true;
}
catch (Exception e)
{
_log.LogError(e, "Could not delete user notification");
}
return false;
}
}
}
Loading…
Cancel
Save