diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
new file mode 100644
index 000000000..b369d2cbc
--- /dev/null
+++ b/app/controllers/admin/settings_controller.rb
@@ -0,0 +1,17 @@
+class Admin::SettingsController < Admin::BaseController
+
+ def index
+ @settings = Setting.all
+ end
+
+ def update
+ @setting = Setting.find(params[:id])
+ @setting.update(settings_params)
+ redirect_to admin_settings_path, notice: t("admin.settings.flash.updated")
+ end
+
+ private
+ def settings_params
+ params.require(:setting).permit(:value)
+ end
+end
\ No newline at end of file
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb
index 8459fcab3..88410238b 100644
--- a/app/views/admin/_menu.html.erb
+++ b/app/views/admin/_menu.html.erb
@@ -1,6 +1,7 @@
diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb
index 779fce36b..d0a98a963 100644
--- a/app/views/admin/officials/index.html.erb
+++ b/app/views/admin/officials/index.html.erb
@@ -15,7 +15,7 @@
<% @officials.each do |official| %>
<%= link_to official.name, edit_admin_official_path(official) %>
<%= official.official_position %>
- <%= official.official_level %>
+ <%= t("admin.officials.level_#{official.official_level}") %>
<% end %>
diff --git a/app/views/admin/officials/search.html.erb b/app/views/admin/officials/search.html.erb
index 8f7f9e670..9549c7ad0 100644
--- a/app/views/admin/officials/search.html.erb
+++ b/app/views/admin/officials/search.html.erb
@@ -15,7 +15,7 @@
<% @users.each do |user| %>
<%= link_to user.name, edit_admin_official_path(user) %>
<%= user.official_position %>
- <%= user.official_level %>
+ <%= t("admin.officials.level_#{user.official_level}") %>
<%= link_to user.official? ? t("admin.officials.search.edit_official") : t("admin.officials.search.make_official"), edit_admin_official_path(user) %>
<% end %>
\ No newline at end of file
diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb
new file mode 100644
index 000000000..321b307d0
--- /dev/null
+++ b/app/views/admin/settings/index.html.erb
@@ -0,0 +1,15 @@
+<%= t("admin.settings.index.title") %>
+
+
+ <% @settings.each do |setting| %>
+ -
+ <%= setting.key.classify %>
+
+ <%= form_for(setting, url: admin_setting_path(setting), html: { id: "edit_#{dom_id(setting)}"}) do |f| %>
+ <%= f.text_field :value, label: false, id: dom_id(setting) %>
+ <%= f.submit(class: "button radius tiny") %>
+ <% end %>
+
+
+ <% end %>
+
\ No newline at end of file
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 25be1568e..d5cc7da64 100644
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -1,12 +1,19 @@
en:
admin:
+ settings:
+ index:
+ title: Global settings
+ flash:
+ updated: 'Setting updated!'
dashboard:
index:
title: Administration
menu:
+ settings: Global settings
debate_topics: Debate topics
hidden_debates: Hidden debates
hidden_comments: Hidden comments
+ officials: Officials
actions:
hide: Hide
restore: Restore
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index f15c63b1e..a3602fa05 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -1,12 +1,19 @@
es:
admin:
+ settings:
+ index:
+ title: Configuración global
+ flash:
+ updated: 'Valor actualizado'
dashboard:
index:
title: Administración
menu:
+ settings: Configuración global
debate_topics: Temas de debate
hidden_debates: Debates ocultos
hidden_comments: Comentarios ocultos
+ officials: Cargos públicos
actions:
hide: Ocultar
restore: Permitir
diff --git a/config/routes.rb b/config/routes.rb
index d7ccc5cb7..ea8e71b52 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -32,6 +32,8 @@ Rails.application.routes.draw do
resources :officials, only: [:index, :edit, :update, :destroy] do
collection { get :search}
end
+
+ resources :settings, only: [:index, :update]
end
namespace :moderation do
diff --git a/spec/factories.rb b/spec/factories.rb
index 3a06c4701..72c5d5522 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -55,4 +55,9 @@ FactoryGirl.define do
end
end
+ factory :setting do
+ sequence(:key) { |n| "setting key number #{n}" }
+ sequence(:value) { |n| "setting number #{n} value" }
+ end
+
end
diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb
new file mode 100644
index 000000000..a64e48a6a
--- /dev/null
+++ b/spec/features/admin/settings_spec.rb
@@ -0,0 +1,30 @@
+require 'rails_helper'
+
+feature 'Admin settings' do
+
+ background do
+ @setting1 = create(:setting)
+ @setting2 = create(:setting)
+ @setting3 = create(:setting)
+ login_as(create(:administrator).user)
+ end
+
+ scenario 'Index' do
+ visit admin_settings_path
+
+ expect(page).to have_content @setting1.key.classify
+ expect(page).to have_content @setting2.key.classify
+ expect(page).to have_content @setting3.key.classify
+ end
+
+ scenario 'Update' do
+ visit admin_settings_path
+
+ within("#edit_setting_#{@setting2.id}") do
+ fill_in "setting_#{@setting2.id}", with: 'Super Users of level 2'
+ click_button 'Update Setting'
+ end
+
+ expect(page).to have_content 'Setting updated!'
+ end
+end
\ No newline at end of file