Sha256: 8b8fa0a9055b5bc05265d44fe68ea0be3f4013adb8368bc590f9a9735e7bec20
Contents?: true
Size: 1.49 KB
Versions: 8
Compression:
Stored size: 1.49 KB
Contents
require 'ostruct' class UiTemplateSyncsController < ApplicationController include ::Foreman::Controller::Parameters::TemplateParams rescue_from ::ForemanTemplates::PathAccessException do |error| render_errors [error.message] end def sync_settings import_settings = setting_definitions(ForemanTemplates::IMPORT_SETTING_NAMES) export_settings = setting_definitions(ForemanTemplates::EXPORT_SETTING_NAMES) @results = OpenStruct.new(:import => import_settings, :export => export_settings) end def import @parse_result = OpenStruct.new ForemanTemplates::TemplateImporter.new(ui_template_import_params).import! end def export @result = OpenStruct.new ForemanTemplates::TemplateExporter.new(ui_template_export_params).export! if @result.error render_errors [@result.error] end if @result.warning render_errors [@result.warning], 'warning' end end def action_permission case params[:action] when 'sync_settings' :view_template_syncs else super end end def parameter_filter_context Foreman::ParameterFilter::Context.new(:api, controller_name, params[:action]) end def render_errors(messages, severity = 'danger') render :json => { :error => { :errors => { :base => messages }, full_messages: messages, :severity => severity } }, :status => :unprocessable_entity end private def setting_definitions(short_names) short_names.map { |name| Foreman.settings.find("template_sync_#{name}") } end end
Version data entries
8 entries across 8 versions & 1 rubygems