diff --git a/hc/accounts/tests/test_profile.py b/hc/accounts/tests/test_profile.py index 6eef305d..d63a75ad 100644 --- a/hc/accounts/tests/test_profile.py +++ b/hc/accounts/tests/test_profile.py @@ -113,8 +113,8 @@ class ProfileTestCase(BaseTestCase): form = {"code": str(self.project.code), "leave_project": "1"} r = self.client.post("/accounts/profile/", form) - self.assertContains(r, "Left project") - self.assertNotContains(r, "Alice's Project") + self.assertContains(r, "Left project Alices Project") + self.assertNotContains(r, "Member") self.bobs_profile.refresh_from_db() self.assertFalse(self.bob.memberships.exists()) @@ -125,3 +125,28 @@ class ProfileTestCase(BaseTestCase): form = {"code": str(self.project.code), "leave_project": "1"} r = self.client.post("/accounts/profile/", form) self.assertEqual(r.status_code, 400) + + def test_it_shows_project_membership(self): + self.client.login(username="bob@example.org", password="password") + + r = self.client.get("/accounts/profile/") + self.assertContains(r, "Alices Project") + self.assertContains(r, "Member") + + def test_it_shows_readonly_project_membership(self): + self.bobs_membership.rw = False + self.bobs_membership.save() + + self.client.login(username="bob@example.org", password="password") + + r = self.client.get("/accounts/profile/") + self.assertContains(r, "Alices Project") + self.assertContains(r, "Read-only") + + def test_it_handles_no_projects(self): + self.project.delete() + + self.client.login(username="alice@example.org", password="password") + + r = self.client.get("/accounts/profile/") + self.assertContains(r, "You do not have any projects. Create one!") diff --git a/hc/accounts/tests/test_project.py b/hc/accounts/tests/test_project.py index 2c899975..b777963c 100644 --- a/hc/accounts/tests/test_project.py +++ b/hc/accounts/tests/test_project.py @@ -83,10 +83,7 @@ class ProjectTestCase(BaseTestCase): self.assertFalse(member.user.project_set.exists()) # And an email should have been sent - subj = ( - "You have been invited to join" - " Alice's Project on %s" % settings.SITE_NAME - ) + subj = f"You have been invited to join Alices Project on {settings.SITE_NAME}" self.assertHTMLEqual(mail.outbox[0].subject, subj) def test_it_adds_readonly_team_member(self): diff --git a/hc/accounts/views.py b/hc/accounts/views.py index d5d2bb8b..55fab5ad 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -219,9 +219,6 @@ def profile(request): ctx["left_project"] = project ctx["my_projects_status"] = "info" - # Retrieve projects right before rendering the template-- - # The list of the projects might have *just* changed - ctx["projects"] = list(profile.projects()) return render(request, "accounts/profile.html", ctx) diff --git a/hc/test.py b/hc/test.py index 0223a8e0..6de3852c 100644 --- a/hc/test.py +++ b/hc/test.py @@ -14,7 +14,7 @@ class BaseTestCase(TestCase): self.alice.save() self.project = Project(owner=self.alice, api_key="X" * 32) - self.project.name = "Alice's Project" + self.project.name = "Alices Project" self.project.badge_key = self.alice.username self.project.save() diff --git a/templates/accounts/profile.html b/templates/accounts/profile.html index dc9c8579..34edeeaa 100644 --- a/templates/accounts/profile.html +++ b/templates/accounts/profile.html @@ -64,14 +64,14 @@ {% csrf_token %}

My Projects

- {% if projects %} + {% if profile.projects.exists %} - {% for project in profile.projects %} + {% for project in request.user.project_set.all %} + - + + {% endfor %} + + {% for m in request.user.memberships.all %} + + + + {% endfor %} @@ -112,7 +124,7 @@ href="#" class="btn btn-default pull-right" data-toggle="modal" - data-target="#add-project-modal">Create New Project + data-target="#add-project-modal">Create a New Project {% if left_project %}
Project My role
@@ -80,25 +80,37 @@
Owner - {% if project.owner == request.user %} - Owner - {% else %} - Collaborator - {% endif %} - - {% if project.owner == request.user %} Settings +
+ + + {% if m.rw %} + Member {% else %} + Read-only + {% endif %} + Leave - {% endif %}