Browse Source

Profile.current_project not used any more, remove last remaining references. cc: #336

pull/340/head
Pēteris Caune 5 years ago
parent
commit
0c9c453ea0
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
21 changed files with 4 additions and 90 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +0
    -2
      hc/accounts/admin.py
  3. +0
    -6
      hc/accounts/models.py
  4. +0
    -4
      hc/accounts/tests/test_close_account.py
  5. +0
    -1
      hc/accounts/tests/test_profile.py
  6. +1
    -12
      hc/accounts/tests/test_project.py
  7. +0
    -4
      hc/accounts/tests/test_remove_project.py
  8. +1
    -10
      hc/accounts/views.py
  9. +0
    -13
      hc/front/tests/test_add_check.py
  10. +0
    -3
      hc/front/tests/test_details.py
  11. +0
    -3
      hc/front/tests/test_log.py
  12. +0
    -3
      hc/front/tests/test_pause.py
  13. +0
    -3
      hc/front/tests/test_ping_details.py
  14. +0
    -3
      hc/front/tests/test_remove_check.py
  15. +0
    -6
      hc/front/tests/test_status.py
  16. +0
    -3
      hc/front/tests/test_status_single.py
  17. +0
    -3
      hc/front/tests/test_switch_channel.py
  18. +0
    -5
      hc/front/tests/test_update_name.py
  19. +0
    -3
      hc/front/tests/test_update_timeout.py
  20. +0
    -2
      hc/test.py
  21. +1
    -1
      templates/front/projects.html

