2019-07-02 09:51:50 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2021-04-08 06:59:14 +00:00
|
|
|
from django.contrib.auth.mixins import UserPassesTestMixin
|
2021-09-12 13:00:51 +00:00
|
|
|
from rest_framework import permissions
|
2022-02-17 12:13:31 +00:00
|
|
|
from rest_framework.decorators import action
|
2021-10-21 08:16:50 +00:00
|
|
|
from rest_framework.request import Request
|
2022-02-17 12:13:31 +00:00
|
|
|
from rest_framework.response import Response
|
2019-07-02 09:51:50 +00:00
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
from common.permissions import IsValidUser
|
2019-07-02 09:51:50 +00:00
|
|
|
|
2022-02-24 04:03:40 +00:00
|
|
|
__all__ = ["PermissionsMixin"]
|
2021-04-08 06:59:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PermissionsMixin(UserPassesTestMixin):
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
2021-10-21 08:16:50 +00:00
|
|
|
request: Request
|
2021-04-08 06:59:14 +00:00
|
|
|
|
|
|
|
def get_permissions(self):
|
|
|
|
return self.permission_classes
|
|
|
|
|
|
|
|
def test_func(self):
|
|
|
|
permission_classes = self.get_permissions()
|
|
|
|
for permission_class in permission_classes:
|
|
|
|
if not permission_class().has_permission(self.request, self):
|
|
|
|
return False
|
2021-04-29 09:15:46 +00:00
|
|
|
return True
|