Skip to content

Commit

Permalink
Merge branch 'IS-101.00' of https://github.com/dfilteau/PSP into IS-1…
Browse files Browse the repository at this point in the history
…01.00
  • Loading branch information
dfilteau committed Mar 5, 2025
2 parents 3255c79 + 14924fc commit c9e2abc
Show file tree
Hide file tree
Showing 81 changed files with 4,922 additions and 5,950 deletions.
10 changes: 0 additions & 10 deletions source/backend/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Net.Compilers" Version="4.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.8.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers;</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\..\.editorconfig" />
Expand Down
26 changes: 25 additions & 1 deletion source/backend/api/Areas/Leases/Controllers/LeaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public IActionResult AddLease(LeaseModel leaseModel, [FromQuery] string[] userOv
}

/// <summary>
/// Update the specified lease, and attached properties.
/// Update the specified lease.
/// </summary>
/// <returns></returns>
[HttpPut("{id:long}")]
Expand All @@ -146,6 +146,30 @@ public IActionResult UpdateLease(LeaseModel leaseModel, [FromQuery] string[] use
return new JsonResult(_mapper.Map<LeaseModel>(updatedLease));
}

/// <summary>
/// Update the lease file properties.
/// </summary>
/// <returns></returns>
[HttpPut("{id:long}/properties")]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(LeaseModel), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult UpdateLeaseProperties([FromBody] LeaseModel leaseModel, [FromQuery] string[] userOverrideCodes)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseController),
nameof(UpdateLease),
User.GetUsername(),
DateTime.Now);

var leaseEntity = _mapper.Map<Dal.Entities.PimsLease>(leaseModel);
var lease = _leaseService.UpdateProperties(leaseEntity, userOverrideCodes.Select(oc => UserOverrideCode.Parse(oc)));
return new JsonResult(_mapper.Map<LeaseModel>(lease));
}

/// <summary>
/// Get the lease checklist items.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion source/backend/api/Pims.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<UserSecretsId>0ef6255f-9ea0-49ec-8c65-c172304b4926</UserSecretsId>
<Version>5.8.0-100.18</Version>
<Version>5.8.0-100.19</Version>
<AssemblyVersion>5.8.0.100</AssemblyVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProjectGuid>{16BC0468-78F6-4C91-87DA-7403C919E646}</ProjectGuid>
Expand Down
2 changes: 2 additions & 0 deletions source/backend/api/Services/ILeaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface ILeaseService

PimsLease Update(PimsLease lease, IEnumerable<UserOverrideCode> userOverrides);

PimsLease UpdateProperties(PimsLease lease, IEnumerable<UserOverrideCode> userOverrides);

IEnumerable<PimsPropertyLease> GetPropertiesByLeaseId(long leaseId);

