Add permissions and settings for priority instance

parent dcc3ccbc
......@@ -8,6 +8,19 @@ SEND_XMPP_ALERTS = True
SEND_PHONE_ALERTS = True
SEND_EMAIL_ALERTS = True
# Priority server?
PRIORITY_SERVER = False
is_priority_server = os.environ.get('DJANGO_PRIORITY_SERVER', None)
if (isinstance(is_priority_server, str) and
is_priority_server.lower() in ['true', 't']):
PRIORITY_SERVER = True
# If priority server, add custom permissions for API
if PRIORITY_SERVER:
default_perms = list(REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'])
default_perms = ['api.permissions.IsPriorityUser'] + default_perms
REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'] = tuple(default_perms)
# Safety check on debug mode for production
if (DEBUG == True):
raise RuntimeError("Turn off debug mode for production")
import logging
from django.conf import settings
from rest_framework import permissions
# Set up logger
logger = logging.getLogger(__name__)
class IsPriorityUser(permissions.BasePermission):
"""Only allow users in the priority users group"""
message = 'You are not authorized to use this API.'
def has_permission(self, request, view):
return request.user.groups.filter(
name=settings.PRIORITY_USERS_GROUP).exists()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment