Skip to content
Draft
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
1 change: 1 addition & 0 deletions app/graphql/types/flow_type_setting_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FlowTypeSettingType < Types::BaseObject
field :flow_type, Types::FlowTypeType, null: true, description: 'Flow type of the flow type setting'
field :identifier, String, null: false, description: 'Identifier of the flow type setting'
field :names, [Types::TranslationType], null: false, description: 'Names of the flow type setting'
field :removed_at, Types::TimeType, null: true, description: 'The timestamp when this setting was soft removed'
field :unique, Boolean, null: false, description: 'Unique status of the flow type setting'

id_field FlowTypeSetting
Expand Down
3 changes: 3 additions & 0 deletions app/models/flow_type_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ class FlowTypeSetting < ApplicationRecord

has_many :names, -> { by_purpose(:name) }, class_name: 'Translation', as: :owner, inverse_of: :owner
has_many :descriptions, -> { by_purpose(:description) }, class_name: 'Translation', as: :owner, inverse_of: :owner

scope :active, -> { where(removed_at: nil) }
scope :removed, -> { where.not(removed_at: nil) }
end
2 changes: 1 addition & 1 deletion app/services/namespaces/projects/flows/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def update_flow_attributes

def update_settings(t)
db_settings = flow.flow_settings.first(flow_input.settings.length)
flow_type_settings = flow.flow_type.flow_type_settings
flow_type_settings = flow.flow_type.flow_type_settings.active.order(:id)

flow_input.settings.each_with_index do |setting, index|
db_settings[index] ||= flow.flow_settings.build
Expand Down
26 changes: 13 additions & 13 deletions app/services/runtimes/grpc/flow_types/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,26 @@ def update_flowtype(flow_type, t)
db_object.version = flow_type.version
db_object.definition_source = flow_type.definition_source
db_object.display_icon = flow_type.display_icon
db_object.flow_type_settings = update_settings(flow_type.settings, db_object.flow_type_settings)
update_settings(flow_type.settings, db_object.flow_type_settings)
link_data_types(db_object, flow_type.linked_data_type_identifiers, t)
db_object.save
db_object
end

def update_settings(flow_type_settings, db_setting_relation)
db_settings = db_setting_relation.first(flow_type_settings.length)
flow_type_settings.each_with_index do |setting, index|
db_settings[index] ||= db_setting_relation.build
db_settings[index].identifier = setting.identifier
db_settings[index].unique = setting.unique.to_s.downcase
db_settings[index].default_value = setting.default_value&.to_ruby
db_settings[index].descriptions = update_translations(setting.description, db_settings[index].descriptions)
db_settings[index].names = update_translations(setting.name, db_settings[index].names)
end

db_setting_relation.excluding(*db_settings).destroy_all
# rubocop:disable Rails/SkipsModelValidations -- when marking settings as removed, we don't care about validations
db_setting_relation.update_all(removed_at: Time.zone.now)
# rubocop:enable Rails/SkipsModelValidations

db_settings
flow_type_settings.map do |setting|
db_setting = db_setting_relation.find_or_initialize_by(identifier: setting.identifier)
db_setting.unique = setting.unique.to_s.downcase
db_setting.default_value = setting.default_value&.to_ruby
db_setting.descriptions = update_translations(setting.description, db_setting.descriptions)
db_setting.names = update_translations(setting.name, db_setting.names)
db_setting.removed_at = nil
db_setting
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddRemovedAtToFlowTypeSettings < Code0::ZeroTrack::Database::Migration[1.0]
def change
add_column :flow_type_settings, :removed_at, :datetime_with_timezone
end
end
1 change: 1 addition & 0 deletions db/schema_migrations/20260504131123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
230a4eedca49cadd700627c194d5f046f32435cecc60120b63a4e53fc419ef4b
3 changes: 2 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ CREATE TABLE flow_type_settings (
default_value jsonb,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
"unique" integer DEFAULT 0 NOT NULL
"unique" integer DEFAULT 0 NOT NULL,
removed_at timestamp with time zone
);

CREATE SEQUENCE flow_type_settings_id_seq
Expand Down
1 change: 1 addition & 0 deletions docs/graphql/object/flowtypesetting.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ Represents a flow type setting
| `id` | [`FlowTypeSettingID!`](../scalar/flowtypesettingid.md) | Global ID of this FlowTypeSetting |
| `identifier` | [`String!`](../scalar/string.md) | Identifier of the flow type setting |
| `names` | [`[Translation!]!`](../object/translation.md) | Names of the flow type setting |
| `removedAt` | [`Time`](../scalar/time.md) | The timestamp when this setting was soft removed |
| `unique` | [`Boolean!`](../scalar/boolean.md) | Unique status of the flow type setting |
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this FlowTypeSetting was last updated |
1 change: 1 addition & 0 deletions spec/graphql/types/flow_type_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
flow_type
names
descriptions
removed_at
id
created_at
updated_at
Expand Down
15 changes: 15 additions & 0 deletions spec/models/flow_type_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@
it { is_expected.to allow_values(:none, :project, 'none', 'project').for(:unique) }
it { is_expected.not_to allow_value(:unknown, 'unknown', 0).for(:unique) }
end

describe 'scopes' do
let!(:active_setting) { create(:flow_type_setting, removed_at: nil) }
let!(:removed_setting) { create(:flow_type_setting, removed_at: Time.zone.now) }

it 'returns active settings' do
expect(described_class.active).to include(active_setting)
expect(described_class.active).not_to include(removed_setting)
end

it 'returns removed settings' do
expect(described_class.removed).to include(removed_setting)
expect(described_class.removed).not_to include(active_setting)
end
end
end
12 changes: 10 additions & 2 deletions spec/requests/grpc/sagittarius/flow_type_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,16 @@

flow_type.reload

expect(flow_type.flow_type_settings.size).to eq(1)
expect(flow_type.flow_type_settings.first.identifier).to eq(flow_types.first[:settings].first[:identifier])
first_setting = flow_type.flow_type_settings.find_by(identifier: 'first_setting')
second_setting = flow_type.flow_type_settings.find_by(identifier: 'second_setting')
other_setting = flow_type.flow_type_settings.find_by(identifier: flow_types.first[:settings].first[:identifier])

expect(first_setting).to be_present
expect(second_setting).to be_present
expect(other_setting).to be_present
expect(first_setting.removed_at).to be_present
expect(second_setting.removed_at).to be_present
expect(other_setting.removed_at).to be_nil
end
end
end
Expand Down