IEnumerable<PimsInsurance> GetInsuranceByLeaseId(long leaseId);
Expand Down
40 changes: 32 additions & 8 deletions source/backend/api/Services/LeaseService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Claims;
using System.Text;
Expand Down Expand Up @@ -254,8 +255,12 @@ public PimsLease Update(PimsLease lease, IEnumerable<UserOverrideCode> userOverr

var pimsUser = _userRepository.GetByKeycloakUserId(_user.GetUserKey());
var currentLease = _leaseRepository.GetNoTracking(lease.LeaseId);
if (currentLease == null)
{
throw new InvalidDataException("Invalid lease");
}

var currentLeaseStatus = _leaseStatusSolver.GetCurrentLeaseStatus(currentLease?.LeaseStatusTypeCode);
var currentLeaseStatus = _leaseStatusSolver.GetCurrentLeaseStatus(currentLease.LeaseStatusTypeCode);
if (!_leaseStatusSolver.CanEditDetails(currentLeaseStatus) && !_user.HasPermission(Permissions.SystemAdmin))
{
throw new BusinessRuleViolationException("The file you are editing is not active, so you cannot save changes. Refresh your browser to see file state.");
Expand All @@ -264,8 +269,6 @@ public PimsLease Update(PimsLease lease, IEnumerable<UserOverrideCode> userOverr
pimsUser.ThrowInvalidAccessToLeaseFile(currentLease.RegionCode); // need to check that the user is able to access the current lease as well as has the region for the updated lease.
pimsUser.ThrowInvalidAccessToLeaseFile(lease.RegionCode);

var currentFileProperties = _propertyLeaseRepository.GetAllByLeaseId(lease.LeaseId);

if (currentLease.LeaseStatusTypeCode != lease.LeaseStatusTypeCode)
{
PimsLeaseNote newLeaseNote = GeneratePimsLeaseNote(currentLease, lease);
Expand All @@ -278,8 +281,30 @@ public PimsLease Update(PimsLease lease, IEnumerable<UserOverrideCode> userOverr
ValidateNewTotalAllowableCompensation(lease.LeaseId, lease.TotalAllowableCompensation);

_leaseRepository.Update(lease, false);

_leaseRepository.UpdateLeaseRenewals(lease.Internal_Id, lease.ConcurrencyControlNumber, lease.PimsLeaseRenewals);

_leaseRepository.CommitTransaction();

return _leaseRepository.GetNoTracking(lease.LeaseId);
}

public PimsLease UpdateProperties(PimsLease lease, IEnumerable<UserOverrideCode> userOverrides)
{
_logger.LogInformation("Updating lease properties with lease id {id}", lease.LeaseId);
_user.ThrowIfNotAuthorized(Permissions.LeaseEdit, Permissions.PropertyView, Permissions.PropertyAdd);

var pimsUser = _userRepository.GetByKeycloakUserId(_user.GetUserKey());
var currentLease = _leaseRepository.GetNoTracking(lease.LeaseId);
var currentLeaseStatus = _leaseStatusSolver.GetCurrentLeaseStatus(currentLease?.LeaseStatusTypeCode);

pimsUser.ThrowInvalidAccessToLeaseFile(currentLease.RegionCode); // need to check that the user is able to access the current lease as well as has the region for the updated lease.
pimsUser.ThrowInvalidAccessToLeaseFile(lease.RegionCode);

var leaseWithProperties = AssociatePropertyLeases(lease, userOverrides);

var currentFileProperties = _propertyLeaseRepository.GetAllByLeaseId(lease.LeaseId);

// Update marker locations in the context of this file
foreach (var incomingLeaseProperty in leaseWithProperties.PimsPropertyLeases)
{
Expand Down Expand Up @@ -313,9 +338,8 @@ public PimsLease Update(PimsLease lease, IEnumerable<UserOverrideCode> userOverr
{
throw new BusinessRuleViolationException("The file you are editing is not active, so you cannot save changes. Refresh your browser to see file state.");
}
_propertyLeaseRepository.UpdatePropertyLeases(lease.Internal_Id, leaseWithProperties.PimsPropertyLeases);

_leaseRepository.UpdateLeaseRenewals(lease.Internal_Id, lease.ConcurrencyControlNumber, lease.PimsLeaseRenewals);
_propertyLeaseRepository.UpdatePropertyLeases(lease.Internal_Id, leaseWithProperties.PimsPropertyLeases);

List<PimsPropertyLease> differenceSet = currentFileProperties.Where(x => !lease.PimsPropertyLeases.Any(y => y.Internal_Id == x.Internal_Id)).ToList();
foreach (var deletedProperty in differenceSet)
Expand All @@ -338,9 +362,9 @@ public PimsLease Update(PimsLease lease, IEnumerable<UserOverrideCode> userOverr
}
}

_leaseRepository.CommitTransaction();
_propertyLeaseRepository.CommitTransaction();

return _leaseRepository.GetNoTracking(lease.LeaseId);
return _leaseRepository.Get(lease.Internal_Id);
}

public IEnumerable<PimsLeaseRenewal> GetRenewalsByLeaseId(long leaseId)
Expand Down Expand Up @@ -505,7 +529,7 @@ private static void ValidateRenewalDates(PimsLease lease, PimsLease currentLease
{
if (renewal.CommencementDt.HasValue && renewal.ExpiryDt.HasValue)
{
renewalDates.Add(new Tuple<long, DateTime, DateTime>(renewal.LeaseRenewalId, renewal.CommencementDt.Value, renewal.ExpiryDt.Value)) ;
renewalDates.Add(new Tuple<long, DateTime, DateTime>(renewal.LeaseRenewalId, renewal.CommencementDt.Value, renewal.ExpiryDt.Value));
}
else
{
Expand Down
13 changes: 0 additions & 13 deletions source/backend/entities/Partials/PropertyMgmtActivitySubType.cs

This file was deleted.

41 changes: 15 additions & 26 deletions source/backend/tests/unit/api/Services/LeaseServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
using Pims.Api.Models.CodeTypes;
using Pims.Api.Services;
using Pims.Core.Exceptions;
using Pims.Core.Security;
using Pims.Core.Test;
using Pims.Dal;
using Pims.Dal.Entities;
using Pims.Dal.Exceptions;
using Pims.Dal.Repositories;
using Pims.Core.Security;
using Xunit;

namespace Pims.Api.Test.Services
Expand Down Expand Up @@ -537,7 +537,6 @@ public void UpdateProperties_Success()

// Assert
leaseRepository.Verify(x => x.Update(lease, false), Times.Once);
propertyService.Verify(x => x.UpdateLocation(It.IsAny<PimsProperty>(), ref It.Ref<PimsProperty>.IsAny, It.IsAny<IEnumerable<UserOverrideCode>>(), false), Times.Once);
}

[Fact]
Expand Down Expand Up @@ -587,7 +586,7 @@ public void UpdateProperties_WithDisposedProperty_Should_Fail()
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
Action act = () => service.Update(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });
Action act = () => service.UpdateProperties(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });

// Assert
var ex = act.Should().Throw<BusinessRuleViolationException>();
Expand Down Expand Up @@ -647,11 +646,11 @@ public void UpdateProperties_WithExistingDisposedProperty_Should_Pass()
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
Action act = () => service.Update(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });
Action act = () => service.UpdateProperties(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });

// Assert
var ex = act.Should().NotThrow<BusinessRuleViolationException>();
leaseRepository.Verify(x => x.Update(lease, false), Times.Once);
propertyLeaseRepository.Verify(x => x.UpdatePropertyLeases(lease.LeaseId, It.IsAny<List<PimsPropertyLease>>()), Times.Once);
}

[Fact]
Expand Down Expand Up @@ -684,7 +683,7 @@ public void UpdateProperties_WithRetiredProperty_Should_Fail()
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
Action act = () => service.Update(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });
Action act = () => service.UpdateProperties(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });

