perf: Export resources to add operation logs

This commit is contained in:
jiangweidong
2025-04-03 14:11:45 +08:00
committed by Bryan
parent e8e0ea920b
commit 1f60e328b6
7 changed files with 105 additions and 91 deletions

View File

@@ -2,20 +2,14 @@
#
from django.contrib.auth.mixins import UserPassesTestMixin
from django.http.response import JsonResponse
from django.db.models import Model
from django.utils import translation
from rest_framework import permissions
from rest_framework.request import Request
from audits.const import ActivityChoices
from audits.handler import create_or_update_operate_log
from audits.models import ActivityLog
from common.exceptions import UserConfirmRequired
from orgs.utils import current_org
__all__ = [
"PermissionsMixin",
"RecordViewLogMixin",
"UserConfirmRequiredExceptionMixin",
]
@@ -45,23 +39,3 @@ class PermissionsMixin(UserPassesTestMixin):
if not permission_class().has_permission(self.request, self):
return False
return True
class RecordViewLogMixin:
model: Model
def record_logs(self, ids, action, detail, model=None, **kwargs):
with translation.override('en'):
model = model or self.model
resource_type = model._meta.verbose_name
create_or_update_operate_log(
action, resource_type, force=True, **kwargs
)
activities = [
ActivityLog(
resource_id=resource_id, type=ActivityChoices.operate_log,
detail=detail, org_id=current_org.id,
)
for resource_id in ids
]
ActivityLog.objects.bulk_create(activities)