Team membership expiration warnings sent before renewal is possible

Bug #1987056 reported by Colin Watson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
Low
Guruprasad

Bug Description

This morning, I received this email:

```
Date: Fri, 19 Aug 2022 05:15:55 -0000
From: Ubuntu IRC members <email address hidden>
To: Colin Watson <email address hidden>
Subject: Your membership in ubuntu-irc-members is about to expire

Hello Colin Watson,

On 2022-09-16, 4 weeks from now, your membership
in the Ubuntu IRC members (ubuntu-irc-members) Launchpad team is due to expire.
<https://launchpad.net/~ubuntu-irc-members>

If you want, you can renew this membership at
<https://launchpad.net/~cjwatson/+expiringmembership/ubuntu-irc-members>

If your membership does expire, we'll send you one more message to let
you know it's happened.

Thanks for using Launchpad!
```

I followed the renewal link, which told me:

```
This membership cannot be renewed because it is not set to expire in 28 days or less. You or one of the team administrators has already renewed it.
```

Odd. What's going on?

Looking at the membership list for that team, my membership is set to expire at 2022-09-16 16:15:49Z, which is a little over 28 days from now, so I expect I'll be able to renew this later today. It looks like we have some kind of fencepost issue here.

The recent changes to expiring membership emails involved `Func("date_trunc", "day", TeamMembership.dateexpires).is_in(dates)` as part of the code to arrange to send weekly reminders between two and four weeks prior to expiration. I suspect that's what results in the fencepost error: 28 days from now is 2022-09-16 which is indeed when my membership expires when truncated to the day, but `TeamMembership.canBeRenewedByMember` and `TeamMembershipSelfRenewalView.reason_for_denied_renewal` don't have that fudge factor: they require that the expiry actually be less than 28 days away.

I can think of a few ways to fix this:

 1) Make sure the expiration warning is only sent if the expiry is strictly less than `DAYS_BEFORE_EXPIRATION_WARNING_IS_SENT` days away;
 2) Change the renewal logic to do similar day-truncation, so that we allow renewal if the day part of the expiration date is less than or equal to the current day plus `DAYS_BEFORE_EXPIRATION_WARNING_IS_SENT`;
 3) Just add a grace period of one day to the renewal logic to cover the fencepost error.

I don't think it's particularly important which we go for, so whatever's easiest.

Related branches

Guruprasad (lgp171188)
Changed in launchpad:
assignee: nobody → Guruprasad (lgp171188)
status: Triaged → In Progress
Colin Watson (cjwatson)
Changed in launchpad:
status: In Progress → Fix Committed
Colin Watson (cjwatson)
Changed in launchpad:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.