Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: handle empty org header and no org header, defaults to public #155

Merged
merged 3 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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