mirror of https://github.com/jumpserver/jumpserver
parent
7d94e17e03
commit
ea7d3c0651
|
@ -45,7 +45,7 @@ class AuthValidateMixin(serializers.Serializer):
|
||||||
validated_data['secret'] = secret
|
validated_data['secret'] = secret
|
||||||
for field in ('secret',):
|
for field in ('secret',):
|
||||||
value = validated_data.get(field)
|
value = validated_data.get(field)
|
||||||
if value is None:
|
if not value:
|
||||||
validated_data.pop(field, None)
|
validated_data.pop(field, None)
|
||||||
validated_data.pop('passphrase', None)
|
validated_data.pop('passphrase', None)
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ class ChangeSecretAutomationSerializer(AuthValidateMixin, BaseAutomationSerializ
|
||||||
}}
|
}}
|
||||||
|
|
||||||
def validate_password_rules(self, password_rules):
|
def validate_password_rules(self, password_rules):
|
||||||
secret_type = self.initial_secret_type
|
secret_type = self.initial_data['secret_type']
|
||||||
if secret_type != SecretType.PASSWORD:
|
if secret_type != SecretType.PASSWORD:
|
||||||
return password_rules
|
return password_rules
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,10 @@ from django.conf import settings
|
||||||
from rest_framework import permissions
|
from rest_framework import permissions
|
||||||
|
|
||||||
from authentication.const import ConfirmType
|
from authentication.const import ConfirmType
|
||||||
from common.exceptions import UserConfirmRequired
|
|
||||||
from orgs.utils import tmp_to_root_org
|
|
||||||
from authentication.models import ConnectionToken
|
from authentication.models import ConnectionToken
|
||||||
|
from common.exceptions import UserConfirmRequired
|
||||||
from common.utils import get_object_or_none
|
from common.utils import get_object_or_none
|
||||||
|
from orgs.utils import tmp_to_root_org
|
||||||
|
|
||||||
|
|
||||||
class IsValidUser(permissions.IsAuthenticated, permissions.BasePermission):
|
class IsValidUser(permissions.IsAuthenticated, permissions.BasePermission):
|
||||||
|
@ -17,13 +17,13 @@ class IsValidUser(permissions.IsAuthenticated, permissions.BasePermission):
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
return super().has_permission(request, view) \
|
return super().has_permission(request, view) \
|
||||||
and request.user.is_valid
|
and request.user.is_valid
|
||||||
|
|
||||||
|
|
||||||
class IsValidUserOrConnectionToken(IsValidUser):
|
class IsValidUserOrConnectionToken(IsValidUser):
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
return super().has_permission(request, view) \
|
return super().has_permission(request, view) \
|
||||||
or self.is_valid_connection_token(request)
|
or self.is_valid_connection_token(request)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_valid_connection_token(request):
|
def is_valid_connection_token(request):
|
||||||
|
@ -38,13 +38,13 @@ class IsValidUserOrConnectionToken(IsValidUser):
|
||||||
class OnlySuperUser(IsValidUser):
|
class OnlySuperUser(IsValidUser):
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
return super().has_permission(request, view) \
|
return super().has_permission(request, view) \
|
||||||
and request.user.is_superuser
|
and request.user.is_superuser
|
||||||
|
|
||||||
|
|
||||||
class IsServiceAccount(IsValidUser):
|
class IsServiceAccount(IsValidUser):
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
return super().has_permission(request, view) \
|
return super().has_permission(request, view) \
|
||||||
and request.user.is_service_account
|
and request.user.is_service_account
|
||||||
|
|
||||||
|
|
||||||
class WithBootstrapToken(permissions.BasePermission):
|
class WithBootstrapToken(permissions.BasePermission):
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.utils import timezone
|
|
||||||
from django.utils.timesince import timesince
|
|
||||||
from django.db.models import Count, Max, F
|
from django.db.models import Count, Max, F
|
||||||
from django.http.response import JsonResponse, HttpResponse
|
from django.http.response import JsonResponse, HttpResponse
|
||||||
from rest_framework.views import APIView
|
from django.utils import timezone
|
||||||
|
from django.utils.timesince import timesince
|
||||||
from rest_framework.permissions import AllowAny
|
from rest_framework.permissions import AllowAny
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from users.models import User
|
|
||||||
from assets.models import Asset
|
|
||||||
from assets.const import AllTypes
|
from assets.const import AllTypes
|
||||||
from terminal.models import Session, Command
|
from assets.models import Asset
|
||||||
from terminal.utils import ComponentsPrometheusMetricsUtil
|
from audits.const import LoginStatusChoices
|
||||||
from orgs.utils import current_org
|
from audits.models import UserLoginLog, PasswordChangeLog, OperateLog, FTPLog
|
||||||
|
from common.utils import lazyproperty
|
||||||
|
from common.utils.timezone import local_now, local_zero_hour
|
||||||
from ops.const import JobStatus
|
from ops.const import JobStatus
|
||||||
from ops.models import Job, JobExecution
|
from ops.models import Job, JobExecution
|
||||||
from common.utils import lazyproperty
|
|
||||||
from audits.models import UserLoginLog, PasswordChangeLog, OperateLog, FTPLog
|
|
||||||
from audits.const import LoginStatusChoices
|
|
||||||
from common.utils.timezone import local_now, local_zero_hour
|
|
||||||
from orgs.caches import OrgResourceStatisticsCache
|
from orgs.caches import OrgResourceStatisticsCache
|
||||||
|
from orgs.utils import current_org
|
||||||
|
from terminal.models import Session, Command
|
||||||
|
from terminal.utils import ComponentsPrometheusMetricsUtil
|
||||||
|
from users.models import User
|
||||||
|
|
||||||
__all__ = ['IndexApi']
|
__all__ = ['IndexApi']
|
||||||
|
|
||||||
|
@ -296,9 +296,13 @@ class DatesLoginMetricMixin:
|
||||||
return self.login_logs_queryset.filter(status=LoginStatusChoices.success).count()
|
return self.login_logs_queryset.filter(status=LoginStatusChoices.success).count()
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def user_login_amount(self):
|
def user_login_logs_amount(self):
|
||||||
return self.login_logs_queryset.values('username').count()
|
return self.login_logs_queryset.values('username').count()
|
||||||
|
|
||||||
|
@lazyproperty
|
||||||
|
def user_login_amount(self):
|
||||||
|
return self.login_logs_queryset.values('username').distinct().count()
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def operate_logs_amount(self):
|
def operate_logs_amount(self):
|
||||||
return self.operate_logs_queryset.count()
|
return self.operate_logs_queryset.count()
|
||||||
|
@ -379,6 +383,11 @@ class IndexApi(DateTimeMixin, DatesLoginMetricMixin, APIView):
|
||||||
'total_count_login_users': self.user_login_amount
|
'total_count_login_users': self.user_login_amount
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if _all or query_params.get('total_count') or query_params.get('total_count_login_user_logs'):
|
||||||
|
data.update({
|
||||||
|
'total_count_login_user_logs': self.user_login_logs_amount
|
||||||
|
})
|
||||||
|
|
||||||
if _all or query_params.get('total_count') or query_params.get('total_count_today_active_assets'):
|
if _all or query_params.get('total_count') or query_params.get('total_count_today_active_assets'):
|
||||||
data.update({
|
data.update({
|
||||||
'total_count_today_active_assets': caches.total_count_today_active_assets,
|
'total_count_today_active_assets': caches.total_count_today_active_assets,
|
||||||
|
|
Loading…
Reference in New Issue