// Assert
var ex = act.Should().Throw<BusinessRuleViolationException>();
Expand Down Expand Up @@ -717,10 +716,10 @@ public void UpdateProperties_MatchProperties_Success()
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
var updatedLease = service.Update(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });
var updatedLease = service.UpdateProperties(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });

// Assert
leaseRepository.Verify(x => x.Update(lease, false), Times.Once);
propertyLeaseRepository.Verify(x => x.UpdatePropertyLeases(lease.LeaseId, It.IsAny<List<PimsPropertyLease>>()), Times.Once);
propertyService.Verify(x => x.UpdateLocation(It.IsAny<PimsProperty>(), ref It.Ref<PimsProperty>.IsAny, It.IsAny<IEnumerable<UserOverrideCode>>(), false), Times.Once);
}

Expand Down Expand Up @@ -772,7 +771,7 @@ public void Update_CommencementDate_Overlap_ExpiryDate_Success()

// Assert
leaseRepository.Verify(x => x.Update(lease, false), Times.Once);
propertyService.Verify(x => x.UpdateLocation(It.IsAny<PimsProperty>(), ref It.Ref<PimsProperty>.IsAny, It.IsAny<IEnumerable<UserOverrideCode>>(), false), Times.Once);
propertyService.Verify(x => x.UpdateLocation(It.IsAny<PimsProperty>(), ref It.Ref<PimsProperty>.IsAny, It.IsAny<IEnumerable<UserOverrideCode>>(), false), Times.Never);
}

[Fact]
Expand Down Expand Up @@ -825,7 +824,7 @@ public void Update_CommencementDate_Overlap_ExpiryDate_MODIFIED_ThrowOverride()
};
updatedLease.OrigStartDate = new DateTime(2024, 1, 1);
updatedLease.OrigExpiryDate = new DateTime(2025, 1, 31);

// Act
Action act = () => service.Update(updatedLease, new List<UserOverrideCode>() { });

Expand Down Expand Up @@ -917,20 +916,10 @@ public void UpdateProperties_MatchProperties_NewProperty_Success()
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
var updatedLease = service.Update(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });
PimsPropertyLease updatedLeaseProperty = updatedLease.PimsPropertyLeases.First();
var updatedLease = service.UpdateProperties(lease, new List<UserOverrideCode>() { UserOverrideCode.AddLocationToProperty });

