made a start !wip

This commit is contained in:
TidusJar 2018-08-29 13:25:43 +01:00
commit bcb193f321
3 changed files with 49 additions and 2 deletions

View file

@ -18,7 +18,7 @@ namespace Ombi.Schedule.Tests
var emailSettings = new Mock<ISettingsService<EmailNotificationSettings>>(); var emailSettings = new Mock<ISettingsService<EmailNotificationSettings>>();
var customziation = new Mock<ISettingsService<CustomizationSettings>>(); var customziation = new Mock<ISettingsService<CustomizationSettings>>();
var newsletterSettings = new Mock<ISettingsService<NewsletterSettings>>(); 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>(); var ep = new List<int>();
foreach (var i in episodes) foreach (var i in episodes)

View 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; }
}
}

View file

@ -60,7 +60,8 @@ namespace Ombi.Controllers
IRepository<IssueComments> issueComments, IRepository<IssueComments> issueComments,
IRepository<NotificationUserId> notificationRepository, IRepository<NotificationUserId> notificationRepository,
IRepository<RequestSubscription> subscriptionRepository, IRepository<RequestSubscription> subscriptionRepository,
ISettingsService<UserManagementSettings> umSettings) ISettingsService<UserManagementSettings> umSettings,
IRepository<UserNotificationPreferences> notificationPreferences)
{ {
UserManager = user; UserManager = user;
Mapper = mapper; Mapper = mapper;
@ -81,6 +82,7 @@ namespace Ombi.Controllers
_requestSubscriptionRepository = subscriptionRepository; _requestSubscriptionRepository = subscriptionRepository;
_notificationRepository = notificationRepository; _notificationRepository = notificationRepository;
_userManagementSettings = umSettings; _userManagementSettings = umSettings;
_userNotificationPreferences = notificationPreferences;
} }
private OmbiUserManager UserManager { get; } private OmbiUserManager UserManager { get; }
@ -102,6 +104,7 @@ namespace Ombi.Controllers
private readonly IRepository<RequestLog> _requestLogRepository; private readonly IRepository<RequestLog> _requestLogRepository;
private readonly IRepository<NotificationUserId> _notificationRepository; private readonly IRepository<NotificationUserId> _notificationRepository;
private readonly IRepository<RequestSubscription> _requestSubscriptionRepository; private readonly IRepository<RequestSubscription> _requestSubscriptionRepository;
private readonly IRepository<UserNotificationPreferences> _userNotificationPreferences;
/// <summary> /// <summary>
@ -787,6 +790,30 @@ namespace Ombi.Controllers
return user.UserAccessToken; 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) private async Task<List<IdentityResult>> AddRoles(IEnumerable<ClaimCheckboxes> roles, OmbiUser ombiUser)
{ {
var roleResult = new List<IdentityResult>(); var roleResult = new List<IdentityResult>();