Browse Source

Access rights checks for team access stuff in profile page.

pull/60/head
Pēteris Caune 9 years ago
parent
commit
813c316888
4 changed files with 66 additions and 49 deletions
  1. +14
    -1
      hc/accounts/tests/test_profile.py
  2. +6
    -0
      hc/accounts/views.py
  3. +2
    -1
      hc/test.py
  4. +44
    -47
      templates/accounts/profile.html

+ 14
- 1
hc/accounts/tests/test_profile.py View File

@ -1,4 +1,3 @@
from django.contrib.auth.models import User
from django.core import mail from django.core import mail
from hc.test import BaseTestCase from hc.test import BaseTestCase
@ -78,6 +77,13 @@ class ProfileTestCase(BaseTestCase):
' [email protected] on healthchecks.io') ' [email protected] on healthchecks.io')
self.assertEqual(mail.outbox[0].subject, subj) self.assertEqual(mail.outbox[0].subject, subj)
def test_add_team_member_checks_team_access_allowed_flag(self):
self.client.login(username="[email protected]", password="password")
form = {"invite_team_member": "1", "email": "[email protected]"}
r = self.client.post("/accounts/profile/", form)
assert r.status_code == 403
def test_it_removes_team_member(self): def test_it_removes_team_member(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
@ -100,6 +106,13 @@ class ProfileTestCase(BaseTestCase):
self.alice.profile.refresh_from_db() self.alice.profile.refresh_from_db()
self.assertEqual(self.alice.profile.team_name, "Alpha Team") self.assertEqual(self.alice.profile.team_name, "Alpha Team")
def test_set_team_name_checks_team_access_allowed_flag(self):
self.client.login(username="[email protected]", password="password")
form = {"set_team_name": "1", "team_name": "Charlies Team"}
r = self.client.post("/accounts/profile/", form)
assert r.status_code == 403
def test_it_switches_to_own_team(self): def test_it_switches_to_own_team(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")


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

@ -149,6 +149,9 @@ def profile(request):
profile.save() profile.save()
messages.info(request, "Your settings have been updated!") messages.info(request, "Your settings have been updated!")
elif "invite_team_member" in request.POST: elif "invite_team_member" in request.POST:
if not profile.team_access_allowed:
return HttpResponseForbidden()
form = InviteTeamMemberForm(request.POST) form = InviteTeamMemberForm(request.POST)
if form.is_valid(): if form.is_valid():
@ -174,6 +177,9 @@ def profile(request):
messages.info(request, "%s removed from team!" % email) messages.info(request, "%s removed from team!" % email)
elif "set_team_name" in request.POST: elif "set_team_name" in request.POST:
if not profile.team_access_allowed:
return HttpResponseForbidden()
form = TeamNameForm(request.POST) form = TeamNameForm(request.POST)
if form.is_valid(): if form.is_valid():
profile.team_name = form.cleaned_data["team_name"] profile.team_name = form.cleaned_data["team_name"]


+ 2
- 1
hc/test.py View File

@ -9,12 +9,13 @@ class BaseTestCase(TestCase):
def setUp(self): def setUp(self):
super(BaseTestCase, self).setUp() super(BaseTestCase, self).setUp()
# Alice is a normal user for tests
# Alice is a normal user for tests. Alice has team access enabled.
self.alice = User(username="alice", email="[email protected]") self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password") self.alice.set_password("password")
self.alice.save() self.alice.save()
self.profile = Profile(user=self.alice, api_key="abc") self.profile = Profile(user=self.alice, api_key="abc")
self.profile.team_access_allowed = True
self.profile.save() self.profile.save()
# Bob is on Alice's team and should have access to her stuff # Bob is on Alice's team and should have access to her stuff


+ 44
- 47
templates/accounts/profile.html View File

@ -100,59 +100,56 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body settings-block"> <div class="panel-body settings-block">
<h2>Team Access</h2> <h2>Team Access</h2>
{% if profile.team_access_allowed %}
{% if profile.member_set.count %}
<table class="table">
<tr>
<td>{{ profile.user.email }}</td>
<td>Owner</td>
<td></td>
</tr>
{% for member in profile.member_set.all %}
<tr>
<td>{{ member.user.email }} </td>
<td>Member</td>
<td>
<a
href="#"
data-email="{{ member.user.email }}"
class="pull-right member-remove">Remove</a>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>
<strong>Invite team members to your account.</strong>
</p>
{% if profile.member_set.count %}
<table class="table">
<tr>
<td>{{ profile.user.email }}</td>
<td>Owner</td>
<td></td>
</tr>
{% for member in profile.member_set.all %}
<tr>
<td>{{ member.user.email }} </td>
<td>Member</td>
<td>
<a
href="#"
data-email="{{ member.user.email }}"
class="pull-right member-remove">Remove</a>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>
<strong>Invite team members to your account.</strong>
</p>
<p>
Share access to your checks and configured integrations
without having to share a login.
</p>
{% if not profile.team_access_allowed %}
<p> <p>
Share access to your checks and configured integrations
without having to share a login.
To enable team access, please upgrade to
one of the <a href="{% url 'hc-pricing' %}">paid plans</a>.
</p> </p>
{% endif %} {% endif %}
{% endif %}
<br />
<br />
<a
href="#"
class="btn btn-default"
data-toggle="modal"
data-target="#set-team-name-modal">Set Team Name</a>
{% if profile.team_access_allowed %}
<a
href="#"
class="btn btn-default"
data-toggle="modal"
data-target="#set-team-name-modal">Set Team Name</a>
<a
href="#"
class="btn btn-primary pull-right"
data-toggle="modal"
data-target="#invite-team-member-modal">Invite a Team Member</a>
{% else %}
<p>
<strong>Invite team members to your account.</strong>
Share access to your checks and configured integrations
without having to share a login.</p>
<p>
To enable team access, please upgrade to
one of the <a href="{% url 'hc-pricing' %}">paid plans</a>.
</p>
<a
href="#"
class="btn btn-primary pull-right"
data-toggle="modal"
data-target="#invite-team-member-modal">Invite a Team Member</a>
{% endif %} {% endif %}
</div> </div>
</div> </div>


Loading…
Cancel
Save