Skip to content

Commit

Permalink
Merge pull request #155 from avantifellows/bug/handle_empty_org_header
Browse files Browse the repository at this point in the history
FIX: handle empty org header and no org header, defaults to public
  • Loading branch information
dalmia authored May 7, 2021
2 parents 844f0ca + f421bca commit 441d189
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion organizations/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def get_organization(request):
"""
Returns the value of the `ORGANIZATION` HTTP header
"""
return request.META.get("HTTP_ORGANIZATION", get_public_schema_name())
org = request.META.get("HTTP_ORGANIZATION", get_public_schema_name())
if not org:
return get_public_schema_name()

return org

def get_tenant(self, tenant_model, request):
"""
Expand Down
3 changes: 2 additions & 1 deletion plio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework.response import Response
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from django_tenants.utils import get_public_schema_name
from django.db.models import Count, Q
from plio.models import Video, Plio, Item, Question
from organizations.middleware import OrganizationTenantMiddleware
Expand Down Expand Up @@ -53,7 +54,7 @@ def get_queryset(self):
)

# personal workspace
if organization_shortcode == "":
if organization_shortcode == get_public_schema_name():
return Plio.objects.filter(created_by=self.request.user)

# organizational workspace
Expand Down

0 comments on commit 441d189

Please sign in to comment.