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))
|
||||
per_page = min(int(request.args.get("per_page", 50)), 200)
|
||||
action_filter = request.args.get("action")
|
||||
user_id_filter = request.args.get("user_id")
|
||||
|
||||
query = AuditLog.query.filter_by(organization_id=org_id)
|
||||
if 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())
|
||||
total = query.count()
|
||||
|
||||
@@ -88,23 +88,28 @@ class AuditService:
|
||||
)
|
||||
|
||||
@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.
|
||||
|
||||
Args:
|
||||
organization_id: Organization ID
|
||||
limit: Maximum number of records to return
|
||||
user_id: Optional user ID to filter by
|
||||
action: Optional action type to filter by
|
||||
|
||||
Returns:
|
||||
List of AuditLog instances
|
||||
"""
|
||||
return (
|
||||
AuditLog.query.filter_by(organization_id=organization_id)
|
||||
.order_by(AuditLog.created_at.desc())
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
query = AuditLog.query.filter_by(organization_id=organization_id)
|
||||
|
||||
if user_id:
|
||||
query = query.filter_by(user_id=user_id)
|
||||
|
||||
if action:
|
||||
query = query.filter_by(action=action)
|
||||
|
||||
return query.order_by(AuditLog.created_at.desc()).limit(limit).all()
|
||||
|
||||
# External Authentication Provider Audit Methods
|
||||
|
||||
|
||||
Reference in New Issue
Block a user