Skip to content

Commit ecb82b9

Browse files
authored
Merge pull request #3360 from vkWeb/fix/admin-access
fix(admin): custom admin permission class
2 parents cb4ed0c + e56addd commit ecb82b9

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

contentcuration/contentcuration/viewsets/channel.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
from rest_framework import serializers
2121
from rest_framework.decorators import action
2222
from rest_framework.exceptions import ValidationError
23-
from rest_framework.pagination import PageNumberPagination
2423
from rest_framework.permissions import AllowAny
25-
from rest_framework.permissions import IsAdminUser
2624
from rest_framework.permissions import IsAuthenticated
2725
from rest_framework.response import Response
2826
from rest_framework.serializers import CharField
@@ -52,6 +50,7 @@
5250
from contentcuration.viewsets.common import UUIDInFilter
5351
from contentcuration.viewsets.sync.constants import CHANNEL
5452
from contentcuration.viewsets.sync.utils import generate_update_event
53+
from contentcuration.viewsets.user import IsAdminUser
5554

5655

5756
class ChannelListPagination(ValuesViewsetPageNumberPagination):

contentcuration/contentcuration/viewsets/user.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from django_filters.rest_framework import FilterSet
1717
from rest_framework.decorators import action
1818
from rest_framework.exceptions import ValidationError
19-
from rest_framework.permissions import IsAdminUser
19+
from rest_framework.permissions import BasePermission
2020
from rest_framework.permissions import IsAuthenticated
2121
from rest_framework.response import Response
2222

@@ -39,6 +39,18 @@
3939
from contentcuration.viewsets.sync.constants import VIEWER_M2M
4040

4141

42+
class IsAdminUser(BasePermission):
43+
"""
44+
Our custom permission to check admin authorization.
45+
"""
46+
47+
def has_permission(self, request, view):
48+
try:
49+
return request.user and request.user.is_admin
50+
except AttributeError:
51+
return False
52+
53+
4254
class UserListPagination(ValuesViewsetPageNumberPagination):
4355
page_size = None
4456
page_size_query_param = "page_size"

0 commit comments

Comments
 (0)