From 8a86be820f9a0bcee79cddc338a9bcf08c637018 Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Mon, 15 Apr 2024 09:15:55 -0700 Subject: [PATCH 1/4] chore: contact info validation for takedown request --- server/StrDss.Service/DelistingService.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/StrDss.Service/DelistingService.cs b/server/StrDss.Service/DelistingService.cs index 537bbfd7..cc308432 100644 --- a/server/StrDss.Service/DelistingService.cs +++ b/server/StrDss.Service/DelistingService.cs @@ -268,7 +268,13 @@ private async Task>> ValidateTakedownRequestAsyn if (platform.ContactPeople == null || !platform.ContactPeople.Any(x => x.IsPrimary && x.EmailAddressDsc.IsNotEmpty() && x.EmailMessageType == EmailMessageTypes.TakedownRequest)) { - errors.AddItem("platformId", $"Platform ({dto.PlatformId}) does not have the primary contact info"); + errors.AddItem("platformId", $"There's no primary '{EmailMessageTypes.TakedownRequest}' contact email for {platform.OrganizationNm}"); + } + + if (platform.ContactPeople == null + || !platform.ContactPeople.Any(x => x.IsPrimary && x.EmailAddressDsc.IsNotEmpty() && x.EmailMessageType == EmailMessageTypes.BatchTakedownRequest)) + { + errors.AddItem("platformId", $"There's no primary '{EmailMessageTypes.BatchTakedownRequest}' contact email for {platform.OrganizationNm}"); } } @@ -431,7 +437,7 @@ private async Task ProcessTakedownRequestBatchEmailAsync(OrganizationDto platfor { EmailMessageType = template.EmailMessageType, MessageDeliveryDtm = DateTime.UtcNow, - MessageTemplateDsc = template.GetContent(), + MessageTemplateDsc = template.GetContent() + $"{Environment.NewLine}Attachments: {content}", IsHostContactedExternally = false, IsSubmitterCcRequired = false, MessageReasonId = null, From 644f276898868b32beac6c645d8510bdadbb8d3e Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Mon, 15 Apr 2024 10:13:16 -0700 Subject: [PATCH 2/4] chore: hangfire exception handling --- .../Hangfire/SkipSameJobAttribute.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs b/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs index 34f8621f..8d39a89d 100644 --- a/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs +++ b/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs @@ -3,6 +3,8 @@ using Hangfire.Server; using System.Text.Json; using Hangfire; +using Npgsql; +using StrDss.Common; namespace StrDss.Service.Hangfire { @@ -32,6 +34,7 @@ public void OnCreating(CreatingContext context) } } + //skip same job var fingerprints = monitor.ProcessingJobs(0, 999999999) .Select(x => GetJobFingerprint(x.Value.Job)) .ToList(); @@ -65,6 +68,10 @@ public void OnPerforming(PerformingContext filterContext) } catch (Exception ex) { + DeleteHangfireLock($"hangfire:{resource}"); + var distributedLock = filterContext.Connection.AcquireDistributedLock(resource, timeout); + filterContext.Items["DistributedLock"] = distributedLock; + Console.WriteLine(ex); } } @@ -91,5 +98,24 @@ private string GetJobFingerprint(Job job) return $"{job.Type.FullName}-{job.Method.Name}{args}"; } + + private void DeleteHangfireLock(string resourceName) + { + var dbHost = Environment.GetEnvironmentVariable("DB_HOST"); + var dbName = Environment.GetEnvironmentVariable("DB_NAME"); + var dbUser = Environment.GetEnvironmentVariable("DB_USER"); + var dbPass = Environment.GetEnvironmentVariable("DB_PASS"); + var dbPort = Environment.GetEnvironmentVariable("DB_PORT"); + var connString = $"Host={dbHost!.GetStringBeforeFirstDot()};Username={dbUser};Password={dbPass};Database={dbName};Port={dbPort};"; + + string sql = @"DELETE FROM Hangfire.Lock WHERE Resource = @ResourceName;"; + + using var connection = new NpgsqlConnection(connString); + connection.Open(); + + using var command = new NpgsqlCommand(sql, connection); + command.Parameters.AddWithValue("@ResourceName", resourceName); + command.ExecuteNonQuery(); + } } } From b6dfdd0531dcaed768aa355f27db706ed71c901a Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Mon, 15 Apr 2024 10:44:48 -0700 Subject: [PATCH 3/4] chore: hangfire exception handling --- server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs b/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs index 8d39a89d..9c4b2abe 100644 --- a/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs +++ b/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs @@ -68,11 +68,12 @@ public void OnPerforming(PerformingContext filterContext) } catch (Exception ex) { - DeleteHangfireLock($"hangfire:{resource}"); - var distributedLock = filterContext.Connection.AcquireDistributedLock(resource, timeout); - filterContext.Items["DistributedLock"] = distributedLock; + //DeleteHangfireLock($"hangfire:{resource}"); + //var distributedLock = filterContext.Connection.AcquireDistributedLock(resource, timeout); + //filterContext.Items["DistributedLock"] = distributedLock; Console.WriteLine(ex); + throw; } } From 959ae35f43ea0c244bfa58240cc1076a191f2002 Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Mon, 15 Apr 2024 11:12:59 -0700 Subject: [PATCH 4/4] chore: new access request link update --- server/StrDss.Service/UserService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/StrDss.Service/UserService.cs b/server/StrDss.Service/UserService.cs index 62a95ab1..171794e3 100644 --- a/server/StrDss.Service/UserService.cs +++ b/server/StrDss.Service/UserService.cs @@ -128,7 +128,7 @@ public async Task>> CreateAccessRequestAsync(Acc var template = new NewAccessRequest(_emailService) { - Link = GetHostUrl(), + Link = GetHostUrl() + "/user-management", To = emails!, Info = $"New Access Request email for {_currentUser.DisplayName}" };