-
Notifications
You must be signed in to change notification settings - Fork 66
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
feat: added operation audit for idp and user #1974
Conversation
"status": idp.status, | ||
"plugin_config": idp.plugin_config, | ||
"data_source_match_rules": idp.data_source_match_rules, | ||
}, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, | ||
}, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 存在二义性字段建议明确名称, departments => data_source_department_ids
- name -> username ,不建议偷偷修改变量 Key,引入排查和理解成本
tenant_id=cur_tenant_id, | ||
id__in=data["user_ids"], | ||
).select_related("data_source_user") | ||
] |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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") | ||
] |
There was a problem hiding this comment.
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") | ||
] |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有 utils 方法
There was a problem hiding this comment.
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}, |
There was a problem hiding this comment.
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=_("修改认证源状态")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObjectTypeEnum 已经确定了操作的了行
那么 OperationEnum 只需要保留 增删改查
, 不需要带资源类型
Description
认证源 & 用户 相关操作审计
Checklist