Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix service dialog edit #15658

Merged
merged 1 commit into from
Jul 27, 2017
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
22 changes: 12 additions & 10 deletions app/models/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,21 @@ def content(target = nil, resource_action = nil, all_attributes = false)
# Creates a new item without an ID,
# Removes any items not passed in the content.
def update_tabs(tabs)
updated_tabs = []
tabs.each do |dialog_tab|
if dialog_tab.key?('id')
DialogTab.find(self.class.uncompress_id(dialog_tab['id'])).tap do |tab|
tab.update_attributes(dialog_tab.except('dialog_groups'))
tab.update_dialog_groups(dialog_tab['dialog_groups'])
updated_tabs << tab
transaction do
updated_tabs = []
tabs.each do |dialog_tab|
if dialog_tab.key?('id')
DialogTab.find(self.class.uncompress_id(dialog_tab['id'])).tap do |tab|
tab.update_attributes(dialog_tab.except('id', 'href', 'dialog_id', 'dialog_groups'))
tab.update_dialog_groups(dialog_tab['dialog_groups'])
updated_tabs << tab
end
else
updated_tabs << DialogImportService.new.build_dialog_tabs('dialog_tabs' => [dialog_tab]).first
end
else
updated_tabs << DialogImportService.new.build_dialog_tabs('dialog_tabs' => [dialog_tab]).first
end
self.dialog_tabs = updated_tabs
end
self.dialog_tabs = updated_tabs
end

def deep_copy(new_attributes = {})
Expand Down
2 changes: 1 addition & 1 deletion app/models/dialog_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def update_dialog_fields(fields)
DialogField.find(self.class.uncompress_id(field['id'])).tap do |dialog_field|
resource_action_fields = field.delete('resource_action') || {}
update_resource_fields(resource_action_fields, dialog_field)
dialog_field.update_attributes(field)
dialog_field.update_attributes(field.except('id', 'href', 'dialog_group_id'))
updated_fields << dialog_field
end
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/dialog_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def update_dialog_groups(groups)
groups.each do |group|
if group.key?('id')
DialogGroup.find(self.class.uncompress_id(group['id'])).tap do |dialog_group|
dialog_group.update_attributes(group.except('dialog_fields'))
dialog_group.update_attributes(group.except('id', 'href', 'dialog_tab_id', 'dialog_fields'))
dialog_group.update_dialog_fields(group['dialog_fields'])
updated_groups << dialog_group
end
Expand Down
9 changes: 6 additions & 3 deletions spec/models/dialog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,16 @@
let(:updated_content) do
[
{
'id' => dialog_tab.first.id,
'id' => dialog_tab.first.compressed_id,
'label' => 'updated_label',
'dialog_groups' => [
{ 'id' => dialog_group.first.id,
{ 'id' => dialog_group.first.compressed_id,
'dialog_tab_id' => dialog_tab.first.compressed_id,
'dialog_fields' =>
[{
'id' => dialog_field.first.id}] },
'id' => dialog_field.first.id,
'dialog_group_id' => dialog_group.first.compressed_id
}] },
{
'label' => 'group 2',
'dialog_fields' => [{
Expand Down