Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/app/models/agents/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ class Workflow < ApplicationRecord
has_many :components, dependent: :destroy
has_many :workflow_runs, dependent: :destroy
has_many :visual_components, as: :configurable, dependent: :destroy
<<<<<<< HEAD
=======
has_one :workflow_integration, dependent: :destroy
>>>>>>> e5a9ff4e (fix(CE): rename integration folder for Workflow Integration (#1387))

enum status: { draft: 0, published: 1 }
enum trigger_type: { website_chatbot: 0, chat_assistant: 1, scheduled: 2, api_trigger: 3 }
enum trigger_type: { website_chatbot: 0, chat_assistant: 1, scheduled: 2, api_trigger: 3, slack: 4 }

validates :name, presence: true, uniqueness: { scope: :workspace_id, case_sensitive: false }
validates :token, uniqueness: true, allow_nil: true
Expand Down
28 changes: 28 additions & 0 deletions server/app/models/agents/workflow_integration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Agents
class WorkflowIntegration < ApplicationRecord
SLACK_CONFIG_JSON_SCHEMA = Rails.root.join("app/models/schema_validations/integrations/configuration_slack.json")

belongs_to :workflow, class_name: "Agents::Workflow"
belongs_to :workspace

enum app_type: { slack: 0 }

validates :connection_configuration, presence: true, json: { schema: lambda {
connection_configuration_schema_validation
} }, if: :requires_configuration?

validates :workflow_id, :workspace_id, :app_type, :metadata, presence: true

def requires_configuration?
%w[slack].include?(app_type)
end

def connection_configuration_schema_validation
return unless slack?

SLACK_CONFIG_JSON_SCHEMA
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"client_id": {
"type": "string"
},
"client_secret": {
"type": "string"
},
"signing_signature": {
"type": "string"
}
}
4 changes: 4 additions & 0 deletions server/app/models/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Workspace < ApplicationRecord
has_many :workflows, class_name: "Agents::Workflow", dependent: :destroy
has_many :workflow_runs, class_name: "Agents::WorkflowRun", dependent: :destroy
has_many :workflow_logs, class_name: "Agents::WorkflowLog", dependent: :nullify
<<<<<<< HEAD
=======
has_many :workflow_integrations, class_name: "Agents::WorkflowIntegration", dependent: :nullify
>>>>>>> e5a9ff4e (fix(CE): rename integration folder for Workflow Integration (#1387))

belongs_to :organization
has_many :sso_configurations, through: :organization
Expand Down
24 changes: 24 additions & 0 deletions server/spec/factories/agents/workflow_integration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

FactoryBot.define do
factory :workflow_integration, class: "Agents::WorkflowIntegration" do
workspace
workflow
app_type { 0 }
connection_configuration do
{
"client_id" => Faker::Alphanumeric.alphanumeric(number: 10),
"client_secret" => Faker::Alphanumeric.alphanumeric(number: 10),
"signing_signature" => Faker::Alphanumeric.alphanumeric(number: 10),
"bot_token" => Faker::Alphanumeric.alphanumeric(number: 10)
}
end
metadata do
{
"data_app_id" => Faker::Alphanumeric.alphanumeric(number: 10),
"workflow_id" => Faker::Alphanumeric.alphanumeric(number: 10),
"visual_component_id" => Faker::Alphanumeric.alphanumeric(number: 10)
}
end
end
end
59 changes: 59 additions & 0 deletions server/spec/models/agents/workflow_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Agents::WorkflowIntegration, type: :model do
describe "associations" do
it { should belong_to(:workspace) }
it { should belong_to(:workflow) }
end

describe "enums" do
it { should define_enum_for(:app_type).with_values(slack: 0) }
end

describe "validations" do
subject { build(:workflow_integration) }

it { should validate_presence_of(:workflow_id) }
it { should validate_presence_of(:workspace_id) }
it { should validate_presence_of(:app_type) }
it { should validate_presence_of(:connection_configuration) }
it { should validate_presence_of(:metadata) }
end

context "validates json schema of configuration" do
context "validates json schema of workflow integrations for slack" do
it "returns invalid for workflow integrations for slack without valid configuration" do
workflow = create(:workflow)
workflow_integration = Agents::WorkflowIntegration.new(
workflow_id: workflow.id,
app_type: :slack,
workspace_id: workflow.workspace_id,
connection_configuration: nil
)
expect(workflow_integration).not_to be_valid
end

it "returns valid for workflow integrations for slack with valid configuration" do
workflow = create(:workflow)
workflow_integration = Agents::WorkflowIntegration.new(
workflow_id: workflow.id,
app_type: :slack,
workspace_id: workflow.workspace_id,
connection_configuration: {
"client_id": "test_client_id",
"client_secret": "test_client_secret",
"signing_signature": "test_signing_signature"
},
metadata: {
"data_app_id": "test_data_app_id",
"workflow_id": "test_workflow_id",
"visual_component_id": "test_visual_component_id"
}
)
expect(workflow_integration).to be_valid
end
end
end
end
3 changes: 2 additions & 1 deletion server/spec/models/agents/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
it { should have_many(:components).dependent(:destroy) }
it { should have_many(:edges).dependent(:destroy) }
it { should have_many(:workflow_runs).dependent(:destroy) }
it { should have_one(:workflow_integration).dependent(:destroy) }
end

describe "enums" do
it { should define_enum_for(:status).with_values(draft: 0, published: 1) }
it {
should define_enum_for(:trigger_type).with_values(website_chatbot: 0, chat_assistant: 1, scheduled: 2,
api_trigger: 3)
api_trigger: 3, slack: 4)
}
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 @@ -39,6 +39,7 @@
it { should belong_to(:organization) }
it { should have_many(:workflows).dependent(:destroy) }
it { should have_many(:workflow_runs).dependent(:destroy) }
it { should have_many(:workflow_integrations).dependent(:nullify) }
end

context "before_validation callbacks" do
Expand Down
Loading