PDJB-1275: Part 2: Fix other assumptions a landlord has a base user ID - #1654
PDJB-1275: Part 2: Fix other assumptions a landlord has a base user ID#1654samyou-softwire wants to merge 15 commits into
Conversation
| import org.springframework.data.jpa.repository.JpaRepository | ||
| import uk.gov.communities.prsdb.webapp.database.entity.OrganisationLandlordUser | ||
|
|
||
| // TODO: PDJB-1275: Move org landlord access checking to use this table |
| ) { | ||
| fun isAddressOwned(uprn: Long): Boolean = propertyOwnershipRepository.existsByIsActiveTrueAndAddress_Uprn(uprn) | ||
|
|
||
| fun isAddressOwnedByUser( |
There was a problem hiding this comment.
this was unused
ffe9a28 to
5db182d
Compare
0163c8e to
8469ec7
Compare
5db182d to
0b68d23
Compare
58de050 to
d4d0ffa
Compare
now it handles whether the current user can request as part of the service, checking landlord details and local council details
d4d0ffa to
537dbf6
Compare
Travis-Softwire
left a comment
There was a problem hiding this comment.
What a monster! I've left some comments but nothing blocking, happy for it to be merged once they've been addressed
| ) | ||
| } | ||
|
|
||
| if (landlordService.retrieveLandlordByBaseUserId(principal.name) != null) { |
There was a problem hiding this comment.
It looks like we've just removed this check altogether? Should we not instead check if the current user is associated with a landlord? This still feels like a failure mode worth checking
| @RequestMapping(LANDLORD_BASE_URL, "/") | ||
| class LandlordController( | ||
| private val landlordService: LandlordService, | ||
| private val userToLandlordService: UserToLandlordService, |
There was a problem hiding this comment.
Not for this PR, but the heavy use of this has got me thinking about whether we should cache the landlord ID in session on login, which would not only save at least one DB roundtrip per call for most LL endpoints, but would also potentially make our system operator functionality MUCH simpler to implement when we get there.
| throw ResponseStatusException( | ||
| HttpStatus.NOT_FOUND, | ||
| "User $baseUserId is not authorized to update property ownership $propertyOwnershipId", | ||
| "Current user is not authorized to update property ownership $propertyOwnershipId", |
There was a problem hiding this comment.
This is a loss of fidelity in the logs that I don't think is necessary - we can still grab the base user Id to tell us who was trying to access something they shouldn't have been
| private val updateConfirmationSender: EmailNotificationService<LandlordUpdateConfirmation>, | ||
| private val absoluteUrlProvider: AbsoluteUrlProvider, | ||
| ) { | ||
| fun retrieveLandlordByRegNum(regNum: RegistrationNumberDataModel): Landlord? { |
There was a problem hiding this comment.
Were we not using this? I thought we let LCs search by LRN?
| fun getPropertyOwnershipIfCurrentUserAuthorized(propertyOwnershipId: Long): PropertyOwnership { | ||
| val propertyOwnership = getPropertyOwnership(propertyOwnershipId) | ||
| val baseUserId = SecurityContextHolder.getContext().authentication.name | ||
| val landlord = userToLandlordService.getLandlordForBaseUserIdOrNull(baseUserId) |
There was a problem hiding this comment.
Why this vs the getCurrentLandlordForUser you've used everywhere else?
| @@ -89,8 +85,9 @@ class LandlordController( | |||
| @RequestParam(value = "page", required = false) @Min(1) page: Int = 1, | |||
There was a problem hiding this comment.
Are we still using the principal param?
| @@ -80,11 +80,9 @@ class InviteJointLandlordController( | |||
| @PathVariable invitationId: Long, | |||
There was a problem hiding this comment.
Still using the principal param?
| @@ -96,22 +94,19 @@ class InviteJointLandlordController( | |||
| principal: Principal, | |||
There was a problem hiding this comment.
Still using the principal param?
| whenever(mockPropertyOwnershipService.getPropertyOwnership(propertyId)).thenReturn(propertyOwnership) | ||
| setMockPrincipal(baseUserId) | ||
| whenever(mockLandlordService.retrieveLandlordByBaseUserId(baseUserId)).thenReturn(null) | ||
| whenever(mockUserToLandlordService.getCurrentLandlordForUser()).thenThrow(PrsdbWebException("Landlord not found")) |
There was a problem hiding this comment.
Is this test actually testing anything now or just asserting on the mock directly?
| 2, | ||
| 3, | ||
| "USER_ID", | ||
| 1, |
There was a problem hiding this comment.
Careful here that we're using the correct arg in the correct place - might be worth using named arguments just in case these args change again in the future
Ticket number
PDJB-1275
Goal of change
remove all general assumptions from the codebase that a landlord has a single base user ID
Description of main change(s)
fixes many controllers & services to use the general methods for getting the current landlord, and uses the landlord to compare base user IDs
Anything you'd like to highlight to the reviewer?
this does not include any changes in function around org landlords. all of these changes should be stuff that would be expected to 'just work' with org landlords. any cases where we may want function to change (emails, page copy etc) are covered by specific tickets, referenced in TODO
most of the changes in this PR are uninteresting, removing the principal param from controllers etc. of particular note are the services which will now base their logic off of landlords directly
Checklist
and any related functionality) not currently based on main, but does work locally right now
mention that here