Skip to content

Commit 2131cea

Browse files
authored
Merge pull request #800 from bcgov/yj
feat(ds-888)
2 parents 8ccb0f4 + 94fc5f4 commit 2131cea

File tree

2 files changed

+0
-274
lines changed

2 files changed

+0
-274
lines changed

server/StrDss.Api/Controllers/DelistingController.cs

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -135,82 +135,6 @@ public async Task<ActionResult> GetTakedownRequestsFromListingPreview(TakedownRe
135135
return Ok(preview);
136136
}
137137

138-
[ApiAuthorize(Permissions.TakedownAction)]
139-
[HttpPost("batchtakedownrequest", Name = "SendBatchTakedownRequest")]
140-
public async Task<ActionResult> SendBatchTakedownRequest([FromForm] BatchTakedownRequestCreateDto dto)
141-
{
142-
Dictionary<string, List<string>> errors = new Dictionary<string, List<string>>();
143-
144-
if (dto.File == null || dto.File.Length == 0)
145-
{
146-
errors.AddItem("File", $"File is null or empty.");
147-
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
148-
}
149-
150-
var maxSizeInMb = _config.GetValue<int>("RENTAL_LISTING_REPORT_MAX_SIZE");
151-
var maxSizeInB = (maxSizeInMb == 0 ? 2 : maxSizeInMb) * 1024 * 1024;
152-
153-
if (dto.File.Length > maxSizeInB)
154-
{
155-
errors.AddItem("File", $"The file size exceeds the maximum size {maxSizeInMb}MB.");
156-
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
157-
}
158-
159-
if (!CommonUtils.IsTextFile(dto.File.ContentType))
160-
{
161-
errors.AddItem("File", $"Uploaded file is not a text file.");
162-
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
163-
}
164-
165-
using var stream = dto.File.OpenReadStream();
166-
167-
errors = await _delistingService.SendBatchTakedownRequestAsync(dto.PlatformId, stream);
168-
if (errors.Count > 0)
169-
{
170-
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
171-
}
172-
173-
return NoContent();
174-
}
175-
176-
[ApiAuthorize(Permissions.TakedownAction)]
177-
[HttpPost("batchtakedownnotice", Name = "SendBatchTakedownNotice")]
178-
public async Task<ActionResult> SendBatchtakedownNotice([FromForm] BatchTakedownNoticeCreateDto dto)
179-
{
180-
Dictionary<string, List<string>> errors = new Dictionary<string, List<string>>();
181-
182-
if (dto.File == null || dto.File.Length == 0)
183-
{
184-
errors.AddItem("File", $"File is null or empty.");
185-
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
186-
}
187-
188-
var maxSizeInMb = _config.GetValue<int>("RENTAL_LISTING_REPORT_MAX_SIZE");
189-
var maxSizeInB = (maxSizeInMb == 0 ? 2 : maxSizeInMb) * 1024 * 1024;
190-
191-
if (dto.File.Length > maxSizeInB)
192-
{
193-
errors.AddItem("File", $"The file size exceeds the maximum size {maxSizeInMb}MB.");
194-
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
195-
}
196-
197-
if (!CommonUtils.IsTextFile(dto.File.ContentType))
198-
{
199-
errors.AddItem("File", $"Uploaded file is not a text file.");
200-
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
201-
}
202-
203-
using var stream = dto.File.OpenReadStream();
204-
205-
errors = await _delistingService.SendBatchTakedownNoticeAsync(dto.PlatformId, stream);
206-
if (errors.Count > 0)
207-
{
208-
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
209-
}
210-
211-
return NoContent();
212-
}
213-
214138
[ApiAuthorize(Permissions.ProvinceAction)]
215139
[HttpPost("complianceorders/preview", Name = "GetComplianceOrdersFromListingPreview")]
216140
public async Task<ActionResult> GetComplianceOrdersFromListingPreview(ComplianceOrderDto[] requests)

server/StrDss.Service/DelistingService.cs

Lines changed: 0 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public interface IDelistingService
2424
Task<Dictionary<string, List<string>>> CreateTakedownRequestAsync(TakedownRequestCreateDto dto);
2525
Task<(Dictionary<string, List<string>> errors, EmailPreview preview)> GetTakedownRequestPreviewAsync(TakedownRequestCreateDto dto);
2626
Task ProcessTakedownRequestBatchEmailsAsync();
27-
Task<Dictionary<string, List<string>>> SendBatchTakedownRequestAsync(long platformId, Stream stream);
28-
Task<Dictionary<string, List<string>>> SendBatchTakedownNoticeAsync(long platformId, Stream stream);
2927
Task<Dictionary<string, List<string>>> CreateTakedownNoticesFromListingAsync(TakedownNoticesFromListingDto[] listings);
3028
Task<(Dictionary<string, List<string>> errors, EmailPreview preview)> GetTakedownNoticesFromListingPreviewAsync(TakedownNoticesFromListingDto[] listings);
3129
Task<Dictionary<string, List<string>>> CreateTakedownRequestsFromListingAsync(TakedownRequestsFromListingDto[] listings);
@@ -893,202 +891,6 @@ private async Task ProcessTakedownRequestBatchEmailAsync(OrganizationDto platfor
893891

894892
_unitOfWork.CommitTransaction(transaction);
895893
}
896-
897-
public async Task<Dictionary<string, List<string>>> SendBatchTakedownRequestAsync(long platformId, Stream stream)
898-
{
899-
var platform = await _orgService.GetOrganizationByIdAsync(platformId);
900-
901-
var errors = await ValidateBatchTakedownRequestAsync(platform);
902-
if (errors.Count > 0)
903-
{
904-
return errors;
905-
}
906-
907-
//the existence of the contact email has been validated above
908-
var contacts = platform!.ContactPeople
909-
.Where(x => x.IsPrimary && x.EmailAddressDsc.IsNotEmpty() && x.EmailMessageType == EmailMessageTypes.BatchTakedownRequest)
910-
.Select(x => x.EmailAddressDsc)
911-
.ToArray();
912-
913-
var content = CommonUtils.StreamToBase64(stream);
914-
var date = DateUtils.ConvertUtcToPacificTime(DateTime.UtcNow).ToString("yyyy-MM-dd-HH-mm");
915-
var fileName = $"{platform.OrganizationNm} - {date}.csv";
916-
var adminEmail = _config.GetValue<string>("ADMIN_EMAIL") ?? throw new Exception($"There's no admin eamil.");
917-
918-
var template = new BatchTakedownRequest(_emailService)
919-
{
920-
To = contacts,
921-
Bcc = new string[] { adminEmail! },
922-
Info = $"{EmailMessageTypes.BatchTakedownRequest} for {platform.OrganizationNm}",
923-
Attachments = new EmailAttachment[] { new EmailAttachment {
924-
Content = content,
925-
ContentType = "text/csv",
926-
Encoding = "base64",
927-
Filename = fileName
928-
}},
929-
};
930-
931-
var emailEntity = new DssEmailMessage
932-
{
933-
EmailMessageType = template.EmailMessageType,
934-
MessageDeliveryDtm = DateTime.UtcNow,
935-
MessageTemplateDsc = template.GetContent() + $" Attachement: {fileName}",
936-
IsHostContactedExternally = false,
937-
IsSubmitterCcRequired = false,
938-
LgPhoneNo = null,
939-
UnreportedListingNo = null,
940-
HostEmailAddressDsc = null,
941-
LgEmailAddressDsc = null,
942-
CcEmailAddressDsc = null,
943-
UnreportedListingUrl = null,
944-
LgStrBylawUrl = null,
945-
InitiatingUserIdentityId = _currentUser.Id,
946-
AffectedByUserIdentityId = null,
947-
InvolvedInOrganizationId = platform.OrganizationId,
948-
RequestingOrganizationId = null
949-
};
950-
951-
await _emailRepo.AddEmailMessage(emailEntity);
952-
953-
emailEntity.ExternalMessageNo = await template.SendEmail();
954-
955-
using var transaction = _unitOfWork.BeginTransaction();
956-
957-
_unitOfWork.Commit();
958-
959-
emailEntity.BatchingEmailMessageId = emailEntity.EmailMessageId;
960-
961-
_unitOfWork.Commit();
962-
963-
_unitOfWork.CommitTransaction(transaction);
964-
965-
return errors;
966-
}
967-
968-
private async Task<Dictionary<string, List<string>>> ValidateBatchTakedownRequestAsync(OrganizationDto? platform)
969-
{
970-
await Task.CompletedTask;
971-
972-
var errors = new Dictionary<string, List<string>>();
973-
974-
if (platform == null)
975-
{
976-
errors.AddItem("platformId", $"Platform ID ({platform!.OrganizationId}) does not exist.");
977-
}
978-
else
979-
{
980-
if (platform.OrganizationType != OrganizationTypes.Platform)
981-
{
982-
errors.AddItem("platformId", $"Organization ({platform!.OrganizationId}) is not a platform");
983-
}
984-
985-
if (platform.ContactPeople == null ||
986-
!platform.ContactPeople.Any(x => x.IsPrimary && x.EmailAddressDsc.IsNotEmpty() && x.EmailMessageType == EmailMessageTypes.BatchTakedownRequest))
987-
{
988-
errors.AddItem("platformId", $"Platform ({platform!.OrganizationId}) does not have the primary '{EmailMessageTypes.BatchTakedownRequest}' contact info");
989-
}
990-
}
991-
992-
return errors;
993-
}
994-
995-
public async Task<Dictionary<string, List<string>>> SendBatchTakedownNoticeAsync(long platformId, Stream stream)
996-
{
997-
var platform = await _orgService.GetOrganizationByIdAsync(platformId);
998-
999-
var errors = await ValidateBatchTakedownNoticeAsync(platform);
1000-
if (errors.Count > 0)
1001-
{
1002-
return errors;
1003-
}
1004-
1005-
//the existence of the contact email has been validated above
1006-
var contacts = platform!.ContactPeople
1007-
.Where(x => x.IsPrimary && x.EmailAddressDsc.IsNotEmpty() && x.EmailMessageType == EmailMessageTypes.NoticeOfTakedown)
1008-
.Select(x => x.EmailAddressDsc)
1009-
.ToArray();
1010-
1011-
var content = CommonUtils.StreamToBase64(stream);
1012-
var date = DateUtils.ConvertUtcToPacificTime(DateTime.UtcNow).ToString("yyyy-MM-dd-HH-mm");
1013-
var fileName = $"Notice of non-compliance - {platform.OrganizationNm} - {date}.csv";
1014-
var adminEmail = _config.GetValue<string>("ADMIN_EMAIL") ?? throw new Exception($"There's no admin eamil.");
1015-
1016-
var template = new BatchTakedownNotice(_emailService)
1017-
{
1018-
To = contacts,
1019-
Bcc = new string[] { adminEmail! },
1020-
Info = $"{EmailMessageTypes.NoticeOfTakedown} for {platform.OrganizationNm}",
1021-
Attachments = new EmailAttachment[] { new EmailAttachment {
1022-
Content = content,
1023-
ContentType = "text/csv",
1024-
Encoding = "base64",
1025-
Filename = fileName
1026-
}},
1027-
};
1028-
1029-
var emailEntity = new DssEmailMessage
1030-
{
1031-
EmailMessageType = template.EmailMessageType,
1032-
MessageDeliveryDtm = DateTime.UtcNow,
1033-
MessageTemplateDsc = template.GetContent() + $" Attachement: {fileName}",
1034-
IsHostContactedExternally = false,
1035-
IsSubmitterCcRequired = false,
1036-
LgPhoneNo = null,
1037-
UnreportedListingNo = null,
1038-
HostEmailAddressDsc = null,
1039-
LgEmailAddressDsc = null,
1040-
CcEmailAddressDsc = null,
1041-
UnreportedListingUrl = null,
1042-
LgStrBylawUrl = null,
1043-
InitiatingUserIdentityId = _currentUser.Id,
1044-
AffectedByUserIdentityId = null,
1045-
InvolvedInOrganizationId = platform.OrganizationId,
1046-
RequestingOrganizationId = null
1047-
};
1048-
1049-
await _emailRepo.AddEmailMessage(emailEntity);
1050-
1051-
emailEntity.ExternalMessageNo = await template.SendEmail();
1052-
1053-
using var transaction = _unitOfWork.BeginTransaction();
1054-
1055-
_unitOfWork.Commit();
1056-
1057-
emailEntity.BatchingEmailMessageId = emailEntity.EmailMessageId;
1058-
1059-
_unitOfWork.Commit();
1060-
1061-
_unitOfWork.CommitTransaction(transaction);
1062-
1063-
return errors;
1064-
}
1065-
1066-
private async Task<Dictionary<string, List<string>>> ValidateBatchTakedownNoticeAsync(OrganizationDto? platform)
1067-
{
1068-
await Task.CompletedTask;
1069-
1070-
var errors = new Dictionary<string, List<string>>();
1071-
1072-
if (platform == null)
1073-
{
1074-
errors.AddItem("platformId", $"Platform ID ({platform!.OrganizationId}) does not exist.");
1075-
}
1076-
else
1077-
{
1078-
if (platform.OrganizationType != OrganizationTypes.Platform)
1079-
{
1080-
errors.AddItem("platformId", $"Organization ({platform!.OrganizationId}) is not a platform");
1081-
}
1082-
1083-
if (platform.ContactPeople == null ||
1084-
!platform.ContactPeople.Any(x => x.IsPrimary && x.EmailAddressDsc.IsNotEmpty() && x.EmailMessageType == EmailMessageTypes.BatchTakedownRequest))
1085-
{
1086-
errors.AddItem("platformId", $"Platform ({platform!.OrganizationId}) does not have the primary '{EmailMessageTypes.BatchTakedownRequest}' contact info");
1087-
}
1088-
}
1089-
1090-
return errors;
1091-
}
1092894
public async Task<(Dictionary<string, List<string>> errors, EmailPreview preview)> GetComplianceOrdersFromListingPreviewAsync(ComplianceOrderDto[] listings)
1093895
{
1094896
CommonUtils.SanitizeObject(listings);

0 commit comments

Comments
 (0)