0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 19:10:29 +01:00
discourse-custom-wizard/controllers/custom_wizard/admin/custom_fields.rb

47 Zeilen
958 B
Ruby

2020-10-20 07:40:23 +02:00
class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
2020-10-17 03:31:07 +02:00
def index
2020-10-20 07:40:23 +02:00
render_json_dump(custom_field_list)
2020-10-17 03:31:07 +02:00
end
2020-10-20 07:40:23 +02:00
def update
custom_fields = custom_field_params[:custom_fields].map do |data|
CustomWizard::CustomField.new(data.to_h)
end
2020-10-17 03:31:07 +02:00
2020-10-20 07:40:23 +02:00
custom_fields.each do |custom_field|
2020-10-17 03:31:07 +02:00
custom_field.validate
unless custom_field.valid?
2020-10-20 07:40:23 +02:00
raise Discourse::InvalidParameters,
custom_field.errors.full_messages.join("\n\n")
2020-10-17 03:31:07 +02:00
end
end
all_fields_saved = true
custom_fields.each do |field|
unless field.save
all_fields_saved = false
end
end
if all_fields_saved
2020-10-20 07:40:23 +02:00
render json: success_json
2020-10-17 03:31:07 +02:00
else
render json: error_json
end
end
2020-10-20 07:40:23 +02:00
private
def custom_field_params
params.permit(
custom_fields: [
:klass,
:name,
:type,
serializers: []
]
2020-10-17 03:31:07 +02:00
)
end
end