Skip to content

Commit

Permalink
Merge pull request #5623 from benjaoming/fix-control-panel-central
Browse files Browse the repository at this point in the history
Fixes control panel errors occurring in certain cases on Central Server
  • Loading branch information
Benjamin Balder Bach authored Dec 3, 2019
2 parents 0cf4f79 + 3c38e10 commit 8937a36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions kalite/control_panel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
from kalite.facility.forms import FacilityForm
from kalite.facility.models import Facility, FacilityUser, FacilityGroup
from kalite.main.models import ExerciseLog, VideoLog, UserLog, UserLogSummary
from kalite.shared.decorators.auth import require_authorized_admin, require_authorized_access_to_student_data
from kalite.shared.decorators.auth import require_authorized_admin, require_authorized_access_to_student_data,\
skip_central
from kalite.version import VERSION
from kalite import PACKAGE_PATH
from kalite.distributed.views import check_setup_status
Expand Down Expand Up @@ -76,7 +77,7 @@ def process_zone_form(request, zone_id):


@require_authorized_admin
@check_setup_status
@skip_central(check_setup_status)
@render_to("control_panel/zone_management.html")
def zone_management(request, zone_id="None"):
context = control_panel_context(request, zone_id=zone_id)
Expand Down
4 changes: 2 additions & 2 deletions kalite/distributed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def check_setup_status_wrapper_fn(request, *args, **kwargs):
if not request.session.get("registered", True) and BaseClient().test_connection() == "success":
# Being able to register is more rare, so prioritize.
messages.warning(request, mark_safe(_("Please <a href='%s'>follow the directions to register your device</a>, so that it can synchronize with the central server.") % reverse("register_public_key")))
elif not request.session["facility_exists"]:
elif not request.session.get("facility_exists", None):
zone_id = (Zone.objects.all() and Zone.objects.all()[0].id) or "None"
messages.warning(request, mark_safe(_("Please <a href='%s'>create a facility</a> now. Users will not be able to sign up for accounts until you have made a facility.") % reverse("add_facility", kwargs={"zone_id": zone_id})))

elif not request.is_logged_in:
if not request.session.get("registered", True) and BaseClient().test_connection() == "success":
# Being able to register is more rare, so prioritize.
redirect_url = reverse("register_public_key")
elif not request.session["facility_exists"]:
elif not request.session.get("facility_exists", None):
zone = Device.get_own_device().get_zone()
zone_id = "None" if not zone else zone.id
redirect_url = reverse("add_facility", kwargs={"zone_id": zone_id})
Expand Down
11 changes: 11 additions & 0 deletions kalite/shared/decorators/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
from securesync.models import Device, Zone


def skip_central(decorator):

def blank_wrapper(fn):
return fn

if settings.CENTRAL_SERVER:
return blank_wrapper

return lambda *a,**kw: decorator(*a **kw)


def get_user_from_request(handler=None, request=None, *args, **kwargs):
"""
Gets ID of requested user (not necessarily the user logged in)
Expand Down

0 comments on commit 8937a36

Please sign in to comment.