Skip to content
Merged
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/services/error_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions app/services/runtimes/grpc/flow_types/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/graphql/enum/errorcodeenum.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/grpc/sagittarius/flow_type_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
],
Expand Down Expand Up @@ -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
Expand Down