From 874135026c72a996f9854aadf169a84f1ac05b95 Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Thu, 25 Dec 2025 11:30:35 +0100 Subject: [PATCH] Implement updating flow type settings --- app/services/error_code.rb | 1 + .../grpc/flow_types/update_service.rb | 27 +++++++++++++++++++ docs/graphql/enum/errorcodeenum.md | 1 + .../sagittarius/flow_type_service_spec.rb | 26 ++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/app/services/error_code.rb b/app/services/error_code.rb index e51c5abd..595f2046 100644 --- a/app/services/error_code.rb +++ b/app/services/error_code.rb @@ -94,6 +94,7 @@ def self.error_codes missing_primary_runtime: { description: 'The project is missing a primary runtime' }, missing_definition: { description: 'The primary runtime has more definitions than this one' }, outdated_definition: { description: 'The primary runtime has a newer definition than this one' }, + invalid_flow_type_setting: { description: 'The flow type setting is invalid because of active model errors' }, } end # rubocop:enable Layout/LineLength diff --git a/app/services/runtimes/grpc/flow_types/update_service.rb b/app/services/runtimes/grpc/flow_types/update_service.rb index fe90271a..5221a893 100644 --- a/app/services/runtimes/grpc/flow_types/update_service.rb +++ b/app/services/runtimes/grpc/flow_types/update_service.rb @@ -63,9 +63,36 @@ def update_flowtype(flow_type, t) db_object.display_messages = update_translations(flow_type.display_message, db_object.display_messages) db_object.aliases = update_translations(flow_type.alias, db_object.aliases) db_object.version = flow_type.version + db_object.flow_type_settings = update_settings(flow_type.settings, db_object, t) db_object.save db_object end + + def update_settings(flow_type_settings, flow_type, t) + flow_type.flow_type_settings = flow_type_settings.map do |setting| + db_setting = FlowTypeSetting.find_or_initialize_by(flow_type: flow_type, identifier: setting.identifier) + db_setting.unique = setting.unique + 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.data_type = find_data_type(setting.data_type_identifier, t) + + unless db_setting.save + logger.error( + message: 'Failed to update flow type setting', + runtime_id: current_runtime.id, + flow_type_identifier: flow_type.identifier, + setting_identifier: setting.identifier, + errors: db_setting.errors.full_messages + ) + t.rollback_and_return! ServiceResponse.error(message: 'Failed to update flow type setting', + error_code: :invalid_flow_type_setting, + details: db_setting.errors) + end + + db_setting + end + end end end end diff --git a/docs/graphql/enum/errorcodeenum.md b/docs/graphql/enum/errorcodeenum.md index e8a0e6a5..060cb8e6 100644 --- a/docs/graphql/enum/errorcodeenum.md +++ b/docs/graphql/enum/errorcodeenum.md @@ -32,6 +32,7 @@ Represents the available error responses | `INVALID_FLOW` | The flow is invalid because of active model errors | | `INVALID_FLOW_SETTING` | The flow setting is invalid because of active model errors | | `INVALID_FLOW_TYPE` | The flow type is invalid because of active model errors | +| `INVALID_FLOW_TYPE_SETTING` | The flow type setting is invalid because of active model errors | | `INVALID_GENERIC_MAPPER` | The generic mapper is invalid because of active model errors | | `INVALID_LOGIN_DATA` | Invalid login data provided | | `INVALID_NAMESPACE_LICENSE` | The namespace license is invalid because of active model errors | diff --git a/spec/requests/grpc/sagittarius/flow_type_service_spec.rb b/spec/requests/grpc/sagittarius/flow_type_service_spec.rb index 72cdbf04..02738e7f 100644 --- a/spec/requests/grpc/sagittarius/flow_type_service_spec.rb +++ b/spec/requests/grpc/sagittarius/flow_type_service_spec.rb @@ -18,6 +18,20 @@ [ { identifier: 'some_flow_type_identifier', + settings: [ + { + identifier: 'some_setting_identifier', + unique: true, + data_type_identifier: create(:data_type, runtime: runtime).identifier, + default_value: Tucana::Shared::Value.from_ruby({ 'value' => 'some default value' }), + name: [ + { code: 'en_US', content: 'Some Setting' } + ], + description: [ + { code: 'en_US', content: 'This is a setting' } + ], + } + ], name: [ { code: 'de_DE', content: 'Keine Ahnung man' } ], @@ -65,6 +79,18 @@ expect(flow_type.editable).to be true expect(flow_type.return_type.identifier).to eq('some_return_type_identifier') expect(flow_type.version).to eq('0.0.0') + + expect(flow_type.flow_type_settings.count).to eq(1) + setting = flow_type.flow_type_settings.first + expect(setting.identifier).to eq('some_setting_identifier') + expect(setting.unique).to be true + expect(setting.default_value).to eq('value' => 'some default value') + expect(setting.names.count).to eq(1) + expect(setting.names.first.code).to eq('en_US') + expect(setting.names.first.content).to eq('Some Setting') + expect(setting.descriptions.count).to eq(1) + expect(setting.descriptions.first.code).to eq('en_US') + expect(setting.descriptions.first.content).to eq('This is a setting') end context 'when removing datatypes' do