Skip to content

Commit

Permalink
Move permission class to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorjerse committed Jan 23, 2025
1 parent cfcb430 commit 0509fca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
23 changes: 2 additions & 21 deletions resolwe/flow/views/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@

from django.db.models import Prefetch
from drf_spectacular.utils import extend_schema
from rest_framework import (
exceptions,
mixins,
permissions,
serializers,
status,
viewsets,
)
from rest_framework import exceptions, mixins, serializers, status, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response

Expand All @@ -33,19 +26,7 @@
ResolweCreateModelMixin,
ResolweUpdateModelMixin,
)
from .utils import get_collection_for_user


class IsStaffuser(permissions.BasePermission):
"""Allow access only to staff users."""

message = "Only staff users are allowed."

def has_permission(self, request, view):
"""Return true when request is allowed."""
return bool(
request.user and request.user.is_authenticated and request.user.is_staff
)
from .utils import IsStaffuser, get_collection_for_user


class MoveDataToCollectionSerializer(serializers.Serializer):
Expand Down
12 changes: 12 additions & 0 deletions resolwe/flow/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ def get_collection_for_user(collection_id, user):
return collection


class IsStaffuser(permissions.BasePermission):
"""Allow access only to staff users."""

message = "Only staff users are allowed."

def has_permission(self, request, view):
"""Return true when request is allowed."""
return bool(
request.user and request.user.is_authenticated and request.user.is_staff
)


class IsStaffOrTargetUser(permissions.BasePermission):
"""Permission class for user endpoint."""

Expand Down

0 comments on commit 0509fca

Please sign in to comment.