Skip to content

Commit

Permalink
feat(api): distinguish between read-only and authenticateed user perm…
Browse files Browse the repository at this point in the history
…issions

ref: #451 #452
  • Loading branch information
jon-nfc committed Dec 24, 2024
1 parent bd31777 commit 384b0e1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
23 changes: 18 additions & 5 deletions app/api/viewsets/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,16 +557,11 @@ def update(self, request, *args, **kwargs):




class ReadOnlyModelViewSet(
viewsets.ReadOnlyModelViewSet,
ModelViewSetBase
):

permission_classes = [
IsAuthenticated,
]


def retrieve(self, request, *args, **kwargs):
"""Sainty override
Expand Down Expand Up @@ -639,3 +634,21 @@ def list(self, request, *args, **kwargs):
)

return response



class AuthUserReadOnlyModelViewSet(
ReadOnlyModelViewSet
):
"""Authenticated User Read-Only Viewset
Use this class if the model only requires that the user be authenticated
to obtain view permission.
Args:
ReadOnlyModelViewSet (class): Read-Only base class
"""

permission_classes = [
IsAuthenticated,
]
4 changes: 2 additions & 2 deletions app/app/viewsets/base/content_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse

from api.viewsets.common import ReadOnlyModelViewSet
from api.viewsets.common import AuthUserReadOnlyModelViewSet

from app.serializers.content_type import (
ContentType,
Expand All @@ -26,7 +26,7 @@
),
)
class ViewSet(
ReadOnlyModelViewSet
AuthUserReadOnlyModelViewSet
):


Expand Down
4 changes: 2 additions & 2 deletions app/app/viewsets/base/permisson.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse

from api.viewsets.common import ReadOnlyModelViewSet
from api.viewsets.common import AuthUserReadOnlyModelViewSet

from app.serializers.permission import (
Permission,
Expand All @@ -26,7 +26,7 @@
),
)
class ViewSet(
ReadOnlyModelViewSet
AuthUserReadOnlyModelViewSet
):


Expand Down
4 changes: 2 additions & 2 deletions app/app/viewsets/base/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse

from api.viewsets.common import ReadOnlyModelViewSet
from api.viewsets.common import AuthUserReadOnlyModelViewSet

from app.serializers.user import (
User,
Expand Down Expand Up @@ -28,7 +28,7 @@
),
)
class ViewSet(
ReadOnlyModelViewSet
AuthUserReadOnlyModelViewSet
):


Expand Down
4 changes: 2 additions & 2 deletions app/core/viewsets/celery_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TaskResultViewSerializer
)

from api.viewsets.common import ReadOnlyModelViewSet
from api.viewsets.common import AuthUserReadOnlyModelViewSet



Expand All @@ -29,7 +29,7 @@
}
),
)
class ViewSet(ReadOnlyModelViewSet):
class ViewSet(AuthUserReadOnlyModelViewSet):

filterset_fields = [
'periodic_task_name',
Expand Down
4 changes: 2 additions & 2 deletions app/itim/viewsets/service_device.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse

from api.viewsets.common import ModelViewSet
from api.viewsets.common import ReadOnlyModelViewSet

from itim.serializers.service import (
Service,
Expand All @@ -18,7 +18,7 @@
partial_update=extend_schema(exclude=True),
destroy=extend_schema(exclude=True)
)
class ViewSet(ModelViewSet):
class ViewSet(ReadOnlyModelViewSet):

filterset_fields = [
'cluster',
Expand Down

0 comments on commit 384b0e1

Please sign in to comment.