Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.springframework.context.ApplicationContext
import uk.gov.communities.prsdb.webapp.annotations.taskAnnotations.PrsdbScheduledTask
import uk.gov.communities.prsdb.webapp.annotations.taskAnnotations.PrsdbTaskService
import uk.gov.communities.prsdb.webapp.constants.INCOMPLETE_PROPERTY_AGE_WHEN_REMINDER_EMAIL_DUE_IN_DAYS
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.exceptions.PersistentEmailSendException
import uk.gov.communities.prsdb.webapp.exceptions.TrackEmailSentException
import uk.gov.communities.prsdb.webapp.exceptions.TransientEmailSentException
Expand Down Expand Up @@ -56,17 +55,18 @@ class IncompletePropertiesReminderTaskLogic(
LocalDate.now().minusDays(INCOMPLETE_PROPERTY_AGE_WHEN_REMINDER_EMAIL_DUE_IN_DAYS.toLong()),
)

val pagesOfProperties = incompletePropertiesService.getNumberOfPagesOfIncompletePropertiesOlderThanDate(cutoffDate)
val pagesOfProperties =
incompletePropertiesService.getNumberOfPagesOfIncompletePropertiesOlderThanDate(cutoffDate)

for (page in 0..<pagesOfProperties) {
val incompleteProperties = incompletePropertiesService.getIncompletePropertiesDueReminderPage(cutoffDate, page)
val incompleteProperties =
incompletePropertiesService.getIncompletePropertiesDueReminderPage(cutoffDate, page)
incompleteProperties.forEach { property ->
// TODO: PDJB-1274: Update emails to account for org landlord
val landlord = property.landlord
check(landlord is IndividualLandlord)
try {
emailSender.sendEmail(
landlord.email,
landlord.contactEmail,
IncompletePropertyReminderEmail(
singleLineAddress =
property.savedJourneyState.getPropertyRegistrationSingleLineAddress(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class IndividualLandlord() : Landlord() {
override val displayEmail: String
get() = email

@get:Transient
override val contactName: String
get() = name

@get:Transient
override val contactEmail: String
get() = email

@OneToOne
@JoinColumn(name = "individual_subject_identifier", unique = true)
lateinit var baseUser: PrsdbUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ abstract class Landlord : ModifiableAuditableEntity() {
@get:Transient
abstract val displayEmail: String

@get:Transient
abstract val contactName: String

// TODO PDJB-1274: This method is temporary - a landlord will soon not have a single email
@get:Transient
abstract val contactEmail: String

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
open val id: Long = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package uk.gov.communities.prsdb.webapp.database.entity
import jakarta.persistence.Column
import jakarta.persistence.DiscriminatorValue
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.Transient
import uk.gov.communities.prsdb.webapp.constants.enums.CharityRegulator
import uk.gov.communities.prsdb.webapp.constants.enums.LandlordType
Expand All @@ -25,6 +27,16 @@ class OrganisationLandlord() : Landlord() {
override val displayEmail: String
get() = email

@get:Transient
override val contactName: String
// TODO PDJB-1274: The single-user assumption must be removed to support multiple organisation users.
get() = organisationLandlordUsers.single().name

@get:Transient
override val contactEmail: String
// TODO PDJB-1274: The single-user assumption must be removed to support multiple organisation users.
get() = organisationLandlordUsers.single().email

@Column(name = "organisation_landlord_name")
lateinit var name: String

Expand Down Expand Up @@ -93,6 +105,13 @@ class OrganisationLandlord() : Landlord() {
@Column(name = "organisation_main_contact_phone")
lateinit var mainContactPhone: String

@OneToMany(mappedBy = "organisationLandlord", fetch = FetchType.EAGER)
private val organisationLandlordUsers: MutableSet<OrganisationLandlordUser> = mutableSetOf()

internal fun addOrganisationLandlordUser(organisationLandlordUser: OrganisationLandlordUser) {
organisationLandlordUsers.add(organisationLandlordUser)
}

constructor(
registrationNumber: RegistrationNumber,
name: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.communities.prsdb.webapp.database.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
Expand Down Expand Up @@ -27,9 +28,22 @@ class OrganisationLandlordUser() : AuditableEntity() {
@JoinColumn(name = "subject_identifier", nullable = false)
lateinit var baseUser: PrsdbUser

constructor(organisationLandlord: OrganisationLandlord, baseUser: PrsdbUser) : this() {
@Column(nullable = false)
lateinit var name: String

@Column(nullable = false)
lateinit var email: String

constructor(
organisationLandlord: OrganisationLandlord,
baseUser: PrsdbUser,
name: String,
email: String,
) : this() {
this.organisationLandlord = organisationLandlord
this.baseUser = baseUser
this.name = name
this.email = email
organisationLandlord.addOrganisationLandlordUser(this)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.communities.prsdb.webapp.journeys.acceptOrRejectJointLandlordInvitation.steps

import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.JourneyFrameworkComponent
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.database.entity.Landlord
import uk.gov.communities.prsdb.webapp.database.entity.PropertyOwnership
import uk.gov.communities.prsdb.webapp.journeys.AbstractRequestableStepConfig
Expand Down Expand Up @@ -85,11 +84,10 @@ class ConfirmYouAreALandlordForThisPropertyStepConfig(
RegistrationNumberDataModel.fromRegistrationNumber(propertyOwnership.registrationNumber).toString()

// TODO: PDJB-1274: Update emails to account for org landlord
check(acceptingLandlord is IndividualLandlord)
acceptedEmailSender.sendEmail(
acceptingLandlord.email,
acceptingLandlord.contactEmail,
JointLandlordInvitationAcceptedEmail(
recipientName = acceptingLandlord.name,
recipientName = acceptingLandlord.contactName,
propertyAddress = propertyAddress,
propertyRecordUrl = propertyRecordUrl,
propertyRegistrationNumber = propertyRegistrationNumber,
Expand All @@ -100,12 +98,11 @@ class ConfirmYouAreALandlordForThisPropertyStepConfig(
.filter { it.id != acceptingLandlord.id }
// TODO: PDJB-1274: Update emails to account for org landlord
.forEach { landlord ->
check(landlord is IndividualLandlord)
otherLandlordEmailSender.sendEmail(
landlord.email,
landlord.contactEmail,
JointLandlordInvitationAcceptedOtherLandlordEmail(
recipientName = landlord.name,
inviteeName = acceptingLandlord.name,
recipientName = landlord.contactName,
inviteeName = acceptingLandlord.displayName,
propertyAddress = propertyAddress,
propertyRecordUrl = propertyRecordUrl,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.communities.prsdb.webapp.journeys.acceptOrRejectJointLandlordInvitation.steps

import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.JourneyFrameworkComponent
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.journeys.AbstractInternalStepConfig
import uk.gov.communities.prsdb.webapp.journeys.JourneyStep
import uk.gov.communities.prsdb.webapp.journeys.acceptOrRejectJointLandlordInvitation.AcceptOrRejectJointLandlordInvitationJourneyState
Expand Down Expand Up @@ -29,11 +28,10 @@ class SendRejectionEmailsStepConfig(

// TODO: PDJB-1274: Update emails to account for org landlord
invitation.registeredOwnership.landlords.forEach { landlord ->
check(landlord is IndividualLandlord)
rejectionEmailSender.sendEmail(
landlord.email,
landlord.contactEmail,
JointLandlordInvitationRejectionEmail(
recipientName = landlord.name,
recipientName = landlord.contactName,
inviteeEmail = invitation.invitedEmail,
propertyAddress = propertyAddress,
propertyRecordUrl = propertyRecordUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.communities.prsdb.webapp.journeys.cancelJointLandlordInvitation.stepConfig

import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.JourneyFrameworkComponent
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.journeys.AbstractInternalStepConfig
import uk.gov.communities.prsdb.webapp.journeys.Destination
import uk.gov.communities.prsdb.webapp.journeys.JourneyStep
Expand Down Expand Up @@ -51,11 +50,10 @@ class CancelInvitationStepConfig(

// Email the canceller
// TODO: PDJB-1274: Update emails to account for org landlord
check(cancellerLandlord is IndividualLandlord)
cancellerEmailSender.sendEmail(
cancellerLandlord.email,
cancellerLandlord.contactEmail,
JointLandlordInvitationCancellationCancellerEmail(
recipientName = cancellerLandlord.name,
recipientName = cancellerLandlord.contactName,
invitedEmail = state.invitedEmail,
propertyAddress = propertyAddress,
propertyRecordUrl = propertyRecordUrl,
Expand All @@ -67,11 +65,10 @@ class CancelInvitationStepConfig(
.filterNot { cancellerLandlord.id == it.id }
// TODO: PDJB-1274: Update emails to account for org landlord
.forEach {
check(it is IndividualLandlord)
otherLandlordEmailSender.sendEmail(
it.email,
it.contactEmail,
JointLandlordInvitationCancellationOtherLandlordEmail(
recipientName = it.name,
recipientName = it.contactName,
invitedEmail = state.invitedEmail,
propertyAddress = propertyAddress,
propertyRecordUrl = propertyRecordUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package uk.gov.communities.prsdb.webapp.journeys.landlordDeregistration.stepConf

import org.springframework.security.core.context.SecurityContextHolder
import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.JourneyFrameworkComponent
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.journeys.AbstractInternalStepConfig
import uk.gov.communities.prsdb.webapp.journeys.Destination
import uk.gov.communities.prsdb.webapp.journeys.JourneyStep
Expand Down Expand Up @@ -40,8 +39,7 @@ class DeregisterStepConfig(
landlordDeregistrationService.addLandlordHadActivePropertiesToSession(landlordHadActiveSoloProperties)

// TODO: PDJB-1274: Update emails to account for org landlord
check(landlord is IndividualLandlord)
val landlordEmailAddress = landlord.email
val landlordEmailAddress = landlord.contactEmail

if (landlordHadActiveSoloProperties) {
// TODO PDJB-311: This email does not address properties that are not deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package uk.gov.communities.prsdb.webapp.journeys.propertyDeregistration.stepConf

import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.JourneyFrameworkComponent
import uk.gov.communities.prsdb.webapp.controllers.PropertyDetailsController
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.journeys.AbstractRequestableStepConfig
import uk.gov.communities.prsdb.webapp.journeys.Destination
import uk.gov.communities.prsdb.webapp.journeys.JourneyStep.RequestableStep
Expand Down Expand Up @@ -58,16 +57,18 @@ class ConfirmStepConfig(
// TODO: PDJB-1274: Update emails to account for org landlord
val landlordContacts =
propertyOwnership.landlords.map { landlord ->
check(landlord is IndividualLandlord)
landlord.name to landlord.email
landlord.contactName to landlord.contactEmail
}
val cancelledInvitationEmailAddresses =
jointLandlordInvitationService.getPendingInvitations(propertyOwnership).map { it.invitedEmail }
val singleLineAddress = propertyOwnership.address.singleLineAddress
val multiLineAddress = propertyOwnership.address.toMultiLineAddress()

propertyDeregistrationService.deregisterProperty(state.propertyOwnershipId)
propertyDeregistrationService.addDeregisteredPropertyOwnershipIdToSession(state.propertyOwnershipId, singleLineAddress)
propertyDeregistrationService.addDeregisteredPropertyOwnershipIdToSession(
state.propertyOwnershipId,
singleLineAddress,
)

landlordContacts.forEach { (landlordName, landlordEmail) ->
confirmationEmailSender.sendEmail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import uk.gov.communities.prsdb.webapp.constants.CONFIRMATION_PATH_SEGMENT
import uk.gov.communities.prsdb.webapp.constants.PROPERTY_REGISTRATION_RESTRUCTURE_AND_SKIPPING
import uk.gov.communities.prsdb.webapp.constants.TASK_LIST_PATH_SEGMENT
import uk.gov.communities.prsdb.webapp.controllers.RegisterPropertyController.Companion.PROPERTY_REGISTRATION_ROUTE
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.exceptions.PrsdbWebException
import uk.gov.communities.prsdb.webapp.journeys.AbstractJourneyState
import uk.gov.communities.prsdb.webapp.journeys.AndParents
Expand Down Expand Up @@ -645,11 +644,7 @@ class PropertyRegistrationJourney(

override val loggedInLandlordEmail: String?
// TODO: PDJB-1274: Update emails to account for org landlord
get() {
val landlord = userToLandlordService.getCurrentLandlordForUser()
check(landlord is IndividualLandlord)
return landlord.email
}
get() = userToLandlordService.getCurrentLandlordForUser().contactEmail

companion object {
fun generateSeedForUser(user: Principal): String = "Prop reg journey for user ${user.name} at time ${System.currentTimeMillis()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import uk.gov.communities.prsdb.webapp.constants.CONFIRMATION_PATH_SEGMENT
import uk.gov.communities.prsdb.webapp.constants.LANDLORD_DETAILS_FRAGMENT
import uk.gov.communities.prsdb.webapp.controllers.InviteJointLandlordController
import uk.gov.communities.prsdb.webapp.controllers.PropertyDetailsController
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.exceptions.PrsdbWebException
import uk.gov.communities.prsdb.webapp.journeys.AbstractPropertyOwnershipUpdateJourneyState
import uk.gov.communities.prsdb.webapp.journeys.Destination
Expand Down Expand Up @@ -186,7 +185,7 @@ class InviteJointLandlordJourney(

// TODO: PDJB-1274: Update emails to account for org landlord
override val existingLandlordEmails: List<String>
get() = propertyOwnershipService.getPropertyOwnership(propertyId).landlords.map { (it as IndividualLandlord).email }
get() = propertyOwnershipService.getPropertyOwnership(propertyId).landlords.map { it.contactEmail }
}

interface InviteJointLandlordJourneyState :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import jakarta.servlet.http.HttpSession
import jakarta.transaction.Transactional
import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.JourneyFrameworkComponent
import uk.gov.communities.prsdb.webapp.constants.SWITCHED_TO_INDIVIDUAL_PROPERTY_ID
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.exceptions.PrsdbWebException
import uk.gov.communities.prsdb.webapp.journeys.AbstractInternalStepConfig
import uk.gov.communities.prsdb.webapp.journeys.Destination
Expand Down Expand Up @@ -44,10 +43,9 @@ class CompleteSwitchToIndividualStepConfig(

// TODO: PDJB-1274: Update emails to account for org landlord
val landlord = propertyOwnership.landlords.first()
check(landlord is IndividualLandlord)
switchToIndividualConfirmationEmailSender.sendEmail(
landlord.email,
SwitchToIndividualConfirmationEmail(landlordName = landlord.name, propertyAddress = propertyAddress),
landlord.contactEmail,
SwitchToIndividualConfirmationEmail(landlordName = landlord.contactName, propertyAddress = propertyAddress),
)

for (invitation in pendingInvitations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package uk.gov.communities.prsdb.webapp.models.dataModels.updateModels
import uk.gov.communities.prsdb.webapp.models.dataModels.AddressDataModel
import java.time.LocalDate

data class LandlordUpdateModel(
data class IndividualLandlordUpdateModel(
val email: String? = null,
val name: String? = null,
val phoneNumber: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package uk.gov.communities.prsdb.webapp.services
import uk.gov.communities.prsdb.webapp.annotations.taskAnnotations.PrsdbTaskService
import uk.gov.communities.prsdb.webapp.constants.JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS
import uk.gov.communities.prsdb.webapp.constants.enums.JointLandlordInvitationStatus
import uk.gov.communities.prsdb.webapp.database.entity.IndividualLandlord
import uk.gov.communities.prsdb.webapp.database.entity.JointLandlordInvitation
import uk.gov.communities.prsdb.webapp.database.repository.JointLandlordInvitationRepository
import uk.gov.communities.prsdb.webapp.exceptions.PersistentEmailSendException
Expand Down Expand Up @@ -48,11 +47,10 @@ class JointLandlordInvitationExpiryEmailService(

// TODO: PDJB-1274: Update emails to account for org landlord
propertyOwnership.landlords.forEach { recipient ->
check(recipient is IndividualLandlord)
expiryEmailNotificationService.sendEmail(
recipient.email,
recipient.contactEmail,
JointLandlordInvitationExpiryEmail(
recipientName = recipient.name,
recipientName = recipient.contactName,
invitedEmail = invitation.invitedEmail,
propertyAddress = propertyAddress,
propertyRecordUri = propertyRecordUri,
Expand Down
Loading
Loading