feat: add user and event filtering to organization activity endpoint
This commit is contained in:
@@ -43,10 +43,13 @@ def get_organization_audit_logs(org_id):
|
|||||||
page = int(request.args.get("page", 1))
|
page = int(request.args.get("page", 1))
|
||||||
per_page = min(int(request.args.get("per_page", 50)), 200)
|
per_page = min(int(request.args.get("per_page", 50)), 200)
|
||||||
action_filter = request.args.get("action")
|
action_filter = request.args.get("action")
|
||||||
|
user_id_filter = request.args.get("user_id")
|
||||||
|
|
||||||
query = AuditLog.query.filter_by(organization_id=org_id)
|
query = AuditLog.query.filter_by(organization_id=org_id)
|
||||||
if action_filter:
|
if action_filter:
|
||||||
query = query.filter_by(action=action_filter)
|
query = query.filter_by(action=action_filter)
|
||||||
|
if user_id_filter:
|
||||||
|
query = query.filter_by(user_id=user_id_filter)
|
||||||
|
|
||||||
query = query.order_by(AuditLog.created_at.desc())
|
query = query.order_by(AuditLog.created_at.desc())
|
||||||
total = query.count()
|
total = query.count()
|
||||||
|
|||||||
@@ -88,23 +88,28 @@ class AuditService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_organization_activity(organization_id, limit=50):
|
def get_organization_activity(organization_id, limit=50, user_id=None, action=None):
|
||||||
"""
|
"""
|
||||||
Get recent activity for an organization.
|
Get recent activity for an organization.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
organization_id: Organization ID
|
organization_id: Organization ID
|
||||||
limit: Maximum number of records to return
|
limit: Maximum number of records to return
|
||||||
|
user_id: Optional user ID to filter by
|
||||||
|
action: Optional action type to filter by
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List of AuditLog instances
|
List of AuditLog instances
|
||||||
"""
|
"""
|
||||||
return (
|
query = AuditLog.query.filter_by(organization_id=organization_id)
|
||||||
AuditLog.query.filter_by(organization_id=organization_id)
|
|
||||||
.order_by(AuditLog.created_at.desc())
|
if user_id:
|
||||||
.limit(limit)
|
query = query.filter_by(user_id=user_id)
|
||||||
.all()
|
|
||||||
)
|
if action:
|
||||||
|
query = query.filter_by(action=action)
|
||||||
|
|
||||||
|
return query.order_by(AuditLog.created_at.desc()).limit(limit).all()
|
||||||
|
|
||||||
# External Authentication Provider Audit Methods
|
# External Authentication Provider Audit Methods
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user