-
Notifications
You must be signed in to change notification settings - Fork 1
PDJB-300: Add invitation lists to property page #1402
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
base: main
Are you sure you want to change the base?
Changes from all commits
f32b887
3d72102
e878a50
856ec34
b5f3f46
d3777f9
16e86a9
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package uk.gov.communities.prsdb.webapp.constants | ||
|
|
||
| const val LOCAL_COUNCIL_INVITATION_LIFETIME_IN_HOURS: Int = 48 | ||
| const val JOINT_LANDLORD_INVITATION_LIFETIME_IN_HOURS: Int = 672 // 28 days | ||
| const val JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS: Int = 28 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,13 @@ import jakarta.persistence.GenerationType | |
| import jakarta.persistence.Id | ||
| import jakarta.persistence.JoinColumn | ||
| import jakarta.persistence.ManyToOne | ||
| import kotlinx.datetime.DatePeriod | ||
| import kotlinx.datetime.plus | ||
| import kotlinx.datetime.toKotlinInstant | ||
| import uk.gov.communities.prsdb.webapp.constants.JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS | ||
| import uk.gov.communities.prsdb.webapp.helpers.DateTimeHelper | ||
| import java.time.Instant | ||
| import java.time.temporal.ChronoUnit | ||
| import java.util.UUID | ||
|
|
||
| @Entity | ||
|
|
@@ -33,6 +40,24 @@ class JointLandlordInvitation( | |
| lateinit var invitingLandlord: Landlord | ||
| private set | ||
|
|
||
| val expiryDate: Instant | ||
| get() = createdDate.plus(JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS.toLong(), ChronoUnit.DAYS) | ||
|
|
||
| val daysUntilExpiry: Long | ||
| get() = ChronoUnit.DAYS.between(Instant.now(), expiryDate).coerceAtLeast(0) | ||
|
|
||
| val isExpired: Boolean | ||
| get() { | ||
| val dateTimeHelper = DateTimeHelper() | ||
|
|
||
| val expiresOnDate = | ||
| DateTimeHelper | ||
| .getDateInUK(createdDate.toKotlinInstant()) | ||
| .plus(DatePeriod(days = JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS)) | ||
|
|
||
| return dateTimeHelper.getCurrentDateInUK() > expiresOnDate | ||
| } | ||
|
|
||
|
Comment on lines
+43
to
+60
Collaborator
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'm just slightly nervous that we have some non-trivial date arithmetic here that all ought to agree. Might be worth some tests for this to check that they all behave as expected, and consistently with each other? Especially at common problem times, like near midnight or near a DST change.
Contributor
Author
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. see #1401 which I'll rebase in when it's merged, there will be some stringent tests for this |
||
| constructor( | ||
| token: UUID, | ||
| email: String, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package uk.gov.communities.prsdb.webapp.models.viewModels | ||
|
|
||
| import kotlinx.datetime.toJavaLocalDate | ||
| import kotlinx.datetime.toKotlinInstant | ||
| import uk.gov.communities.prsdb.webapp.database.entity.JointLandlordInvitation | ||
| import uk.gov.communities.prsdb.webapp.helpers.DateTimeHelper | ||
| import java.time.Instant | ||
| import java.time.format.DateTimeFormatter | ||
| import java.util.Locale | ||
|
|
||
| data class PendingInvitationViewModel( | ||
| val email: String, | ||
| val expiresInDays: Long, | ||
| val expiryDate: String, | ||
| val sentDate: String, | ||
| ) | ||
|
|
||
| data class ExpiredInvitationViewModel( | ||
| val email: String, | ||
| val expiredDate: String, | ||
| ) | ||
|
|
||
| class InvitationViewModelBuilder { | ||
| companion object { | ||
| private val DATE_FORMATTER = DateTimeFormatter.ofPattern("d MMMM yyyy", Locale.UK) | ||
|
|
||
| fun buildPendingViewModel(invitation: JointLandlordInvitation): PendingInvitationViewModel = | ||
| PendingInvitationViewModel( | ||
| email = invitation.invitedEmail, | ||
| expiresInDays = invitation.daysUntilExpiry, | ||
| expiryDate = formatInstant(invitation.expiryDate), | ||
| sentDate = formatInstant(invitation.createdDate), | ||
| ) | ||
|
|
||
| fun buildExpiredViewModel(invitation: JointLandlordInvitation): ExpiredInvitationViewModel = | ||
| ExpiredInvitationViewModel( | ||
| email = invitation.invitedEmail, | ||
| expiredDate = formatInstant(invitation.expiryDate), | ||
| ) | ||
|
|
||
| private fun formatInstant(instant: Instant): String = | ||
| DateTimeHelper.getDateInUK(instant.toKotlinInstant()).toJavaLocalDate().format(DATE_FORMATTER) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| @import "govuk/base"; | ||
|
|
||
| .prsdb-link-group-list { | ||
| list-style: none; | ||
| padding: 0; | ||
| margin: 0; | ||
| display: flex; | ||
|
|
||
| .prsdb-link-group-item:first-child { | ||
| padding: 0; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .prsdb-link-group-item:not(:first-child) { | ||
| margin-left: govuk-spacing(2); | ||
| padding-left: govuk-spacing(2); | ||
| border-left: 1px solid govuk-colour("mid-grey"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| @use "dashboard"; | ||
| @use "deregisterLinks"; | ||
| @use "linkGroupList"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,19 @@ landlordDetails: | |
| contactNumber: Contact number | ||
| addressNonEnglandOrWales: Address (outside England or Wales) | ||
| contactAddressInEnglandOrWales: Contact address in England or Wales | ||
| invitations: | ||
| pendingInvitations: | ||
| heading: 'Pending invitations ({0})' | ||
| expiresIn: 'Expires in {0} days ({1})' | ||
|
Collaborator
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. Do we need to worry about "1 days" and "0 days"?
Contributor
Author
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. suspect we do, have added alternate copy for this I don't think any of these other strings need a singular equivalent |
||
| expiresInSingular: 'Expires in 1 day ({0})' | ||
| sentOn: 'Sent on {0}' | ||
| sendNewInvitationEmail: Send a new email invitation | ||
| cancelInvitation: Cancel invitation | ||
| expiredInvitations: | ||
| heading: 'Expired invitations ({0})' | ||
| expiredOn: 'Expired on {0}' | ||
| sendNewInvitationEmail: Send a new invitation email | ||
| removeFromList: Remove from list | ||
| complianceInformation: | ||
| heading: Compliance information | ||
| certificateStatus: Certificate status | ||
|
|
||
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.
this may change - right now assuming that LCs won't be able to view pending/expired invites though design to input on what should happen here