← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ilasc/launchpad:add-expiry-date-to-participation-view into launchpad:master

 

Ioana Lasc has proposed merging ~ilasc/launchpad:add-expiry-date-to-participation-view into launchpad:master.

Commit message:
Add team membership expiry date to participation view

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ilasc/launchpad/+git/launchpad/+merge/422121
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:add-expiry-date-to-participation-view into launchpad:master.
diff --git a/lib/lp/registry/browser/person.py b/lib/lp/registry/browser/person.py
index 7005a54..c53195c 100644
--- a/lib/lp/registry/browser/person.py
+++ b/lib/lp/registry/browser/person.py
@@ -1997,9 +1997,11 @@ class PersonParticipationView(LaunchpadView):
             role = 'Member'
             # The Person never joined, and can't have a join date.
             datejoined = None
+            dateexpires = None
         else:
             # The member is a direct member; use the membership data.
             datejoined = membership.datejoined
+            dateexpires = membership.dateexpires
             if membership.personID == team.teamownerID:
                 role = 'Owner'
             elif membership.status == TeamMembershipStatus.ADMIN:
@@ -2017,7 +2019,7 @@ class PersonParticipationView(LaunchpadView):
 
         return dict(
             displayname=team.displayname, team=team, datejoined=datejoined,
-            role=role, via=via, subscribed=subscribed)
+            role=role, via=via, subscribed=subscribed, dateexpires=dateexpires)
 
     @cachedproperty
     def active_participations(self):
diff --git a/lib/lp/registry/browser/tests/test_person.py b/lib/lp/registry/browser/tests/test_person.py
index 1d43c17..de9f8d2 100644
--- a/lib/lp/registry/browser/tests/test_person.py
+++ b/lib/lp/registry/browser/tests/test_person.py
@@ -1,6 +1,10 @@
 # Copyright 2009-2021 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
+from datetime import (
+    datetime,
+    timedelta,
+    )
 import doctest
 import email
 from operator import attrgetter
@@ -9,6 +13,7 @@ from textwrap import dedent
 from urllib.parse import urljoin
 
 from fixtures import FakeLogger
+import pytz
 import soupmatchers
 from storm.store import Store
 from testscenarios import (
@@ -1225,6 +1230,22 @@ class TestPersonParticipationView(TestCaseWithFactory):
             get_participations, create_subscriptions, 5)
         self.assertThat(recorder2, HasQueryCount.byEquality(recorder1))
 
+    def test__asParticipation_dateexpires(self):
+        team = self.factory.makeTeam(owner=self.user)
+        [participation] = self.view.active_participations
+
+        self.assertEqual(None, participation['dateexpires'])
+
+        membership_set = getUtility(ITeamMembershipSet)
+        membership = membership_set.getByPersonAndTeam(self.user, team)
+        tomorrow = datetime.now(pytz.timezone('UTC')) + timedelta(days=1)
+        with person_logged_in(self.user):
+            membership.setExpirationDate(tomorrow, self.user)
+        view = create_view(self.user, name='+participation')
+        [participation] = view.active_participations
+
+        self.assertEqual(tomorrow, participation['dateexpires'])
+
 
 class TestPersonRelatedPackagesView(TestCaseWithFactory):
     """Test the related software view."""
diff --git a/lib/lp/registry/templates/person-participation.pt b/lib/lp/registry/templates/person-participation.pt
index 35f7283..739b6f6 100644
--- a/lib/lp/registry/templates/person-participation.pt
+++ b/lib/lp/registry/templates/person-participation.pt
@@ -26,6 +26,7 @@
         <tr>
           <th>Team</th>
           <th>Joined</th>
+          <th>Membership expiration</th>
           <th>Role</th>
           <th>Via</th>
           <th
@@ -46,6 +47,15 @@
               &mdash;
             </tal:no-date>
           </td>
+          <td>
+            <tal:date condition="not: participation/via"
+              tal:replace="participation/dateexpires/fmt:date">
+              2005-06-17
+            </tal:date>
+            <tal:no-date condition="participation/via">
+              &mdash;
+            </tal:no-date>
+          </td>
           <td tal:content="participation/role">
             Member
           </td>