Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move permission class to utils #1192

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading