refactor: remove db.commit() from audit_service.log_action, all callers use UoW
This commit is contained in:
@@ -128,18 +128,17 @@ def create_test(
|
||||
creator_id=current_user.id,
|
||||
**payload.model_dump(exclude={"technique_id"}),
|
||||
)
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="create_test",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={"name": test.name, "technique_id": str(test.technique_id)},
|
||||
)
|
||||
uow.commit()
|
||||
db.refresh(test)
|
||||
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="create_test",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={"name": test.name, "technique_id": str(test.technique_id)},
|
||||
)
|
||||
|
||||
return test
|
||||
|
||||
|
||||
@@ -169,22 +168,21 @@ def create_test_from_template(
|
||||
technique_id_or_mitre=payload.technique_id,
|
||||
creator_id=current_user.id,
|
||||
)
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="create_test_from_template",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={
|
||||
"name": test.name,
|
||||
"template_id": str(payload.template_id),
|
||||
"technique_id": str(test.technique_id),
|
||||
},
|
||||
)
|
||||
uow.commit()
|
||||
db.refresh(test)
|
||||
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="create_test_from_template",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={
|
||||
"name": test.name,
|
||||
"template_id": str(payload.template_id),
|
||||
"technique_id": str(test.technique_id),
|
||||
},
|
||||
)
|
||||
|
||||
return test
|
||||
|
||||
|
||||
@@ -229,18 +227,17 @@ def update_test(
|
||||
updater_role=current_user.role,
|
||||
**update_data,
|
||||
)
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="update_test",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={"updated_fields": list(update_data.keys())},
|
||||
)
|
||||
uow.commit()
|
||||
db.refresh(test)
|
||||
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="update_test",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={"updated_fields": list(update_data.keys())},
|
||||
)
|
||||
|
||||
return test
|
||||
|
||||
|
||||
@@ -260,18 +257,17 @@ def update_test_red(
|
||||
update_data = payload.model_dump(exclude_unset=True)
|
||||
with UnitOfWork(db) as uow:
|
||||
test = crud_update_test_red(db, test_id, **update_data)
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="update_test_red",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={"updated_fields": list(update_data.keys())},
|
||||
)
|
||||
uow.commit()
|
||||
db.refresh(test)
|
||||
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="update_test_red",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={"updated_fields": list(update_data.keys())},
|
||||
)
|
||||
|
||||
return test
|
||||
|
||||
|
||||
@@ -291,18 +287,17 @@ def update_test_blue(
|
||||
update_data = payload.model_dump(exclude_unset=True)
|
||||
with UnitOfWork(db) as uow:
|
||||
test = crud_update_test_blue(db, test_id, **update_data)
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="update_test_blue",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={"updated_fields": list(update_data.keys())},
|
||||
)
|
||||
uow.commit()
|
||||
db.refresh(test)
|
||||
|
||||
log_action(
|
||||
db,
|
||||
user_id=current_user.id,
|
||||
action="update_test_blue",
|
||||
entity_type="test",
|
||||
entity_id=test.id,
|
||||
details={"updated_fields": list(update_data.keys())},
|
||||
)
|
||||
|
||||
return test
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user