Skip to content
Open
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
@@ -0,0 +1,109 @@
package uk.gov.communities.prsdb.webapp.controllers

import org.springframework.http.HttpStatus
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.server.ResponseStatusException
import org.springframework.web.servlet.ModelAndView
import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.AvailableWhenFeatureEnabled
import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.PrsdbController
import uk.gov.communities.prsdb.webapp.constants.CONFIRMATION_PATH_SEGMENT
import uk.gov.communities.prsdb.webapp.constants.JOINT_LANDLORDS
import uk.gov.communities.prsdb.webapp.constants.LANDLORD_DETAILS_FRAGMENT
import uk.gov.communities.prsdb.webapp.constants.LANDLORD_PATH_SEGMENT
import uk.gov.communities.prsdb.webapp.constants.PROPERTY_DETAILS_SEGMENT
import uk.gov.communities.prsdb.webapp.controllers.InviteJointLandlordController.Companion.INVITE_JOINT_LANDLORD_ROUTE
import uk.gov.communities.prsdb.webapp.journeys.FormData
import uk.gov.communities.prsdb.webapp.journeys.JourneyStateService
import uk.gov.communities.prsdb.webapp.journeys.NoSuchJourneyException
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.update.inviteJointLandlord.InviteJointLandlordJourneyFactory
import uk.gov.communities.prsdb.webapp.services.PropertyOwnershipService
import java.security.Principal