+ 1
- 0
CHANGELOG.md View File

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Improvements ### Improvements
- Improved UI to invite users from account's other projects (#258) - Improved UI to invite users from account's other projects (#258)
- Experimental Prometheus metrics endpoint (#300) - Experimental Prometheus metrics endpoint (#300)
- Don't store user's current project in DB, put it explicitly in page URLs (#336)
### Bug Fixes ### Bug Fixes
- The "render_docs" command checks if markdown and pygments is installed (#329) - The "render_docs" command checks if markdown and pygments is installed (#329)


+ 0
- 2
hc/accounts/admin.py View File

@ -22,7 +22,6 @@ class ProfileFieldset(Fieldset):
name = "User Profile" name = "User Profile"
fields = ( fields = (
"email", "email",
"current_project",
"reports_allowed", "reports_allowed",
"next_report_date", "next_report_date",
"nag_period", "nag_period",
@ -51,7 +50,6 @@ class ProfileAdmin(admin.ModelAdmin):
css = {"all": ("css/admin/profiles.css",)} css = {"all": ("css/admin/profiles.css",)}
readonly_fields = ("user", "email") readonly_fields = ("user", "email")
raw_id_fields = ("current_project",)
search_fields = ["id", "user__email"] search_fields = ["id", "user__email"]
list_per_page = 50 list_per_page = 50
list_select_related = ("user",) list_select_related = ("user",)


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

@ -260,12 +260,6 @@ class Project(models.Model):
def invite(self, user): def invite(self, user):
Member.objects.create(user=user, project=self) Member.objects.create(user=user, project=self)
# Switch the invited user over to the new team so they
# notice the new team on next visit:
user.profile.current_project = self
user.profile.save()
user.profile.send_instant_login_link(self) user.profile.send_instant_login_link(self)
def set_next_nag_date(self): def set_next_nag_date(self):


+ 0
- 4
hc/accounts/tests/test_close_account.py View File

@ -21,10 +21,6 @@ class CloseAccountTestCase(BaseTestCase):
alices = User.objects.filter(username="alice") alices = User.objects.filter(username="alice")
self.assertFalse(alices.exists()) self.assertFalse(alices.exists())
# Bob's current team should now be None
self.bobs_profile.refresh_from_db()
self.assertIsNone(self.bobs_profile.current_project)
# Check should be gone # Check should be gone
self.assertFalse(Check.objects.exists()) self.assertFalse(Check.objects.exists())


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

@ -117,7 +117,6 @@ class ProfileTestCase(BaseTestCase):
self.assertNotContains(r, "Alice's Project") self.assertNotContains(r, "Alice's Project")
self.bobs_profile.refresh_from_db() self.bobs_profile.refresh_from_db()
self.assertIsNone(self.bobs_profile.current_project)
self.assertFalse(self.bob.memberships.exists()) self.assertFalse(self.bob.memberships.exists())
def test_leaving_checks_membership(self): def test_leaving_checks_membership(self):


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

@ -76,8 +76,6 @@ class ProjectTestCase(BaseTestCase):
project=self.project, user__email="[email protected]" project=self.project, user__email="[email protected]"
) )
profile = member.user.profile
self.assertEqual(profile.current_project, self.project)
# The new user should not have their own project # The new user should not have their own project
self.assertFalse(member.user.project_set.exists()) self.assertFalse(member.user.project_set.exists())
@ -148,10 +146,7 @@ class ProjectTestCase(BaseTestCase):
r = self.client.post(self.url, form) r = self.client.post(self.url, form)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
self.assertEqual(Member.objects.count(), 0)
self.bobs_profile.refresh_from_db()
self.assertEqual(self.bobs_profile.current_project, None)
self.assertFalse(Member.objects.exists())
def test_it_requires_owner_to_remove_team_member(self): def test_it_requires_owner_to_remove_team_member(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
@ -161,9 +156,6 @@ class ProjectTestCase(BaseTestCase):
self.assertEqual(r.status_code, 403) self.assertEqual(r.status_code, 403)
def test_it_checks_membership_when_removing_team_member(self): def test_it_checks_membership_when_removing_team_member(self):
self.profile.current_project = self.project
self.profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
url = "/projects/%s/settings/" % self.charlies_project.code url = "/projects/%s/settings/" % self.charlies_project.code
@ -171,9 +163,6 @@ class ProjectTestCase(BaseTestCase):
r = self.client.post(url, form) r = self.client.post(url, form)
self.assertEqual(r.status_code, 400) self.assertEqual(r.status_code, 400)
self.profile.refresh_from_db()
self.assertIsNotNone(self.profile.current_project)
def test_it_sets_project_name(self): def test_it_sets_project_name(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")


+ 0
- 4
hc/accounts/tests/test_remove_project.py View File

@ -15,10 +15,6 @@ class RemoveProjectTestCase(BaseTestCase):
r = self.client.post(self.url) r = self.client.post(self.url)
self.assertRedirects(r, "/") self.assertRedirects(r, "/")
# Alice's current project should be not set
self.profile.refresh_from_db()
self.assertEqual(self.profile.current_project, None)
# Alice should not own any projects # Alice should not own any projects
self.assertFalse(self.alice.project_set.exists()) self.assertFalse(self.alice.project_set.exists())


+ 1
- 10
hc/accounts/views.py View File

@ -79,9 +79,7 @@ def _make_user(email, with_project=True):
channel.checks.add(check) channel.checks.add(check)
# Ensure a profile gets created # Ensure a profile gets created
profile = Profile.objects.for_user(user)
profile.current_project = project
profile.save()
Profile.objects.for_user(user)
return user return user
@ -222,10 +220,6 @@ def profile(request):
except Project.DoesNotExist: except Project.DoesNotExist:
return HttpResponseBadRequest() return HttpResponseBadRequest()
if profile.current_project == project:
profile.current_project = None
profile.save()
Member.objects.filter(project=project, user=request.user).delete() Member.objects.filter(project=project, user=request.user).delete()
ctx["left_project"] = project ctx["left_project"] = project
@ -333,9 +327,6 @@ def project(request, code):
if farewell_user is None: if farewell_user is None:
return HttpResponseBadRequest() return HttpResponseBadRequest()
farewell_user.profile.current_project = None
farewell_user.profile.save()
Member.objects.filter(project=project, user=farewell_user).delete() Member.objects.filter(project=project, user=farewell_user).delete()
ctx["team_member_removed"] = form.cleaned_data["email"] ctx["team_member_removed"] = form.cleaned_data["email"]


+ 0
- 13
hc/front/tests/test_add_check.py View File

@ -19,19 +19,6 @@ class AddCheckTestCase(BaseTestCase):
redirect_url = "/checks/%s/details/?new" % check.code redirect_url = "/checks/%s/details/?new" % check.code
self.assertRedirects(r, redirect_url) self.assertRedirects(r, redirect_url)
def test_it_handles_unset_current_project(self):
self.profile.current_project = None
self.profile.save()
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url)
check = Check.objects.get()
self.assertEqual(check.project, self.project)
redirect_url = "/checks/%s/details/?new" % check.code
self.assertRedirects(r, redirect_url)
def test_team_access_works(self): def test_team_access_works(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
self.client.post(self.url) self.client.post(self.url)


+ 0
- 3
hc/front/tests/test_details.py View File

@ -37,9 +37,6 @@ class DetailsTestCase(BaseTestCase):
self.assertContains(r, "Cron Expression", status_code=200) self.assertContains(r, "Cron Expression", status_code=200)
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url) r = self.client.get(self.url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)


+ 0
- 3
hc/front/tests/test_log.py View File

@ -91,9 +91,6 @@ class LogTestCase(BaseTestCase):
self.assertContains(r, "Called webhook foo/$NAME", status_code=200) self.assertContains(r, "Called webhook foo/$NAME", status_code=200)
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url) r = self.client.get(self.url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)

+ 0
- 3
hc/front/tests/test_pause.py View File

@ -26,9 +26,6 @@ class PauseTestCase(BaseTestCase):
self.assertEqual(r.status_code, 405) self.assertEqual(r.status_code, 405)
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url) r = self.client.post(self.url)
self.assertRedirects(r, self.redirect_url) self.assertRedirects(r, self.redirect_url)


+ 0
- 3
hc/front/tests/test_ping_details.py View File

@ -43,9 +43,6 @@ class LastPingTestCase(BaseTestCase):
self.assertContains(r, "bar-456", status_code=200) self.assertContains(r, "bar-456", status_code=200)
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
check = Check.objects.create(project=self.project) check = Check.objects.create(project=self.project)
Ping.objects.create(owner=check, body="this is body") Ping.objects.create(owner=check, body="this is body")


+ 0
- 3
hc/front/tests/test_remove_check.py View File

@ -48,9 +48,6 @@ class RemoveCheckTestCase(BaseTestCase):
self.assertEqual(r.status_code, 405) self.assertEqual(r.status_code, 405)
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.remove_url) r = self.client.post(self.remove_url)
self.assertRedirects(r, self.redirect_url) self.assertRedirects(r, self.redirect_url)

+ 0
- 6
hc/front/tests/test_status.py View File

@ -25,17 +25,11 @@ class MyChecksTestCase(BaseTestCase):
self.assertIn("Never", detail["last_ping"]) self.assertIn("Never", detail["last_ping"])
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url) r = self.client.get(self.url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
def test_it_checks_ownership(self): def test_it_checks_ownership(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url) r = self.client.get(self.url)
self.assertEqual(r.status_code, 404) self.assertEqual(r.status_code, 404)

+ 0
- 3
hc/front/tests/test_status_single.py View File

@ -47,9 +47,6 @@ class StatusSingleTestCase(BaseTestCase):
self.assertFalse("events" in doc) self.assertFalse("events" in doc)
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get("/checks/%s/status/" % self.check.code) r = self.client.get("/checks/%s/status/" % self.check.code)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)

+ 0
- 3
hc/front/tests/test_switch_channel.py View File

@ -48,9 +48,6 @@ class SwitchChannelTestCase(BaseTestCase):
self.assertEqual(r.status_code, 400) self.assertEqual(r.status_code, 400)
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, {"state": "on"}) r = self.client.post(self.url, {"state": "on"})
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)

