1 class Admin::ConfigurationController < ApplicationController
2
3 # Admin::ConfigurationController handles the batch-updating of Radiant::Config entries.
4 # It accepts any set of config name-value pairs but is accessible only to administrators.
5 # Note that configuration is routed as a singular resource so we only deal with show/edit/update
6 # and the show and edit views determine what set of config values is shown and made editable.
7
8 before_filter :initialize_config
9
10 only_allow_access_to :edit, :update,
11 :when => [:admin],
12 :denied_url => { :controller => 'admin/configuration', :action => 'show' },
13 :denied_message => 'You must have admin privileges to edit site configuration.'
14
15 def show
16 @user = current_user
17 render
18 end
19
20 def edit
21 render
22 end
23
24 def update
25 if params[:config]
26 begin
27 Radiant.config.transaction do
28 params["config"].each_pair do |key, value|
29 @config[key] = Radiant::Config.find_or_create_by_key(key)
30 @config[key].value = value # validation sets errors on @config['key'] that the helper methods will pick up
31 end
32 redirect_to :action => :show
33 end
34 rescue ActiveRecord::RecordInvalid => e
35 flash[:error] = "Configuration error: please check the form"
36 render :action => :edit
37 rescue Radiant::Config::ConfigError => e
38 flash[:error] = "Configuration error: #{e}"
39 render :action => :edit
40 end
41 end
42 end
43
44 protected
45
46 def initialize_config
47 @config = {}
48 end
49
50 en