Ejemplo n.º 1
0
        public void Setup(NotificationOptions opts, ChildRequests req, CustomizationSettings s)
        {
            LoadIssues(opts);
            string title;

            if (req == null)
            {
                opts.Substitutes.TryGetValue("Title", out title);
            }
            else
            {
                title = req?.ParentRequest.Title;
            }
            ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
            RequestedUser   = string.IsNullOrEmpty(req?.RequestedUser.Alias)
                ? req?.RequestedUser.UserName
                : req?.RequestedUser.Alias;
            Title         = title;
            RequestedDate = req?.RequestedDate.ToString("D");
            Type          = req?.RequestType.ToString();
            Overview      = req?.ParentRequest.Overview;
            Year          = req?.ParentRequest.ReleaseDate.Year.ToString();
            PosterImage   = req?.RequestType == RequestType.Movie ?
                            $"https://image.tmdb.org/t/p/w300{req?.ParentRequest.PosterPath}" : req?.ParentRequest.PosterPath;
            AdditionalInformation = opts.AdditionalInformation;
            // DO Episode and Season Lists
        }
        public void MovieNotificationTests()
        {
            var notificationOptions = new NotificationOptions();
            var req = F.Build <MovieRequests>()
                      .With(x => x.RequestType, RequestType.Movie)
                      .With(x => x.Available, true)
                      .Create();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };
            var userPrefs = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That(req.Id.ToString(), Is.EqualTo(sut.RequestId));
            Assert.That(req.TheMovieDbId.ToString(), Is.EqualTo(sut.ProviderId));
            Assert.That(req.Title.ToString(), Is.EqualTo(sut.Title));
            Assert.That(req.RequestedUser.UserName, Is.EqualTo(sut.RequestedUser));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.Alias));
            Assert.That(req.RequestedDate.ToString("D"), Is.EqualTo(sut.RequestedDate));
            Assert.That("Movie", Is.EqualTo(sut.Type));
            Assert.That(req.Overview, Is.EqualTo(sut.Overview));
            Assert.That(req.ReleaseDate.Year.ToString(), Is.EqualTo(sut.Year));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.MarkedAsAvailable?.ToString("D"), Is.EqualTo(sut.AvailableDate));
            Assert.That("https://image.tmdb.org/t/p/w300/" + req.PosterPath, Is.EqualTo(sut.PosterImage));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.UserPreference));
            Assert.That(string.Empty, Is.EqualTo(sut.AdditionalInformation));
            Assert.That("Available", Is.EqualTo(sut.RequestStatus));
            Assert.That("url", Is.EqualTo(sut.ApplicationUrl));
            Assert.That("name", Is.EqualTo(sut.ApplicationName));
        }
Ejemplo n.º 3
0
        public void Setup(NotificationOptions opts, FullBaseRequest req, CustomizationSettings s)
        {
            LoadIssues(opts);
            string title;

            if (req == null)
            {
                opts.Substitutes.TryGetValue("Title", out title);
            }
            else
            {
                title = req?.Title;
            }
            ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
            RequestedUser   = req?.RequestedUser?.UserName;
            UserName        = req?.RequestedUser?.UserName;
            Alias           = (req?.RequestedUser?.Alias.HasValue() ?? false) ? req?.RequestedUser?.Alias : req?.RequestedUser?.UserName;
            Title           = title;
            RequestedDate   = req?.RequestedDate.ToString("D");
            Type            = req?.RequestType.ToString();
            Overview        = req?.Overview;
            Year            = req?.ReleaseDate.Year.ToString();
            PosterImage     = req?.RequestType == RequestType.Movie ?
                              string.Format("https://image.tmdb.org/t/p/w300{0}", req?.PosterPath) : req?.PosterPath;
            AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
        }
        public void MovieIssueNotificationTests()
        {
            var notificationOptions = new NotificationOptions
            {
                Substitutes = new Dictionary <string, string>
                {
                    { "IssueDescription", "Desc" },
                    { "IssueCategory", "Cat" },
                    { "IssueStatus", "state" },
                    { "IssueSubject", "sub" },
                    { "NewIssueComment", "a" },
                    { "IssueUser", "User" },
                    { "IssueUserAlias", "alias" },
                    { "RequestType", "Movie" },
                }
            };
            var req = F.Build <MovieRequests>()
                      .With(x => x.RequestType, RequestType.Movie)
                      .Create();
            var customization = new CustomizationSettings();
            var userPrefs     = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That("Desc", Is.EqualTo(sut.IssueDescription));
            Assert.That("Cat", Is.EqualTo(sut.IssueCategory));
            Assert.That("state", Is.EqualTo(sut.IssueStatus));
            Assert.That("a", Is.EqualTo(sut.NewIssueComment));
            Assert.That("User", Is.EqualTo(sut.UserName));
            Assert.That("alias", Is.EqualTo(sut.Alias));
            Assert.That("Movie", Is.EqualTo(sut.Type));
        }
