diff --git a/hc/accounts/admin.py b/hc/accounts/admin.py index 22cf828d..44fc7557 100644 --- a/hc/accounts/admin.py +++ b/hc/accounts/admin.py @@ -19,15 +19,15 @@ class Fieldset: class ProfileFieldset(Fieldset): name = "User Profile" - fields = ("email", "current_team", "reports_allowed", + fields = ("email", "current_project", "reports_allowed", "next_report_date", "nag_period", "next_nag_date", "token", "sort") class TeamFieldset(Fieldset): name = "Team" - fields = ("team_name", "team_limit", "check_limit", - "ping_log_limit", "sms_limit", "sms_sent", "last_sms_date") + fields = ("team_limit", "check_limit", "ping_log_limit", "sms_limit", + "sms_sent", "last_sms_date") @admin.register(Profile) @@ -39,7 +39,7 @@ class ProfileAdmin(admin.ModelAdmin): } readonly_fields = ("user", "email") - raw_id_fields = ("current_team", ) + raw_id_fields = ("current_project", ) list_select_related = ("user", ) list_display = ("id", "users", "checks", "invited", "reports_allowed", "ping_log_limit", "sms") diff --git a/hc/accounts/migrations/0024_auto_20190119_1540.py b/hc/accounts/migrations/0024_auto_20190119_1540.py new file mode 100644 index 00000000..1d78032c --- /dev/null +++ b/hc/accounts/migrations/0024_auto_20190119_1540.py @@ -0,0 +1,21 @@ +# Generated by Django 2.1.5 on 2019-01-19 15:40 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0023_auto_20190117_1419'), + ] + + operations = [ + migrations.RemoveField( + model_name='profile', + name='current_team', + ), + migrations.RemoveField( + model_name='profile', + name='team_name', + ), + ] diff --git a/hc/accounts/models.py b/hc/accounts/models.py index 682dfca8..81e62bbb 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -41,9 +41,7 @@ class ProfileManager(models.Manager): class Profile(models.Model): - # Owner: user = models.OneToOneField(User, models.CASCADE, blank=True, null=True) - team_name = models.CharField(max_length=200, blank=True) next_report_date = models.DateTimeField(null=True, blank=True) reports_allowed = models.BooleanField(default=True) nag_period = models.DurationField(default=NO_NAG, choices=NAG_PERIODS) @@ -51,7 +49,6 @@ class Profile(models.Model): ping_log_limit = models.IntegerField(default=100) check_limit = models.IntegerField(default=20) token = models.CharField(max_length=128, blank=True) - current_team = models.ForeignKey("self", models.SET_NULL, null=True) current_project = models.ForeignKey("Project", models.SET_NULL, null=True) last_sms_date = models.DateTimeField(null=True, blank=True) sms_limit = models.IntegerField(default=0) @@ -62,7 +59,7 @@ class Profile(models.Model): objects = ProfileManager() def __str__(self): - return self.team_name or self.user.email + return "Profile for %s" % self.user.email def notifications_url(self): return settings.SITE_ROOT + reverse("hc-notifications") @@ -73,13 +70,6 @@ class Profile(models.Model): path = reverse("hc-unsubscribe-reports", args=[signed_username]) return settings.SITE_ROOT + path - def team(self): - # compare ids to avoid SQL queries - if self.current_team_id and self.current_team_id != self.id: - return self.current_team - - return self - def prepare_token(self, salt): token = urlsafe_b64encode(os.urandom(24)).decode() self.token = make_password(token, salt) @@ -185,7 +175,6 @@ class Profile(models.Model): # Switch the invited user over to the new team so they # notice the new team on next visit: - user.profile.current_team = self user.profile.current_project = project user.profile.save() diff --git a/hc/accounts/tests/test_close_account.py b/hc/accounts/tests/test_close_account.py index cc322a8c..5a89ace5 100644 --- a/hc/accounts/tests/test_close_account.py +++ b/hc/accounts/tests/test_close_account.py @@ -26,7 +26,6 @@ class CloseAccountTestCase(BaseTestCase): # Bob's current team should now be None self.bobs_profile.refresh_from_db() - self.assertIsNone(self.bobs_profile.current_team) self.assertIsNone(self.bobs_profile.current_project) # Check should be gone @@ -46,7 +45,6 @@ class CloseAccountTestCase(BaseTestCase): # Alice should be still present self.alice.refresh_from_db() self.profile.refresh_from_db() - self.assertEqual(self.profile.current_team, None) # Bob should be gone bobs = User.objects.filter(username="bob") diff --git a/hc/accounts/tests/test_profile.py b/hc/accounts/tests/test_profile.py index 7281dd7b..90ac3864 100644 --- a/hc/accounts/tests/test_profile.py +++ b/hc/accounts/tests/test_profile.py @@ -173,7 +173,6 @@ class ProfileTestCase(BaseTestCase): self.assertEqual(Member.objects.count(), 0) self.bobs_profile.refresh_from_db() - self.assertEqual(self.bobs_profile.current_team, None) self.assertEqual(self.bobs_profile.current_project, None) def test_it_sets_team_name(self): @@ -183,9 +182,6 @@ class ProfileTestCase(BaseTestCase): r = self.client.post("/accounts/profile/", form) self.assertEqual(r.status_code, 200) - self.profile.refresh_from_db() - self.assertEqual(self.profile.team_name, "Alpha Team") - self.project.refresh_from_db() self.assertEqual(self.project.name, "Alpha Team") @@ -197,7 +193,6 @@ class ProfileTestCase(BaseTestCase): # After visiting the profile page, team should be switched back # to user's default team. self.bobs_profile.refresh_from_db() - self.assertEqual(self.bobs_profile.current_team, self.bobs_profile) self.assertEqual(self.bobs_profile.current_project, self.bobs_project) def test_it_sends_change_email_link(self): diff --git a/hc/accounts/views.py b/hc/accounts/views.py index f234fae2..a69bac07 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -79,7 +79,6 @@ def _ensure_own_team(request): if request.project.owner != request.user: request.project = request.profile.get_own_project() - request.profile.current_team = request.profile request.profile.current_project = request.project request.profile.save() @@ -247,7 +246,6 @@ def profile(request): email = form.cleaned_data["email"] farewell_user = User.objects.get(email=email) - farewell_user.profile.current_team = None farewell_user.profile.current_project = None farewell_user.profile.save() @@ -259,9 +257,6 @@ def profile(request): elif "set_team_name" in request.POST: form = TeamNameForm(request.POST) if form.is_valid(): - profile.team_name = form.cleaned_data["team_name"] - profile.save() - request.project.name = form.cleaned_data["team_name"] request.project.save() @@ -445,7 +440,6 @@ def switch_team(request, target_username): if not access_ok: return HttpResponseForbidden() - request.profile.current_team = target_team request.profile.current_project = target_project request.profile.save() diff --git a/hc/front/tests/test_details.py b/hc/front/tests/test_details.py index 0e2e96a9..63542809 100644 --- a/hc/front/tests/test_details.py +++ b/hc/front/tests/test_details.py @@ -38,7 +38,7 @@ class DetailsTestCase(BaseTestCase): self.assertContains(r, "Cron Expression", status_code=200) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() self.client.login(username="bob@example.org", password="password") diff --git a/hc/front/tests/test_log.py b/hc/front/tests/test_log.py index 85c5844d..8559d344 100644 --- a/hc/front/tests/test_log.py +++ b/hc/front/tests/test_log.py @@ -77,7 +77,7 @@ class LogTestCase(BaseTestCase): self.assertContains(r, "Called webhook foo/$NAME", status_code=200) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() url = "/checks/%s/log/" % self.check.code diff --git a/hc/front/tests/test_pause.py b/hc/front/tests/test_pause.py index 28e25f21..10413191 100644 --- a/hc/front/tests/test_pause.py +++ b/hc/front/tests/test_pause.py @@ -26,7 +26,7 @@ class PauseTestCase(BaseTestCase): self.assertEqual(r.status_code, 405) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() self.client.login(username="bob@example.org", password="password") diff --git a/hc/front/tests/test_ping_details.py b/hc/front/tests/test_ping_details.py index 7b56b1f1..8fcf19f6 100644 --- a/hc/front/tests/test_ping_details.py +++ b/hc/front/tests/test_ping_details.py @@ -44,7 +44,7 @@ class LastPingTestCase(BaseTestCase): self.assertContains(r, "bar-456", status_code=200) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() check = Check.objects.create(project=self.project) diff --git a/hc/front/tests/test_remove_check.py b/hc/front/tests/test_remove_check.py index b5de5189..185fc764 100644 --- a/hc/front/tests/test_remove_check.py +++ b/hc/front/tests/test_remove_check.py @@ -48,7 +48,7 @@ class RemoveCheckTestCase(BaseTestCase): self.assertEqual(r.status_code, 405) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() self.client.login(username="bob@example.org", password="password") diff --git a/hc/front/tests/test_status.py b/hc/front/tests/test_status.py index 63a8f703..7bf78907 100644 --- a/hc/front/tests/test_status.py +++ b/hc/front/tests/test_status.py @@ -24,7 +24,7 @@ class MyChecksTestCase(BaseTestCase): self.assertIn("Never", detail["last_ping"]) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() self.client.login(username="bob@example.org", password="password") @@ -32,7 +32,7 @@ class MyChecksTestCase(BaseTestCase): self.assertEqual(r.status_code, 200) def test_it_checks_ownership(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() self.client.login(username="charlie@example.org", password="password") diff --git a/hc/front/tests/test_status_single.py b/hc/front/tests/test_status_single.py index 6caef26e..cb806c8a 100644 --- a/hc/front/tests/test_status_single.py +++ b/hc/front/tests/test_status_single.py @@ -48,7 +48,7 @@ class StatusSingleTestCase(BaseTestCase): self.assertFalse("events" in doc) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() self.client.login(username="bob@example.org", password="password") diff --git a/hc/front/tests/test_switch_channel.py b/hc/front/tests/test_switch_channel.py index 53237ffb..d5abd8dd 100644 --- a/hc/front/tests/test_switch_channel.py +++ b/hc/front/tests/test_switch_channel.py @@ -46,7 +46,7 @@ class SwitchChannelTestCase(BaseTestCase): self.assertEqual(r.status_code, 400) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() self.client.login(username="bob@example.org", password="password") diff --git a/hc/front/tests/test_update_name.py b/hc/front/tests/test_update_name.py index 4efa1df3..33fb7f8c 100644 --- a/hc/front/tests/test_update_name.py +++ b/hc/front/tests/test_update_name.py @@ -30,8 +30,8 @@ class UpdateNameTestCase(BaseTestCase): self.assertEqual(self.check.name, "Bob Was Here") def test_it_allows_cross_team_access(self): - # Bob's current team is not set - self.bobs_profile.current_team = None + # Bob's current profile is not set + self.bobs_profile.current_project = None self.bobs_profile.save() # But this should still work: diff --git a/hc/front/tests/test_update_timeout.py b/hc/front/tests/test_update_timeout.py index 1b52e8dd..a1ebbca1 100644 --- a/hc/front/tests/test_update_timeout.py +++ b/hc/front/tests/test_update_timeout.py @@ -177,7 +177,7 @@ class UpdateTimeoutTestCase(BaseTestCase): self.assertEqual(r.status_code, 405) def test_it_allows_cross_team_access(self): - self.bobs_profile.current_team = None + self.bobs_profile.current_project = None self.bobs_profile.save() payload = {"kind": "simple", "timeout": 3600, "grace": 60} diff --git a/hc/payments/views.py b/hc/payments/views.py index c4acfd6b..c6275a1e 100644 --- a/hc/payments/views.py +++ b/hc/payments/views.py @@ -38,7 +38,6 @@ def billing(request): if request.project.owner != request.user: request.project = request.profile.get_own_project() - request.profile.current_team = request.profile request.profile.current_project = request.project request.profile.save() diff --git a/hc/test.py b/hc/test.py index d3318b84..0c56ec57 100644 --- a/hc/test.py +++ b/hc/test.py @@ -33,7 +33,6 @@ class BaseTestCase(TestCase): self.bobs_project.save() self.bobs_profile = Profile(user=self.bob) - self.bobs_profile.current_team = self.profile self.bobs_profile.current_project = self.project self.bobs_profile.save()