本文整理汇总了Python中grouper.models.audit_log.AuditLog.get_entries方法的典型用法代码示例。如果您正苦于以下问题:Python AuditLog.get_entries方法的具体用法?Python AuditLog.get_entries怎么用?Python AuditLog.get_entries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grouper.models.audit_log.AuditLog
的用法示例。
在下文中一共展示了AuditLog.get_entries方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_expire_edges
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def test_expire_edges(expired_graph, session): # noqa
""" Test expiration auditing and notification. """
email = session.query(AsyncNotification).all()
assert email == []
for edge in session.query(GroupEdge).all():
assert edge.active == True
# Expire the edges.
background = BackgroundThread(settings, None)
background.expire_edges(session)
# Check that the edges are now marked as inactive.
edges = session.query(GroupEdge).filter(
GroupEdge.group_id == Group.id,
Group.enabled == True,
GroupEdge.expiration != None
).all()
for edge in edges:
assert edge.active == False
# Check that we have two queued email messages.
#
# TODO(rra): It would be nice to check the contents as well.
email = session.query(AsyncNotification).all()
assert len(email) == 2
# Check that we have three audit log entries: one for the expired user and
# two for both "sides" of the expired group membership.
audits = AuditLog.get_entries(session, action="expired_from_group")
assert len(audits) == 3
示例2: get
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def get(self):
user = self.get_current_user()
if not (user_has_permission(self.session, user, AUDIT_VIEWER) or
user_has_permission(self.session, user, AUDIT_MANAGER)):
return self.forbidden()
offset = int(self.get_argument("offset", 0))
limit = int(self.get_argument("limit", 50))
if limit > 200:
limit = 200
open_filter = self.get_argument("filter", "Open Audits")
audits = get_audits(self.session, only_open=(open_filter == "Open Audits"))
open_audits = any([not audit.complete for audit in audits])
total = audits.count()
audits = audits.offset(offset).limit(limit).all()
open_audits = self.session.query(Audit).filter(
Audit.complete == False).all()
can_start = user_has_permission(self.session, user, AUDIT_MANAGER)
# FIXME(herb): make limit selected from ui
audit_log_entries = AuditLog.get_entries(self.session, category=AuditLogCategory.audit,
limit=100)
self.render(
"audits.html", audits=audits, open_filter=open_filter, can_start=can_start,
offset=offset, limit=limit, total=total, open_audits=open_audits,
audit_log_entries=audit_log_entries,
)
示例3: my_log_entries
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def my_log_entries(self):
# type: () -> List[AuditLog]
"""Returns the 20 most recent audit log entries involving this tag
Returns:
a list of AuditLog entries
"""
return AuditLog.get_entries(self.session, on_tag_id=self.id, limit=20)
示例4: get_log_entries_by_permission
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def get_log_entries_by_permission(session, permission, limit=20):
"""For a given permission, return the audit logs that pertain.
Args:
session(models.base.session.Session): database session
permission_name(Permission): permission in question
limit(int): number of results to return
"""
return AuditLog.get_entries(session, on_permission_id=permission.id, limit=limit)
示例5: get_log_entries_by_user
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def get_log_entries_by_user(session, user, limit=20):
"""For a given user, return the audit logs that pertain.
Args:
session(models.base.session.Session): database session
user(User): user in question
limit(int): number of results to return
"""
return AuditLog.get_entries(session, involve_user_id=user.id, limit=limit)
示例6: test_audit_end_to_end
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def test_audit_end_to_end(session, users, groups, http_client, base_url, graph): # noqa: F811
""" Tests an end-to-end audit cycle. """
groupname = "audited-team"
gary_id = users["[email protected]"].id
# make everyone an auditor or global audit will have issues
add_member(groups["auditors"], users["[email protected]"])
add_member(groups["auditors"], users["[email protected]"])
add_member(groups["auditors"], users["[email protected]"])
add_member(groups["auditors"], users["[email protected]"])
# add some users to test removal
add_member(groups[groupname], users["[email protected]"])
add_member(groups[groupname], users["[email protected]"])
graph.update_from_db(session)
# start the audit
end_at_str = (datetime.now() + timedelta(days=10)).strftime("%m/%d/%Y")
fe_url = url(base_url, "/audits/create")
resp = yield http_client.fetch(
fe_url,
method="POST",
body=urlencode({"ends_at": end_at_str}),
headers={"X-Grouper-User": "[email protected]"},
)
assert resp.code == 200
open_audits = get_audits(session, only_open=True).all()
assert len(open_audits) == 4, "audits created"
assert groupname in [x.group.name for x in open_audits], "group we expect also gets audit"
# pull all the info we need to resolve audits, avoids detached sqlalchemy sessions
AuditMember = namedtuple("AuditMember", "am_id, edge_type, edge_id")
Audit = namedtuple("Audit", "audit_id, owner_name, group_name, audit_members")
all_group_ids = [x.group.id for x in open_audits]
open_audits = [
Audit(
x.id,
next(iter(x.group.my_owners())),
x.group.name,
[AuditMember(am.id, am.edge.member_type, am.edge_id) for am in x.my_members()],
)
for x in open_audits
]
# approve everything but the one we added members to
for one_audit in open_audits:
fe_url = url(base_url, "/audits/{}/complete".format(one_audit.audit_id))
if one_audit.group_name == groupname:
continue
# blanket approval
body = urlencode(
{"audit_{}".format(am.am_id): "approved" for am in one_audit.audit_members}
)
resp = yield http_client.fetch(
fe_url, method="POST", body=body, headers={"X-Grouper-User": one_audit.owner_name}
)
assert resp.code == 200
open_audits = get_audits(session, only_open=True).all()
assert len(open_audits) == 1, "only our test group remaining"
one_audit = open_audits[0]
one_audit.id
body_dict = {}
for am in one_audit.my_members():
if gary_id == am.member.id:
# deny
body_dict["audit_{}".format(am.id)] = "remove"
else:
# approve
body_dict["audit_{}".format(am.id)] = "approved"
owner_name = next(iter(one_audit.group.my_owners()))
fe_url = url(base_url, "/audits/{}/complete".format(one_audit.id))
resp = yield http_client.fetch(
fe_url, method="POST", body=urlencode(body_dict), headers={"X-Grouper-User": owner_name}
)
assert resp.code == 200
# check all the logs
assert len(AuditLog.get_entries(session, action="start_audit")) == 1, "global start is logged"
assert (
len(AuditLog.get_entries(session, action="complete_global_audit")) == 1
), "global complete is logged"
for group_id in all_group_ids:
assert (
len(
AuditLog.get_entries(
session,
on_group_id=group_id,
action="complete_audit",
#.........这里部分代码省略.........
示例7: my_log_entries
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def my_log_entries(self):
return AuditLog.get_entries(self.session, on_group_id=self.id, limit=20)
示例8: test_expire_nonauditors
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def test_expire_nonauditors(standard_graph, users, groups, session, permissions):
""" Test expiration auditing and notification. """
graph = standard_graph # noqa
# Test audit autoexpiration for all approvers
approver_roles = ["owner", "np-owner", "manager"]
for role in approver_roles:
# Add non-auditor as an owner to an audited group
add_member(groups["audited-team"], users["[email protected]"], role=role)
session.commit()
graph.update_from_db(session)
group_md = graph.get_group_details("audited-team")
assert group_md.get('audited', False)
# Expire the edges.
background = BackgroundThread(settings, None)
background.expire_nonauditors(session)
# Check that the edges are now marked as inactive.
edge = session.query(GroupEdge).filter_by(group_id=groups["audited-team"].id, member_pk=users["[email protected]"].id).scalar()
assert edge.expiration is not None
assert edge.expiration < datetime.utcnow() + timedelta(days=settings.nonauditor_expiration_days)
assert edge.expiration > datetime.utcnow() + timedelta(days=settings.nonauditor_expiration_days - 1)
assert any(["Subject: Membership in audited-team set to expire" in email.body and "To: [email protected]" in email.body for email in _get_unsent_emails_and_send(session)])
audits = AuditLog.get_entries(session, action="nonauditor_flagged")
assert len(audits) == 3 + 1 * (approver_roles.index(role) + 1)
revoke_member(groups["audited-team"], users["[email protected]"])
# Ensure nonauditor, nonapprovers in audited groups do not get set to expired
member_roles = ["member"]
for role in member_roles:
# Add non-auditor as an owner to an audited group
add_member(groups["audited-team"], users["[email protected]"], role=role)
session.commit()
graph.update_from_db(session)
group_md = graph.get_group_details("audited-team")
assert group_md.get('audited', False)
# Expire the edges.
background = BackgroundThread(settings, None)
background.expire_nonauditors(session)
# Check that the edges are now marked as inactive.
edge = session.query(GroupEdge).filter_by(group_id=groups["audited-team"].id, member_pk=users["[email protected]"].id).scalar()
assert edge.expiration is None
assert not any(["Subject: Membership in audited-team set to expire" in email.body and "To: [email protected]" in email.body for email in _get_unsent_emails_and_send(session)])
audits = AuditLog.get_entries(session, action="nonauditor_flagged")
assert len(audits) == 3 + 1 * len(approver_roles)
revoke_member(groups["audited-team"], users["[email protected]"])
示例9: my_log_entries
# 需要导入模块: from grouper.models.audit_log import AuditLog [as 别名]
# 或者: from grouper.models.audit_log.AuditLog import get_entries [as 别名]
def my_log_entries(self):
return AuditLog.get_entries(self.session, involve_user_id=self.id, limit=20)