Ejemplo n.º 5
0
 public void SetCustomizationOptions(CustomizationSettings settings)
 {
     foreach (CustomizableSetting setting in settings.Settings)
     {
         setting.ApplySetting(CustomizableObject);
     }
 }
Ejemplo n.º 6
0
        private void LoadCommon(BaseRequest req, CustomizationSettings s, UserNotificationPreferences pref)
        {
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s.ApplicationName;
            ApplicationUrl  = s?.ApplicationUrl.HasValue() ?? false ? s.ApplicationUrl : string.Empty;
            AvailableDate   = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            DenyReason      = req?.DeniedReason;
            RequestId       = req?.Id.ToString();
            RequestedUser   = req?.RequestedUser?.UserName;
            RequestedDate   = req?.RequestedDate.ToString("D");

            if (Type.IsNullOrEmpty())
            {
                Type = HumanizeReturnType(req?.RequestType);
            }

            if (UserName.IsNullOrEmpty())
            {
                UserName = req?.RequestedUser?.UserName;
            }

            if (Alias.IsNullOrEmpty())
            {
                Alias = req?.RequestedUser?.Alias.HasValue() ?? false
                    ? req.RequestedUser?.Alias
                    : req?.RequestedUser?.UserName;
            }

            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }
        }
Ejemplo n.º 7
0
        public void IssueNotificationTests_NoRequest()
        {
            var notificationOptions = new NotificationOptions
            {
                Substitutes = new Dictionary <string, string>
                {
                    { "IssueDescription", "Desc" },
                    { "IssueCategory", "Cat" },
                    { "IssueStatus", "state" },
                    { "IssueSubject", "sub" },
                    { "NewIssueComment", "a" },
                    { "IssueUser", "User" },
                    { "IssueUserAlias", "alias" },
                    { "RequestType", "Movie" },
                    { "PosterPath", "aaaaa" }
                }
            };

            var customization = new CustomizationSettings();
            var userPrefs     = new UserNotificationPreferences();

            sut.Setup(notificationOptions, (MovieRequests)null, customization, userPrefs);

            Assert.That("Desc", Is.EqualTo(sut.IssueDescription));
            Assert.That("Cat", Is.EqualTo(sut.IssueCategory));
            Assert.That("state", Is.EqualTo(sut.IssueStatus));
            Assert.That("a", Is.EqualTo(sut.NewIssueComment));
            Assert.That("User", Is.EqualTo(sut.UserName));
            Assert.That("alias", Is.EqualTo(sut.Alias));
            Assert.That("Movie", Is.EqualTo(sut.Type));
            Assert.That("https://image.tmdb.org/t/p/w300/aaaaa", Is.EqualTo(sut.PosterImage));
        }
