mirror of https://github.com/jumpserver/jumpserver
refactor: 移动 PermissionsMixin 位置
parent
607b7fd29f
commit
7e4f20f443
|
@ -1,12 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# coding: utf-8
|
||||
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
__all__ = ["DatetimeSearchMixin"]
|
||||
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
class DatetimeSearchMixin:
|
||||
date_format = '%Y-%m-%d'
|
||||
|
@ -36,3 +38,17 @@ class DatetimeSearchMixin:
|
|||
def get(self, request, *args, **kwargs):
|
||||
self.get_date_range()
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class PermissionsMixin(UserPassesTestMixin):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
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
|
||||
return True
|
|
@ -2,7 +2,6 @@
|
|||
#
|
||||
import time
|
||||
from rest_framework import permissions
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
from django.conf import settings
|
||||
|
||||
from orgs.utils import current_org
|
||||
|
@ -95,20 +94,6 @@ class WithBootstrapToken(permissions.BasePermission):
|
|||
return settings.BOOTSTRAP_TOKEN == request_bootstrap_token
|
||||
|
||||
|
||||
class PermissionsMixin(UserPassesTestMixin):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
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
|
||||
return True
|
||||
|
||||
|
||||
class UserCanAnyPermCurrentOrg(permissions.BasePermission):
|
||||
def has_permission(self, request, view):
|
||||
return current_org.can_any_by(request.user)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.views.generic import TemplateView
|
||||
from django.shortcuts import redirect
|
||||
from common.permissions import PermissionsMixin, IsValidUser
|
||||
from common.permissions import IsValidUser
|
||||
from common.mixins.views import PermissionsMixin
|
||||
|
||||
__all__ = ['IndexView']
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
from django.views.generic import TemplateView
|
||||
from django.conf import settings
|
||||
|
||||
from common.permissions import PermissionsMixin, IsOrgAdmin, IsOrgAuditor
|
||||
|
||||
from common.permissions import IsOrgAdmin, IsOrgAuditor
|
||||
from common.mixins.views import PermissionsMixin
|
||||
|
||||
__all__ = ['CeleryTaskLogView']
|
||||
|
||||
|
|
|
@ -11,9 +11,10 @@ from django.contrib.auth import logout as auth_logout
|
|||
|
||||
from common.utils import get_logger
|
||||
from common.permissions import (
|
||||
PermissionsMixin, IsValidUser,
|
||||
IsValidUser,
|
||||
UserCanUpdatePassword
|
||||
)
|
||||
from common.mixins.views import PermissionsMixin
|
||||
from ... import forms
|
||||
from ...models import User
|
||||
from ...utils import (
|
||||
|
|
|
@ -8,9 +8,10 @@ from django.views.generic.edit import UpdateView
|
|||
|
||||
from common.utils import get_logger, ssh_key_gen
|
||||
from common.permissions import (
|
||||
PermissionsMixin, IsValidUser,
|
||||
IsValidUser,
|
||||
UserCanUpdateSSHKey,
|
||||
)
|
||||
from common.mixins.views import PermissionsMixin
|
||||
from ... import forms
|
||||
from ...models import User
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ from formtools.wizard.views import SessionWizardView
|
|||
from django.views.generic import FormView
|
||||
|
||||
from common.utils import get_object_or_none
|
||||
from common.permissions import PermissionsMixin, IsValidUser
|
||||
from common.permissions import IsValidUser
|
||||
from common.mixins.views import PermissionsMixin
|
||||
from ...models import User
|
||||
from ...utils import (
|
||||
send_reset_password_mail, get_password_check_rules, check_password_rules,
|
||||
|
|
Loading…
Reference in New Issue