Skip to content

Commit 7ff46e6

Browse files
chore(CE): add audit logs to sync runs controller (#450)
Co-authored-by: TivonB-AI2 <[email protected]>
1 parent 53b74c4 commit 7ff46e6

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

server/app/controllers/api/v1/sync_runs_controller.rb

+6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
module Api
44
module V1
55
class SyncRunsController < ApplicationController
6+
include AuditLogger
67
before_action :set_sync
78
before_action :set_sync_run, only: [:show]
9+
after_action :create_audit_log
810
attr_reader :sync
911

1012
def index
@@ -31,6 +33,10 @@ def set_sync_run
3133
@sync_run = @sync.sync_runs.find_by(id: params[:id])
3234
render_error(message: "Sync Run not found", status: :not_found) unless @sync_run
3335
end
36+
37+
def create_audit_log
38+
audit!(resource_id: params[:id])
39+
end
3440
end
3541
end
3642
end

server/spec/requests/api/v1/sync_runs_controller_spec.rb

+66
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@
5353
expect(row.dig(:attributes, :status)).to eq(sync_run.status)
5454
expect(response_hash.dig(:links, :first)).to include("http://www.example.com/api/v1/syncs/#{sync.id}/sync_runs?page=1")
5555
end
56+
57+
audit_log = AuditLog.last
58+
expect(audit_log).not_to be_nil
59+
expect(audit_log.user_id).to eq(user.id)
60+
expect(audit_log.action).to eq("index")
61+
expect(audit_log.resource_type).to eq("Sync_run")
62+
expect(audit_log.resource_id).to eq(nil)
63+
expect(audit_log.resource).to eq(nil)
64+
expect(audit_log.workspace_id).to eq(workspace.id)
65+
expect(audit_log.created_at).not_to be_nil
66+
expect(audit_log.updated_at).not_to be_nil
5667
end
5768

5869
it "returns success and fetch sync for member_role" do
@@ -72,6 +83,17 @@
7283
expect(row.dig(:attributes, :status)).to eq(sync_run.status)
7384
expect(response_hash.dig(:links, :first)).to include("http://www.example.com/api/v1/syncs/#{sync.id}/sync_runs?page=1")
7485
end
86+
87+
audit_log = AuditLog.last
88+
expect(audit_log).not_to be_nil
89+
expect(audit_log.user_id).to eq(user.id)
90+
expect(audit_log.action).to eq("index")
91+
expect(audit_log.resource_type).to eq("Sync_run")
92+
expect(audit_log.resource_id).to eq(nil)
93+
expect(audit_log.resource).to eq(nil)
94+
expect(audit_log.workspace_id).to eq(workspace.id)
95+
expect(audit_log.created_at).not_to be_nil
96+
expect(audit_log.updated_at).not_to be_nil
7597
end
7698

7799
it "returns success and fetch sync for viewer_role" do
@@ -91,6 +113,17 @@
91113
expect(row.dig(:attributes, :status)).to eq(sync_run.status)
92114
expect(response_hash.dig(:links, :first)).to include("http://www.example.com/api/v1/syncs/#{sync.id}/sync_runs?page=1")
93115
end
116+
117+
audit_log = AuditLog.last
118+
expect(audit_log).not_to be_nil
119+
expect(audit_log.user_id).to eq(user.id)
120+
expect(audit_log.action).to eq("index")
121+
expect(audit_log.resource_type).to eq("Sync_run")
122+
expect(audit_log.resource_id).to eq(nil)
123+
expect(audit_log.resource).to eq(nil)
124+
expect(audit_log.workspace_id).to eq(workspace.id)
125+
expect(audit_log.created_at).not_to be_nil
126+
expect(audit_log.updated_at).not_to be_nil
94127
end
95128
end
96129

@@ -139,6 +172,17 @@
139172
expect(response_hash.dig(:data, :attributes, :successful_rows)).to eq(sync_runs.first.successful_rows)
140173
expect(response_hash.dig(:data, :attributes, :failed_rows)).to eq(sync_runs.first.failed_rows)
141174
expect(response_hash.dig(:data, :attributes, :status)).to eq(sync_runs.first.status)
175+
176+
audit_log = AuditLog.last
177+
expect(audit_log).not_to be_nil
178+
expect(audit_log.user_id).to eq(user.id)
179+
expect(audit_log.action).to eq("show")
180+
expect(audit_log.resource_type).to eq("Sync_run")
181+
expect(audit_log.resource_id).to eq(sync_runs.first.id)
182+
expect(audit_log.resource).to eq(nil)
183+
expect(audit_log.workspace_id).to eq(workspace.id)
184+
expect(audit_log.created_at).not_to be_nil
185+
expect(audit_log.updated_at).not_to be_nil
142186
end
143187

144188
it "returns success and fetch sync for " do
@@ -153,6 +197,17 @@
153197
expect(response_hash.dig(:data, :attributes, :successful_rows)).to eq(sync_runs.first.successful_rows)
154198
expect(response_hash.dig(:data, :attributes, :failed_rows)).to eq(sync_runs.first.failed_rows)
155199
expect(response_hash.dig(:data, :attributes, :status)).to eq(sync_runs.first.status)
200+
201+
audit_log = AuditLog.last
202+
expect(audit_log).not_to be_nil
203+
expect(audit_log.user_id).to eq(user.id)
204+
expect(audit_log.action).to eq("show")
205+
expect(audit_log.resource_type).to eq("Sync_run")
206+
expect(audit_log.resource_id).to eq(sync_runs.first.id)
207+
expect(audit_log.resource).to eq(nil)
208+
expect(audit_log.workspace_id).to eq(workspace.id)
209+
expect(audit_log.created_at).not_to be_nil
210+
expect(audit_log.updated_at).not_to be_nil
156211
end
157212

158213
it "returns success and fetch sync " do
@@ -166,6 +221,17 @@
166221
expect(response_hash.dig(:data, :attributes, :successful_rows)).to eq(sync_runs.first.successful_rows)
167222
expect(response_hash.dig(:data, :attributes, :failed_rows)).to eq(sync_runs.first.failed_rows)
168223
expect(response_hash.dig(:data, :attributes, :status)).to eq(sync_runs.first.status)
224+
225+
audit_log = AuditLog.last
226+
expect(audit_log).not_to be_nil
227+
expect(audit_log.user_id).to eq(user.id)
228+
expect(audit_log.action).to eq("show")
229+
expect(audit_log.resource_type).to eq("Sync_run")
230+
expect(audit_log.resource_id).to eq(sync_runs.first.id)
231+
expect(audit_log.resource).to eq(nil)
232+
expect(audit_log.workspace_id).to eq(workspace.id)
233+
expect(audit_log.created_at).not_to be_nil
234+
expect(audit_log.updated_at).not_to be_nil
169235
end
170236
end
171237

0 commit comments

Comments
 (0)