Ejemplo n.º 8
0
        public void Setup(NotificationOptions opts, MovieRequests req, CustomizationSettings s,
                          UserNotificationPreferences pref)
        {
            LoadIssues(opts);
            LoadCommon(req, s, pref, opts);
            LoadTitle(opts, req);
            ProviderId            = req?.TheMovieDbId.ToString() ?? string.Empty;
            Year                  = req?.ReleaseDate.Year.ToString();
            Overview              = req?.Overview;
            AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;

            var img = req?.PosterPath ?? string.Empty;

            if (img.HasValue())
            {
                if (img.StartsWith("http"))
                {
                    // This means it's a legacy request from when we used TvMaze as a provider.
                    // The poster url is the fully qualified address, so just use it
                    PosterImage = img;
                }
                else
                {
                    PosterImage =
                        $"https://image.tmdb.org/t/p/w300/{img?.TrimStart('/') ?? string.Empty}";
                }
            }
            CalculateRequestStatus(req);
        }
Ejemplo n.º 9
0
        private async Task SendIndividualEmails(MassEmailModel model, CustomizationSettings customization, EmailNotificationSettings email, List <Task> messagesSent)
        {
            var resolver = new NotificationMessageResolver();
            var curlys   = new NotificationMessageCurlys();

            foreach (var user in model.Users)
            {
                var fullUser = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == user.Id);

                if (!fullUser.Email.HasValue())
                {
                    _log.LogInformation("User {0} has no email, cannot send mass email to this user", fullUser.UserName);
                    continue;
                }
                curlys.Setup(fullUser, customization);
                var template = new NotificationTemplates()
                {
                    Message = model.Body, Subject = model.Subject
                };
                var content = resolver.ParseMessage(template, curlys);
                var msg     = new NotificationMessage
                {
                    Message = content.Message,
                    To      = fullUser.Email,
                    Subject = content.Subject
                };
                messagesSent.Add(DelayEmail(msg, email));
                _log.LogInformation("Sent mass email to user {0} @ {1}", fullUser.UserName, fullUser.Email);
            }
        }
Ejemplo n.º 10
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Hashtable requestParameters = new Hashtable()
            {
                { "SolutionName", SolutionManagementHelper.GetSolutionUniqueName(_repository, Id, false) },
                { "ExportAutoNumberingSettings", AutoNumberingSettings.ToBool() },
                { "ExportCalendarSettings", CalendarSettings.ToBool() },
                { "ExportCustomizationSettings", CustomizationSettings.ToBool() },
                { "ExportEmailTrackingSettings", EmailTrackingSettings.ToBool() },
                { "ExportGeneralSettings", GeneralSettings.ToBool() },
                { "ExportIsvConfig", IsvConfig.ToBool() },
                { "ExportMarketingSettings", MarketingSettings.ToBool() },
                { "ExportOutlookSynchronizationSettings", OutlookSynchronizationSettings.ToBool() },
                { "ExportRelationshipRoles", RelationshipRoles.ToBool() },
                { "Managed", Managed.ToBool() }
            };

            if (_context != null)
            {
                _context.SetParametersOnRequest(requestParameters);
            }

            OrganizationResponse response = _repository.Execute("ExportSolution", requestParameters);

            File.WriteAllBytes(Path, (byte[])response.Results["ExportSolutionFile"]);
        }
Ejemplo n.º 11
0
        public void MusicNotificationTests()
        {
            var notificationOptions = new NotificationOptions();
            var req = F.Build <AlbumRequest>()
                      .With(x => x.RequestType, RequestType.Album)
                      .With(x => x.Available, true)
                      .Create();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };
            var userPrefs = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That(req.Id.ToString(), Is.EqualTo(sut.RequestId));
            Assert.That(req.ForeignArtistId.ToString(), Is.EqualTo(sut.ProviderId));
            Assert.That(req.Title.ToString(), Is.EqualTo(sut.Title));
            Assert.That(req.RequestedUser.UserName, Is.EqualTo(sut.RequestedUser));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.Alias));
            Assert.That(req.RequestedDate.ToString("D"), Is.EqualTo(sut.RequestedDate));
            Assert.That("Album", Is.EqualTo(sut.Type));
            Assert.That(req.ReleaseDate.Year.ToString(), Is.EqualTo(sut.Year));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.MarkedAsAvailable?.ToString("D"), Is.EqualTo(sut.AvailableDate));
            Assert.That(req.Cover, Is.EqualTo(sut.PosterImage));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.UserPreference));
            Assert.That(string.Empty, Is.EqualTo(sut.AdditionalInformation));
            Assert.That("Available", Is.EqualTo(sut.RequestStatus));
            Assert.That("url", Is.EqualTo(sut.ApplicationUrl));
            Assert.That("name", Is.EqualTo(sut.ApplicationName));
        }
