Skip to content

Commit

Permalink
chore(CE): Add resource link to Syncs Controller (#535)
Browse files Browse the repository at this point in the history
Co-authored-by: TivonB-AI2
  • Loading branch information
github-actions[bot] authored Dec 16, 2024
1 parent d672005 commit 0935457
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/app/controllers/api/v1/syncs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module V1
class SyncsController < ApplicationController
include Syncs
include AuditLogger
include ResourceLinkBuilder
before_action :set_sync, only: %i[show update enable destroy]
before_action :modify_sync_params, only: %i[create update]

Expand Down Expand Up @@ -129,7 +130,8 @@ def modify_sync_params

def create_audit_log
resource_id = @resource_id || params[:id]
audit!(action: @action, resource_id:, resource: @audit_resource, payload: @payload)
resource_link = @action == "delete" ? nil : build_link!(resource_id:)
audit!(action: @action, resource_id:, resource: @audit_resource, payload: @payload, resource_link:)
end

def sync_params
Expand Down
10 changes: 10 additions & 0 deletions server/spec/requests/api/v1/syncs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
expect(audit_log.resource_id).to eq(response_hash["data"]["id"].to_i)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{response_hash['data']['id'].to_i}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand Down Expand Up @@ -254,6 +255,7 @@
expect(audit_log.resource_id).to eq(response_hash["data"]["id"].to_i)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{response_hash['data']['id'].to_i}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand Down Expand Up @@ -284,6 +286,7 @@
expect(audit_log.resource_id).to eq(response_hash["data"]["id"].to_i)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{response_hash['data']['id'].to_i}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand Down Expand Up @@ -345,6 +348,7 @@
expect(audit_log.resource_id).to eq(response_hash["data"]["id"].to_i)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{response_hash['data']['id'].to_i}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand All @@ -371,6 +375,7 @@
expect(audit_log.resource_id).to eq(response_hash["data"]["id"].to_i)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{response_hash['data']['id'].to_i}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand Down Expand Up @@ -427,6 +432,7 @@
expect(audit_log.resource_id).to eq(syncs.first.id)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{syncs.first.id}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand Down Expand Up @@ -454,6 +460,7 @@
expect(audit_log.resource_id).to eq(syncs.first.id)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{syncs.first.id}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand Down Expand Up @@ -509,6 +516,7 @@
expect(audit_log.resource_id).to eq(syncs.first.id)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{syncs.first.id}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand All @@ -535,6 +543,7 @@
expect(audit_log.resource_id).to eq(syncs.first.id)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{syncs.first.id}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand Down Expand Up @@ -581,6 +590,7 @@
expect(audit_log.resource_id).to eq(syncs.first.id)
expect(audit_log.resource).to eq(request_body.dig(:sync, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.resource_link).to eq("/activate/syncs/#{syncs.first.id}")
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
Expand Down

0 comments on commit 0935457

Please sign in to comment.