2017-01-26 15:34:24 +01:00
|
|
|
from django.contrib.auth.models import AnonymousUser
|
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
from ..utils.access_permissions import BaseAccessPermissions
|
2017-01-26 15:34:24 +01:00
|
|
|
from ..utils.auth import anonymous_is_enabled, has_perm
|
2016-02-11 22:58:32 +01:00
|
|
|
|
2016-02-11 11:29:19 +01:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
class ProjectorAccessPermissions(BaseAccessPermissions):
|
|
|
|
"""
|
|
|
|
Access permissions container for Projector and ProjectorViewSet.
|
|
|
|
"""
|
2016-09-17 22:26:23 +02:00
|
|
|
def check_permissions(self, user):
|
2016-02-11 11:29:19 +01:00
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
Returns True if the user has read access model instances.
|
2016-02-11 11:29:19 +01:00
|
|
|
"""
|
2016-12-17 09:30:20 +01:00
|
|
|
return has_perm(user, 'core.can_see_projector')
|
2016-02-11 22:58:32 +01:00
|
|
|
|
2016-03-02 00:46:19 +01:00
|
|
|
def get_serializer_class(self, user=None):
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
|
|
|
Returns serializer class.
|
|
|
|
"""
|
|
|
|
from .serializers import ProjectorSerializer
|
|
|
|
|
|
|
|
return ProjectorSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class TagAccessPermissions(BaseAccessPermissions):
|
|
|
|
"""
|
|
|
|
Access permissions container for Tag and TagViewSet.
|
|
|
|
"""
|
2016-09-17 22:26:23 +02:00
|
|
|
def check_permissions(self, user):
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
|
|
|
Returns True if the user has read access model instances.
|
|
|
|
"""
|
|
|
|
# Every authenticated user can retrieve tags. Anonymous users can do
|
|
|
|
# so if they are enabled.
|
2017-01-26 15:34:24 +01:00
|
|
|
return not isinstance(user, AnonymousUser) or anonymous_is_enabled()
|
2016-02-11 22:58:32 +01:00
|
|
|
|
2016-03-02 00:46:19 +01:00
|
|
|
def get_serializer_class(self, user=None):
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
|
|
|
Returns serializer class.
|
|
|
|
"""
|
|
|
|
from .serializers import TagSerializer
|
|
|
|
|
|
|
|
return TagSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class ChatMessageAccessPermissions(BaseAccessPermissions):
|
|
|
|
"""
|
|
|
|
Access permissions container for ChatMessage and ChatMessageViewSet.
|
|
|
|
"""
|
2016-09-17 22:26:23 +02:00
|
|
|
def check_permissions(self, user):
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
|
|
|
Returns True if the user has read access model instances.
|
|
|
|
"""
|
|
|
|
# Anonymous users can see the chat if the anonymous group has the
|
|
|
|
# permission core.can_use_chat. But they can not use it. See views.py.
|
2016-12-17 09:30:20 +01:00
|
|
|
return has_perm(user, 'core.can_use_chat')
|
2016-02-11 22:58:32 +01:00
|
|
|
|
2016-03-02 00:46:19 +01:00
|
|
|
def get_serializer_class(self, user=None):
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
|
|
|
Returns serializer class.
|
|
|
|
"""
|
|
|
|
from .serializers import ChatMessageSerializer
|
|
|
|
|
|
|
|
return ChatMessageSerializer
|
|
|
|
|
|
|
|
|
2016-10-21 11:05:24 +02:00
|
|
|
class ProjectorMessageAccessPermissions(BaseAccessPermissions):
|
|
|
|
"""
|
|
|
|
Access permissions for ProjectorMessage.
|
|
|
|
"""
|
|
|
|
def check_permissions(self, user):
|
|
|
|
"""
|
|
|
|
Returns True if the user has read access model instances.
|
|
|
|
"""
|
2016-12-17 09:30:20 +01:00
|
|
|
return has_perm(user, 'core.can_see_projector')
|
2016-10-21 11:05:24 +02:00
|
|
|
|
|
|
|
def get_serializer_class(self, user=None):
|
|
|
|
"""
|
|
|
|
Returns serializer class.
|
|
|
|
"""
|
|
|
|
from .serializers import ProjectorMessageSerializer
|
|
|
|
|
|
|
|
return ProjectorMessageSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class CountdownAccessPermissions(BaseAccessPermissions):
|
|
|
|
"""
|
|
|
|
Access permissions for Countdown.
|
|
|
|
"""
|
|
|
|
def check_permissions(self, user):
|
|
|
|
"""
|
|
|
|
Returns True if the user has read access model instances.
|
|
|
|
"""
|
2016-12-17 09:30:20 +01:00
|
|
|
return has_perm(user, 'core.can_see_projector')
|
2016-10-21 11:05:24 +02:00
|
|
|
|
|
|
|
def get_serializer_class(self, user=None):
|
|
|
|
"""
|
|
|
|
Returns serializer class.
|
|
|
|
"""
|
|
|
|
from .serializers import CountdownSerializer
|
|
|
|
|
|
|
|
return CountdownSerializer
|
|
|
|
|
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
class ConfigAccessPermissions(BaseAccessPermissions):
|
|
|
|
"""
|
|
|
|
Access permissions container for the config (ConfigStore and
|
|
|
|
ConfigViewSet).
|
|
|
|
"""
|
2016-09-17 22:26:23 +02:00
|
|
|
def check_permissions(self, user):
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
|
|
|
Returns True if the user has read access model instances.
|
|
|
|
"""
|
|
|
|
# Every authenticated user can see the metadata and list or retrieve
|
|
|
|
# the config. Anonymous users can do so if they are enabled.
|
2017-01-26 15:34:24 +01:00
|
|
|
return not isinstance(user, AnonymousUser) or anonymous_is_enabled()
|
2016-02-11 22:58:32 +01:00
|
|
|
|
2016-03-02 00:46:19 +01:00
|
|
|
def get_full_data(self, instance):
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
2016-03-02 00:46:19 +01:00
|
|
|
Returns the serlialized config data.
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
|
|
|
from .config import config
|
2016-09-30 20:42:58 +02:00
|
|
|
from .models import ConfigStore
|
2016-02-11 22:58:32 +01:00
|
|
|
|
2016-03-02 00:46:19 +01:00
|
|
|
# Attention: The format of this response has to be the same as in
|
|
|
|
# the retrieve method of ConfigViewSet.
|
2016-09-30 20:42:58 +02:00
|
|
|
if isinstance(instance, ConfigStore):
|
|
|
|
result = {'key': instance.key, 'value': config[instance.key]}
|
|
|
|
else:
|
|
|
|
# It is possible, that the caching system already sends the correct data as "instance".
|
|
|
|
result = instance
|
|
|
|
return result
|