Ejemplo n.º 12
0
 public void Setup(OmbiUser user, CustomizationSettings s)
 {
     ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
     ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
     RequestedUser   = user.UserName;
     Alias           = user.UserAlias;
     UserName        = user.UserName;
 }
Ejemplo n.º 13
0
 public void SetupNewsletter(CustomizationSettings s, OmbiUser username)
 {
     ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
     ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
     RequestedUser   = username.UserName;
     UserName        = username.UserName;
     Alias           = username.Alias.HasValue() ? username.Alias : username.UserName;
 }
Ejemplo n.º 14
0
        public void Setup(NotificationOptions opts, ChildRequests req, CustomizationSettings s,
                          UserNotificationPreferences pref)
        {
            LoadIssues(opts);
            LoadCommon(req, s, pref, opts);
            LoadTitle(opts, req);
            ProviderId            = req?.ParentRequest?.ExternalProviderId.ToString() ?? string.Empty;
            Year                  = req?.ParentRequest?.ReleaseDate.Year.ToString();
            Overview              = req?.ParentRequest?.Overview;
            AdditionalInformation = opts.AdditionalInformation;
            var img = req?.ParentRequest?.PosterPath ?? string.Empty;

            if (img.HasValue())
            {
                if (img.StartsWith("http"))
                {
                    // This means it's a legacy request from when we used TvMaze as a provider.
                    // The poster url is the fully qualified address, so just use it
                    PosterImage = img;
                }
                else
                {
                    PosterImage =
                        $"https://image.tmdb.org/t/p/w300/{img?.TrimStart('/') ?? string.Empty}";
                }
            }

            // Generate episode list.
            StringBuilder epSb = new StringBuilder();
            IEnumerable <EpisodeRequests> episodes = req?.SeasonRequests?
                                                     .SelectMany(x => x.Episodes) ?? new List <EpisodeRequests>();

            episodes
            .OrderBy(x => x.EpisodeNumber)
            .ToList()
            .ForEach(ep => epSb.Append($"{ep.EpisodeNumber},"));
            if (epSb.Length > 0)
            {
                epSb.Remove(epSb.Length - 1, 1);
            }
            EpisodesList = epSb.ToString();

            // Generate season list.
            StringBuilder         seasonSb = new StringBuilder();
            List <SeasonRequests> seasons  = req?.SeasonRequests ?? new List <SeasonRequests>();

            seasons
            .OrderBy(x => x.SeasonNumber)
            .ToList()
            .ForEach(ep => seasonSb.Append($"{ep.SeasonNumber},"));
            if (seasonSb.Length > 0)
            {
                seasonSb.Remove(seasonSb.Length - 1, 1);
            }
            SeasonsList = seasonSb.ToString();
            CalculateRequestStatus(req);
        }
Ejemplo n.º 15
0
        private async Task <Negotiator> LoadRequests()
        {
            var settings = await PrSettings.GetSettingsAsync();

            var custom = await CustomizationSettings.GetSettingsAsync();

            return(View["Index", new RequestsIndexViewModel {
                            CustomizationSettings = custom, PlexRequestSettings = settings
                        }]);
        }
Ejemplo n.º 16
0
        public string AddToUrlTests(string applicationUrl, string append)
        {
            var c = new CustomizationSettings
            {
                ApplicationUrl = applicationUrl
            };
            var result = c.AddToUrl(append);

            return(result);
        }
