Skip to content

Commit

Permalink
chore(CE): added audit log to workspace (#442)
Browse files Browse the repository at this point in the history
Co-authored-by: TivonB-AI2 <[email protected]>
  • Loading branch information
github-actions[bot] and TivonB-AI2 authored Oct 28, 2024
1 parent 5c71e0c commit 3740339
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/app/models/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Workspace < ApplicationRecord
has_many :sync_runs, dependent: :nullify
has_many :data_apps, dependent: :nullify
has_many :data_app_sessions, dependent: :nullify
has_many :audit_logs, dependent: :nullify
belongs_to :organization

STATUS_ACTIVE = "active"
Expand Down
2 changes: 1 addition & 1 deletion server/app/serializers/audit_logs_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# app/serializers/audit_logs_serializer.rb
class AuditLogsSerializer < ActiveModel::Serializer
attributes :id, :user_id, :action, :resource_type, :resource_id, :resource, :workspace_id,
:metadata
:metadata, :created_at, :updated_at
end
2 changes: 2 additions & 0 deletions server/spec/controllers/concerns/audit_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace.id).to eq(workspace.id)
expect(audit_log.metadata).to eq(payload.to_unsafe_h)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
end

Expand Down
1 change: 1 addition & 0 deletions server/spec/models/workspace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
it { should have_many(:syncs).dependent(:nullify) }
it { should have_many(:data_apps).dependent(:nullify) }
it { should have_many(:data_app_sessions).dependent(:nullify) }
it { should have_many(:audit_logs).dependent(:nullify) }
it { should belong_to(:organization) }
end

Expand Down
8 changes: 8 additions & 0 deletions server/spec/requests/api/v1/catalogs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(connector.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
end

Expand Down Expand Up @@ -123,6 +125,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(connector.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
end

Expand Down Expand Up @@ -172,6 +176,8 @@
expect(audit_log.resource_id).to eq(existing_catalog.id)
expect(audit_log.resource).to eq(connector.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
end

Expand Down Expand Up @@ -200,6 +206,8 @@
expect(audit_log.resource_id).to eq(existing_catalog.id)
expect(audit_log.resource).to eq(connector.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
end

Expand Down
22 changes: 22 additions & 0 deletions server/spec/requests/api/v1/connector_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns only ai/ml sources" do
Expand All @@ -63,6 +65,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns only ai/ml connectors" do
Expand All @@ -86,6 +90,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success viewer role" do
Expand All @@ -105,6 +111,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success member role" do
Expand All @@ -124,6 +132,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
end
end
Expand All @@ -146,6 +156,8 @@
expect(audit_log.resource_id).to eq(0)
expect(audit_log.resource).to eq("Snowflake")
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns a connector when found for member role" do
Expand All @@ -166,6 +178,8 @@
expect(audit_log.resource_id).to eq(0)
expect(audit_log.resource).to eq("Snowflake")
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns a connector when found for viewer role" do
Expand All @@ -186,6 +200,8 @@
expect(audit_log.resource_id).to eq(0)
expect(audit_log.resource).to eq("Snowflake")
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns empty array not found" do
Expand All @@ -204,6 +220,8 @@
expect(audit_log.resource_id).to eq(0)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end
end

Expand Down Expand Up @@ -239,6 +257,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq("Snowflake")
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success status for a valid connection fro member role" do
Expand All @@ -263,6 +283,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq("Snowflake")
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns authorization failure for a view role user" do
Expand Down
42 changes: 42 additions & 0 deletions server/spec/requests/api/v1/connectors_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and all connectors member role" do
Expand All @@ -67,6 +69,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and all connectors viewer role" do
Expand Down Expand Up @@ -96,6 +100,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and all source connectors" do
Expand All @@ -115,6 +121,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and destination connectors" do
Expand All @@ -134,6 +142,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(nil)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns only data connectors" do
Expand Down Expand Up @@ -193,6 +203,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and fetch connector viewer role" do
Expand Down Expand Up @@ -230,6 +242,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns an error response while fetch connector" do
Expand Down Expand Up @@ -289,6 +303,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(request_body.dig(:connector, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "creates a new connector and returns success for member role" do
Expand All @@ -312,6 +328,8 @@
expect(audit_log.resource_id).to eq(nil)
expect(audit_log.resource).to eq(request_body.dig(:connector, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns unauthorize viewer role" do
Expand Down Expand Up @@ -376,6 +394,8 @@
expect(audit_log.resource_id).to eq(connectors.second.id)
expect(audit_log.resource).to eq(request_body.dig(:connector, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "updates the connector and returns success for member role" do
Expand All @@ -397,6 +417,8 @@
expect(audit_log.resource_id).to eq(connectors.second.id)
expect(audit_log.resource).to eq(request_body.dig(:connector, :name))
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns unauthorize viewer role" do
Expand Down Expand Up @@ -443,6 +465,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and discover object for member role" do
Expand All @@ -465,6 +489,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and should not refresh the catalog when refresh flag is absent" do
Expand All @@ -486,6 +512,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and refresh the catalog when refresh is true" do
Expand All @@ -507,6 +535,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and discover object for viewer role" do
Expand All @@ -529,6 +559,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns an error response while get discover object" do
Expand Down Expand Up @@ -561,6 +593,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success and delete connector" do
Expand All @@ -576,6 +610,8 @@
expect(audit_log.resource_id).to eq(connectors.first.id)
expect(audit_log.resource).to eq(connectors.first.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns fail viwer role" do
Expand Down Expand Up @@ -639,6 +675,8 @@
expect(audit_log.resource_id).to eq(connector.id)
expect(audit_log.resource).to eq(connector.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns success status for a valid query for member role" do
Expand All @@ -659,6 +697,8 @@
expect(audit_log.resource_id).to eq(connector.id)
expect(audit_log.resource).to eq(connector.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns an error message for missing catalog for ai connectors" do
Expand Down Expand Up @@ -713,6 +753,8 @@
expect(audit_log.resource_id).to eq(connector.id)
expect(audit_log.resource).to eq(connector.name)
expect(audit_log.workspace_id).to eq(workspace.id)
expect(audit_log.created_at).not_to be_nil
expect(audit_log.updated_at).not_to be_nil
end

it "returns failure status for a invalid query" do
Expand Down
Loading

0 comments on commit 3740339

Please sign in to comment.