Files
docuseal/app/controllers/templates_preferences_controller.rb
T

45 lines
1.5 KiB
Ruby
Raw Normal View History

2024-04-17 16:08:58 +03:00
# frozen_string_literal: true
class TemplatesPreferencesController < ApplicationController
load_and_authorize_resource :template
def show; end
def create
authorize!(:update, @template)
@template.preferences = @template.preferences.merge(template_params[:preferences])
2024-09-12 22:41:39 +03:00
@template.preferences = @template.preferences.reject { |_, v| (v.is_a?(String) || v.is_a?(Hash)) && v.blank? }
2024-04-17 16:08:58 +03:00
@template.save!
head :ok
end
private
def template_params
params.require(:template).permit(
preferences: %i[bcc_completed request_email_subject request_email_body
2024-06-14 12:19:13 +03:00
documents_copy_email_subject documents_copy_email_body
2024-06-21 14:05:23 +03:00
documents_copy_email_enabled documents_copy_email_attach_audit
2024-11-27 21:59:45 +02:00
documents_copy_email_attach_documents
completed_notification_email_attach_documents
2024-09-12 22:41:39 +03:00
completed_redirect_url
2024-09-26 12:19:33 +03:00
submitters_order
2024-06-21 14:05:23 +03:00
completed_notification_email_subject completed_notification_email_body
2024-09-12 22:41:39 +03:00
completed_notification_email_enabled completed_notification_email_attach_audit] +
[completed_message: %i[title body]]
2024-06-14 12:19:13 +03:00
).tap do |attrs|
attrs[:preferences] = attrs[:preferences].transform_values do |value|
if %w[true false].include?(value)
value == 'true'
2024-09-12 22:41:39 +03:00
elsif value.respond_to?(:compact_blank)
value.compact_blank
2024-06-14 12:19:13 +03:00
else
value
end
end
end
2024-04-17 16:08:58 +03:00
end
end