21 lines
687 B
Python
21 lines
687 B
Python
from rest_framework import generics
|
|
|
|
from account.permissions import ReadOnly, IsAdmin
|
|
from core.models import GlobalSettings
|
|
from core.serializers import GlobalSettingsSerializer, AnonymousGlobalSettingsSerializer
|
|
|
|
|
|
class GlobalSettingsAPI(generics.RetrieveUpdateAPIView):
|
|
serializer_class = GlobalSettingsSerializer
|
|
permission_classes = [IsAdmin | ReadOnly]
|
|
|
|
def get_serializer_class(self):
|
|
if getattr(self.request.user, 'is_manager', False):
|
|
return GlobalSettingsSerializer
|
|
|
|
# Anonymous users can view only a certain set of fields
|
|
return AnonymousGlobalSettingsSerializer
|
|
|
|
def get_object(self):
|
|
return GlobalSettings.load()
|