Ejemplo n.º 17
0
        public void TvNotification_EpisodeList()
        {
            var episodeRequests = new List <EpisodeRequests>
            {
                new EpisodeRequests
                {
                    EpisodeNumber = 1,
                },
                new EpisodeRequests
                {
                    EpisodeNumber = 2,
                },
                new EpisodeRequests
                {
                    EpisodeNumber = 3,
                }
            };
            var seasonRequests = new List <SeasonRequests>
            {
                new SeasonRequests
                {
                    Episodes     = episodeRequests,
                    SeasonNumber = 1
                },
                new SeasonRequests
                {
                    Episodes     = episodeRequests,
                    SeasonNumber = 2
                },
                new SeasonRequests
                {
                    Episodes     = episodeRequests,
                    SeasonNumber = 3
                }
            };


            var notificationOptions = new NotificationOptions();
            var req = F.Build <ChildRequests>()
                      .With(x => x.RequestType, RequestType.TvShow)
                      .With(x => x.Available, true)
                      .With(x => x.SeasonRequests, seasonRequests)
                      .Create();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };
            var userPrefs = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That(sut.EpisodesList, Is.EqualTo("1,1,1,2,2,2,3,3,3"));
            Assert.That(sut.SeasonsList, Is.EqualTo("1,2,3"));
        }
Ejemplo n.º 18
0
 public void Setup(NotificationOptions opts, AlbumRequest req, CustomizationSettings s,
                   UserNotificationPreferences pref)
 {
     LoadIssues(opts);
     LoadCommon(req, s, pref, opts);
     LoadTitle(opts, req);
     ProviderId            = req?.ForeignArtistId ?? string.Empty;
     Year                  = req?.ReleaseDate.Year.ToString();
     AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
     PosterImage           = req?.Cover.HasValue() ?? false ? req.Cover : req?.Disk ?? string.Empty;
     CalculateRequestStatus(req);
 }
Ejemplo n.º 19
0
        public void Setup(NotificationOptions opts, FullBaseRequest req, CustomizationSettings s, UserNotificationPreferences pref)
        {
            LoadIssues(opts);

            RequestId = req?.Id.ToString();

            string title;

            if (req == null)
            {
                opts.Substitutes.TryGetValue("Title", out title);
            }
            else
            {
                title = req?.Title;
            }
            ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
            RequestedUser   = req?.RequestedUser?.UserName;
            if (UserName.IsNullOrEmpty())
            {
                // Can be set if it's an issue
                UserName = req?.RequestedUser?.UserName;
            }

            Alias = (req?.RequestedUser?.Alias.HasValue() ?? false) ? req?.RequestedUser?.Alias : req?.RequestedUser?.UserName;
            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }
            Title         = title;
            RequestedDate = req?.RequestedDate.ToString("D");
            if (Type.IsNullOrEmpty())
            {
                Type = req?.RequestType.Humanize();
            }
            Overview      = req?.Overview;
            Year          = req?.ReleaseDate.Year.ToString();
            DenyReason    = req?.DeniedReason;
            AvailableDate = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            if (req?.RequestType == RequestType.Movie)
            {
                PosterImage = string.Format((req?.PosterPath ?? string.Empty).StartsWith("/", StringComparison.InvariantCultureIgnoreCase)
                    ? "https://image.tmdb.org/t/p/w300{0}" : "https://image.tmdb.org/t/p/w300/{0}", req?.PosterPath);
            }
            else
            {
                PosterImage = req?.PosterPath;
            }

            AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
        }
Ejemplo n.º 20
0
 public void Setup(NotificationOptions opts, MovieRequests req, CustomizationSettings s,
                   UserNotificationPreferences pref)
 {
     LoadIssues(opts);
     LoadCommon(req, s, pref);
     LoadTitle(opts, req);
     ProviderId            = req?.TheMovieDbId.ToString() ?? string.Empty;
     Year                  = req?.ReleaseDate.Year.ToString();
     Overview              = req?.Overview;
     AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
     PosterImage           = $"https://image.tmdb.org/t/p/w300/{req?.PosterPath?.TrimStart('/') ?? string.Empty}";
     CalculateRequestStatus(req);
 }
