made a start !wip

pull/2519/head
TidusJar 6 years ago
parent 4b7e4adb23
commit bcb193f321

@ -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)

@ -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…
Cancel
Save