// Assert
// since this is a new property, the following default fields should be set.
var updatedProperty = updatedLeaseProperty.Property;
newProperty.PropertyTypeCode.Should().Be("UNKNOWN");
newProperty.PropertyStatusTypeCode.Should().Be("UNKNOWN");
newProperty.SurplusDeclarationTypeCode.Should().Be("UNKNOWN");
newProperty.PropertyDataSourceEffectiveDate.Should().Be(DateOnly.FromDateTime(DateTime.Now));
newProperty.PropertyDataSourceTypeCode.Should().Be("PMBC");
newProperty.IsOwned.Should().Be(false);

leaseRepository.Verify(x => x.Update(lease, false), Times.Once);
propertyLeaseRepository.Verify(x => x.UpdatePropertyLeases(lease.LeaseId, It.IsAny<List<PimsPropertyLease>>()), Times.Once);
propertyService.Verify(x => x.PopulateNewProperty(It.IsAny<PimsProperty>(), It.IsAny<Boolean>(), It.IsAny<Boolean>()), Times.Once);
}

Expand Down Expand Up @@ -962,7 +951,7 @@ public void UpdateProperties_RemovePropertyFile_Success()
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
updatedLease = service.Update(updatedLease, new List<UserOverrideCode>());
updatedLease = service.UpdateProperties(updatedLease, new List<UserOverrideCode>());

// Assert
propertyLeaseRepository.Verify(x => x.UpdatePropertyLeases(It.IsAny<long>(), It.IsAny<ICollection<PimsPropertyLease>>()));
Expand Down Expand Up @@ -1000,7 +989,7 @@ public void UpdateProperties_RemoveProperty_Fails_PropertyAssignedToCompReq()
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
Action act = () => service.Update(updatedLease, new List<UserOverrideCode>());
Action act = () => service.UpdateProperties(updatedLease, new List<UserOverrideCode>());

// Assert
act.Should().Throw<BusinessRuleViolationException>().WithMessage("Lease File property can not be removed since it's assigned as a property for a compensation requisition");
Expand Down Expand Up @@ -1037,7 +1026,7 @@ public void UpdateProperties_RemoveProperty_Fails_PropertyIsSubdividedOrConsolid
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
Action act = () => service.Update(updatedLease, new List<UserOverrideCode>());
Action act = () => service.UpdateProperties(updatedLease, new List<UserOverrideCode>());

// Assert
act.Should().Throw<BusinessRuleViolationException>().WithMessage("This property cannot be deleted because it is part of a subdivision or consolidation");
Expand Down Expand Up @@ -1074,7 +1063,7 @@ public void UpdateProperties_RemoveProperty_Success()
solver.Setup(x => x.CanEditProperties(It.IsAny<LeaseStatusTypes?>())).Returns(true);

// Act
updatedLease = service.Update(updatedLease, new List<UserOverrideCode>());
updatedLease = service.UpdateProperties(updatedLease, new List<UserOverrideCode>());

// Assert
propertyLeaseRepository.Verify(x => x.UpdatePropertyLeases(It.IsAny<long>(), It.IsAny<ICollection<PimsPropertyLease>>()));
Expand Down
2 changes: 1 addition & 1 deletion source/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "5.8.0-100.18",
"version": "5.8.0-100.19",
"private": true,
"dependencies": {
"@bcgov/bc-sans": "1.0.1",
Expand Down
1 change: 1 addition & 0 deletions source/frontend/src/AppRouter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ vi.mocked(useApiLeases).mockReturnValue({
getLeaseChecklist: vi.fn(),
getLeaseRenewals: vi.fn(),
getLeaseStakeholderTypes: vi.fn(),
putLeaseProperties: vi.fn(),
});

vi.mock('./hooks/pims-api/useApiAcquisitionFile');
Expand Down
4 changes: 4 additions & 0 deletions source/frontend/src/constants/formDocumentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ export enum FormDocumentType {
H179T = 'H179T',
// General Letter
LETTER = 'LETTER',
// >Licence of Occupation for Public Highway (H-1005)
H1005 = 'H1005',
// >Licence of Occupation (BCTFA as licensor) (H-1005 A)
H1005A = 'H1005A',
}
Loading

0 comments on commit c9e2abc

Please sign in to comment.