Skip to content

Commit

Permalink
Ignore delete and undelete bulk actions for project history logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Guitlle committed Nov 21, 2024
1 parent 2b86136 commit b7433ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 1 addition & 3 deletions kobo/apps/audit_log/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,8 @@ def create_from_bulk_request(request):
bulk_action_to_audit_action = {
'archive': AuditAction.ARCHIVE,
'unarchive': AuditAction.UNARCHIVE,
'delete': AuditAction.DELETE,
'undelete': AuditAction.UNDELETE,
}
audit_action = bulk_action_to_audit_action[action]
audit_action = bulk_action_to_audit_action.get(action)
if audit_action is None:
return # Unsupported action

Expand Down
15 changes: 9 additions & 6 deletions kobo/apps/audit_log/tests/test_project_history_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,13 +882,13 @@ def test_export_v1_creates_log(self):
self.assertEqual(log.object_id, self.asset.id)

@data(
('archive', AuditAction.ARCHIVE),
('unarchive', AuditAction.UNARCHIVE),
('undelete', AuditAction.UNDELETE),
('delete', AuditAction.DELETE),
('archive', AuditAction.ARCHIVE, False),
('unarchive', AuditAction.UNARCHIVE, False),
('undelete', AuditAction.UNDELETE, True),
('delete', AuditAction.DELETE, True),
)
@unpack
def test_bulk_actions(self, bulk_action, audit_action):
def test_bulk_actions(self, bulk_action, audit_action, should_ignore):
assets = [Asset.objects.create(
content={
'survey': [
Expand Down Expand Up @@ -916,4 +916,7 @@ def test_bulk_actions(self, bulk_action, audit_action):
project_hist_logs = ProjectHistoryLog.objects.filter(
object_id__in=[asset.id for asset in assets], action=audit_action
)
self.assertEqual(project_hist_logs.count(), 2)
if not should_ignore:
self.assertEqual(project_hist_logs.count(), 2)
else:
self.assertEqual(project_hist_logs.count(), 0)

0 comments on commit b7433ef

Please sign in to comment.