Browse Source

Remove Profile.team_name (use Project.name instead) and Profile.current_team (use Profile.current_project instead)

pull/214/head
Pēteris Caune 6 years ago
parent
commit
664aad916a
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
18 changed files with 38 additions and 43 deletions
  1. +4
    -4
      hc/accounts/admin.py
  2. +21
    -0
      hc/accounts/migrations/0024_auto_20190119_1540.py
  3. +1
    -12
      hc/accounts/models.py
  4. +0
    -2
      hc/accounts/tests/test_close_account.py
  5. +0
    -5
      hc/accounts/tests/test_profile.py
  6. +0
    -6
      hc/accounts/views.py
  7. +1
    -1
      hc/front/tests/test_details.py
  8. +1
    -1
      hc/front/tests/test_log.py
  9. +1
    -1
      hc/front/tests/test_pause.py
  10. +1
    -1
      hc/front/tests/test_ping_details.py
  11. +1
    -1
      hc/front/tests/test_remove_check.py
  12. +2
    -2
      hc/front/tests/test_status.py
  13. +1
    -1
      hc/front/tests/test_status_single.py
  14. +1
    -1
      hc/front/tests/test_switch_channel.py
  15. +2
    -2
      hc/front/tests/test_update_name.py
  16. +1
    -1
      hc/front/tests/test_update_timeout.py
  17. +0
    -1
      hc/payments/views.py
  18. +0
    -1
      hc/test.py

+ 4
- 4
hc/accounts/admin.py View File

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


+ 21
- 0
hc/accounts/migrations/0024_auto_20190119_1540.py View File

@ -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',
),
]

+ 1
- 12
hc/accounts/models.py View File

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


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

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


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

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


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

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


+ 1
- 1
hc/front/tests/test_details.py View File

@ -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="[email protected]", password="password")


+ 1
- 1
hc/front/tests/test_log.py View File

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


+ 1
- 1
hc/front/tests/test_pause.py View File

@ -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="[email protected]", password="password")


+ 1
- 1
hc/front/tests/test_ping_details.py View File

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


+ 1
- 1
hc/front/tests/test_remove_check.py View File

@ -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="[email protected]", password="password")


+ 2
- 2
hc/front/tests/test_status.py View File

@ -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="[email protected]", 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="[email protected]", password="password")


+ 1
- 1
hc/front/tests/test_status_single.py View File

@ -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="[email protected]", password="password")


+ 1
- 1
hc/front/tests/test_switch_channel.py View File

@ -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="[email protected]", password="password")


+ 2
- 2
hc/front/tests/test_update_name.py View File

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


+ 1
- 1
hc/front/tests/test_update_timeout.py View File

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


+ 0
- 1
hc/payments/views.py View File

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


+ 0
- 1
hc/test.py View File

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


Loading…
Cancel
Save