-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSP-7929 : Backend error - For all files do not include a retired property on selection #3884
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using System.Security.Claims; | ||
using Microsoft.Extensions.Logging; | ||
using Pims.Api.Models.CodeTypes; | ||
using Pims.Core.Exceptions; | ||
using Pims.Core.Extensions; | ||
using Pims.Dal.Entities; | ||
using Pims.Dal.Entities.Models; | ||
|
@@ -184,6 +185,11 @@ public PimsLease Add(PimsLease lease, IEnumerable<UserOverrideCode> userOverride | |
var pimsUser = _userRepository.GetByKeycloakUserId(_user.GetUserKey()); | ||
pimsUser.ThrowInvalidAccessToLeaseFile(lease.RegionCode); | ||
|
||
if (lease.PimsPropertyLeases.Any(x => x.Property.IsRetired.HasValue && x.Property.IsRetired.Value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like your pattern here is to add this logic to both the service and also to the repository, but not in the case of leases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
{ | ||
throw new BusinessRuleViolationException("Retired property can not be selected."); | ||
} | ||
|
||
var leasesWithProperties = AssociatePropertyLeases(lease, userOverrides); | ||
return _leaseRepository.Add(leasesWithProperties); | ||
} | ||
|
@@ -237,7 +243,7 @@ public PimsLease Update(PimsLease lease, IEnumerable<UserOverrideCode> userOverr | |
List<PimsPropertyLease> differenceSet = currentProperties.Where(x => !lease.PimsPropertyLeases.Any(y => y.Internal_Id == x.Internal_Id)).ToList(); | ||
foreach (var deletedProperty in differenceSet) | ||
{ | ||
if (deletedProperty.Property.IsPropertyOfInterest == true) | ||
if (deletedProperty.Property.IsPropertyOfInterest) | ||
{ | ||
PimsProperty propertyWithAssociations = _propertyRepository.GetAllAssociationsById(deletedProperty.PropertyId); | ||
var leaseAssociationCount = propertyWithAssociations.PimsPropertyLeases.Count; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using System.Security.Claims; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using Pims.Core.Exceptions; | ||
using Pims.Core.Extensions; | ||
using Pims.Dal.Entities; | ||
|
||
|
@@ -62,6 +63,11 @@ public PimsPropertyAcquisitionFile Add(PimsPropertyAcquisitionFile propertyAcqui | |
{ | ||
propertyAcquisitionFile.ThrowIfNull(nameof(propertyAcquisitionFile)); | ||
|
||
if (propertyAcquisitionFile.Property.IsRetired.HasValue && propertyAcquisitionFile.Property.IsRetired.Value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do sort of like having this logic at the repository level, because that means regardless of what service calls this, the user will be unable to add an acq file with a retired property. Is there a good argument for also having this at the service level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not particularly besides short-circuiting the method and the fact that the repository Add is only called in this Service so it's more contained. But yeah, I guess it could be done in the repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
{ | ||
throw new BusinessRuleViolationException("Retired property can not be selected."); | ||
} | ||
|
||
// Mark the property not to be changed if it did not exist already. | ||
if (propertyAcquisitionFile.PropertyId != 0) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, yes. This appears to only affect add but I imagine it should affect update as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you were expecting the repository to handle file update adding new properties? in that case the lease property probably needs something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The adding does not call the AcquisitionFilePropertyRepository methods, so the check had to be added in the Service.
For the update I am taking into consideration the developer note that states: "Although if a property is already on a file, it can be ignored during this process." So it's only when "UpdatingProperties" and the flow is to "Add".