Skip to content

Commit

Permalink
resolve: modify the code style
Browse files Browse the repository at this point in the history
  • Loading branch information
rolin999 committed Dec 3, 2024
1 parent d2980fe commit 0ae6e84
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 109 deletions.
20 changes: 10 additions & 10 deletions src/bk-user/bkuser/apis/web/data_source/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def post(self, request, *args, **kwargs):
)

# 【审计】创建数据源审计对象
auditor = DataSourceAuditor(request.user.username, current_tenant_id, ds)
auditor = DataSourceAuditor(request.user.username, current_tenant_id)
# 【审计】将审计记录保存至数据库
auditor.record_create()
auditor.record_create(ds)

return Response(
DataSourceCreateOutputSLZ(instance={"id": ds.id}).data,
Expand Down Expand Up @@ -243,8 +243,8 @@ def put(self, request, *args, **kwargs):
data = slz.validated_data

# 【审计】创建数据源审计对象并记录变更前数据
auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id, data_source)
auditor.pre_record_data_before()
auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id)
auditor.pre_record_data_before(data_source)

with transaction.atomic():
data_source.field_mapping = data["field_mapping"]
Expand Down Expand Up @@ -289,8 +289,8 @@ def delete(self, request, *args, **kwargs):
waiting_delete_idps = Idp.objects.filter(**idp_filters)

# 【审计】创建数据源审计对象并记录变更前数据
auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id, data_source)
auditor.pre_record_data_before(list(waiting_delete_idps))
auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id)
auditor.pre_record_data_before(data_source, list(waiting_delete_idps))

with transaction.atomic():
# 删除认证源敏感信息
Expand Down Expand Up @@ -506,9 +506,9 @@ def post(self, request, *args, **kwargs):
raise error_codes.DATA_SOURCE_IMPORT_FAILED.f(str(e))

# 【审计】创建数据源审计对象
auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id, data_source)
auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id)
# 【审计】将审计记录保存至数据库
auditor.record_sync(options)
auditor.record_sync(data_source, options)

return Response(
DataSourceImportOrSyncOutputSLZ(
Expand Down Expand Up @@ -554,9 +554,9 @@ def post(self, request, *args, **kwargs):
raise error_codes.DATA_SOURCE_SYNC_TASK_CREATE_FAILED.f(str(e))

# 【审计】创建数据源审计对象
auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id, data_source)
auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id)
# 【审计】将审计记录保存至数据库
auditor.record_sync(options)
auditor.record_sync(data_source, options)

return Response(
DataSourceImportOrSyncOutputSLZ(
Expand Down
24 changes: 14 additions & 10 deletions src/bk-user/bkuser/apis/web/idp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from bkuser.apps.idp.models import Idp, IdpPlugin, IdpSensitiveInfo
from bkuser.apps.permission.constants import PermAction
from bkuser.apps.permission.permissions import perm_class
from bkuser.biz.auditor import IdpAuditor
from bkuser.biz.auditor import DataSourceAuditor, IdpAuditor
from bkuser.common.error_codes import error_codes
from bkuser.common.views import ExcludePatchAPIViewMixin
from bkuser.idp_plugins.constants import BuiltinIdpPluginEnum
Expand Down Expand Up @@ -151,9 +151,9 @@ def post(self, request, *args, **kwargs):
)

# 【审计】创建认证源审计对象
auditor = IdpAuditor(request.user.username, current_tenant_id, idp)
auditor = IdpAuditor(request.user.username, current_tenant_id)
# 【审计】将审计记录保存至数据库
auditor.record_create()
auditor.record_create(idp)

return Response(IdpCreateOutputSLZ(instance=idp).data, status=status.HTTP_201_CREATED)

Expand Down Expand Up @@ -222,8 +222,8 @@ def put(self, request, *args, **kwargs):
data = slz.validated_data

# 【审计】创建认证源审计对象,并记录变更前数据
auditor = IdpAuditor(request.user.username, current_tenant_id, idp)
auditor.pre_record_data_before()
auditor = IdpAuditor(request.user.username, current_tenant_id)
auditor.pre_record_data_before(idp)

with transaction.atomic():
idp.name = data["name"]
Expand Down Expand Up @@ -325,9 +325,9 @@ def post(self, request, *args, **kwargs):
data_source.set_plugin_cfg(plugin_config)

# 【审计】创建认证源审计对象
auditor = IdpAuditor(request.user.username, current_tenant_id, idp)
auditor = IdpAuditor(request.user.username, current_tenant_id)
# 【审计】将审计记录保存至数据库
auditor.record_create()
auditor.record_create(idp)

return Response(IdpCreateOutputSLZ(instance=idp).data, status=status.HTTP_201_CREATED)

Expand Down Expand Up @@ -393,8 +393,11 @@ def put(self, request, *args, **kwargs):
data = slz.validated_data

# 【审计】创建认证源审计对象并记录变更前数据
auditor = IdpAuditor(request.user.username, current_tenant_id, idp)
auditor.pre_record_data_before()
idp_auditor = IdpAuditor(request.user.username, current_tenant_id)
idp_auditor.pre_record_data_before(idp)
# 【审计】创建数据源审计对象并记录变更前数据(本地数据源插件配置)
ds_auditor = DataSourceAuditor(request.user.username, data_source.owner_tenant_id)
ds_auditor.pre_record_data_before(data_source)

with transaction.atomic():
idp.name = data["name"]
Expand All @@ -404,6 +407,7 @@ def put(self, request, *args, **kwargs):
data_source.set_plugin_cfg(data["plugin_config"])

# 【审计】将审计记录保存至数据库
auditor.record_update(idp)
idp_auditor.record_update(idp)
ds_auditor.record_update(data_source)

return Response(status=status.HTTP_204_NO_CONTENT)
12 changes: 4 additions & 8 deletions src/bk-user/bkuser/apis/web/organization/views/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def post(self, request, *args, **kwargs):
request.user.username,
cur_tenant_id,
data_source_user_ids,
OperationEnum.CREATE_USER_DEPARTMENT,
)
auditor.pre_record_data_before()

Expand All @@ -86,7 +85,7 @@ def post(self, request, *args, **kwargs):
DataSourceDepartmentUserRelation.objects.bulk_create(relations, ignore_conflicts=True)

# 【审计】将审计记录保存至数据库
auditor.record(extras={"department_ids": list(data_source_dept_ids)})
auditor.record(OperationEnum.CREATE_USER_DEPARTMENT, extras={"department_ids": list(data_source_dept_ids)})

return Response(status=status.HTTP_204_NO_CONTENT)

Expand Down Expand Up @@ -126,7 +125,6 @@ def put(self, request, *args, **kwargs):
request.user.username,
cur_tenant_id,
data_source_user_ids,
OperationEnum.MODIFY_USER_DEPARTMENT,
)
auditor.pre_record_data_before()

Expand All @@ -142,7 +140,7 @@ def put(self, request, *args, **kwargs):
DataSourceDepartmentUserRelation.objects.bulk_create(relations)

# 【审计】将审计记录保存至数据库
auditor.record(extras={"department_ids": list(data_source_dept_ids)})
auditor.record(OperationEnum.MODIFY_USER_DEPARTMENT, extras={"department_ids": list(data_source_dept_ids)})

return Response(status=status.HTTP_204_NO_CONTENT)

Expand Down Expand Up @@ -178,7 +176,6 @@ def patch(self, request, *args, **kwargs):
request.user.username,
cur_tenant_id,
data_source_user_ids,
OperationEnum.MODIFY_USER_DEPARTMENT,
)
auditor.pre_record_data_before()

Expand All @@ -196,7 +193,7 @@ def patch(self, request, *args, **kwargs):
DataSourceDepartmentUserRelation.objects.bulk_create(relations, ignore_conflicts=True)

# 【审计】将审计记录保存至数据库
auditor.record(extras={"department_id": source_data_source_dept.id})
auditor.record(OperationEnum.MODIFY_USER_DEPARTMENT, extras={"department_id": source_data_source_dept.id})

return Response(status=status.HTTP_204_NO_CONTENT)

Expand Down Expand Up @@ -234,7 +231,6 @@ def delete(self, request, *args, **kwargs):
request.user.username,
cur_tenant_id,
data_source_user_ids,
OperationEnum.DELETE_USER_DEPARTMENT,
)
auditor.pre_record_data_before()

Expand All @@ -243,6 +239,6 @@ def delete(self, request, *args, **kwargs):
).delete()

# 【审计】将审计记录保存至数据库
auditor.record(extras={"department_id": source_data_source_dept.id})
auditor.record(OperationEnum.DELETE_USER_DEPARTMENT, extras={"department_id": source_data_source_dept.id})

return Response(status=status.HTTP_204_NO_CONTENT)
4 changes: 2 additions & 2 deletions src/bk-user/bkuser/apis/web/organization/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def put(self, request, *args, **kwargs):

# 【审计】创建租户用户修改操作审计对象并记录变更前的用户相关信息(数据源用户、部门、上级、租户用户)
auditor = TenantUserUpdateAuditor(request.user.username, cur_tenant_id)
auditor.pre_record_data_before(tenant_user, data_source_user)
auditor.pre_record_data_before(tenant_user)

with transaction.atomic():
data_source_user.username = data["username"]
Expand Down Expand Up @@ -535,7 +535,7 @@ def put(self, request, *args, **kwargs):
tenant_user.save(update_fields=["account_expired_at", "status", "updater", "updated_at"])

# 【审计】将审计记录保存至数据库
auditor.record(tenant_user, data_source_user)
auditor.record(tenant_user)

return Response(status=status.HTTP_204_NO_CONTENT)

Expand Down
Loading

0 comments on commit 0ae6e84

Please sign in to comment.