Skip to content

Commit 1e5d254

Browse files
chore(CE): Add Slack App to DB (#1364)
Co-authored-by: TivonB-AI2 <[email protected]>
1 parent 12d9f3b commit 1e5d254

9 files changed

+121
-1
lines changed

server/app/models/agents/workflow.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Workflow < ApplicationRecord
99
has_many :components, dependent: :destroy
1010
has_many :workflow_runs, dependent: :destroy
1111
has_many :visual_components, as: :configurable, dependent: :destroy
12+
has_one :workflow_integration, dependent: :nullify
1213

1314
enum status: { draft: 0, published: 1 }
1415
enum trigger_type: { website_chatbot: 0, chat_assistant: 1, scheduled: 2, api_trigger: 3 }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"client_id": {
3+
"type": "string"
4+
},
5+
"client_secret": {
6+
"type": "string"
7+
},
8+
"signing_signature": {
9+
"type": "string"
10+
}
11+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
class WorkflowIntegration < ApplicationRecord
4+
SLACK_CONFIG_JSON_SCHEMA = Rails.root.join("app/models/schema_validations/integrations/configuration_slack.json")
5+
6+
belongs_to :workflow, class_name: "Agents::Workflow"
7+
belongs_to :workspace
8+
9+
enum app_type: { slack: 0 }
10+
11+
validates :connection_configuration, presence: true, json: { schema: lambda {
12+
connection_configuration_schema_validation
13+
} }, if: :requires_configuration?
14+
15+
validates :workflow_id, :workspace_id, :app_type, :metadata, presence: true
16+
17+
def requires_configuration?
18+
%w[slack].include?(app_type)
19+
end
20+
21+
def connection_configuration_schema_validation
22+
return unless slack?
23+
24+
SLACK_CONFIG_JSON_SCHEMA
25+
end
26+
end

server/app/models/workspace.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Workspace < ApplicationRecord
3030
has_many :workflows, class_name: "Agents::Workflow", dependent: :destroy
3131
has_many :workflow_runs, class_name: "Agents::WorkflowRun", dependent: :destroy
3232
has_many :workflow_logs, class_name: "Agents::WorkflowLog", dependent: :nullify
33+
has_many :workflow_integrations, dependent: :nullify
3334

3435
belongs_to :organization
3536
has_many :sso_configurations, through: :organization
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class CreateWorkflowIntegration < ActiveRecord::Migration[7.1]
2+
def change
3+
create_table :workflow_integrations, id: :uuid do |t|
4+
t.jsonb :metadata, null: false
5+
t.integer :workspace_id, null: false
6+
t.string :workflow_id, null: false
7+
8+
t.timestamps
9+
end
10+
11+
add_foreign_key :workflow_integrations, :workspaces, validate: false
12+
end
13+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class AddConnectionConfigurationForWorkflowIntegration < ActiveRecord::Migration[7.1]
2+
def up
3+
unless column_exists?(:workflow_integrations, :app_type)
4+
add_column :workflow_integrations, :app_type, :integer, null: false
5+
end
6+
7+
unless column_exists?(:workflow_integrations, :connection_configuration)
8+
add_column :workflow_integrations, :connection_configuration, :jsonb, null: false
9+
end
10+
end
11+
12+
def down
13+
if column_exists?(:workflow_integrations, :app_type)
14+
safety_assured { remove_column :workflow_integrations, :app_type }
15+
end
16+
17+
if column_exists?(:workflow_integrations, :connection_configuration)
18+
safety_assured { remove_column :workflow_integrations, :connection_configuration }
19+
end
20+
end
21+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class ChangeWorkflowIdFromStringtoUuidInWorkflowIntegration < ActiveRecord::Migration[7.1]
2+
def up
3+
safety_assured { change_column :workflow_integrations, :workflow_id, 'uuid USING workflow_id::uuid' }
4+
add_foreign_key :workflow_integrations, :workflows, column: :workflow_id, validate: false
5+
end
6+
7+
def down
8+
safety_assured { change_column :workflow_integrations, :workflow_id, :string }
9+
remove_foreign_key :workflow_integrations, column: :workflow_id
10+
end
11+
end

server/db/schema.rb

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
FactoryBot.define do
4+
factory :workflow_integration, class: "WorkflowIntegration" do
5+
workspace
6+
workflow
7+
app_type { 0 }
8+
connection_configuration do
9+
{
10+
"client_id" => Faker::Alphanumeric.alphanumeric(number: 10),
11+
"client_secret" => Faker::Alphanumeric.alphanumeric(number: 10),
12+
"signing_signature" => Faker::Alphanumeric.alphanumeric(number: 10),
13+
"bot_token" => Faker::Alphanumeric.alphanumeric(number: 10)
14+
}
15+
end
16+
metadata do
17+
{
18+
"data_app_id" => Faker::Alphanumeric.alphanumeric(number: 10),
19+
"workflow_id" => Faker::Alphanumeric.alphanumeric(number: 10),
20+
"visual_component_id" => Faker::Alphanumeric.alphanumeric(number: 10)
21+
}
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)