Skip to content

Commit

Permalink
Merge pull request #153 from bcgov/yj
Browse files Browse the repository at this point in the history
feat(dss-305): remove organization id from takedown request dto
  • Loading branch information
ychung-mot authored Apr 16, 2024
2 parents df10bbe + 324fa4b commit 5abadfc
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
- CHANGELOG.md
- .conventional-changelog.mjs
- .release-it.json
- postman/**
- localdb/**
- postgres/**
- crunchydb/**

jobs:
build-backend:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Our CI/CD process is facilitated through GitHub Actions, ensuring seamless integ
- Facilitates deployment of selected tag's images into the `Production` environment.
- Triggered through the GitHub UI upon publishing a new release from a tag.

1. [Create Version Tag with Changelog PR](./.github/workflows/create-tag-changelog-pr.yml):
1. [Create Version Tag](./.github/workflows/create-tag.yml):

- Supports for generating version tags.
- Triggered through the GitHub UI, allowing specification of tag versions excluding prefixes.
Expand Down
12 changes: 6 additions & 6 deletions postman/str-dss.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"platformId\": 2,\r\n \"listingId\": 1,\r\n \"listingUrl\": \"https://www.airbnb.com/rooms/16120388?check_in=2024-04-25&check_out=2024-04-27&guests=1&adults=1&s=67&unique_share_id=fa107d24-b0df-49bd-91e4-576dd7d368ab\",\r\n \"hostEmail\": \"young-jin.chung@gov.bc.ca\",\r\n \"hostEmailSent\": false, \r\n \"reasonId\": 1,\r\n \"sendCopy\": true,\r\n \"ccList\": [\r\n \"young-jin.chung@dxcas.com\"\r\n ],\r\n \"lgContactEmail\": \"lgcontact@lg.ca\",\r\n \"lgContactPhone\": \"123-456-7890\",\r\n \"strBylawUrl\": \"https://bylaw.ca\",\r\n \"comment\": \"Test comment\"\r\n}",
"raw": "{\r\n \"platformId\": 2,\r\n \"listingId\": \"1\",\r\n \"listingUrl\": \"https://www.airbnb.com/rooms/16120388?check_in=2024-04-25&check_out=2024-04-27&guests=1&adults=1&s=67&unique_share_id=fa107d24-b0df-49bd-91e4-576dd7d368ab\",\r\n \"hostEmail\": \"young-jin.chung@gov.bc.ca\",\r\n \"hostEmailSent\": false, \r\n \"reasonId\": 1,\r\n \"sendCopy\": true,\r\n \"ccList\": [\r\n \"young-jin.chung@dxcas.com\"\r\n ],\r\n \"lgContactEmail\": \"lgcontact@lg.ca\",\r\n \"lgContactPhone\": \"123-456-7890\",\r\n \"strBylawUrl\": \"https://bylaw.ca\",\r\n \"comment\": \"Test comment\"\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -98,7 +98,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"platformId\": 2,\r\n \"listingId\": 1,\r\n \"listingUrl\": \"https://www.airbnb.com/rooms/16120388?check_in=2024-04-25&check_out=2024-04-27&guests=1&adults=1&s=67&unique_share_id=fa107d24-b0df-49bd-91e4-576dd7d368ab\",\r\n \"hostEmail\": \"young-jin.chung@dxc.com\",\r\n \"hostEmailSent\": false, \r\n \"reasonId\": 5,\r\n \"sendCopy\": true,\r\n \"ccList\": [\r\n \"young-jin.chung@dxcas.com\"\r\n ],\r\n \"lgContactEmail\": \"lgcontact@lg.ca\",\r\n \"lgContactPhone\": \"123-456-7890\",\r\n \"strBylawUrl\": \"https://bylaw.ca\",\r\n \"comment\": \"Test comment\"\r\n}",
"raw": "{\r\n \"platformId\": 2,\r\n \"listingId\": \"1\",\r\n \"listingUrl\": \"https://www.airbnb.com/rooms/16120388?check_in=2024-04-25&check_out=2024-04-27&guests=1&adults=1&s=67&unique_share_id=fa107d24-b0df-49bd-91e4-576dd7d368ab\",\r\n \"hostEmail\": \"\",\r\n \"hostEmailSent\": true, \r\n \"reasonId\": 5,\r\n \"ccList\": [\r\n \"young-jin.chung@dxcas.com\"\r\n ],\r\n \"lgContactEmail\": \"lgcontact@lg.ca\",\r\n \"lgContactPhone\": \"123-456-7890\",\r\n \"strBylawUrl\": \"https://bylaw.ca\",\r\n \"comment\": \"Test comment\"\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -127,7 +127,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"lgId\": 1,\r\n \"platformId\": 2,\r\n \"listingId\": 1,\r\n \"listingUrl\": \"https://www.airbnb.com/rooms/16120388?check_in=2024-04-25&check_out=2024-04-27&guests=1&adults=1&s=67&unique_share_id=fa107d24-b0df-49bd-91e4-576dd7d368ab\",\r\n \"sendCopy\": true,\r\n \"ccList\": [\r\n \"young-jin.1.chung@gov.bc.ca\"\r\n ]\r\n}",
"raw": "{\r\n \"platformId\": 2,\r\n \"listingId\": \"1\",\r\n \"listingUrl\": \"https://www.airbnb.com/rooms/16120388?check_in=2024-04-25&check_out=2024-04-27&guests=1&adults=1&s=67&unique_share_id=fa107d24-b0df-49bd-91e4-576dd7d368ab\",\r\n \"sendCopy\": true,\r\n \"ccList\": [\r\n \"young-jin.1.chung@gov.bc.ca\"\r\n ]\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -155,7 +155,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"lgId\": 1,\r\n \"platformId\": 2,\r\n \"listingId\": 1,\r\n \"listingUrl\": \"https://www.airbnb.com/rooms/16120388?check_in=2024-04-25&check_out=2024-04-27&guests=1&adults=1&s=67&unique_share_id=fa107d24-b0df-49bd-91e4-576dd7d368ab\",\r\n \"sendCopy\": true,\r\n \"ccList\": [\r\n \"young-jin.1.chung@gov.bc.ca\"\r\n ]\r\n}",
"raw": "{\r\n \"platformId\": 2,\r\n \"listingId\": \"1\",\r\n \"listingUrl\": \"https://www.airbnb.com/rooms/16120388?check_in=2024-04-25&check_out=2024-04-27&guests=1&adults=1&s=67&unique_share_id=fa107d24-b0df-49bd-91e4-576dd7d368ab\",\r\n \"sendCopy\": true,\r\n \"ccList\": [\r\n \"young-jin.1.chung@gov.bc.ca\"\r\n ]\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -559,7 +559,7 @@
"formdata": [
{
"key": "ReportPeriod",
"value": "2024-05",
"value": "2024-03",
"type": "text"
},
{
Expand All @@ -570,7 +570,7 @@
{
"key": "File",
"type": "file",
"src": "postman-cloud:///1eef47cf-0716-4770-88ff-15d6dd59453f"
"src": "/C:/Users/chungy/OneDrive - Advanced Solutions, a DXC Technology Company/Documents/STR/listing-valid2.csv"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions server/StrDss.Api/Authentication/KcJwtBearerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public override async Task TokenValidated(TokenValidatedContext context)
_currentUser.AccessRequestStatus = user.AccessRequestStatusCd;
_currentUser.AccessRequestRequired = _currentUser.AccessRequestStatus == AccessRequestStatuses.Denied;
_currentUser.OrganizationType = user.RepresentedByOrganization?.OrganizationType ?? "";
_currentUser.OrganizationId = user.RepresentedByOrganizationId ?? 0;
_currentUser.TermsAcceptanceDtm = user.TermsAcceptanceDtm;

if (user.IsEnabled)
Expand Down
4 changes: 3 additions & 1 deletion server/StrDss.Model/CurrentUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface ICurrentUser
public bool AccessRequestRequired { get; set; }
public List<string> Permissions { get; set; }
public string OrganizationType { get; set; }
public long OrganizationId { get; set; }
public DateTime? TermsAcceptanceDtm { get; set; }
void LoadUserSession(ClaimsPrincipal user);
void AddClaim(ClaimsPrincipal user, string claimType, string value);
Expand All @@ -44,7 +45,8 @@ public class CurrentUser : ICurrentUser
public string AccessRequestStatus { get; set; } = "";
public bool AccessRequestRequired { get; set; }
public List<string> Permissions { get; set; } = new List<string>();
public string OrganizationType { get; set; }
public string OrganizationType { get; set; } = "";
public long OrganizationId { get; set; }
public DateTime? TermsAcceptanceDtm { get; set; }

public void LoadUserSession(ClaimsPrincipal user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace StrDss.Model.DelistingDtos
{
public class TakedownRequestCreateDto
{
public long LgId { get; set; }
public long PlatformId { get; set; }
public string? ListingId { get; set; }
public string ListingUrl { get; set; } = "";
Expand Down
6 changes: 3 additions & 3 deletions server/StrDss.Service/DelistingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private TakedownNotice GetTakedownNoticeTemplate(TakedownNoticeCreateDto dto, Or
public async Task<Dictionary<string, List<string>>> CreateTakedownRequestAsync(TakedownRequestCreateDto dto)
{
var platform = await _orgService.GetOrganizationByIdAsync(dto.PlatformId);
var lg = await _orgService.GetOrganizationByIdAsync(dto.LgId);
var lg = await _orgService.GetOrganizationByIdAsync(_currentUser.OrganizationId);

var errors = await ValidateTakedownRequestAsync(dto, platform, lg);
if (errors.Count > 0)
Expand Down Expand Up @@ -280,7 +280,7 @@ private async Task<Dictionary<string, List<string>>> ValidateTakedownRequestAsyn

if (lg == null)
{
errors.AddItem("lgId", $"Local Government ID ({dto.LgId}) does not exist.");
errors.AddItem("lgId", $"Local Government ID ({_currentUser.OrganizationId}) does not exist.");
}
else
{
Expand Down Expand Up @@ -366,7 +366,7 @@ private TakedownRequest GetTakedownRequestTemplate(TakedownRequestCreateDto dto,
public async Task<(Dictionary<string, List<string>> errors, EmailPreview preview)> GetTakedownRequestPreviewAsync(TakedownRequestCreateDto dto)
{
var platform = await _orgService.GetOrganizationByIdAsync(dto.PlatformId);
var lg = await _orgService.GetOrganizationByIdAsync(dto.LgId);
var lg = await _orgService.GetOrganizationByIdAsync(_currentUser.OrganizationId);

var errors = await ValidateTakedownRequestAsync(dto, platform, lg);
if (errors.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public object Create(object request, ISpecimenContext context)
return 1;
case nameof(TakedownRequestCreateDto.ListingId):
return 1;
case nameof(TakedownRequestCreateDto.LgId):
return 2;

case nameof(TakedownRequestCreateDto.ListingUrl):
return "https://example.com/listing";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public object Create(object request, ISpecimenContext context)
switch (pi.Name)
{
case nameof(OrganizationDto.OrganizationId):
return 1;
return 2;
case nameof(OrganizationDto.OrganizationType):
return OrganizationTypes.Platform;
case nameof(OrganizationDto.OrganizationCd):
Expand Down
15 changes: 9 additions & 6 deletions server/StrDss.Test/DelistingServiceShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using Microsoft.Extensions.Logging;
using Moq;
using StrDss.Common;
using StrDss.Data.Entities;
using StrDss.Data.Repositories;
using StrDss.Model;
using StrDss.Model.DelistingDtos;
using StrDss.Model.OrganizationDtos;
Expand Down Expand Up @@ -323,18 +321,19 @@ public async Task ValidateDelistingRequest_NullLocalGovernment_ReturnsLocalGover
[Frozen] Mock<IConfiguration> configMock,
[Frozen] Mock<IChesTokenApi> chesTokenApiMock,
[Frozen] Mock<ILogger<StrDssLogger>> loggerMock,
[Frozen] Mock<ICurrentUser> currentUserMock,
DelistingService sut)
{
// Arrange
dto.LgId = 0;
currentUserMock.Setup(m => m.OrganizationId).Returns(0);

// Act
var result = await sut.CreateTakedownRequestAsync(dto);

// Assert
Assert.Contains("lgId", result.Keys);
Assert.Single(result["lgId"]);
Assert.Equal($"Local Government ID ({dto.LgId}) does not exist.", result["lgId"].First());
Assert.Equal($"Local Government ID (0) does not exist.", result["lgId"].First());
}

[Theory]
Expand Down Expand Up @@ -506,12 +505,14 @@ public async Task SendDelistingRequestAsync_WhenCalled_ShouldSendEmail(
DelistingService sut)
{
// Arrange
dto.PlatformId = 2;
currentUserMock.Setup(m => m.EmailAddress).Returns("currentUser@example.com");
currentUserMock.Setup(m => m.OrganizationId).Returns(1);
orgServiceMock.Setup(x => x.GetOrganizationByIdAsync(dto.PlatformId)).ReturnsAsync(platform);

var lg = CommonUtils.CloneObject(platform);
lg.OrganizationType = OrganizationTypes.LG;
orgServiceMock.Setup(x => x.GetOrganizationByIdAsync(dto.LgId)).ReturnsAsync(lg);
orgServiceMock.Setup(x => x.GetOrganizationByIdAsync(1)).ReturnsAsync(lg);

platform.ContactPeople.First().EmailMessageType = EmailMessageTypes.TakedownRequest;

Expand All @@ -534,13 +535,15 @@ public async Task SendDelistingRequestAsync_WhenSendCopyIsTrue_AddsCurrentUserEm
{
// Arrange
dto.SendCopy = true;
dto.PlatformId = 2;
var currentUserEmail = "user@example.com";
currentUserMock.Setup(m => m.EmailAddress).Returns(currentUserEmail);
currentUserMock.Setup(m => m.OrganizationId).Returns(1);
orgServiceMock.Setup(x => x.GetOrganizationByIdAsync(dto.PlatformId)).ReturnsAsync(platform);

var lg = CommonUtils.CloneObject(platform);
lg.OrganizationType = OrganizationTypes.LG;
orgServiceMock.Setup(x => x.GetOrganizationByIdAsync(dto.LgId)).ReturnsAsync(lg);
orgServiceMock.Setup(x => x.GetOrganizationByIdAsync(1)).ReturnsAsync(lg);

platform.ContactPeople.First().EmailMessageType = EmailMessageTypes.TakedownRequest;

Expand Down

0 comments on commit 5abadfc

Please sign in to comment.