Ejemplo n.º 21
0
        public void NewsletterTests()
        {
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };

            sut.SetupNewsletter(customization);

            Assert.That("url", Is.EqualTo(sut.ApplicationUrl));
            Assert.That("name", Is.EqualTo(sut.ApplicationName));
        }
Ejemplo n.º 22
0
        public string TvShowNotificationTests_RequestStatus(bool available, bool denied, bool approved)
        {
            var notificationOptions = new NotificationOptions();
            var req = F.Build <ChildRequests>()
                      .With(x => x.RequestType, RequestType.TvShow)
                      .With(x => x.Available, available)
                      .With(x => x.Denied, denied)
                      .With(x => x.Approved, approved)
                      .Create();
            var customization = new CustomizationSettings();
            var userPrefs     = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);
            return(sut.RequestStatus);
        }
Ejemplo n.º 23
0
        private async Task <Response> GetFilterAndSortSettings()
        {
            var s = await CustomizationSettings.GetSettingsAsync();

            var sortVal = EnumHelper <SortOptions> .GetDisplayValue((SortOptions)s.DefaultSort);

            var filterVal = EnumHelper <FilterOptions> .GetDisplayValue((FilterOptions)s.DefaultFilter);

            var vm = new
            {
                DefaultSort   = sortVal,
                DefaultFilter = filterVal
            };

            return(Response.AsJson(vm));
        }
Ejemplo n.º 24
0
        private async Task SendBccMails(MassEmailModel model, CustomizationSettings customization, EmailNotificationSettings email, List <Task> messagesSent)
        {
            var resolver = new NotificationMessageResolver();
            var curlys   = new NotificationMessageCurlys();

            var validUsers = new List <OmbiUser>();

            foreach (var user in model.Users)
            {
                var fullUser = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == user.Id);

                if (!fullUser.Email.HasValue())
                {
                    _log.LogInformation("User {0} has no email, cannot send mass email to this user", fullUser.UserName);
                    continue;
                }

                validUsers.Add(fullUser);
            }

            if (!validUsers.Any())
            {
                return;
            }

            var firstUser = validUsers.FirstOrDefault();

            var bccAddress = string.Join(',', validUsers.Select(x => x.Email));

            curlys.Setup(firstUser, customization);
            var template = new NotificationTemplates()
            {
                Message = model.Body, Subject = model.Subject
            };
            var content = resolver.ParseMessage(template, curlys);
            var msg     = new NotificationMessage
            {
                Message = content.Message,
                Subject = content.Subject,
                Other   = new Dictionary <string, string> {
                    { "bcc", bccAddress }
                }
            };

            messagesSent.Add(_email.SendAdHoc(msg, email));
        }
Ejemplo n.º 25
0
        public void EmailSetupTests()
        {
            var user          = F.Create <OmbiUser>();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };

            sut.Setup(user, customization);

            Assert.That(user.UserName, Is.EqualTo(sut.RequestedUser));
            Assert.That(user.UserName, Is.EqualTo(sut.UserName));
            Assert.That(user.UserAlias, Is.EqualTo(sut.Alias));
            Assert.That(sut.ApplicationUrl, Is.EqualTo("url"));
            Assert.That(sut.ApplicationName, Is.EqualTo("name"));
        }
Ejemplo n.º 26
0
        private void LoadCommon(BaseRequest req, CustomizationSettings s, UserNotificationPreferences pref, NotificationOptions opts)
        {
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s.ApplicationName;
            ApplicationUrl  = s?.ApplicationUrl.HasValue() ?? false ? s.ApplicationUrl : string.Empty;
            AvailableDate   = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            DenyReason      = req?.DeniedReason;
            RequestId       = req?.Id.ToString();
            RequestedUser   = req?.RequestedUser?.UserName;
            RequestedDate   = req?.RequestedDate.ToString("D");
            DetailsUrl      = GetDetailsUrl(s, req);

            if (Type.IsNullOrEmpty())
            {
                Type = HumanizeReturnType(req?.RequestType);
            }

            if (UserName.IsNullOrEmpty())
            {
                UserName = req?.RequestedUser?.UserName;
            }

            if (Alias.IsNullOrEmpty())
            {
                Alias = req?.RequestedUser?.Alias.HasValue() ?? false
                    ? req.RequestedUser?.Alias
                    : req?.RequestedUser?.UserName;
            }

            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }

            if (opts.NotificationType == NotificationType.PartiallyAvailable)
            {
                if (opts.Substitutes.TryGetValue("Season", out var sNumber))
                {
                    PartiallyAvailableSeasonNumber = sNumber;
                }
                if (opts.Substitutes.TryGetValue("Episodes", out var epNumber))
                {
                    PartiallyAvailableEpisodeNumbers = epNumber;
                }
            }
        }
Ejemplo n.º 27
0
        public void Setup(NotificationOptions opts, ChildRequests req, CustomizationSettings s,
                          UserNotificationPreferences pref)
        {
            LoadIssues(opts);
            LoadCommon(req, s, pref);
            LoadTitle(opts, req);
            ProviderId            = req?.ParentRequest?.ExternalProviderId.ToString() ?? string.Empty;
            Year                  = req?.ParentRequest?.ReleaseDate.Year.ToString();
            Overview              = req?.ParentRequest?.Overview;
            AdditionalInformation = opts.AdditionalInformation;
            PosterImage           =
                $"https://image.tmdb.org/t/p/w300/{req?.ParentRequest?.PosterPath?.TrimStart('/') ?? string.Empty}";

            // Generate episode list.
            StringBuilder epSb = new StringBuilder();
            IEnumerable <EpisodeRequests> episodes = req?.SeasonRequests?
                                                     .SelectMany(x => x.Episodes) ?? new List <EpisodeRequests>();

            episodes
            .OrderBy(x => x.EpisodeNumber)
            .ToList()
            .ForEach(ep => epSb.Append($"{ep.EpisodeNumber},"));
            if (epSb.Length > 0)
            {
                epSb.Remove(epSb.Length - 1, 1);
            }
            EpisodesList = epSb.ToString();

            // Generate season list.
            StringBuilder         seasonSb = new StringBuilder();
            List <SeasonRequests> seasons  = req?.SeasonRequests ?? new List <SeasonRequests>();

            seasons
            .OrderBy(x => x.SeasonNumber)
            .ToList()
            .ForEach(ep => seasonSb.Append($"{ep.SeasonNumber},"));
            if (seasonSb.Length > 0)
            {
                seasonSb.Remove(seasonSb.Length - 1, 1);
            }
            SeasonsList = seasonSb.ToString();
            CalculateRequestStatus(req);
        }
Ejemplo n.º 28
0
        public void Setup(NotificationOptions opts, AlbumRequest req, CustomizationSettings s, UserNotificationPreferences pref)
        {
            LoadIssues(opts);

            RequestId = req?.Id.ToString();

            string title;

            if (req == null)
            {
                opts.Substitutes.TryGetValue("Title", out title);
            }
            else
            {
                title = req?.Title;
            }
            ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
            RequestedUser   = req?.RequestedUser?.UserName;
            if (UserName.IsNullOrEmpty())
            {
                // Can be set if it's an issue
                UserName = req?.RequestedUser?.UserName;
            }

            AvailableDate = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            DenyReason    = req?.DeniedReason;
            Alias         = (req?.RequestedUser?.Alias.HasValue() ?? false) ? req?.RequestedUser?.Alias : req?.RequestedUser?.UserName;
            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }
            Title         = title;
            RequestedDate = req?.RequestedDate.ToString("D");
            if (Type.IsNullOrEmpty())
            {
                Type = req?.RequestType.Humanize();
            }
            Year        = req?.ReleaseDate.Year.ToString();
            PosterImage = (req?.Cover.HasValue() ?? false) ? req.Cover : req?.Disk ?? string.Empty;

            AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
        }
Ejemplo n.º 29
0
        public async Task <OmbiIdentityResult> SubmitResetPassword([FromBody] SubmitPasswordReset email)
        {
            // Check if account exists
            var user = await UserManager.FindByEmailAsync(email.Email);

            var defaultMessage = new OmbiIdentityResult
            {
                Successful = true,
                Errors     = new List <string> {
                    "If this account exists you should recieve a password reset link."
                }
            };

            if (user == null)
            {
                return(defaultMessage);
            }

            // We have the user
            var token = await UserManager.GeneratePasswordResetTokenAsync(user);

            // We now need to email the user with this token
            var emailSettings = await EmailSettings.GetSettingsAsync();

            var customizationSettings = await CustomizationSettings.GetSettingsAsync();

            var appName = (string.IsNullOrEmpty(customizationSettings.ApplicationName)
                ? "Ombi"
                : customizationSettings.ApplicationName);

            customizationSettings.AddToUrl("/token?token=");
            var url = customizationSettings.ApplicationUrl;

            await EmailProvider.SendAdHoc(new NotificationMessage
            {
                To      = user.Email,
                Subject = $"{appName} Password Reset",
                Message = $"You recently made a request to reset your {appName} account. Please click the link below to complete the process.<br/><br/>" +
                          $"<a href=\"{url}{token}\"> Reset </a>"
            }, emailSettings);

            return(defaultMessage);
        }
Ejemplo n.º 30
0
        public void TvNotificationPartialAvailablilityTests()
        {
            var notificationOptions = new NotificationOptions {
                NotificationType = Helpers.NotificationType.PartiallyAvailable
            };

            notificationOptions.Substitutes.Add("Season", "1");
            notificationOptions.Substitutes.Add("Episodes", "1, 2");
            var req = F.Build <ChildRequests>()
                      .With(x => x.RequestType, RequestType.TvShow)
                      .With(x => x.Available, true)
                      .Create();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };
            var userPrefs = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That(req.Id.ToString(), Is.EqualTo(sut.RequestId));
            Assert.That(req.ParentRequest.ExternalProviderId.ToString(), Is.EqualTo(sut.ProviderId));
            Assert.That(req.ParentRequest.Title.ToString(), Is.EqualTo(sut.Title));
            Assert.That(req.RequestedUser.UserName, Is.EqualTo(sut.RequestedUser));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.Alias));
            Assert.That(req.RequestedDate.ToString("D"), Is.EqualTo(sut.RequestedDate));
            Assert.That("TV Show", Is.EqualTo(sut.Type));
            Assert.That(req.ParentRequest.Overview, Is.EqualTo(sut.Overview));
            Assert.That(req.ParentRequest.ReleaseDate.Year.ToString(), Is.EqualTo(sut.Year));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.MarkedAsAvailable?.ToString("D"), Is.EqualTo(sut.AvailableDate));
            Assert.That("https://image.tmdb.org/t/p/w300/" + req.ParentRequest.PosterPath, Is.EqualTo(sut.PosterImage));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.UserPreference));
            Assert.That(null, Is.EqualTo(sut.AdditionalInformation));
            Assert.That("Available", Is.EqualTo(sut.RequestStatus));
            Assert.That("url", Is.EqualTo(sut.ApplicationUrl));
            Assert.That("name", Is.EqualTo(sut.ApplicationName));
            Assert.That(sut.PartiallyAvailableEpisodeNumbers, Is.EqualTo("1, 2"));
            Assert.That(sut.PartiallyAvailableSeasonNumber, Is.EqualTo("1"));
        }