@PrsdbController
@RequestMapping(INVITE_JOINT_LANDLORD_ROUTE)
@PreAuthorize("hasRole('LANDLORD')")
class InviteJointLandlordController(
private val journeyFactory: InviteJointLandlordJourneyFactory,
private val propertyOwnershipService: PropertyOwnershipService,
) {
@GetMapping("{stepName}")
@AvailableWhenFeatureEnabled(JOINT_LANDLORDS)
fun getUpdateStep(
principal: Principal,
@PathVariable propertyOwnershipId: Long,
@PathVariable("stepName") stepName: String,
): ModelAndView {
throwErrorIfUserIsNotAuthorized(principal.name, propertyOwnershipId)
return try {
val journeyMap = journeyFactory.createJourneySteps(propertyOwnershipId)
journeyMap[stepName]?.getStepModelAndView()
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Step not found")
} catch (_: NoSuchJourneyException) {
val journeyId = journeyFactory.initializeJourneyState(propertyOwnershipId, principal)
val redirectUrl = JourneyStateService.urlWithJourneyState(stepName, journeyId)
ModelAndView("redirect:$redirectUrl")
}
}

@PostMapping("{stepName}")
@AvailableWhenFeatureEnabled(JOINT_LANDLORDS)
fun postUpdateStep(
model: Model,
principal: Principal,
@PathVariable propertyOwnershipId: Long,
@PathVariable("stepName") stepName: String,
@RequestParam formData: FormData,
): ModelAndView {
throwErrorIfUserIsNotAuthorized(principal.name, propertyOwnershipId)
return try {
val journeyMap = journeyFactory.createJourneySteps(propertyOwnershipId)
journeyMap[stepName]?.postStepModelAndView(formData)
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Step not found")
} catch (_: NoSuchJourneyException) {
val journeyId = journeyFactory.initializeJourneyState(propertyOwnershipId, principal)
val redirectUrl = JourneyStateService.urlWithJourneyState(stepName, journeyId)
ModelAndView("redirect:$redirectUrl")
}
}

@GetMapping(CONFIRMATION_PATH_SEGMENT)
@AvailableWhenFeatureEnabled(JOINT_LANDLORDS)
fun getConfirmation(
model: Model,
principal: Principal,
@PathVariable propertyOwnershipId: Long,
): String {
throwErrorIfUserIsNotAuthorized(principal.name, propertyOwnershipId)
model.addAttribute(
"propertyDetailsUrl",
PropertyDetailsController.getPropertyDetailsPath(propertyOwnershipId) + "#$LANDLORD_DETAILS_FRAGMENT",
)
return "inviteJointLandlordConfirmation"
}

private fun throwErrorIfUserIsNotAuthorized(
baseUserId: String,
propertyOwnershipId: Long,
) {
if (!propertyOwnershipService.getIsAuthorizedToEditRecord(propertyOwnershipId, baseUserId)) {
throw ResponseStatusException(
HttpStatus.NOT_FOUND,
"User $baseUserId is not authorized to update property ownership $propertyOwnershipId",
)
}
}

companion object {
const val INVITE_JOINT_LANDLORD_ROUTE =
"/$LANDLORD_PATH_SEGMENT/$PROPERTY_DETAILS_SEGMENT/{propertyOwnershipId}/invite-joint-landlord"

fun getInviteJointLandlordRoute(propertyOwnershipId: Long): String =
INVITE_JOINT_LANDLORD_ROUTE.replace("{propertyOwnershipId}", propertyOwnershipId.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import uk.gov.communities.prsdb.webapp.journeys.hasOutcome
import uk.gov.communities.prsdb.webapp.journeys.isComplete
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.CertificateUpload
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.CombinedComplianceCheckState
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.JointLandlordsState
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.InviteJointLandlordPropertyRegistrationState
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.LicensingState
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.OccupationState
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.PropertyRegistrationAddressState
Expand All @@ -33,7 +33,6 @@ import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.Check
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.CheckEpcAnswersStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.CheckGasCertUploadsStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.CheckGasSafetyAnswersStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.CheckJointLandlordsStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.ConfirmEpcDetailsRetrievedByCertificateNumberStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.ConfirmEpcRetrievedByUprnStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.ConfirmMissingComplianceCheckResult
Expand Down Expand Up @@ -69,7 +68,6 @@ import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.HasMi
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.HmoAdditionalLicenceStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.HmoMandatoryLicenceStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.HouseholdStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.InviteJointLandlordStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.IsEpcRequiredStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.LicensingTypeStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.LocalCouncilStep
Expand All @@ -86,7 +84,6 @@ import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.Provi
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.ProvideGasCertLaterStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.RemoveElectricalCertUploadStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.RemoveGasCertUploadStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.RemoveJointLandlordAreYouSureStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.RentAmountStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.RentFrequencyStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.RentIncludesBillsStep
Expand All @@ -109,6 +106,10 @@ import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.tasks.Occup
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.tasks.PropertyRegistrationAddressTask
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.tasks.RentFrequencyAndAmountTask
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.tasks.RentIncludesBillsTask
import uk.gov.communities.prsdb.webapp.journeys.shared.inviteJointLandlord.CheckJointLandlordsStep
import uk.gov.communities.prsdb.webapp.journeys.shared.inviteJointLandlord.InviteJointLandlordStep
import uk.gov.communities.prsdb.webapp.journeys.shared.inviteJointLandlord.RemoveJointLandlordAreYouSureStep
import uk.gov.communities.prsdb.webapp.journeys.shared.inviteJointLandlord.SharedInviteJointLandlordsTask
import uk.gov.communities.prsdb.webapp.journeys.shared.states.CheckYourAnswersJourneyState
import uk.gov.communities.prsdb.webapp.journeys.shared.states.CheckYourAnswersJourneyState.Companion.checkAnswerStep
import uk.gov.communities.prsdb.webapp.journeys.shared.states.CheckYourAnswersJourneyState.Companion.checkAnswerTask
Expand Down Expand Up @@ -436,6 +437,7 @@ class PropertyRegistrationJourney(
override val rentAmount: RentAmountStep,
// Joint landlords task
override val jointLandlordsTask: JointLandlordsTask,
override val inviteJointLandlordsTask: SharedInviteJointLandlordsTask,
override val hasAnyJointLandlordsInvitedStep: HasAnyJointLandlordsInvitedStep,
override val hasJointLandlordsStep: HasJointLandlordsStep,
override val inviteJointLandlordStep: InviteJointLandlordStep,
Expand Down Expand Up @@ -572,7 +574,7 @@ interface PropertyRegistrationJourneyState :
PropertyRegistrationAddressState,
LicensingState,
OccupationState,
JointLandlordsState,
InviteJointLandlordPropertyRegistrationState,
CombinedComplianceCheckState,
CheckYourAnswersJourneyState {
val taskListStep: PropertyRegistrationTaskListStep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states

import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.HasAnyJointLandlordsInvitedStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.steps.HasJointLandlordsStep
import uk.gov.communities.prsdb.webapp.journeys.shared.inviteJointLandlord.SharedInviteJointLandlordsTask
import uk.gov.communities.prsdb.webapp.journeys.shared.states.SharedInviteJointLandlordState

interface InviteJointLandlordPropertyRegistrationState : SharedInviteJointLandlordState {
val hasAnyJointLandlordsInvitedStep: HasAnyJointLandlordsInvitedStep
val hasJointLandlordsStep: HasJointLandlordsStep
val inviteJointLandlordsTask: SharedInviteJointLandlordsTask
}

enum class AnyLandlordsInvited {
NO_LANDLORDS,
SOME_LANDLORDS,
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.JourneyFramewo
import uk.gov.communities.prsdb.webapp.journeys.AbstractInternalStepConfig
import uk.gov.communities.prsdb.webapp.journeys.JourneyStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.AnyLandlordsInvited
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.JointLandlordsState
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.InviteJointLandlordPropertyRegistrationState

@JourneyFrameworkComponent
class HasAnyJointLandlordsInvitedStepConfig : AbstractInternalStepConfig<AnyLandlordsInvited, JointLandlordsState>() {
override fun mode(state: JointLandlordsState) =
class HasAnyJointLandlordsInvitedStepConfig :
AbstractInternalStepConfig<AnyLandlordsInvited, InviteJointLandlordPropertyRegistrationState>() {
override fun mode(state: InviteJointLandlordPropertyRegistrationState) =
if (state.invitedJointLandlords.isNotEmpty()) AnyLandlordsInvited.SOME_LANDLORDS else AnyLandlordsInvited.NO_LANDLORDS
}

@JourneyFrameworkComponent
final class HasAnyJointLandlordsInvitedStep(
stepConfig: HasAnyJointLandlordsInvitedStepConfig,
) : JourneyStep.InternalStep<AnyLandlordsInvited, JointLandlordsState>(stepConfig)
) : JourneyStep.InternalStep<AnyLandlordsInvited, InviteJointLandlordPropertyRegistrationState>(stepConfig)
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import uk.gov.communities.prsdb.webapp.annotations.webAnnotations.JourneyFramewo
import uk.gov.communities.prsdb.webapp.constants.GOV_LEGAL_ADVICE_URL
import uk.gov.communities.prsdb.webapp.journeys.AbstractRequestableStepConfig
import uk.gov.communities.prsdb.webapp.journeys.JourneyStep.RequestableStep
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.JointLandlordsState
import uk.gov.communities.prsdb.webapp.journeys.propertyRegistration.states.InviteJointLandlordPropertyRegistrationState
import uk.gov.communities.prsdb.webapp.journeys.shared.YesOrNo
import uk.gov.communities.prsdb.webapp.models.requestModels.formModels.HasJointLandlordsFormModel
import uk.gov.communities.prsdb.webapp.models.viewModels.formModels.RadiosButtonViewModel

@JourneyFrameworkComponent
class HasJointLandlordsConfig : AbstractRequestableStepConfig<YesOrNo, HasJointLandlordsFormModel, JointLandlordsState>() {
class HasJointLandlordsConfig :
AbstractRequestableStepConfig<YesOrNo, HasJointLandlordsFormModel, InviteJointLandlordPropertyRegistrationState>() {
override val formModelClass = HasJointLandlordsFormModel::class

override fun getStepSpecificContent(state: JointLandlordsState) =
override fun getStepSpecificContent(state: InviteJointLandlordPropertyRegistrationState) =
mapOf(
"title" to "registerProperty.title",
"fieldSetHeading" to "jointLandlords.hasJointLandlords.heading",
Expand All @@ -32,9 +33,9 @@ class HasJointLandlordsConfig : AbstractRequestableStepConfig<YesOrNo, HasJointL
"findLegalAdviceUrl" to GOV_LEGAL_ADVICE_URL,
)

override fun chooseTemplate(state: JointLandlordsState): String = "forms/hasJointLandlordsForm"
override fun chooseTemplate(state: InviteJointLandlordPropertyRegistrationState): String = "forms/hasJointLandlordsForm"

override fun mode(state: JointLandlordsState): YesOrNo? =
override fun mode(state: InviteJointLandlordPropertyRegistrationState): YesOrNo? =
getFormModelFromStateOrNull(state)?.hasJointLandlords?.let {
when (it) {
true -> YesOrNo.YES
Expand All @@ -46,7 +47,7 @@ class HasJointLandlordsConfig : AbstractRequestableStepConfig<YesOrNo, HasJointL
@JourneyFrameworkComponent
final class HasJointLandlordsStep(
stepConfig: HasJointLandlordsConfig,
) : RequestableStep<YesOrNo, HasJointLandlordsFormModel, JointLandlordsState>(stepConfig) {
) : RequestableStep<YesOrNo, HasJointLandlordsFormModel, InviteJointLandlordPropertyRegistrationState>(stepConfig) {
companion object {
const val ROUTE_SEGMENT = "has-joint-landlords"
}
Expand Down
Loading
Loading