Merge pull request #9554 from jumpserver/pr@dev@perf_activities_log

perf: 优化Activity日志[操作日志、登录日志]显示
pull/9574/head
老广 2023-02-15 20:44:40 +08:00 committed by GitHub
commit b464261ed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -53,8 +53,9 @@ class UserLoginCommonMixin:
search_fields = ['id', 'username', 'ip', 'city']
class UserLoginLogViewSet(UserLoginCommonMixin, ListModelMixin, JMSGenericViewSet):
class UserLoginLogViewSet(
UserLoginCommonMixin, RetrieveModelMixin, ListModelMixin, JMSGenericViewSet
):
@staticmethod
def get_org_members():
users = current_org.get_members().values_list('username', flat=True)

View File

@ -110,6 +110,7 @@ class ActivityUnionLogSerializer(serializers.Serializer):
timestamp = serializers.SerializerMethodField()
detail_url = serializers.SerializerMethodField()
content = serializers.SerializerMethodField()
r_type = serializers.CharField(read_only=True)
@staticmethod
def get_timestamp(obj):
@ -132,18 +133,19 @@ class ActivityUnionLogSerializer(serializers.Serializer):
return detail_url
if obj_type == ActivityChoices.operate_log:
detail_url = reverse(
view_name='audits:operate-log-detail',
kwargs={'pk': obj['id']},
api_to_ui=True, is_audit=True
)
detail_url = '%s?%s' % (
reverse(
'audits:operate-log-detail',
kwargs={'pk': obj['id']},
), 'type=action_detail')
elif obj_type == ActivityChoices.task:
detail_url = reverse(
'ops:celery-task-log', kwargs={'pk': detail_id}
)
elif obj_type == ActivityChoices.login_log:
detail_url = '%s?id=%s' % (
reverse('api-audits:login-log-list', api_to_ui=True, is_audit=True),
detail_id
detail_url = reverse(
'audits:login-log-detail',
kwargs={'pk': detail_id},
api_to_ui=True, is_audit=True
)
return detail_url