+ 0
- 5
hc/front/tests/test_update_name.py View File

@ -30,11 +30,6 @@ class UpdateNameTestCase(BaseTestCase):
self.assertEqual(self.check.name, "Bob Was Here") self.assertEqual(self.check.name, "Bob Was Here")
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
# Bob's current profile is not set
self.bobs_profile.current_project = None
self.bobs_profile.save()
# But this should still work:
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, data={"name": "Bob Was Here"}) r = self.client.post(self.url, data={"name": "Bob Was Here"})
self.assertRedirects(r, self.redirect_url) self.assertRedirects(r, self.redirect_url)


+ 0
- 3
hc/front/tests/test_update_timeout.py View File

@ -175,9 +175,6 @@ class UpdateTimeoutTestCase(BaseTestCase):
self.assertEqual(r.status_code, 405) self.assertEqual(r.status_code, 405)
def test_it_allows_cross_team_access(self): def test_it_allows_cross_team_access(self):
self.bobs_profile.current_project = None
self.bobs_profile.save()
payload = {"kind": "simple", "timeout": 3600, "grace": 60} payload = {"kind": "simple", "timeout": 3600, "grace": 60}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")


+ 0
- 2
hc/test.py View File

@ -32,7 +32,6 @@ class BaseTestCase(TestCase):
self.bobs_project.save() self.bobs_project.save()
self.bobs_profile = Profile(user=self.bob) self.bobs_profile = Profile(user=self.bob)
self.bobs_profile.current_project = self.project
self.bobs_profile.save() self.bobs_profile.save()
Member.objects.create(user=self.bob, project=self.project) Member.objects.create(user=self.bob, project=self.project)
@ -47,7 +46,6 @@ class BaseTestCase(TestCase):
self.charlies_project.save() self.charlies_project.save()
self.charlies_profile = Profile(user=self.charlie) self.charlies_profile = Profile(user=self.charlie)
self.charlies_profile.current_project = self.charlies_project
self.charlies_profile.save() self.charlies_profile.save()
self.channels_url = "/projects/%s/integrations/" % self.project.code self.channels_url = "/projects/%s/integrations/" % self.project.code

+ 1
- 1
templates/front/projects.html View File

@ -40,7 +40,7 @@
<a id="add-project" href="#" data-toggle="modal" data-target="#add-project-modal"> <a id="add-project" href="#" data-toggle="modal" data-target="#add-project-modal">
<div class="col-sm-6 col-md-4"> <div class="col-sm-6 col-md-4">
<div class="panel project {% if project == request.profile.current_project %}selected{% endif %}">
<div class="panel project">
New Project&hellip; New Project&hellip;
</div> </div>
</div> </div>


Loading…
Cancel
Save