feat(audit): add audit logging for organization invites
Log ORG_INVITE_SENT action when a user sends an organization invite, capturing the invited email and role in the audit metadata.
This commit is contained in:
@@ -8,7 +8,8 @@ from gatehouse_app.services.notification_service import NotificationService
|
|||||||
from gatehouse_app.services.auth_service import AuthService
|
from gatehouse_app.services.auth_service import AuthService
|
||||||
from gatehouse_app.services.organization_service import OrganizationService
|
from gatehouse_app.services.organization_service import OrganizationService
|
||||||
from gatehouse_app.services.email_templates import build_org_invite_html
|
from gatehouse_app.services.email_templates import build_org_invite_html
|
||||||
from gatehouse_app.utils.constants import OrganizationRole
|
from gatehouse_app.utils.constants import AuditAction, OrganizationRole
|
||||||
|
from gatehouse_app.services.audit_service import AuditService
|
||||||
|
|
||||||
|
|
||||||
@api_v1_bp.route("/organizations/<org_id>/invites", methods=["POST"])
|
@api_v1_bp.route("/organizations/<org_id>/invites", methods=["POST"])
|
||||||
@@ -56,6 +57,19 @@ def create_org_invite(org_id):
|
|||||||
logging.getLogger(__name__).info(f"[INVITE] Email queued for {email}")
|
logging.getLogger(__name__).info(f"[INVITE] Email queued for {email}")
|
||||||
email_sent = True # async — assume queued successfully
|
email_sent = True # async — assume queued successfully
|
||||||
|
|
||||||
|
AuditService.log_action(
|
||||||
|
action=AuditAction.ORG_INVITE_SENT,
|
||||||
|
user_id=g.current_user.id,
|
||||||
|
organization_id=org_id,
|
||||||
|
resource_type="org_invite",
|
||||||
|
resource_id=invite.id,
|
||||||
|
metadata={
|
||||||
|
"invited_email": email,
|
||||||
|
"role": role,
|
||||||
|
},
|
||||||
|
description=f"Invitation sent to {email} with role {role}",
|
||||||
|
)
|
||||||
|
|
||||||
response_data = {
|
response_data = {
|
||||||
"invite": {
|
"invite": {
|
||||||
"id": invite.id,
|
"id": invite.id,
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ class AuditAction(str, Enum):
|
|||||||
ORG_MEMBER_REMOVE = "org.member.remove"
|
ORG_MEMBER_REMOVE = "org.member.remove"
|
||||||
ORG_MEMBER_ROLE_CHANGE = "org.member.role_change"
|
ORG_MEMBER_ROLE_CHANGE = "org.member.role_change"
|
||||||
ORG_OWNERSHIP_TRANSFERRED = "org.ownership.transferred"
|
ORG_OWNERSHIP_TRANSFERRED = "org.ownership.transferred"
|
||||||
|
ORG_INVITE_SENT = "org.invite.sent"
|
||||||
|
|
||||||
# Session actions
|
# Session actions
|
||||||
SESSION_CREATE = "session.create"
|
SESSION_CREATE = "session.create"
|
||||||
|
|||||||
Reference in New Issue
Block a user