mirror of
https://github.com/sartography/spiffworkflow-backend.git
synced 2025-02-23 21:08:18 +00:00
Add current_user to logs
This commit is contained in:
parent
0586788d30
commit
539d9a6347
@ -1,8 +1,8 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: ab77f4ccb4d6
|
||||
Revision ID: 097f52a3ec5d
|
||||
Revises:
|
||||
Create Date: 2022-09-15 10:40:27.958824
|
||||
Create Date: 2022-09-16 10:44:23.258357
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ab77f4ccb4d6'
|
||||
revision = '097f52a3ec5d'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
@ -213,6 +213,8 @@ def upgrade():
|
||||
sa.Column('spiff_task_guid', sa.String(length=50), nullable=False),
|
||||
sa.Column('timestamp', sa.DECIMAL(precision=17, scale=6), nullable=False),
|
||||
sa.Column('message', sa.String(length=50), nullable=True),
|
||||
sa.Column('current_user_id', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['current_user_id'], ['user.id'], ),
|
||||
sa.ForeignKeyConstraint(['process_instance_id'], ['process_instance.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
@ -7,6 +7,7 @@ from flask_bpmn.models.db import SpiffworkflowBaseDBModel
|
||||
from sqlalchemy import ForeignKey
|
||||
|
||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||
from spiffworkflow_backend.models.user import UserModel
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -21,3 +22,4 @@ class SpiffLoggingModel(SpiffworkflowBaseDBModel):
|
||||
spiff_task_guid: str = db.Column(db.String(50), nullable=False)
|
||||
timestamp: float = db.Column(db.DECIMAL(17, 6), nullable=False)
|
||||
message: Optional[str] = db.Column(db.String(50), nullable=True)
|
||||
current_user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True)
|
||||
|
@ -4,6 +4,7 @@ import logging
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
|
||||
from flask import g
|
||||
from flask.app import Flask
|
||||
from flask_bpmn.models.db import db
|
||||
|
||||
@ -99,6 +100,8 @@ class SpiffFilter(logging.Filter):
|
||||
if hasattr(tld, "process_instance_id"):
|
||||
process_instance_id = tld.process_instance_id
|
||||
setattr(record, "process_instance_id", process_instance_id) # noqa: B010
|
||||
if hasattr(g, "user") and g.user:
|
||||
setattr(record, "current_user_id", g.user.id) # noqa: B010
|
||||
return True
|
||||
|
||||
|
||||
@ -175,6 +178,7 @@ class DBHandler(logging.Handler):
|
||||
bpmn_task_identifier = str(record.task_spec) # type: ignore
|
||||
timestamp = record.created
|
||||
message = record.msg if hasattr(record, "msg") else None
|
||||
current_user_id = record.current_user_id if hasattr(record, "current_user_id") else None # type: ignore
|
||||
spiff_log = SpiffLoggingModel(
|
||||
process_instance_id=record.process_instance_id, # type: ignore
|
||||
bpmn_process_identifier=bpmn_process_identifier,
|
||||
@ -182,6 +186,7 @@ class DBHandler(logging.Handler):
|
||||
bpmn_task_identifier=bpmn_task_identifier,
|
||||
message=message,
|
||||
timestamp=timestamp,
|
||||
current_user_id=current_user_id,
|
||||
)
|
||||
db.session.add(spiff_log)
|
||||
db.session.commit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user