diff --git a/hc/accounts/tests/test_profile.py b/hc/accounts/tests/test_profile.py index 62f1a1f3..4318f079 100644 --- a/hc/accounts/tests/test_profile.py +++ b/hc/accounts/tests/test_profile.py @@ -1,4 +1,3 @@ -from django.contrib.auth.models import User from django.core import mail from hc.test import BaseTestCase @@ -78,6 +77,13 @@ class ProfileTestCase(BaseTestCase): ' alice@example.org on healthchecks.io') self.assertEqual(mail.outbox[0].subject, subj) + def test_add_team_member_checks_team_access_allowed_flag(self): + self.client.login(username="charlie@example.org", password="password") + + form = {"invite_team_member": "1", "email": "frank@example.org"} + r = self.client.post("/accounts/profile/", form) + assert r.status_code == 403 + def test_it_removes_team_member(self): self.client.login(username="alice@example.org", password="password") @@ -100,6 +106,13 @@ class ProfileTestCase(BaseTestCase): self.alice.profile.refresh_from_db() self.assertEqual(self.alice.profile.team_name, "Alpha Team") + def test_set_team_name_checks_team_access_allowed_flag(self): + self.client.login(username="charlie@example.org", 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): self.client.login(username="bob@example.org", password="password") diff --git a/hc/accounts/views.py b/hc/accounts/views.py index 90bb3c56..4b70dbfa 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -149,6 +149,9 @@ def profile(request): profile.save() messages.info(request, "Your settings have been updated!") elif "invite_team_member" in request.POST: + if not profile.team_access_allowed: + return HttpResponseForbidden() + form = InviteTeamMemberForm(request.POST) if form.is_valid(): @@ -174,6 +177,9 @@ def profile(request): messages.info(request, "%s removed from team!" % email) elif "set_team_name" in request.POST: + if not profile.team_access_allowed: + return HttpResponseForbidden() + form = TeamNameForm(request.POST) if form.is_valid(): profile.team_name = form.cleaned_data["team_name"] diff --git a/hc/test.py b/hc/test.py index 9844f66b..ac2fbf9d 100644 --- a/hc/test.py +++ b/hc/test.py @@ -9,12 +9,13 @@ class BaseTestCase(TestCase): def setUp(self): 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="alice@example.org") self.alice.set_password("password") self.alice.save() self.profile = Profile(user=self.alice, api_key="abc") + self.profile.team_access_allowed = True self.profile.save() # Bob is on Alice's team and should have access to her stuff diff --git a/templates/accounts/profile.html b/templates/accounts/profile.html index a584fec2..d9b3d28a 100644 --- a/templates/accounts/profile.html +++ b/templates/accounts/profile.html @@ -100,59 +100,56 @@
{{ profile.user.email }} | -Owner | -- |
{{ member.user.email }} | -Member | -- Remove - | -
- Invite team members to your account. -
+ {% if profile.member_set.count %} +{{ profile.user.email }} | +Owner | ++ |
{{ member.user.email }} | +Member | ++ Remove + | +
+ Invite team members to your account. +
++ Share access to your checks and configured integrations + without having to share a login. +
+ {% if not profile.team_access_allowed %}- Share access to your checks and configured integrations - without having to share a login. + To enable team access, please upgrade to + one of the paid plans.
{% endif %} + {% endif %} -- Invite team members to your account. - Share access to your checks and configured integrations - without having to share a login.
-- To enable team access, please upgrade to - one of the paid plans. -
+ Invite a Team Member {% endif %}