mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
Added the functionality to remove a user from getting notifications to their mobile device #2780
This commit is contained in:
parent
42eae458d8
commit
14d8d98979
5 changed files with 54 additions and 4 deletions
|
@ -29,7 +29,6 @@ export class SeriesInformationComponent implements OnInit {
|
||||||
this.searchService.getShowInformation(this.seriesId)
|
this.searchService.getShowInformation(this.seriesId)
|
||||||
.subscribe(x => {
|
.subscribe(x => {
|
||||||
this.series = x;
|
this.series = x;
|
||||||
debugger;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,8 @@ export class MobileService extends ServiceHelpers {
|
||||||
public getUserDeviceList(): Observable<IMobileUsersViewModel[]> {
|
public getUserDeviceList(): Observable<IMobileUsersViewModel[]> {
|
||||||
return this.http.get<IMobileUsersViewModel[]>(`${this.url}notification/`, {headers: this.headers});
|
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="row">
|
||||||
<div class="form-group">
|
<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>
|
<div>
|
||||||
<select class="form-control form-control-custom" id="select" [(ngModel)]="testUserId" [ngModelOptions]="{standalone: true}">
|
<select class="form-control form-control-custom" id="select" [(ngModel)]="testUserId" [ngModelOptions]="{standalone: true}">
|
||||||
<option value="">Please select</option>
|
<option value="">Please select</option>
|
||||||
|
@ -46,7 +46,12 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div>
|
<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>
|
||||||
</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.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Ombi.Attributes;
|
using Ombi.Attributes;
|
||||||
using Ombi.Core.Authentication;
|
using Ombi.Core.Authentication;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
|
@ -20,14 +21,16 @@ namespace Ombi.Controllers
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class MobileController : ControllerBase
|
public class MobileController : ControllerBase
|
||||||
{
|
{
|
||||||
public MobileController(IRepository<NotificationUserId> notification, OmbiUserManager user)
|
public MobileController(IRepository<NotificationUserId> notification, OmbiUserManager user, ILogger<MobileController> log)
|
||||||
{
|
{
|
||||||
_notification = notification;
|
_notification = notification;
|
||||||
_userManager = user;
|
_userManager = user;
|
||||||
|
_log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IRepository<NotificationUserId> _notification;
|
private readonly IRepository<NotificationUserId> _notification;
|
||||||
private readonly OmbiUserManager _userManager;
|
private readonly OmbiUserManager _userManager;
|
||||||
|
private readonly ILogger _log;
|
||||||
|
|
||||||
[HttpPost("Notification")]
|
[HttpPost("Notification")]
|
||||||
[ApiExplorerSettings(IgnoreApi = true)]
|
[ApiExplorerSettings(IgnoreApi = true)]
|
||||||
|
@ -78,5 +81,24 @@ namespace Ombi.Controllers
|
||||||
}
|
}
|
||||||
return vm;
|
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…
Add table
Add a link
Reference in a new issue