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
11 changes: 11 additions & 0 deletions app/graphql/types/flow_disabled_reason_enum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Types
class FlowDisabledReasonEnum < Types::BaseEnum
description 'The disabled reason of a flow.'

Flow::DISABLED_REASON.each do |reason, settings|
value reason.upcase, settings[:description], value: reason.to_s
end
end
end
4 changes: 4 additions & 0 deletions app/graphql/types/flow_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class FlowType < Types::BaseObject

field :name, String, null: false, description: 'Name of the flow'

field :disabled_reason, Types::FlowDisabledReasonEnum,
null: true,
description: 'The reason why the flow is disabled, if it is disabled'

field :validation_status, Types::FlowValidationStatusEnum,
null: false,
description: 'The validation status of the flow'
Expand Down
23 changes: 23 additions & 0 deletions app/models/flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ class Flow < ApplicationRecord
invalid: 2,
}.with_indifferent_access

DISABLED_REASON = {
_dummy: { db: 0, description: 'Dummy value' }, # temporary until the first real disabled reason gets introduced
}.with_indifferent_access

belongs_to :project, class_name: 'NamespaceProject'
belongs_to :flow_type
belongs_to :starting_node, class_name: 'NodeFunction', optional: true

enum :validation_status, VALIDATION_STATUS, prefix: :validation_status
enum :disabled_reason, DISABLED_REASON.transform_values { |v| v[:db] }, prefix: :disabled_reason

has_many :flow_settings, class_name: 'FlowSetting', inverse_of: :flow
has_many :node_functions, class_name: 'NodeFunction', inverse_of: :flow
Expand All @@ -25,20 +30,38 @@ class Flow < ApplicationRecord
in: VALIDATION_STATUS.keys.map(&:to_s),
}

validates :disabled_reason,
inclusion: {
in: DISABLED_REASON.keys.map(&:to_s),
},
if: :disabled?

validates :name, presence: true,
allow_blank: false,
uniqueness: { case_sensitive: false, scope: :project_id }

validates :input_type, length: { maximum: 2000 }, allow_nil: true
validates :return_type, length: { maximum: 2000 }, allow_nil: true

validates :disabled_reason, presence: false,
allow_blank: true,
length: { maximum: 100, minimum: 0 }

scope :enabled, -> { where(disabled_reason: nil) }
scope :disabled, -> { where.not(disabled_reason: nil) }

def disabled?
disabled_reason.present?
end

def to_grpc
Tucana::Shared::ValidationFlow.new(
flow_id: id,
project_id: project.id,
project_slug: project.slug,
type: flow_type.identifier,
data_types: [], # TODO: when data types are creatable
disable_reason: disabled_reason,
input_type: input_type,
return_type: return_type,
settings: flow_settings.map(&:to_grpc),
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20260328152854_add_disabled_reason_to_flows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddDisabledReasonToFlows < Code0::ZeroTrack::Database::Migration[1.0]
def change
add_column :flows, :disabled_reason, :integer, null: true
end
end
1 change: 1 addition & 0 deletions db/schema_migrations/20260328152854
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a75b8ec7e9c47f5967a2f4b3fc2ffb6870f850479132b0fb7c0f64eb951a5cb8
1 change: 1 addition & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ CREATE TABLE flows (
input_type text,
return_type text,
validation_status integer DEFAULT 0 NOT NULL,
disabled_reason integer,
CONSTRAINT check_1c805d704f CHECK ((char_length(input_type) <= 2000)),
CONSTRAINT check_b2f3f83908 CHECK ((char_length(return_type) <= 2000))
);
Expand Down
9 changes: 9 additions & 0 deletions docs/graphql/enum/flowdisabledreason.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: FlowDisabledReason
---

The disabled reason of a flow.

| Value | Description |
|-------|-------------|
| `_DUMMY` | Dummy value |
1 change: 1 addition & 0 deletions docs/graphql/object/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Represents a flow
| Name | Type | Description |
|------|------|-------------|
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this Flow was created |
| `disabledReason` | [`FlowDisabledReason`](../enum/flowdisabledreason.md) | The reason why the flow is disabled, if it is disabled |
| `id` | [`FlowID!`](../scalar/flowid.md) | Global ID of this Flow |
| `inputType` | [`String`](../scalar/string.md) | The input data type of the flow |
| `linkedDataTypes` | [`DataTypeConnection!`](../object/datatypeconnection.md) | The data types that are referenced in this flow |
Expand Down
4 changes: 4 additions & 0 deletions spec/models/flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
describe 'validations' do
it { is_expected.to allow_values(*described_class::VALIDATION_STATUS.keys).for(:validation_status) }

it { is_expected.to allow_values(nil, *described_class::DISABLED_REASON.keys).for(:disabled_reason) }

it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_uniqueness_of(:name).case_insensitive.scoped_to(:project_id) }

Expand All @@ -47,6 +49,7 @@
flow_type: create(:flow_type, identifier: 'HTTP'),
input_type: 'string',
return_type: 'number',
disabled_reason: 0,
flow_settings: [
create(
:flow_setting,
Expand Down Expand Up @@ -131,6 +134,7 @@
},
}
],
disable_reason: '_dummy',
}
)
end
Expand Down