Skip to content

Commit

Permalink
feat(dss-304) populated lg name in the takedown notice template
Browse files Browse the repository at this point in the history
  • Loading branch information
ychung-mot committed Apr 17, 2024
1 parent 12ccb65 commit 476a132
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
37 changes: 21 additions & 16 deletions server/StrDss.Service/DelistingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ public DelistingService(ICurrentUser currentUser, IFieldValidatorService validat
public async Task<Dictionary<string, List<string>>> 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<Dictionary<string, List<string>>> ValidateTakedownNoticeAsync(TakedownNoticeCreateDto dto, OrganizationDto? platform, DropdownNumDto? reasonDto)
private async Task<Dictionary<string, List<string>>> ValidateTakedownNoticeAsync(TakedownNoticeCreateDto dto, OrganizationDto? platform, OrganizationDto? lg)
{
await Task.CompletedTask;

Expand Down Expand Up @@ -114,9 +114,16 @@ private async Task<Dictionary<string, List<string>>> 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);
Expand Down Expand Up @@ -156,9 +163,9 @@ private async Task<Dictionary<string, List<string>>> 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
{
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -218,15 +223,15 @@ private TakedownNotice GetTakedownNoticeTemplate(TakedownNoticeCreateDto dto, Or
public async Task<(Dictionary<string, List<string>> 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() });
}
Expand Down
14 changes: 7 additions & 7 deletions server/StrDss.Service/EmailTemplates/TakedownNotice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,<br/><br/>
Short-term rental accommodations in your community are regulated by your local government.<br/><br/>
The local government has determined that the following short-term rental listing is not in compliance with an applicable local government business licence requirement:<br/><br/>
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:<br/><br/>
<b>{Url}</b><br/><br/>
Listing ID Number: <b>{ListingId}</b><br/><br/>
Under the provincial <a href='https://www.bclaws.gov.bc.ca/civix/document/id/bills/billsprevious/4th42nd:gov35-1'>Short-Term Rental Accommodations Act</a> 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.<br/><br/>
Under the provincial <a href='https://www.bclaws.gov.bc.ca/civix/document/id/bills/billsprevious/4th42nd:gov35-1'>Short-Term Rental Accommodations Act</a> 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.<br/><br/>
This Notice has been issued by {LgName}.<br/><br/>
{Comment}<br/><br/>
For more information on this Notice, or local government short-term rental business licences, please contact your local government.<br/><br/>
For more information on the Short-term Rental Accommodations Act, please visit: <a href='https://www2.gov.bc.ca/gov/content/housing-tenancy/short-term-rentals'>New rules for short-term rentals - Province of British Columbia (gov.bc.ca)</a>.<br/><br/>
{ Comment}<br/><br/>
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.<br/><br/>
";
}
Expand Down

0 comments on commit 476a132

Please sign in to comment.