From 0935457ebd7844476255da7a50f7325a082e2af7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:35:17 -0500 Subject: [PATCH] chore(CE): Add resource link to Syncs Controller (#535) Co-authored-by: TivonB-AI2 --- server/app/controllers/api/v1/syncs_controller.rb | 4 +++- server/spec/requests/api/v1/syncs_controller_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/server/app/controllers/api/v1/syncs_controller.rb b/server/app/controllers/api/v1/syncs_controller.rb index 290bb03f..97a396dd 100644 --- a/server/app/controllers/api/v1/syncs_controller.rb +++ b/server/app/controllers/api/v1/syncs_controller.rb @@ -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] @@ -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 diff --git a/server/spec/requests/api/v1/syncs_controller_spec.rb b/server/spec/requests/api/v1/syncs_controller_spec.rb index fa07b0af..49ea560b 100644 --- a/server/spec/requests/api/v1/syncs_controller_spec.rb +++ b/server/spec/requests/api/v1/syncs_controller_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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