Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added operation audit for idp and user #1974

Closed

Conversation

rolin999
Copy link
Collaborator

@rolin999 rolin999 commented Nov 5, 2024

Description

认证源 & 用户 相关操作审计

Checklist

  • 填写 PR 描述及相关 issue (write PR description and related issue)
  • 代码风格检查通过 (code style check passed)
  • PR 中包含单元测试 (include unit test)
  • 单元测试通过 (unit test passed)
  • 本地开发联调环境验证通过 (local development environment verification passed)

@rolin999 rolin999 requested review from nannan00, narasux and wklken and removed request for nannan00 November 7, 2024 03:54
"status": idp.status,
"plugin_config": idp.plugin_config,
"data_source_match_rules": idp.data_source_match_rules,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于创建场景,建议 plugin_id 也记录

@@ -226,6 +251,16 @@ def put(self, request, *args, **kwargs):
)
idp.set_plugin_cfg(data["plugin_config"])

# 审计记录
add_audit_record(
operator=idp.updater,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 建议提前 current_user 变量,避免依赖使用 B.x = u , C.y = B.x, D.z = C.y

"status": idp.status,
"plugin_config": idp.plugin_config,
"data_source_match_rules": idp.data_source_match_rules,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于创建场景,建议 plugin_id 也记录

extras={
"departments": list(data_source_dept_ids),
# 记录 name 便于前端展示
"name": user.data_source_user.username,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 存在二义性字段建议明确名称, departments => data_source_department_ids
  2. name -> username ,不建议偷偷修改变量 Key,引入排查和理解成本

tenant_id=cur_tenant_id,
id__in=data["user_ids"],
).select_related("data_source_user")
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样查询是将之前已经添加都查询出来了,而不是本次添加的

user_department_relations = DataSourceDepartmentUserRelation.objects.filter(
user_id__in=data_source_user_ids
).values("department_id", "user_id")
user_departments_map = defaultdict(list)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user_departments_map 就近原则

tenant_id=cur_tenant_id,
id__in=data["user_ids"],
).select_related("data_source_user")
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

tenant_id=cur_tenant_id,
id__in=data["user_ids"],
).select_related("data_source_user")
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上;
下同

"extras": data_source_user.extras,
"departments": list(department_ids),
"leaders": list(leader_ids),
"account_expired_at": tenant_user.account_expired_at.strftime("%Y-%m-%d %H:%M:%S"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有 utils 方法

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最好下沉到 tenant_user.account_expored_at_display() 对象的方法;

operation=OperationEnum.MODIFY_IDP,
object_type=ObjectTypeEnum.IDP,
object_id=idp.id,
extras={"data_before": data_before},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不记录data_after?

@@ -41,7 +41,6 @@ class OperationEnum(str, StructuredEnum):
# 认证源
CREATE_IDP = EnumField("create_idp", label=_("创建认证源"))
MODIFY_IDP = EnumField("modify_idp", label=_("修改认证源"))
MODIFY_IDP_STATUS = EnumField("modify_idp_status", label=_("修改认证源状态"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ObjectTypeEnum 已经确定了操作的了行
那么 OperationEnum 只需要保留 增删改查, 不需要带资源类型

@rolin999 rolin999 closed this Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants