Browse Source

When user has no projects, don't auto-create a project.

pull/217/head
Pēteris Caune 6 years ago
parent
commit
8dd91b247b
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 16 additions and 14 deletions
  1. +0
    -3
      hc/accounts/middleware.py
  2. +0
    -7
      hc/accounts/models.py
  3. +3
    -0
      hc/accounts/views.py
  4. +3
    -2
      hc/front/views.py
  5. +7
    -1
      hc/test.py
  6. +3
    -1
      templates/base.html

+ 0
- 3
hc/accounts/middleware.py View File

@ -10,9 +10,6 @@ class TeamAccessMiddleware(object):
return self.get_response(request)
profile = Profile.objects.for_user(request.user)
if profile.current_project is None:
profile.current_project = profile.get_own_project()
profile.save()
request.profile = profile
request.project = profile.current_project


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

@ -193,13 +193,6 @@ class Profile(models.Model):
self.save()
return True
def get_own_project(self):
project = self.user.project_set.first()
if project is None:
project = Project.objects.create(owner=self.user)
return project
class Project(models.Model):
code = models.UUIDField(default=uuid.uuid4, unique=True)


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

@ -204,6 +204,9 @@ def profile(request):
profile.current_project = None
profile.save()
if request.project == project:
request.project = None
Member.objects.filter(project=project, user=request.user).delete()
ctx["left_project"] = project


+ 3
- 2
hc/front/views.py View File

@ -83,7 +83,7 @@ def _get_project_for_user(request, project_code):
""" Return true if current user has access to the specified account. """
if request.user.is_superuser:
q = Project.objects.all
q = Project.objects.all()
else:
q = request.profile.projects()
@ -434,7 +434,7 @@ def _get_events(check, limit):
def log(request, code):
check = _get_check_for_user(request, code)
limit = request.project.owner_profile.ping_log_limit
limit = check.project.owner_profile.ping_log_limit
ctx = {
"check": check,
"events": _get_events(check, limit),
@ -486,6 +486,7 @@ def status_single(request, code):
@login_required
# @project_required
def channels(request):
if request.method == "POST":
code = request.POST["channel"]


+ 7
- 1
hc/test.py View File

@ -43,4 +43,10 @@ class BaseTestCase(TestCase):
self.charlie.set_password("password")
self.charlie.save()
Profile.objects.create(user=self.charlie)
self.charlies_project = Project(owner=self.charlie)
self.charlies_project.badge_key = self.charlie.username
self.charlies_project.save()
self.charlies_profile = Profile(user=self.charlie)
self.charlies_profile.current_project = self.charlies_project
self.charlies_profile.save()

+ 3
- 1
templates/base.html View File

@ -118,8 +118,10 @@
<a id="nav-email" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">
{% if check %}
{{ check.project }}
{% else %}
{% elif request.project %}
{{ request.project }}
{% else %}
{{ request.user.email }}
{% endif %}
<span class="caret"></span>
</a>


Loading…
Cancel
Save