Browse Source

In Account Settings > My Projects, indicate read-only memberships as read-only

pull/419/head
Pēteris Caune 4 years ago
parent
commit
0a85c5ed12
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 55 additions and 24 deletions
  1. +27
    -2
      hc/accounts/tests/test_profile.py
  2. +1
    -4
      hc/accounts/tests/test_project.py
  3. +0
    -3
      hc/accounts/views.py
  4. +1
    -1
      hc/test.py
  5. +26
    -14
      templates/accounts/profile.html

+ 27
- 2
hc/accounts/tests/test_profile.py View File

@ -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 <strong>Alices Project</strong>")
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="[email protected]", 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="[email protected]", 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="[email protected]", password="password")
r = self.client.get("/accounts/profile/")
self.assertContains(r, "You do not have any projects. Create one!")

+ 1
- 4
hc/accounts/tests/test_project.py View File

@ -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):


+ 0
- 3
hc/accounts/views.py View File

@ -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)


+ 1
- 1
hc/test.py View File

@ -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()


+ 26
- 14
templates/accounts/profile.html View File

@ -64,14 +64,14 @@
{% csrf_token %}
<h2>My Projects</h2>
{% if projects %}
{% if profile.projects.exists %}
<table id="my-projects" class="table">
<tr>
<th>Project</th>
<th>My role</th>
<th></th>
</tr>
{% for project in profile.projects %}
{% for project in request.user.project_set.all %}
<tr>
<td>
<div class="name">
@ -80,25 +80,37 @@
</a>
</div>
</td>
<td>Owner</td>
<td>
{% if project.owner == request.user %}
Owner
{% else %}
Collaborator
{% endif %}
</td>
<td>
{% if project.owner == request.user %}
<a
href="{% url 'hc-project-settings' project.code %}"
class="pull-right">Settings</a>
</td>
</tr>
{% endfor %}
{% for m in request.user.memberships.all %}
<tr>
<td>
<div class="name">
<a href="{% url 'hc-checks' m.project.code %}">
{{ m.project }}
</a>
</div>
</td>
<td>
{% if m.rw %}
Member
{% else %}
Read-only
{% endif %}
</td>
<td>
<a
href="#"
data-name="{{ project }}"
data-code="{{ project.code }}"
data-name="{{ m.project }}"
data-code="{{ m.project.code }}"
class="pull-right leave-project">Leave</a>
{% endif %}
</td>
</tr>
{% endfor %}
@ -112,7 +124,7 @@
href="#"
class="btn btn-default pull-right"
data-toggle="modal"
data-target="#add-project-modal">Create New Project</a>
data-target="#add-project-modal">Create a New Project</a>
</div>
{% if left_project %}


Loading…
Cancel
Save