mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
made a start !wip
This commit is contained in:
parent
4b7e4adb23
commit
bcb193f321
3 changed files with 49 additions and 2 deletions
|
@ -18,7 +18,7 @@ namespace Ombi.Schedule.Tests
|
|||
var emailSettings = new Mock<ISettingsService<EmailNotificationSettings>>();
|
||||
var customziation = new Mock<ISettingsService<CustomizationSettings>>();
|
||||
var newsletterSettings = new Mock<ISettingsService<NewsletterSettings>>();
|
||||
var newsletter = new NewsletterJob(null, null, null, null, null, null, customziation.Object, emailSettings.Object, null, null, newsletterSettings.Object, null);
|
||||
var newsletter = new NewsletterJob(null, null, null, null, null, null, customziation.Object, emailSettings.Object, null, null, newsletterSettings.Object, null, null, null, null);
|
||||
|
||||
var ep = new List<int>();
|
||||
foreach (var i in episodes)
|
||||
|
|
20
src/Ombi.Store/Entities/UserNotificationPreferences.cs
Normal file
20
src/Ombi.Store/Entities/UserNotificationPreferences.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
using Ombi.Helpers;
|
||||
|
||||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table(nameof(UserNotificationPreferences))]
|
||||
public class UserNotificationPreferences : Entity
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
public NotificationAgent Agent { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public string Value { get; set; }
|
||||
|
||||
[ForeignKey(nameof(UserId))]
|
||||
public OmbiUser User { get; set; }
|
||||
}
|
||||
}
|
|
@ -60,7 +60,8 @@ namespace Ombi.Controllers
|
|||
IRepository<IssueComments> issueComments,
|
||||
IRepository<NotificationUserId> notificationRepository,
|
||||
IRepository<RequestSubscription> subscriptionRepository,
|
||||
ISettingsService<UserManagementSettings> umSettings)
|
||||
ISettingsService<UserManagementSettings> umSettings,
|
||||
IRepository<UserNotificationPreferences> notificationPreferences)
|
||||
{
|
||||
UserManager = user;
|
||||
Mapper = mapper;
|
||||
|
@ -81,6 +82,7 @@ namespace Ombi.Controllers
|
|||
_requestSubscriptionRepository = subscriptionRepository;
|
||||
_notificationRepository = notificationRepository;
|
||||
_userManagementSettings = umSettings;
|
||||
_userNotificationPreferences = notificationPreferences;
|
||||
}
|
||||
|
||||
private OmbiUserManager UserManager { get; }
|
||||
|
@ -102,6 +104,7 @@ namespace Ombi.Controllers
|
|||
private readonly IRepository<RequestLog> _requestLogRepository;
|
||||
private readonly IRepository<NotificationUserId> _notificationRepository;
|
||||
private readonly IRepository<RequestSubscription> _requestSubscriptionRepository;
|
||||
private readonly IRepository<UserNotificationPreferences> _userNotificationPreferences;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -787,6 +790,30 @@ namespace Ombi.Controllers
|
|||
return user.UserAccessToken;
|
||||
}
|
||||
|
||||
[HttpGet("notificationpreferences")]
|
||||
public async Task<List<UserNotificationPreferences>> GetUserPreferences()
|
||||
{
|
||||
//TODO potentially use a view model
|
||||
var user = await UserManager.Users.FirstOrDefaultAsync(x => x.UserName == User.Identity.Name);
|
||||
var userPreferences = await _userNotificationPreferences.GetAll().Where(x => x.UserId == user.Id).ToListAsync();
|
||||
|
||||
var agents = Enum.GetValues(typeof(NotificationAgent)).Cast<NotificationAgent>();
|
||||
foreach (var a in agents)
|
||||
{
|
||||
var hasAgent = userPreferences.Any(x => x.Agent == a);
|
||||
if (!hasAgent)
|
||||
{
|
||||
// Create the default
|
||||
userPreferences.Add(new UserNotificationPreferences
|
||||
{
|
||||
Agent = a,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return userPreferences;
|
||||
}
|
||||
|
||||
private async Task<List<IdentityResult>> AddRoles(IEnumerable<ClaimCheckboxes> roles, OmbiUser ombiUser)
|
||||
{
|
||||
var roleResult = new List<IdentityResult>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue