本文整理汇总了Python中grouper.models.audit_log.AuditLog.add方法的典型用法代码示例。如果您正苦于以下问题:Python AuditLog.add方法的具体用法?Python AuditLog.add怎么用?Python AuditLog.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grouper.models.audit_log.AuditLog
的用法示例。
在下文中一共展示了AuditLog.add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: log
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import add [as 别名]
def log(
self,
authorization, # type: Authorization
action, # type: str
description, # type: str
on_user=None, # type: Optional[str]
on_group=None, # type: Optional[str]
on_permission=None, # type: Optional[str]
category=AuditLogCategory.general, # type: AuditLogCategory
date=None, # type: Optional[datetime]
):
# type: (...) -> None
"""Log an action to the audit log.
Arguments don't cover all use cases yet. This method will be expanded as further use cases
are ported to this service.
"""
actor = self._id_for_user(authorization.actor)
if not date:
date = datetime.utcnow()
# We currently have no way to log audit log entries for objects that no longer exist. This
# should eventually be fixed via a schema change to use strings for all fields of the audit
# log. For now, we'll die with an exception.
user = self._id_for_user(on_user) if on_user else None
group = self._id_for_group(on_group) if on_group else None
permission = self._id_for_permission(on_permission) if on_permission else None
entry = AuditLog(
actor_id=actor,
log_time=date,
action=action,
description=description,
on_user_id=user,
on_group_id=group,
on_permission_id=permission,
category=int(category),
)
entry.add(self.session)
# This should happen at the service layer, not the repository layer, but the API for the
# plugin currently takes a SQL object. This can move to the service layer once a data
# transfer object is defined instead.
self.plugins.log_auditlog_entry(entry)