From 476a13291d142761a99d9dc8f25175161600ff7f Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Wed, 17 Apr 2024 09:44:47 -0700 Subject: [PATCH] feat(dss-304) populated lg name in the takedown notice template --- server/StrDss.Service/DelistingService.cs | 37 +++++++++++-------- .../EmailTemplates/TakedownNotice.cs | 14 +++---- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/server/StrDss.Service/DelistingService.cs b/server/StrDss.Service/DelistingService.cs index ed3e7fba..105dc420 100644 --- a/server/StrDss.Service/DelistingService.cs +++ b/server/StrDss.Service/DelistingService.cs @@ -47,20 +47,20 @@ public DelistingService(ICurrentUser currentUser, IFieldValidatorService validat public async Task>> CreateTakedownNoticeAsync(TakedownNoticeCreateDto dto) { var platform = await _orgService.GetOrganizationByIdAsync(dto.PlatformId); - var reasonDto = await _emailService.GetMessageReasonByMessageTypeAndId(EmailMessageTypes.NoticeOfTakedown, dto.ReasonId); + var lg = await _orgService.GetOrganizationByIdAsync(_currentUser.OrganizationId); - var errors = await ValidateTakedownNoticeAsync(dto, platform, reasonDto); + var errors = await ValidateTakedownNoticeAsync(dto, platform, lg); if (errors.Count > 0) { return errors; } - await SendTakedownNoticeAsync(dto, platform, reasonDto); + await SendTakedownNoticeAsync(dto, platform, lg); return errors; } - private async Task>> ValidateTakedownNoticeAsync(TakedownNoticeCreateDto dto, OrganizationDto? platform, DropdownNumDto? reasonDto) + private async Task>> ValidateTakedownNoticeAsync(TakedownNoticeCreateDto dto, OrganizationDto? platform, OrganizationDto? lg) { await Task.CompletedTask; @@ -114,9 +114,16 @@ private async Task>> ValidateTakedownNoticeAsync } } - if (reasonDto == null) + if (lg == null) + { + errors.AddItem("currentUser", $"User's organization ({_currentUser.OrganizationId}) does not exist."); + } + else { - errors.AddItem("reasonId", $"Reason ID ({dto.ReasonId}) does not exist."); + if (lg.OrganizationType != OrganizationTypes.LG) + { + errors.AddItem("currentUser", $"User's organization ({_currentUser.OrganizationId}) is not a local government"); + } } regex = RegexDefs.GetRegexInfo(RegexDefs.Email); @@ -156,9 +163,9 @@ private async Task>> ValidateTakedownNoticeAsync return errors; } - private async Task SendTakedownNoticeAsync(TakedownNoticeCreateDto dto, OrganizationDto? platform, DropdownNumDto? reasonDto) + private async Task SendTakedownNoticeAsync(TakedownNoticeCreateDto dto, OrganizationDto? platform, OrganizationDto? lg) { - var template = GetTakedownNoticeTemplate(dto, platform, reasonDto); + var template = GetTakedownNoticeTemplate(dto, platform, lg); var emailEntity = new DssEmailMessage { @@ -167,7 +174,7 @@ private async Task SendTakedownNoticeAsync(TakedownNoticeCreateDto dto, Organiza MessageTemplateDsc = template.GetContent(), IsHostContactedExternally = dto.HostEmailSent, IsSubmitterCcRequired = true, - MessageReasonId = reasonDto?.Id, + MessageReasonId = null, LgPhoneNo = dto.LgContactPhone, UnreportedListingNo = dto.ListingId, HostEmailAddressDsc = dto.HostEmail, @@ -187,7 +194,7 @@ private async Task SendTakedownNoticeAsync(TakedownNoticeCreateDto dto, Organiza _unitOfWork.Commit(); } - private TakedownNotice GetTakedownNoticeTemplate(TakedownNoticeCreateDto dto, OrganizationDto? platform, DropdownNumDto? reasonDto, bool preview = false) + private TakedownNotice GetTakedownNoticeTemplate(TakedownNoticeCreateDto dto, OrganizationDto? platform, OrganizationDto? lg, bool preview = false) { // To: [host] (optional), [Local Gov contact info email] if (dto.HostEmail.IsNotEmpty()) dto.ToList.Add(dto.HostEmail); @@ -201,11 +208,9 @@ private TakedownNotice GetTakedownNoticeTemplate(TakedownNoticeCreateDto dto, Or var template = new TakedownNotice(_emailService) { - Reason = reasonDto!.Description, Url = dto.ListingUrl, ListingId = dto.ListingId, - LgContactInfo = dto.LgContactEmail, - LgStrBylawLink = dto.StrBylawUrl, + LgName = lg!.OrganizationNm, To = dto.ToList, Bcc = dto.CcList, Info = dto.ListingUrl, @@ -218,15 +223,15 @@ private TakedownNotice GetTakedownNoticeTemplate(TakedownNoticeCreateDto dto, Or public async Task<(Dictionary> errors, EmailPreview preview)> GetTakedownNoticePreviewAsync(TakedownNoticeCreateDto dto) { var platform = await _orgService.GetOrganizationByIdAsync(dto.PlatformId); - var reasonDto = await _emailService.GetMessageReasonByMessageTypeAndId(EmailMessageTypes.NoticeOfTakedown, dto.ReasonId); + var lg = await _orgService.GetOrganizationByIdAsync(_currentUser.OrganizationId); - var errors = await ValidateTakedownNoticeAsync(dto, platform, reasonDto); + var errors = await ValidateTakedownNoticeAsync(dto, platform, lg); if (errors.Count > 0) { return (errors, new EmailPreview()); } - var template = GetTakedownNoticeTemplate(dto, platform, reasonDto, true); + var template = GetTakedownNoticeTemplate(dto, platform, lg, true); return (errors, new EmailPreview { Content = template.GetContent().HtmlToPlainText() }); } diff --git a/server/StrDss.Service/EmailTemplates/TakedownNotice.cs b/server/StrDss.Service/EmailTemplates/TakedownNotice.cs index dd552889..2b984271 100644 --- a/server/StrDss.Service/EmailTemplates/TakedownNotice.cs +++ b/server/StrDss.Service/EmailTemplates/TakedownNotice.cs @@ -10,26 +10,26 @@ public TakedownNotice(IEmailMessageService emailService) EmailMessageType = EmailMessageTypes.NoticeOfTakedown; } - public string Reason { get; set; } = ""; public string Url { get; set; } = ""; public string? ListingId { get; set; } - public string LgContactInfo { get; set; } = ""; - public string LgStrBylawLink { get; set; } = ""; public string Comment { get; set; } = ""; + public string LgName { get; set; } = ""; + public override string GetContent() { Subject = "Notice of non-compliance with short-term rental business licence requirement"; return (Preview ? GetPreviewContent() : "") + $@" Dear Host,

-Short-term rental accommodations in your community are regulated by your local government.

-The local government has determined that the following short-term rental listing is not in compliance with an applicable local government business licence requirement:

+Short-term rental accommodations in your community are regulated by your local government. The {LgName} has determined that the following short-term rental listing is not in compliance with an applicable local government business licence requirement:

{Url}

Listing ID Number: {ListingId}

-Under the provincial Short-Term Rental Accommodations Act and its regulations, the local government may submit a request to the short-term rental platform to cease providing platform services (e.g., remove this listing from the platform) within a period of 5-90 days after the date of delivery of this Notice. Short-term rental platforms are required to comply with the local government’s request within 5 days of receiving the request.

+Under the provincial Short-Term Rental Accommodations Act and its regulations, the local government may submit a request to the short-term rental platform to cease providing platform services (e.g., remove this listing from the platform and cancel all bookings) within a period of 5-90 days after the date of delivery of this Notice. Short-term rental platforms are required to comply with the local government’s request within 5 days of receiving the request.

+This Notice has been issued by {LgName}.

+{Comment}

For more information on this Notice, or local government short-term rental business licences, please contact your local government.

For more information on the Short-term Rental Accommodations Act, please visit: New rules for short-term rentals - Province of British Columbia (gov.bc.ca).

-{ Comment}

+ This email has been automatically generated. Please do not reply to this email. A copy of this Notice has been sent to the short-term rental platform.

"; }