diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 12d465b..994fabd 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -1,62 +1,62 @@ class Admin::SettingsController < Admin::BaseController before_action :fetch_configuration_settings, only: [:edit, :update, :reset] # GET /admin/settings def index @settings = ConfigurationSetting.last || ConfigurationSetting.new end # GET /admin/settings/new def new @setting = ConfigurationSetting.new end # GET /admin/settings/1/edit def edit end # POST /admin/settings def create @setting = ConfigurationSetting.new(fetch_params) if @setting.save flash[:success] = 'Configuration Submitted' redirect_to admin_settings_path else flash[:error] = 'Configuration was not submitted' render :new end end # PATCH /admin/settings/1/update def update if fetch_params.present? && @setting.update_attributes(fetch_params) flash[:success] = 'Configuration Submitted' redirect_to admin_settings_path else flash[:error] = 'Configuration was not submitted' render :edit end end # DELETE /admin/settings/1/reset def reset @setting.destroy redirect_to admin_settings_path end private def fetch_configuration_settings @setting = ConfigurationSetting.find(params[:id]) end def fetch_params params.require(:configuration_setting). permit( job: [:storage, :pool, :messages, :priority, :'Write Bootstrap'], client: [:catalog, :file_retention, :file_retention_period_type, :job_retention, - :job_retention_period_type, :autoprune], + :job_retention_period_type, :autoprune, :quota], pool: [:full, :differential, :incremental] ) end end diff --git a/app/models/configuration_setting.rb b/app/models/configuration_setting.rb index 9b7aebe..2554fa6 100644 --- a/app/models/configuration_setting.rb +++ b/app/models/configuration_setting.rb @@ -1,111 +1,112 @@ # ConfigurationSetting class describes a model that keeps the current Bacula # configuration. # # It has some hard coded settings as defaults. # Archiving's admins can enter new settings concerning: # # * jobs # * clients # # and override the default ones. # # ConfigurationSetting is supposed to have only one record in persisted in the database # which will hold the altered configuration as a patch to the defaults. # Admins can reset this change at any time. class ConfigurationSetting < ActiveRecord::Base establish_connection ARCHIVING_CONF serialize :job, JSON serialize :client, JSON serialize :pool, JSON JOB = { storage: :File, pool: Archiving.settings[:default_pool], messages: :Standard, priority: 10, :'Write Bootstrap' => '"/var/lib/bacula/%c.bsr"' } CLIENT = { catalog: 'MyCatalog', file_retention: 60, file_retention_period_type: 'days', job_retention: 180, job_retention_period_type: 'days', - autoprune: 'yes' + autoprune: 'yes', + quota: Archiving.settings[:client_quota] } POOL = { full: Archiving.settings[:default_pool], differential: Archiving.settings[:default_pool], incremental: Archiving.settings[:default_pool] } RETENTION_PERIODS = %w{seconds minutes hours days weeks months quarters years} AUTOPRUNE_OPTIONS = ['yes', 'no'] # Fetches the current configuration for jobs. # # The current configuration is the last submitted record, patched to the default # settings. # If there is no record, the default settings are returned # # @return [Hash] with settings def self.current_job_settings (last || new).job.symbolize_keys.reverse_merge(JOB.dup) end # Fetches the current configuration for clients. # # The current configuration is the last submitted record, patched to the default # settings. # If there is no record, the default settings are returned # # @return [Hash] with settings def self.current_client_settings (last || new).client.symbolize_keys.reverse_merge(CLIENT.dup) end # Fetches the current configuration for pools. # # The current configuration is the last submitted record, patched to the default # settings. # If there is no record, the default settings are returned # # @return [Hash] with settings def self.current_pool_settings (last || new).pool.symbolize_keys.reverse_merge(POOL.dup) end # Fetches the record's configuration for jobs. # # The configuration is the record's configuration patched to the default # settings. # # @return [Hash] with settings def current_job_settings job.symbolize_keys.reverse_merge(JOB.dup) end # Fetches the record's configuration for clients. # # The configuration is the record's configuration patched to the default # settings. # # @return [Hash] with settings def current_client_settings client.symbolize_keys.reverse_merge(CLIENT.dup) end # Fetches the record's configuration for pools. # # The configuration is the record's configuration patched to the default # settings. # # @return [Hash] with settings def current_pool_settings pool.symbolize_keys.reverse_merge(POOL.dup) end end diff --git a/app/views/admin/settings/_form.html.erb b/app/views/admin/settings/_form.html.erb index f4c48fd..41bd71c 100644 --- a/app/views/admin/settings/_form.html.erb +++ b/app/views/admin/settings/_form.html.erb @@ -1,79 +1,81 @@ <%= bootstrap_form_for(@setting, url: path, layout: :horizontal, label_col: 'col-xs-5', control_col: 'col-xs-5') do |f| %>