Skip to content
Snippets Groups Projects
Verified Commit 7f874743 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Disable multi-tenancy for now. Mitigates #77.

parent 1f897403
No related branches found
No related tags found
No related merge requests found
......@@ -3,22 +3,11 @@ from django.db import models
from .util.core_helpers import get_current_school
class SchoolRelatedManager(models.Manager):
def get_queryset(self) -> models.query.QuerySet:
qs = super().get_queryset()
school = get_current_school()
if school:
return qs.filter(school=school)
else:
return qs.none()
class SchoolRelated(models.Model):
class Meta:
abstract = True
objects = SchoolRelatedManager()
# objects = SchoolRelatedManager()
school = models.ForeignKey(
'core.School', on_delete=models.CASCADE, default=get_current_school)
from importlib import import_module
import pkgutil
from typing import Optional, Sequence
from warnings import warn
from django.apps import apps
from django.conf import settings
from django.http import HttpRequest
from django_global_request.middleware import get_request
def get_app_packages() -> Sequence[str]:
""" Find all packages within the biscuit.apps namespace. """
......@@ -34,36 +29,8 @@ def get_app_packages() -> Sequence[str]:
return pkgs
# FIXME Use more specific result type
def get_current_school() -> Optional:
request = get_request()
if request:
# We are inside a web request, thus called from a public interface
if hasattr(request, 'user') and hasattr(request.user, 'person'):
# Use the same school as that of the logged-in user
return request.user.person.school
else:
# Set no school so no data is ever returned
# during an unauthenticated request
return None
else:
# We are called from outside a request (probably shell),
# thus called from a private interface
School = apps.get_model('core.School')
if hasattr(settings, 'DEFAULT_SCHOOL'):
# Use school defined in settings
return School.objects.get(pk=settings.DEFAULT_SCHOOL)
else:
# Use first school
warn('No school set, using first known school.', RuntimeWarning)
return School.objects.first()
# Raise an exception because not finding a school wreaks havoc
raise RuntimeError('No school set or found. Check your database.')
def get_current_school() -> int:
return 1
def is_impersonate(request: HttpRequest) -> bool:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment