From 27553e9058254be78a840e94e623fab977bd1b64 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Mon, 11 Mar 2019 15:07:54 +0100 Subject: [PATCH 01/10] Move setting next to similar/related settings --- db/dev_seeds/settings.rb | 2 +- db/seeds.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index b3254ea1a..6cecac651 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -41,12 +41,12 @@ section "Creating Settings" do Setting.create(key: "feature.user.recommendations", value: "true") Setting.create(key: "feature.user.recommendations_on_debates", value: "true") Setting.create(key: "feature.user.recommendations_on_proposals", value: "true") + Setting.create(key: "feature.user.skip_verification", value: "true") Setting.create(key: "feature.community", value: "true") Setting.create(key: "feature.map", value: "true") Setting.create(key: "feature.allow_images", value: "true") Setting.create(key: "feature.allow_attached_documents", value: "true") Setting.create(key: "feature.public_stats", value: "true") - Setting.create(key: "feature.user.skip_verification", value: "true") Setting.create(key: "feature.help_page", value: "true") Setting.create(key: "per_page_code_head", value: "") diff --git a/db/seeds.rb b/db/seeds.rb index 6a9957c1c..acd473e00 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -81,6 +81,7 @@ Setting["feature.legislation"] = true Setting["feature.user.recommendations"] = true Setting["feature.user.recommendations_on_debates"] = true Setting["feature.user.recommendations_on_proposals"] = true +Setting["feature.user.skip_verification"] = "true" Setting["feature.community"] = true Setting["feature.map"] = nil Setting["feature.allow_images"] = true @@ -112,8 +113,6 @@ Setting["map_zoom"] = 10 # Related content Setting["related_content_score_threshold"] = -0.3 -Setting["feature.user.skip_verification"] = "true" - Setting["feature.homepage.widgets.feeds.proposals"] = true Setting["feature.homepage.widgets.feeds.debates"] = true Setting["feature.homepage.widgets.feeds.processes"] = true From 8ae80cd1a101da30926a9e1ffe8def5b7b52f41d Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 11:51:12 +0100 Subject: [PATCH 02/10] Cleanup (remove unnecessary code) --- spec/features/admin/feature_flags_spec.rb | 5 ----- spec/features/admin/legislation/questions_spec.rb | 4 ---- spec/features/comments/budget_investments_valuation_spec.rb | 5 ----- spec/features/moderation/budget_investments_spec.rb | 2 -- spec/features/users_spec.rb | 3 --- spec/features/valuation/budget_investments_spec.rb | 2 -- 6 files changed, 21 deletions(-) diff --git a/spec/features/admin/feature_flags_spec.rb b/spec/features/admin/feature_flags_spec.rb index 181a8a34c..92b8f0f55 100644 --- a/spec/features/admin/feature_flags_spec.rb +++ b/spec/features/admin/feature_flags_spec.rb @@ -8,11 +8,6 @@ feature "Admin feature flags" do login_as(create(:administrator).user) end - after do - Setting["feature.spending_proposals"] = nil - Setting["feature.spending_proposal_features.voting_allowed"] = nil - end - scenario "Enabled features are listed on menu" do visit admin_root_path diff --git a/spec/features/admin/legislation/questions_spec.rb b/spec/features/admin/legislation/questions_spec.rb index f90a59ecc..bd97672c7 100644 --- a/spec/features/admin/legislation/questions_spec.rb +++ b/spec/features/admin/legislation/questions_spec.rb @@ -20,10 +20,6 @@ feature "Admin legislation questions" do Setting["feature.legislation"] = nil end - after do - Setting["feature.legislation"] = true - end - scenario "Disabled with a feature flag" do expect{ visit admin_legislation_process_questions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled) end diff --git a/spec/features/comments/budget_investments_valuation_spec.rb b/spec/features/comments/budget_investments_valuation_spec.rb index b17cd1b47..1db3ab8be 100644 --- a/spec/features/comments/budget_investments_valuation_spec.rb +++ b/spec/features/comments/budget_investments_valuation_spec.rb @@ -10,15 +10,10 @@ feature "Internal valuation comments on Budget::Investments" do let(:investment) { create(:budget_investment, budget: budget, group: group, heading: heading) } background do - Setting["feature.budgets"] = true investment.valuators << valuator_user.valuator login_as(valuator_user) end - after do - Setting["feature.budgets"] = nil - end - context "Show valuation comments" do context "Show valuation comments without public comments" do background do diff --git a/spec/features/moderation/budget_investments_spec.rb b/spec/features/moderation/budget_investments_spec.rb index 83191120e..58d61aa30 100644 --- a/spec/features/moderation/budget_investments_spec.rb +++ b/spec/features/moderation/budget_investments_spec.rb @@ -16,8 +16,6 @@ feature "Moderate budget investments" do login_as(@mod.user) expect{ visit moderation_budget_investments_path }.to raise_exception(FeatureFlags::FeatureDisabled) - - Setting["feature.budgets"] = true end scenario "Hiding an investment", :js do diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index ec4970887..81c8cc2c6 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -416,9 +416,6 @@ feature "Users" do Setting["feature.budgets"] = nil visit user_path(user) expect(page).to have_content("4 Comments") - - Setting["feature.debates"] = true - Setting["feature.budgets"] = true end end diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index 5649c8873..560d1ec14 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -16,8 +16,6 @@ feature "Valuation budget investments" do expect{ visit valuation_budget_budget_investments_path(create(:budget)) }.to raise_exception(FeatureFlags::FeatureDisabled) - - Setting["feature.budgets"] = true end scenario "Display link to valuation section" do From 9ed6aae3488e855f9fb789bcbba9d47f9c15f78a Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 11:54:20 +0100 Subject: [PATCH 03/10] Refactor Setting model - Make easier to group settings by using prefixes - Add method to rename setting keys - Add method to remove setting keys --- app/models/setting.rb | 26 +++++++---- spec/models/setting_spec.rb | 87 ++++++++++++++++++++++++++++++++----- 2 files changed, 93 insertions(+), 20 deletions(-) diff --git a/app/models/setting.rb b/app/models/setting.rb index 00b87a4db..764408d27 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -4,19 +4,16 @@ class Setting < ActiveRecord::Base default_scope { order(id: :asc) } def type - if feature_flag? - "feature" + prefix = key.split(".").first + if %w[feature process map html homepage].include? prefix + prefix else - "common" + "configuration" end end - def feature_flag? - key.start_with?("feature.") - end - def enabled? - feature_flag? && value.present? + value.present? end class << self @@ -30,5 +27,18 @@ class Setting < ActiveRecord::Base setting.save! value end + + def rename_key(from:, to:) + if where(key: to).empty? + value = where(key: from).pluck(:value).first.presence + create!(key: to, value: value) + end + remove(from) + end + + def remove(key) + setting = where(key: key).first + setting.destroy if setting.present? + end end end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 77f2d3daf..c0e060a3c 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -17,20 +17,40 @@ describe Setting do expect(described_class.where(key: "official_level_1_name", value: "Stormtrooper")).to exist end - describe "#feature_flag?" do - it "is true if key starts with 'feature.'" do - setting = described_class.create(key: "feature.whatever") - expect(setting.feature_flag?).to eq true + describe "#type" do + it "returns the key prefix for 'process' settings" do + process_setting = Setting.create(key: "process.whatever") + expect(process_setting.type).to eq "process" end - it "is false if key does not start with 'feature.'" do - setting = described_class.create(key: "whatever") - expect(setting.feature_flag?).to eq false + it "returns the key prefix for 'feature' settings" do + feature_setting = Setting.create(key: "feature.whatever") + expect(feature_setting.type).to eq "feature" + end + + it "returns the key prefix for 'map' settings" do + map_setting = Setting.create(key: "map.whatever") + expect(map_setting.type).to eq "map" + end + + it "returns the key prefix for 'html' settings" do + html_setting = Setting.create(key: "html.whatever") + expect(html_setting.type).to eq "html" + end + + it "returns the key prefix for 'homepage' settings" do + homepage_setting = Setting.create(key: "homepage.whatever") + expect(homepage_setting.type).to eq "homepage" + end + + it "returns 'configuration' for the rest of the settings" do + configuration_setting = Setting.create(key: "whatever") + expect(configuration_setting.type).to eq "configuration" end end describe "#enabled?" do - it "is true if feature_flag and value present" do + it "is true if value is present" do setting = described_class.create(key: "feature.whatever", value: 1) expect(setting.enabled?).to eq true @@ -41,17 +61,60 @@ describe Setting do expect(setting.enabled?).to eq true end - it "is false if feature_flag and value blank" do + it "is false if value is blank" do setting = described_class.create(key: "feature.whatever") expect(setting.enabled?).to eq false setting.value = "" expect(setting.enabled?).to eq false end + end - it "is false if not feature_flag" do - setting = described_class.create(key: "whatever", value: "whatever") - expect(setting.enabled?).to eq false + describe ".rename_key" do + it "renames the setting keeping the original value and deletes the old setting" do + Setting["old_key"] = "old_value" + + Setting.rename_key from: "old_key", to: "new_key" + + expect(Setting.where(key: "new_key", value: "old_value")).to exist + expect(Setting.where(key: "old_key")).not_to exist + end + + it "initialize the setting with null value if old key doesn't exist" do + expect(Setting.where(key: "old_key")).not_to exist + + Setting.rename_key from: "old_key", to: "new_key" + + expect(Setting.where(key: "new_key", value: nil)).to exist + expect(Setting.where(key: "old_key")).not_to exist + end + + it "does not change value if new key already exists, but deletes setting with old key" do + Setting["new_key"] = "new_value" + Setting["old_key"] = "old_value" + + Setting.rename_key from: "old_key", to: "new_key" + + expect(Setting["new_key"]).to eq "new_value" + expect(Setting.where(key: "old_key")).not_to exist + end + end + + describe ".remove" do + it "deletes the setting by given key" do + expect(Setting.where(key: "official_level_1_name")).to exist + + Setting.remove("official_level_1_name") + + expect(Setting.where(key: "official_level_1_name")).not_to exist + end + + it "does nothing if key doesn't exists" do + all_settings = Setting.all + + Setting.remove("not_existing_key") + + expect(Setting.all).to eq all_settings end end end From c0d2776e8d70ba410bceaf97f38b6db8d3b96330 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 12:16:25 +0100 Subject: [PATCH 04/10] Refactor Admin settings tabs - Rename partial views for tabs. - Extract tables settings to reuse across the tabs. --- app/controllers/admin/settings_controller.rb | 6 +++--- .../_configuration_settings_tab.html.erb | 3 +++ ...l.erb => _featured_settings_table.html.erb} | 18 ++++++++---------- .../admin/settings/_features_tab.html.erb | 3 +++ ...ation.html.erb => _settings_table.html.erb} | 4 +--- app/views/admin/settings/index.html.erb | 6 +++--- 6 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 app/views/admin/settings/_configuration_settings_tab.html.erb rename app/views/admin/settings/{_feature_flags.html.erb => _featured_settings_table.html.erb} (56%) create mode 100644 app/views/admin/settings/_features_tab.html.erb rename app/views/admin/settings/{_configuration.html.erb => _settings_table.html.erb} (92%) diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 5176bcc33..b13387269 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -1,9 +1,9 @@ class Admin::SettingsController < Admin::BaseController def index - all_settings = Setting.all.group_by { |s| s.type } - @settings = all_settings["common"] - @feature_flags = all_settings["feature"] + all_settings = Setting.all.group_by { |setting| setting.type } + @configuration_settings = all_settings["configuration"] + @feature_settings = all_settings["feature"] end def update diff --git a/app/views/admin/settings/_configuration_settings_tab.html.erb b/app/views/admin/settings/_configuration_settings_tab.html.erb new file mode 100644 index 000000000..d2b552138 --- /dev/null +++ b/app/views/admin/settings/_configuration_settings_tab.html.erb @@ -0,0 +1,3 @@ +

<%= t("admin.settings.index.title") %>

+ +<%= render "settings_table", settings: @configuration_settings %> diff --git a/app/views/admin/settings/_feature_flags.html.erb b/app/views/admin/settings/_featured_settings_table.html.erb similarity index 56% rename from app/views/admin/settings/_feature_flags.html.erb rename to app/views/admin/settings/_featured_settings_table.html.erb index 493c89873..c8b32c7de 100644 --- a/app/views/admin/settings/_feature_flags.html.erb +++ b/app/views/admin/settings/_featured_settings_table.html.erb @@ -1,5 +1,3 @@ -

<%= t("admin.settings.index.feature_flags") %>

- @@ -9,18 +7,18 @@ - <% @feature_flags.each do |feature_flag| %> + <% features.each do |feature| %> diff --git a/app/views/admin/settings/_features_tab.html.erb b/app/views/admin/settings/_features_tab.html.erb new file mode 100644 index 000000000..a8423ac04 --- /dev/null +++ b/app/views/admin/settings/_features_tab.html.erb @@ -0,0 +1,3 @@ +

<%= t("admin.settings.index.feature_flags") %>

+ +<%= render "featured_settings_table", features: @feature_settings %> diff --git a/app/views/admin/settings/_configuration.html.erb b/app/views/admin/settings/_settings_table.html.erb similarity index 92% rename from app/views/admin/settings/_configuration.html.erb rename to app/views/admin/settings/_settings_table.html.erb index 18a2a1cb4..b6c75b440 100644 --- a/app/views/admin/settings/_configuration.html.erb +++ b/app/views/admin/settings/_settings_table.html.erb @@ -1,5 +1,3 @@ -

<%= t("admin.settings.index.title") %>

-
- <%= t("settings.#{feature_flag.key}") %> + <%= t("settings.#{feature.key}") %>
- <%= t("settings.#{feature_flag.key}_description", default: t("admin.settings.no_description")) %> + <%= t("settings.#{feature.key}_description", default: t("admin.settings.no_description")) %>
- <% if feature_flag.enabled? %> + <% if feature.enabled? %> <%= t ("admin.settings.index.features.enabled") %> @@ -34,11 +32,11 @@ - <%= form_for(feature_flag, url: admin_setting_path(feature_flag), html: { id: "edit_#{dom_id(feature_flag)}"}) do |f| %> + <%= form_for(feature, url: admin_setting_path(feature), html: { id: "edit_#{dom_id(feature)}"}) do |f| %> - <%= f.hidden_field :value, id: dom_id(feature_flag), value: (feature_flag.enabled? ? "" : "active") %> - <%= f.submit(t("admin.settings.index.features.#{feature_flag.enabled? ? 'disable' : 'enable'}"), - class: "button expanded #{feature_flag.enabled? ? 'hollow alert' : 'success'}", + <%= f.hidden_field :value, id: dom_id(feature), value: (feature.enabled? ? "" : "active") %> + <%= f.submit(t("admin.settings.index.features.#{feature.enabled? ? 'disable' : 'enable'}"), + class: "button expanded #{feature.enabled? ? 'hollow alert' : 'success'}", data: {confirm: t("admin.actions.confirm")}) %> <% end %>
@@ -8,7 +6,7 @@ - <% @settings.each do |setting| %> + <% settings.each do |setting| %>
<%= t("settings.#{setting.key}") %> diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index 4316bdce2..8005e4db7 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -3,14 +3,14 @@ <%= render "filter_subnav" %>
- <%= render "configuration" %> + <%= render "configuration_settings_tab" %>
- <%= render "feature_flags" %> + <%= render "features_tab" %>
- <%= render "map_configuration" %> + <%= render "map_configuration_tab" %>
From dbac4bc222628648a55666c9c1ac2fa2832a6614 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 12:24:10 +0100 Subject: [PATCH 05/10] Change admin settings tab for maps - Rename map settings keys - Add fields for latitude, longitude and zoom - Add a callout message on how to enable map feature --- app/controllers/admin/settings_controller.rb | 7 ++++--- app/helpers/map_locations_helper.rb | 6 +++--- ....html.erb => _map_configuration_tab.html.erb} | 7 ++++++- app/views/admin/settings/_map_form.html.erb | 16 ++++++++-------- config/locales/en/admin.yml | 1 + config/locales/en/settings.yml | 13 +++++++------ config/locales/es/admin.yml | 1 + config/locales/es/settings.yml | 13 +++++++------ db/dev_seeds/budgets.rb | 6 +++--- db/dev_seeds/settings.rb | 6 +++--- db/seeds.rb | 6 +++--- spec/features/admin/settings_spec.rb | 6 ++++++ 12 files changed, 52 insertions(+), 36 deletions(-) rename app/views/admin/settings/{_map_configuration.html.erb => _map_configuration_tab.html.erb} (51%) diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index b13387269..509d6aa97 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -4,6 +4,7 @@ class Admin::SettingsController < Admin::BaseController all_settings = Setting.all.group_by { |setting| setting.type } @configuration_settings = all_settings["configuration"] @feature_settings = all_settings["feature"] + @map_configuration_settings = all_settings["map"] end def update @@ -13,9 +14,9 @@ class Admin::SettingsController < Admin::BaseController end def update_map - Setting["map_latitude"] = params[:latitude].to_f - Setting["map_longitude"] = params[:longitude].to_f - Setting["map_zoom"] = params[:zoom].to_i + Setting["map.latitude"] = params[:latitude].to_f + Setting["map.longitude"] = params[:longitude].to_f + Setting["map.zoom"] = params[:zoom].to_i redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update") end diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index a471d1b8d..d05f2c722 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -5,15 +5,15 @@ module MapLocationsHelper end def map_location_latitude(map_location) - map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map_latitude"] + map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"] end def map_location_longitude(map_location) - map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map_longitude"] + map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"] end def map_location_zoom(map_location) - map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map_zoom"] + map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"] end def map_location_input_id(prefix, attribute) diff --git a/app/views/admin/settings/_map_configuration.html.erb b/app/views/admin/settings/_map_configuration_tab.html.erb similarity index 51% rename from app/views/admin/settings/_map_configuration.html.erb rename to app/views/admin/settings/_map_configuration_tab.html.erb index 342e05f32..871739337 100644 --- a/app/views/admin/settings/_map_configuration.html.erb +++ b/app/views/admin/settings/_map_configuration_tab.html.erb @@ -1,8 +1,13 @@ <% if feature?(:map) %>

<%= t("admin.settings.index.map.title") %>

+ + <%= render "settings_table", settings: @map_configuration_settings %> +

<%= t("admin.settings.index.map.help") %>

<%= render "map_form" %> <% else %> -

No map to show.

+
+ <%= t("admin.settings.index.map.how_to_enable") %> +
<% end %> diff --git a/app/views/admin/settings/_map_form.html.erb b/app/views/admin/settings/_map_form.html.erb index 4a25082f7..49d2496f2 100644 --- a/app/views/admin/settings/_map_form.html.erb +++ b/app/views/admin/settings/_map_form.html.erb @@ -2,14 +2,14 @@
" - data-map-center-longitude="<%= Setting["map_longitude"] %>" - data-map-zoom="<%= Setting["map_zoom"] %>" + data-map-center-latitude="<%= Setting["map.latitude"] %>" + data-map-center-longitude="<%= Setting["map.longitude"] %>" + data-map-zoom="<%= Setting["map.zoom"] %>" data-map-tiles-provider="<%= Rails.application.secrets.map_tiles_provider %>" data-map-tiles-provider-attribution="<%= Rails.application.secrets.map_tiles_provider_attribution %>" data-marker-editable="true" - data-marker-latitude="<%= Setting["map_latitude"] %>" - data-marker-longitude="<%= Setting["map_longitude"] %>" + data-marker-latitude="<%= Setting["map.latitude"] %>" + data-marker-longitude="<%= Setting["map.longitude"] %>" data-latitude-input-selector="#latitude" data-longitude-input-selector="#longitude" data-zoom-input-selector="#zoom"> @@ -17,9 +17,9 @@ <%= form_tag admin_update_map_path, method: :put, id: "map-form" do |f| %> - <%= hidden_field_tag :latitude, Setting["map_latitude"] %> - <%= hidden_field_tag :longitude, Setting["map_longitude"] %> - <%= hidden_field_tag :zoom, Setting["map_zoom"] %> + <%= hidden_field_tag :latitude, Setting["map.latitude"] %> + <%= hidden_field_tag :longitude, Setting["map.longitude"] %> + <%= hidden_field_tag :zoom, Setting["map.zoom"] %>
<%= submit_tag t("admin.settings.index.map.form.submit"), diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 656e102ea..bfbd5f9bd 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1188,6 +1188,7 @@ en: update: Map configuration updated succesfully. form: submit: Update + how_to_enable: 'To show the map to users you must enable "Proposals and budget investments geolocation" on "Features" tab.' setting: Feature setting_actions: Actions setting_name: Setting diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index 363c3b875..ab4b34803 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -52,12 +52,6 @@ en: related_content_score_threshold_description: "According to the rating of votes in a related content, hides content that users mark as unrelated" hot_score_period_in_days: "Period (days) used by the filter 'most active'" hot_score_period_in_days_description: "The filter 'most active' used in multiple sections will be based on the votes during the last X days" - map_latitude: "Latitude" - map_latitude_description: "Latitude to show the map position" - map_longitude: "Longitude" - map_longitude_description: "Longitude to show the position of the map" - map_zoom: "Zoom" - map_zoom_description: "Zoom to show the map position" mailer_from_name: "Sender email name" mailer_from_name_description: "This name will appear as sender name in emails sent from the application" mailer_from_address: "Sender email address" @@ -124,3 +118,10 @@ en: public_stats_description: "Display public stats in the Administration panel" help_page: "Help page" help_page_description: 'Displays a Help menu that contains a page with an info section about each enabled feature. Also custom pages and menus can be created in the "Custom pages" and "Custom content blocks" sections' + map: + latitude: "Latitude" + latitude_description: "Latitude to show the map position" + longitude: "Longitude" + longitude_description: "Longitude to show the position of the map" + zoom: "Zoom" + zoom_description: "Zoom to show the map position" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 36fc3d59b..037620ab8 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1187,6 +1187,7 @@ es: update: La configuración del mapa se ha guardado correctamente. form: submit: Actualizar + how_to_enable: 'Para mostrar el mapa a los usuarios se debe de activar "Geolocalización de propuestas y proyectos de gasto" en la pestaña "Funcionalidades".' setting: Funcionalidad setting_actions: Acciones setting_name: Configuración diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index 33f1c9d80..6a251102c 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -52,12 +52,6 @@ es: related_content_score_threshold_description: "Según la puntuación de votos en un contenido relacionado, oculta el contenido que los usuarios marquen como no relacionado" hot_score_period_in_days: "Periodo (días) usado para el filtro 'Más Activos'" hot_score_period_in_days_description: "El filtro 'Más Activos' usado en diferentes secciones se basará en los votos de los últimos X días" - map_latitude: "Latitud" - map_latitude_description: "Latitud para mostrar la posición del mapa" - map_longitude: "Longitud" - map_longitude_description: "Longitud para mostrar la posición del mapa" - map_zoom: "Zoom" - map_zoom_description: "Zoom para mostrar la posición del mapa" mailer_from_name: "Nombre email remitente" mailer_from_name_description: "Este nombre aparecerá como nombre del remitente en los emails enviados desde la aplicación" mailer_from_address: "Dirección email remitente" @@ -124,3 +118,10 @@ es: public_stats_description: "Muestra las estadísticas públicas en el panel de Administración" help_page: "Página de ayuda" help_page_description: 'Muestra un menú Ayuda que contiene una página con una sección de información sobre cada funcionalidad habilitada. También se pueden crear páginas y menús personalizados en las secciones "Personalizar páginas" y "Personalizar bloques"' + map: + latitude: "Latitud" + latitude_description: "Latitud para mostrar la posición del mapa" + longitude: "Longitud" + longitude_description: "Longitud para mostrar la posición del mapa" + zoom: "Zoom" + zoom_description: "Zoom para mostrar la posición del mapa" diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index f0f842d73..dc96d658c 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -151,9 +151,9 @@ end section "Geolocating Investments" do Budget.find_each do |budget| budget.investments.each do |investment| - MapLocation.create(latitude: Setting["map_latitude"].to_f + rand(-10..10)/100.to_f, - longitude: Setting["map_longitude"].to_f + rand(-10..10)/100.to_f, - zoom: Setting["map_zoom"], + MapLocation.create(latitude: Setting["map.latitude"].to_f + rand(-10..10)/100.to_f, + longitude: Setting["map.longitude"].to_f + rand(-10..10)/100.to_f, + zoom: Setting["map.zoom"], investment_id: investment.id) end end diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 6cecac651..5d4abbb6b 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -59,9 +59,9 @@ section "Creating Settings" do "transparent and democratic government") Setting.create(key: "meta_keywords", value: "citizen participation, open government") Setting.create(key: "min_age_to_participate", value: "16") - Setting.create(key: "map_latitude", value: 40.41) - Setting.create(key: "map_longitude", value: -3.7) - Setting.create(key: "map_zoom", value: 10) + Setting.create(key: "map.latitude", value: 40.4332002) + Setting.create(key: "map.longitude", value: -3.7009591) + Setting.create(key: "map.zoom", value: 10) Setting.create(key: "featured_proposals_number", value: 3) Setting.create(key: "proposal_notification_minimum_interval_in_days", value: 0) Setting.create(key: "direct_message_max_per_day", value: 3) diff --git a/db/seeds.rb b/db/seeds.rb index acd473e00..72e800f8d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -106,9 +106,9 @@ Setting["min_age_to_participate"] = 16 Setting["featured_proposals_number"] = 3 # City map feature default configuration (Greenwich) -Setting["map_latitude"] = 51.48 -Setting["map_longitude"] = 0.0 -Setting["map_zoom"] = 10 +Setting["map.latitude"] = 51.48 +Setting["map.longitude"] = 0.0 +Setting["map.zoom"] = 10 # Related content Setting["related_content_score_threshold"] = -0.3 diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb index 954365d89..41d573299 100644 --- a/spec/features/admin/settings_spec.rb +++ b/spec/features/admin/settings_spec.rb @@ -37,6 +37,9 @@ feature "Admin settings" do visit admin_settings_path find("#map-tab").click + expect(page).to have_content 'To show the map to users you must enable ' \ + '"Proposals and budget investments geolocation" ' \ + 'on "Features" tab.' expect(page).not_to have_css("#admin-map") end @@ -48,6 +51,9 @@ feature "Admin settings" do find("#map-tab").click expect(page).to have_css("#admin-map") + expect(page).not_to have_content 'To show the map to users you must enable ' \ + '"Proposals and budget investments geolocation" ' \ + 'on "Features" tab.' end scenario "Should show successful notice" do From 1ece761beb00597d0065cfb77448c089b57c0bf6 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 12:26:56 +0100 Subject: [PATCH 06/10] Render map properly when changing between setting tabs --- app/assets/javascripts/application.js | 2 ++ app/assets/javascripts/settings.js.coffee | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 app/assets/javascripts/settings.js.coffee diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d07c64fb1..70f9b5f53 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -81,6 +81,7 @@ //= require managers //= require globalize //= require send_admin_notification_alert +//= require settings var initialize_modules = function() { App.Comments.initialize(); @@ -127,6 +128,7 @@ var initialize_modules = function() { App.Managers.initialize(); App.Globalize.initialize(); App.SendAdminNotificationAlert.initialize(); + App.Settings.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/settings.js.coffee b/app/assets/javascripts/settings.js.coffee new file mode 100644 index 000000000..beb70d7af --- /dev/null +++ b/app/assets/javascripts/settings.js.coffee @@ -0,0 +1,10 @@ +App.Settings = + + initialize: -> + + $("#settings-tabs").on "change.zf.tabs", -> + if $("#tab-map-configuration:visible").length + map_container = L.DomUtil.get "admin-map" + unless map_container is null + map_container._leaflet_id = null + App.Map.initialize() From c82b2a975a0f6fd873617919d72fb8e8379e162a Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 12:41:42 +0100 Subject: [PATCH 07/10] Add new settings tab for participation processes - Rename setting keys - New tab por participation processes - Hide these settings from features tab --- app/controllers/admin/settings_controller.rb | 1 + app/controllers/concerns/feature_flags.rb | 2 +- app/controllers/users_controller.rb | 8 +- app/helpers/settings_helper.rb | 2 +- .../admin/settings/_filter_subnav.html.erb | 6 + .../_participation_processes_tab.html.erb | 3 + app/views/admin/settings/index.html.erb | 4 + app/views/management/_menu.html.erb | 4 +- config/locales/en/admin.yml | 1 + config/locales/en/settings.yml | 21 ++-- config/locales/es/admin.yml | 1 + config/locales/es/settings.yml | 21 ++-- db/dev_seeds/settings.rb | 14 ++- db/seeds.rb | 12 +- spec/features/admin/budget_groups_spec.rb | 4 +- spec/features/admin/budget_headings_spec.rb | 4 +- .../features/admin/budget_investments_spec.rb | 4 +- spec/features/admin/budgets_spec.rb | 106 +++++++++--------- spec/features/admin/debates_spec.rb | 4 +- spec/features/admin/feature_flags_spec.rb | 67 ++++++++--- .../admin/hidden_budget_investments_spec.rb | 4 +- spec/features/admin/hidden_proposals_spec.rb | 4 +- .../admin/legislation/draft_versions_spec.rb | 2 +- .../admin/legislation/processes_spec.rb | 2 +- .../admin/legislation/questions_spec.rb | 2 +- spec/features/debates_spec.rb | 3 +- spec/features/emails_spec.rb | 2 +- .../moderation/budget_investments_spec.rb | 2 +- spec/features/moderation/debates_spec.rb | 4 +- spec/features/moderation/proposals_spec.rb | 4 +- spec/features/proposals_spec.rb | 3 +- spec/features/users_spec.rb | 4 +- .../valuation/budget_investments_spec.rb | 2 +- spec/features/valuation/budgets_spec.rb | 4 +- 34 files changed, 188 insertions(+), 143 deletions(-) create mode 100644 app/views/admin/settings/_participation_processes_tab.html.erb diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 509d6aa97..384a91ce4 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -4,6 +4,7 @@ class Admin::SettingsController < Admin::BaseController all_settings = Setting.all.group_by { |setting| setting.type } @configuration_settings = all_settings["configuration"] @feature_settings = all_settings["feature"] + @participation_processes_settings = all_settings["process"] @map_configuration_settings = all_settings["map"] end diff --git a/app/controllers/concerns/feature_flags.rb b/app/controllers/concerns/feature_flags.rb index ca3cd929e..830b44f4b 100644 --- a/app/controllers/concerns/feature_flags.rb +++ b/app/controllers/concerns/feature_flags.rb @@ -10,7 +10,7 @@ module FeatureFlags end def check_feature_flag(name) - raise FeatureDisabled, name unless Setting["feature.#{name}"] + raise FeatureDisabled, name unless Setting["feature.#{name}"] || Setting["process.#{name}"] end class FeatureDisabled < Exception diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 76723b232..6b2e141e3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,8 +14,8 @@ class UsersController < ApplicationController def set_activity_counts @activity_counts = HashWithIndifferentAccess.new( proposals: Proposal.where(author_id: @user.id).count, - debates: (Setting["feature.debates"] ? Debate.where(author_id: @user.id).count : 0), - budget_investments: (Setting["feature.budgets"] ? Budget::Investment.where(author_id: @user.id).count : 0), + debates: (Setting["process.debates"] ? Debate.where(author_id: @user.id).count : 0), + budget_investments: (Setting["process.budgets"] ? Budget::Investment.where(author_id: @user.id).count : 0), comments: only_active_commentables.count, follows: @user.follows.map(&:followable).compact.count) end @@ -93,8 +93,8 @@ class UsersController < ApplicationController def only_active_commentables disabled_commentables = [] - disabled_commentables << "Debate" unless Setting["feature.debates"] - disabled_commentables << "Budget::Investment" unless Setting["feature.budgets"] + disabled_commentables << "Debate" unless Setting["process.debates"] + disabled_commentables << "Budget::Investment" unless Setting["process.budgets"] if disabled_commentables.present? all_user_comments.where("commentable_type NOT IN (?)", disabled_commentables) else diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index ad844e29f..b7db90beb 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -1,7 +1,7 @@ module SettingsHelper def feature?(name) - setting["feature.#{name}"].presence + setting["feature.#{name}"].presence || setting["process.#{name}"].presence end def setting diff --git a/app/views/admin/settings/_filter_subnav.html.erb b/app/views/admin/settings/_filter_subnav.html.erb index 71894ec43..81523aad3 100644 --- a/app/views/admin/settings/_filter_subnav.html.erb +++ b/app/views/admin/settings/_filter_subnav.html.erb @@ -11,6 +11,12 @@ <% end %> +
  • + <%= link_to "#tab-participation-processes" do %> + <%= t("admin.settings.index.participation_processes") %> + <% end %> +
  • +
  • <%= link_to "#tab-feature-flags" do %> <%= t("admin.settings.index.feature_flags") %> diff --git a/app/views/admin/settings/_participation_processes_tab.html.erb b/app/views/admin/settings/_participation_processes_tab.html.erb new file mode 100644 index 000000000..c554dd7c6 --- /dev/null +++ b/app/views/admin/settings/_participation_processes_tab.html.erb @@ -0,0 +1,3 @@ +

    <%= t("admin.settings.index.participation_processes") %>

    + +<%= render "featured_settings_table", features: @participation_processes_settings %> diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index 8005e4db7..d105d765f 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -6,6 +6,10 @@ <%= render "configuration_settings_tab" %>
  • +
    + <%= render "participation_processes_tab" %> +
    +
    <%= render "features_tab" %>
    diff --git a/app/views/management/_menu.html.erb b/app/views/management/_menu.html.erb index a3030406e..90add29e8 100644 --- a/app/views/management/_menu.html.erb +++ b/app/views/management/_menu.html.erb @@ -29,7 +29,7 @@ <%= link_to t("management.menu.support_proposals"), management_proposals_path %> - <% if Setting["feature.budgets"] %> + <% if Setting["process.budgets"] %>
  • > <%= link_to t("management.menu.create_budget_investment"), create_investments_management_budgets_path %>
  • @@ -42,7 +42,7 @@ - <% if Setting["feature.budgets"] %> + <% if Setting["process.budgets"] %>
  • > <%= link_to print_investments_management_budgets_path do %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index bfbd5f9bd..44376c5d2 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1175,6 +1175,7 @@ en: index: title: Configuration settings update_setting: Update + participation_processes: "Participation processes" feature_flags: Features features: enabled: "Feature enabled" diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index ab4b34803..b039d547b 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -70,26 +70,16 @@ en: direct_message_max_per_day: "Direct Message max number per day" direct_message_max_per_day_description: "Number max of direct messages one user can send per day" feature: - budgets: "Participatory budgeting" - budgets_description: "With participatory budgets, citizens decide which projects presented by their neighbours will receive a part of the budget" twitter_login: "Twitter login" twitter_login_description: "Allow users to sign up with their Twitter account" facebook_login: "Facebook login" facebook_login_description: "Allow users to sign up with their Facebook account" google_login: "Google login" google_login_description: "Allow users to sign up with their Google Account" - proposals: "Proposals" - proposals_description: "Citizens' proposals are an opportunity for neighbours and collectives to decide directly how they want their society to be, after getting sufficient support and submitting to a citizens' vote" featured_proposals: "Featured proposals" featured_proposals_description: "Shows featured proposals on index proposals page" - debates: "Debates" - debates_description: "The citizens' debate space is aimed at anyone who can present issues that concern them and about which they want to share their views with others" - polls: "Polls" - polls_description: "Citizens' polls are a participatory mechanism by which citizens with voting rights can make direct decisions" signature_sheets: "Signature sheets" signature_sheets_description: "It allows adding from the Administration panel signatures collected on-site to Proposals and investment projects of the Participative Budgets" - legislation: "Collaborative Legislation" - legislation_description: "In participatory processes, citizens are offered the opportunity to participate in the drafting and modification of regulations and to give their opinion on certain actions that are planned to be carried out" spending_proposals: "Spending proposals" spending_proposals_description: "⚠️ NOTE: This functionality has been replaced by Participatory Budgeting and will disappear in new versions" spending_proposal_features: @@ -125,3 +115,14 @@ en: longitude_description: "Longitude to show the position of the map" zoom: "Zoom" zoom_description: "Zoom to show the map position" + process: + debates: "Debates" + debates_description: "The citizens' debate space is aimed at anyone who can present issues that concern them and about which they want to share their views with others" + proposals: "Proposals" + proposals_description: "Citizens' proposals are an opportunity for neighbours and collectives to decide directly how they want their society to be, after getting sufficient support and submitting to a citizens' vote" + polls: "Polls" + polls_description: "Citizens' polls are a participatory mechanism by which citizens with voting rights can make direct decisions" + budgets: "Participatory budgeting" + budgets_description: "With participatory budgets, citizens decide which projects presented by their neighbours will receive a part of the budget" + legislation: "Legislation" + legislation_description: "In participatory processes, citizens are offered the opportunity to participate in the drafting and modification of regulations that affect the society and to give their opinion on certain actions that are planned to be carried out" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 037620ab8..dab5eccdb 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1174,6 +1174,7 @@ es: index: title: Configuración global update_setting: Actualizar + participation_processes: "Procesos de participación" feature_flags: Funcionalidades features: enabled: "Funcionalidad activada" diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index 6a251102c..c33e2f6f7 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -70,26 +70,16 @@ es: direct_message_max_per_day: "Mensajes directos máximos por día" direct_message_max_per_day_description: "Número de mensajes directos máximos que un usuario puede enviar por día" feature: - budgets: "Presupuestos participativos" - budgets_description: "Con los presupuestos participativos la ciudadanía decide a qué proyectos presentados por los vecinos y vecinas va destinada una parte del presupuesto" twitter_login: "Registro con Twitter" twitter_login_description: "Permitir que los usuarios se registren con su cuenta de Twitter" facebook_login: "Registro con Facebook" facebook_login_description: "Permitir que los usuarios se registren con su cuenta de Facebook" google_login: "Registro con Google" google_login_description: "Permitir que los usuarios se registren con su cuenta de Google" - proposals: "Propuestas" - proposals_description: "Las propuestas ciudadanas son una oportunidad para que los vecinos y colectivos decidan directamente cómo quieren que sea su sociedad, después de conseguir los apoyos suficientes y de someterse a votación ciudadana" featured_proposals: "Propuestas destacadas" featured_proposals_description: "Muestra propuestas destacadas en la página principal de propuestas" - debates: "Debates" - debates_description: "El espacio de debates ciudadanos está dirigido a que cualquier persona pueda exponer temas que le preocupan y sobre los que quiera compartir puntos de vista con otras personas" - polls: "Votaciones" - polls_description: "Las votaciones ciudadanas son un mecanismo de participación por el que la ciudadanía con derecho a voto puede tomar decisiones de forma directa" signature_sheets: "Hojas de firmas" signature_sheets_description: "Permite añadir desde el panel de Administración firmas recogidas de forma presencial a Propuestas y proyectos de gasto de los Presupuestos participativos" - legislation: "Legislación colaborativa" - legislation_description: "En los procesos participativos se ofrece a la ciudadanía la oportunidad de participar en la elaboración y modificación de normativa y de dar su opinión sobre ciertas actuaciones que se tiene previsto llevar a cabo" spending_proposals: "Propuestas de inversión" spending_proposals_description: "⚠️ NOTA: Esta funcionalidad ha sido sustituida por Pesupuestos Participativos y desaparecerá en nuevas versiones" spending_proposal_features: @@ -125,3 +115,14 @@ es: longitude_description: "Longitud para mostrar la posición del mapa" zoom: "Zoom" zoom_description: "Zoom para mostrar la posición del mapa" + process: + debates: "Debates" + debates_description: "El espacio de debates ciudadanos está dirigido a que cualquier persona pueda exponer temas que le preocupan y sobre los que quiera compartir puntos de vista con otras personas" + proposals: "Propuestas" + proposals_description: "Las propuestas ciudadanas son una oportunidad para que los vecinos y colectivos decidan directamente cómo quieren que sea su sociedad, después de conseguir los apoyos suficientes y de someterse a votación ciudadana" + polls: "Votaciones" + polls_description: "Las votaciones ciudadanas son un mecanismo de participación por el que la ciudadanía con derecho a voto puede tomar decisiones de forma directa" + budgets: "Presupuestos participativos" + budgets_description: "Con los presupuestos participativos la ciudadanía decide a qué proyectos presentados por los vecinos y vecinas va destinada una parte del presupuesto" + legislation: "Legislación" + legislation_description: "En los procesos participativos se ofrece a la ciudadanía la oportunidad de participar en la elaboración y modificación de normativa que afecta a la sociedad y de dar su opinión sobre ciertas actuaciones que se tiene previsto llevar a cabo" diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 5d4abbb6b..157e99b72 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -26,18 +26,20 @@ section "Creating Settings" do Setting.create(key: "url", value: "http://localhost:3000") Setting.create(key: "org_name", value: "CONSUL") - Setting.create(key: "feature.debates", value: "true") - Setting.create(key: "feature.proposals", value: "true") - Setting.create(key: "feature.featured_proposals", value: nil) - Setting.create(key: "feature.polls", value: "true") + Setting.create(key: "process.debates", value: "true") + Setting.create(key: "process.proposals", value: "true") + Setting.create(key: "process.polls", value: "true") + Setting.create(key: "process.budgets", value: "true") + Setting.create(key: "process.legislation", value: "true") + + Setting.create(key: "feature.featured_proposals", value: "true") Setting.create(key: "feature.spending_proposals", value: nil) Setting.create(key: "feature.spending_proposal_features.voting_allowed", value: nil) - Setting.create(key: "feature.budgets", value: "true") + Setting.create(key: "feature.twitter_login", value: "true") Setting.create(key: "feature.facebook_login", value: "true") Setting.create(key: "feature.google_login", value: "true") Setting.create(key: "feature.signature_sheets", value: "true") - Setting.create(key: "feature.legislation", value: "true") Setting.create(key: "feature.user.recommendations", value: "true") Setting.create(key: "feature.user.recommendations_on_debates", value: "true") Setting.create(key: "feature.user.recommendations_on_proposals", value: "true") diff --git a/db/seeds.rb b/db/seeds.rb index 72e800f8d..581e5e932 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -65,19 +65,21 @@ Setting["meta_title"] = nil Setting["meta_description"] = nil Setting["meta_keywords"] = nil +# Processes +Setting["process.debates"] = true +Setting["process.proposals"] = true +Setting["process.polls"] = true +Setting["process.budgets"] = true +Setting["process.legislation"] = true + # Feature flags -Setting["feature.debates"] = true -Setting["feature.proposals"] = true Setting["feature.featured_proposals"] = nil Setting["feature.spending_proposals"] = nil -Setting["feature.polls"] = true Setting["feature.twitter_login"] = true Setting["feature.facebook_login"] = true Setting["feature.google_login"] = true Setting["feature.public_stats"] = true -Setting["feature.budgets"] = true Setting["feature.signature_sheets"] = true -Setting["feature.legislation"] = true Setting["feature.user.recommendations"] = true Setting["feature.user.recommendations_on_debates"] = true Setting["feature.user.recommendations_on_proposals"] = true diff --git a/spec/features/admin/budget_groups_spec.rb b/spec/features/admin/budget_groups_spec.rb index 4c89abaeb..f719dc6a8 100644 --- a/spec/features/admin/budget_groups_spec.rb +++ b/spec/features/admin/budget_groups_spec.rb @@ -17,11 +17,11 @@ feature "Admin budget groups" do context "Feature flag" do background do - Setting["feature.budgets"] = nil + Setting["process.budgets"] = nil end after do - Setting["feature.budgets"] = true + Setting["process.budgets"] = true end scenario "Disabled with a feature flag" do diff --git a/spec/features/admin/budget_headings_spec.rb b/spec/features/admin/budget_headings_spec.rb index 2c918b6da..2429b1ad4 100644 --- a/spec/features/admin/budget_headings_spec.rb +++ b/spec/features/admin/budget_headings_spec.rb @@ -18,11 +18,11 @@ feature "Admin budget headings" do context "Feature flag" do background do - Setting["feature.budgets"] = nil + Setting["process.budgets"] = nil end after do - Setting["feature.budgets"] = true + Setting["process.budgets"] = true end scenario "Disabled with a feature flag" do diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index fc9d51ce1..ea3711364 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -19,11 +19,11 @@ feature "Admin budget investments" do context "Feature flag" do background do - Setting["feature.budgets"] = nil + Setting["process.budgets"] = nil end after do - Setting["feature.budgets"] = true + Setting["process.budgets"] = true end scenario "Disabled with a feature flag" do diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index fb441844a..e24c344b2 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -1,6 +1,6 @@ -require 'rails_helper' +require "rails_helper" -feature 'Admin budgets' do +feature "Admin budgets" do background do admin = create(:administrator) @@ -12,31 +12,27 @@ feature 'Admin budgets' do "edit_admin_budget_path", %w[name] - context 'Feature flag' do + context "Feature flag" do background do - Setting['feature.budgets'] = nil + Setting["process.budgets"] = nil end - after do - Setting['feature.budgets'] = true - end - - scenario 'Disabled with a feature flag' do + scenario "Disabled with a feature flag" do expect{ visit admin_budgets_path }.to raise_exception(FeatureFlags::FeatureDisabled) end end - context 'Index' do + context "Index" do - scenario 'Displaying no open budgets text' do + scenario "Displaying no open budgets text" do visit admin_budgets_path expect(page).to have_content("There are no budgets.") end - scenario 'Displaying budgets' do + scenario "Displaying budgets" do budget = create(:budget) visit admin_budgets_path @@ -44,7 +40,7 @@ feature 'Admin budgets' do expect(page).to have_content(translated_phase_name(phase_kind: budget.phase)) end - scenario 'Filters by phase' do + scenario "Filters by phase" do drafting_budget = create(:budget, :drafting) accepting_budget = create(:budget, :accepting) selecting_budget = create(:budget, :selecting) @@ -58,14 +54,14 @@ feature 'Admin budgets' do expect(page).to have_content(balloting_budget.name) expect(page).not_to have_content(finished_budget.name) - click_link 'Finished' + click_link "Finished" expect(page).not_to have_content(drafting_budget.name) expect(page).not_to have_content(accepting_budget.name) expect(page).not_to have_content(selecting_budget.name) expect(page).not_to have_content(balloting_budget.name) expect(page).to have_content(finished_budget.name) - click_link 'Open' + click_link "Open" expect(page).to have_content(drafting_budget.name) expect(page).to have_content(accepting_budget.name) expect(page).to have_content(selecting_budget.name) @@ -73,8 +69,8 @@ feature 'Admin budgets' do expect(page).not_to have_content(finished_budget.name) end - scenario 'Open filter is properly highlighted' do - filters_links = {'current' => 'Open', 'finished' => 'Finished'} + scenario "Open filter is properly highlighted" do + filters_links = {"current" => "Open", "finished" => "Finished"} visit admin_budgets_path @@ -94,26 +90,26 @@ feature 'Admin budgets' do end - context 'New' do + context "New" do - scenario 'Create budget' do + scenario "Create budget" do visit admin_budgets_path - click_link 'Create new budget' + click_link "Create new budget" fill_in "Name", with: "M30 - Summer campaign" - select 'Accepting projects', from: 'budget[phase]' + select "Accepting projects", from: "budget[phase]" - click_button 'Create Budget' + click_button "Create Budget" - expect(page).to have_content 'New participatory budget created successfully!' - expect(page).to have_content 'M30 - Summer campaign' + expect(page).to have_content "New participatory budget created successfully!" + expect(page).to have_content "M30 - Summer campaign" end - scenario 'Name is mandatory' do + scenario "Name is mandatory" do visit new_admin_budget_path - click_button 'Create Budget' + click_button "Create Budget" - expect(page).not_to have_content 'New participatory budget created successfully!' + expect(page).not_to have_content "New participatory budget created successfully!" expect(page).to have_css("label.error", text: "Name") end @@ -131,44 +127,44 @@ feature 'Admin budgets' do end - context 'Destroy' do + context "Destroy" do let!(:budget) { create(:budget) } let(:heading) { create(:budget_heading, group: create(:budget_group, budget: budget)) } - scenario 'Destroy a budget without investments' do + scenario "Destroy a budget without investments" do visit admin_budgets_path - click_link 'Edit budget' - click_link 'Delete budget' + click_link "Edit budget" + click_link "Delete budget" - expect(page).to have_content('Budget deleted successfully') + expect(page).to have_content("Budget deleted successfully") expect(page).to have_content("There are no budgets.") end - scenario 'Try to destroy a budget with investments' do + scenario "Try to destroy a budget with investments" do create(:budget_investment, heading: heading) visit admin_budgets_path - click_link 'Edit budget' - click_link 'Delete budget' + click_link "Edit budget" + click_link "Delete budget" - expect(page).to have_content('You cannot destroy a Budget that has associated investments') - expect(page).to have_content('There is 1 budget') + expect(page).to have_content("You cannot destroy a Budget that has associated investments") + expect(page).to have_content("There is 1 budget") end end - context 'Edit' do + context "Edit" do let!(:budget) { create(:budget) } - scenario 'Show phases table' do + scenario "Show phases table" do budget.update(phase: "selecting") visit admin_budgets_path - click_link 'Edit budget' + click_link "Edit budget" expect(page).to have_select("budget_phase", selected: "Selecting projects") - within '#budget-phases-table' do + within "#budget-phases-table" do Budget::Phase::PHASE_KINDS.each do |phase_kind| phase_index = Budget::Phase::PHASE_KINDS.index(phase_kind) @@ -184,9 +180,9 @@ feature 'Admin budgets' do within "#budget_phase_#{phase.id}" do expect(page).to have_content(translated_phase_name(phase_kind: phase.kind)) expect(page).to have_content("#{phase.starts_at.to_date} - #{phase.ends_at.to_date}") - expect(page).to have_css('.budget-phase-enabled.enabled') - expect(page).to have_link('Edit phase', href: edit_phase_link) - expect(page).to have_content('Active') if budget.current_phase == phase + expect(page).to have_css(".budget-phase-enabled.enabled") + expect(page).to have_link("Edit phase", href: edit_phase_link) + expect(page).to have_content("Active") if budget.current_phase == phase end end end @@ -218,20 +214,20 @@ feature 'Admin budgets' do end - context 'Update' do + context "Update" do background do create(:budget) end - scenario 'Update budget' do + scenario "Update budget" do visit admin_budgets_path - click_link 'Edit budget' + click_link "Edit budget" fill_in "Name", with: "More trees on the streets" - click_button 'Update Budget' + click_button "Update Budget" - expect(page).to have_content('More trees on the streets') + expect(page).to have_content("More trees on the streets") expect(page).to have_current_path(admin_budgets_path) end @@ -239,8 +235,8 @@ feature 'Admin budgets' do context "Calculate Budget's Winner Investments" do - scenario 'For a Budget in reviewing balloting', :js do - budget = create(:budget, phase: 'reviewing_ballots') + scenario "For a Budget in reviewing balloting", :js do + budget = create(:budget, phase: "reviewing_ballots") group = create(:budget_group, budget: budget) heading = create(:budget_heading, group: group, price: 4) unselected = create(:budget_investment, :unselected, heading: heading, price: 1, @@ -250,16 +246,16 @@ feature 'Admin budgets' do selected = create(:budget_investment, :selected, heading: heading, price: 2, ballot_lines_count: 1) visit edit_admin_budget_path(budget) - expect(page).not_to have_content 'See results' - click_link 'Calculate Winner Investments' - expect(page).to have_content 'Winners being calculated, it may take a minute.' + expect(page).not_to have_content "See results" + click_link "Calculate Winner Investments" + expect(page).to have_content "Winners being calculated, it may take a minute." expect(page).to have_content winner.title expect(page).not_to have_content unselected.title expect(page).not_to have_content selected.title visit edit_admin_budget_path(budget) - expect(page).to have_content 'See results' + expect(page).to have_content "See results" end scenario "For a finished Budget" do diff --git a/spec/features/admin/debates_spec.rb b/spec/features/admin/debates_spec.rb index 874707eac..18c238646 100644 --- a/spec/features/admin/debates_spec.rb +++ b/spec/features/admin/debates_spec.rb @@ -3,13 +3,13 @@ require "rails_helper" feature "Admin debates" do scenario "Disabled with a feature flag" do - Setting["feature.debates"] = nil + Setting["process.debates"] = nil admin = create(:administrator) login_as(admin.user) expect{ visit admin_debates_path }.to raise_exception(FeatureFlags::FeatureDisabled) - Setting["feature.debates"] = true + Setting["process.debates"] = true end background do diff --git a/spec/features/admin/feature_flags_spec.rb b/spec/features/admin/feature_flags_spec.rb index 92b8f0f55..155c822e7 100644 --- a/spec/features/admin/feature_flags_spec.rb +++ b/spec/features/admin/feature_flags_spec.rb @@ -17,12 +17,14 @@ feature "Admin feature flags" do end end - scenario "Disable a feature" do - setting_id = Setting.find_by(key: "feature.spending_proposals").id + scenario "Disable a participatory process" do + setting = Setting.find_by(key: "process.budgets") + budget = create(:budget) visit admin_settings_path + within("#settings-tabs") { click_link "Participation processes" } - within("#edit_setting_#{setting_id}") do + within("#edit_setting_#{setting.id}") do expect(page).to have_button "Disable" expect(page).not_to have_button "Enable" click_button "Disable" @@ -31,28 +33,27 @@ feature "Admin feature flags" do visit admin_root_path within("#side_menu") do - expect(page).not_to have_link "Budgets" - expect(page).not_to have_link "Spending proposals" + expect(page).not_to have_link "Participatory budgets" end - expect{ visit spending_proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled) - expect{ visit admin_spending_proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled) + expect{ visit budget_path(budget) }.to raise_exception(FeatureFlags::FeatureDisabled) + expect{ visit admin_budgets_path }.to raise_exception(FeatureFlags::FeatureDisabled) end - scenario "Enable a disabled feature" do - Setting["feature.spending_proposals"] = nil - setting_id = Setting.find_by(key: "feature.spending_proposals").id + scenario "Enable a disabled participatory process" do + Setting["process.budgets"] = nil + setting = Setting.find_by(key: "process.budgets") visit admin_root_path within("#side_menu") do - expect(page).not_to have_link "Budgets" - expect(page).not_to have_link "Spending proposals" + expect(page).not_to have_link "Participatory budgets" end visit admin_settings_path + within("#settings-tabs") { click_link "Participation processes" } - within("#edit_setting_#{setting_id}") do + within("#edit_setting_#{setting.id}") do expect(page).to have_button "Enable" expect(page).not_to have_button "Disable" click_button "Enable" @@ -61,7 +62,45 @@ feature "Admin feature flags" do visit admin_root_path within("#side_menu") do - expect(page).to have_link "Spending proposals" + expect(page).to have_link "Participatory budgets" + end + end + + scenario "Disable a feature" do + setting = Setting.find_by(key: "feature.spending_proposals") + + visit admin_settings_path + + within("#edit_setting_#{setting.id}") do + expect(page).to have_button "Disable" + expect(page).not_to have_button "Enable" + click_button "Disable" + end + + expect(page).to have_content "Value updated" + + within("#edit_setting_#{setting.id}") do + expect(page).to have_button "Enable" + expect(page).not_to have_button "Disable" + end + end + + scenario "Enable a disabled feature" do + setting = Setting.find_by(key: "feature.map") + + visit admin_settings_path + + within("#edit_setting_#{setting.id}") do + expect(page).to have_button "Enable" + expect(page).not_to have_button "Disable" + click_button "Enable" + end + + expect(page).to have_content "Value updated" + + within("#edit_setting_#{setting.id}") do + expect(page).to have_button "Disable" + expect(page).not_to have_button "Enable" end end diff --git a/spec/features/admin/hidden_budget_investments_spec.rb b/spec/features/admin/hidden_budget_investments_spec.rb index 592f04144..1b1944ea0 100644 --- a/spec/features/admin/hidden_budget_investments_spec.rb +++ b/spec/features/admin/hidden_budget_investments_spec.rb @@ -12,11 +12,9 @@ feature "Admin hidden budget investments" do end scenario "Disabled with a feature flag" do - Setting["feature.budgets"] = nil + Setting["process.budgets"] = nil expect{ visit admin_hidden_budget_investments_path }.to raise_exception(FeatureFlags::FeatureDisabled) - - Setting["feature.budgets"] = true end scenario "List shows all relevant info" do diff --git a/spec/features/admin/hidden_proposals_spec.rb b/spec/features/admin/hidden_proposals_spec.rb index 71a290ecb..eb8c69b59 100644 --- a/spec/features/admin/hidden_proposals_spec.rb +++ b/spec/features/admin/hidden_proposals_spec.rb @@ -8,13 +8,11 @@ feature "Admin hidden proposals" do end scenario "Disabled with a feature flag" do - Setting["feature.proposals"] = nil + Setting["process.proposals"] = nil admin = create(:administrator) login_as(admin.user) expect{ visit admin_hidden_proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled) - - Setting["feature.proposals"] = true end scenario "List shows all relevant info" do diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb index 2de2345d6..5fedbab5a 100644 --- a/spec/features/admin/legislation/draft_versions_spec.rb +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -16,7 +16,7 @@ feature "Admin legislation draft versions" do context "Feature flag" do scenario "Disabled with a feature flag" do - Setting["feature.legislation"] = nil + Setting["process.legislation"] = nil process = create(:legislation_process) expect{ visit admin_legislation_process_draft_versions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled) end diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index 895ea65f8..838dbe2bb 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -19,7 +19,7 @@ feature "Admin collaborative legislation" do context "Feature flag" do scenario "Disabled with a feature flag" do - Setting["feature.legislation"] = nil + Setting["process.legislation"] = nil expect{ visit admin_legislation_processes_path } .to raise_exception(FeatureFlags::FeatureDisabled) end diff --git a/spec/features/admin/legislation/questions_spec.rb b/spec/features/admin/legislation/questions_spec.rb index bd97672c7..ec1355f15 100644 --- a/spec/features/admin/legislation/questions_spec.rb +++ b/spec/features/admin/legislation/questions_spec.rb @@ -17,7 +17,7 @@ feature "Admin legislation questions" do context "Feature flag" do background do - Setting["feature.legislation"] = nil + Setting["process.legislation"] = nil end scenario "Disabled with a feature flag" do diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 8282ab265..2424597cf 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -4,9 +4,8 @@ require "rails_helper" feature "Debates" do scenario "Disabled with a feature flag" do - Setting["feature.debates"] = nil + Setting["process.debates"] = nil expect{ visit debates_path }.to raise_exception(FeatureFlags::FeatureDisabled) - Setting["feature.debates"] = true end context "Concerns" do diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index ff71ec6d5..94904695a 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -380,7 +380,7 @@ feature "Emails" do context "Budgets" do background do - Setting["feature.budgets"] = true + Setting["process.budgets"] = true end let(:author) { create(:user, :level_two) } diff --git a/spec/features/moderation/budget_investments_spec.rb b/spec/features/moderation/budget_investments_spec.rb index 58d61aa30..79aac76b5 100644 --- a/spec/features/moderation/budget_investments_spec.rb +++ b/spec/features/moderation/budget_investments_spec.rb @@ -12,7 +12,7 @@ feature "Moderate budget investments" do end scenario "Disabled with a feature flag" do - Setting["feature.budgets"] = nil + Setting["process.budgets"] = nil login_as(@mod.user) expect{ visit moderation_budget_investments_path }.to raise_exception(FeatureFlags::FeatureDisabled) diff --git a/spec/features/moderation/debates_spec.rb b/spec/features/moderation/debates_spec.rb index df55f5cd5..bcf32e065 100644 --- a/spec/features/moderation/debates_spec.rb +++ b/spec/features/moderation/debates_spec.rb @@ -3,13 +3,11 @@ require "rails_helper" feature "Moderate debates" do scenario "Disabled with a feature flag" do - Setting["feature.debates"] = nil + Setting["process.debates"] = nil moderator = create(:moderator) login_as(moderator.user) expect{ visit moderation_debates_path }.to raise_exception(FeatureFlags::FeatureDisabled) - - Setting["feature.debates"] = true end scenario "Hide", :js do diff --git a/spec/features/moderation/proposals_spec.rb b/spec/features/moderation/proposals_spec.rb index 6dad35f57..513baf0b8 100644 --- a/spec/features/moderation/proposals_spec.rb +++ b/spec/features/moderation/proposals_spec.rb @@ -3,13 +3,11 @@ require "rails_helper" feature "Moderate proposals" do scenario "Disabled with a feature flag" do - Setting["feature.proposals"] = nil + Setting["process.proposals"] = nil moderator = create(:moderator) login_as(moderator.user) expect{ visit moderation_proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled) - - Setting["feature.proposals"] = true end scenario "Hide", :js do diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index f185a44ab..557c3d6a9 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -8,9 +8,8 @@ feature "Proposals" do "proposal_path" scenario "Disabled with a feature flag" do - Setting["feature.proposals"] = nil + Setting["process.proposals"] = nil expect{ visit proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled) - Setting["feature.proposals"] = true end context "Concerns" do diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 81c8cc2c6..49ef05562 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -409,11 +409,11 @@ feature "Users" do visit user_path(user) expect(page).to have_content("7 Comments") - Setting["feature.debates"] = nil + Setting["process.debates"] = nil visit user_path(user) expect(page).to have_content("6 Comments") - Setting["feature.budgets"] = nil + Setting["process.budgets"] = nil visit user_path(user) expect(page).to have_content("4 Comments") end diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index 560d1ec14..fa918b500 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -12,7 +12,7 @@ feature "Valuation budget investments" do end scenario "Disabled with a feature flag" do - Setting["feature.budgets"] = nil + Setting["process.budgets"] = nil expect{ visit valuation_budget_budget_investments_path(create(:budget)) }.to raise_exception(FeatureFlags::FeatureDisabled) diff --git a/spec/features/valuation/budgets_spec.rb b/spec/features/valuation/budgets_spec.rb index bc5a828ec..fc20dcd75 100644 --- a/spec/features/valuation/budgets_spec.rb +++ b/spec/features/valuation/budgets_spec.rb @@ -8,10 +8,8 @@ feature "Valuation budgets" do end scenario "Disabled with a feature flag" do - Setting["feature.budgets"] = nil + Setting["process.budgets"] = nil expect{ visit valuation_budgets_path }.to raise_exception(FeatureFlags::FeatureDisabled) - - Setting["feature.budgets"] = true end context "Index" do From 89d4ea5aa3b779a360afa531211919dc30b2d9f5 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 12:47:51 +0100 Subject: [PATCH 08/10] Remove homepage widget settings from configuration tab - Rename homepage widget settings keys --- app/helpers/feeds_helper.rb | 6 +++--- app/models/widget/feed.rb | 2 +- db/dev_seeds/settings.rb | 6 +++--- db/seeds.rb | 7 ++++--- spec/features/admin/homepage/homepage_spec.rb | 6 +++--- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/helpers/feeds_helper.rb b/app/helpers/feeds_helper.rb index 1657a6887..a863de56c 100644 --- a/app/helpers/feeds_helper.rb +++ b/app/helpers/feeds_helper.rb @@ -13,15 +13,15 @@ module FeedsHelper end def feed_debates_enabled? - Setting["feature.homepage.widgets.feeds.debates"].present? + Setting["homepage.widgets.feeds.debates"].present? end def feed_proposals_enabled? - Setting["feature.homepage.widgets.feeds.proposals"].present? + Setting["homepage.widgets.feeds.proposals"].present? end def feed_processes_enabled? - Setting["feature.homepage.widgets.feeds.processes"].present? + Setting["homepage.widgets.feeds.processes"].present? end def feed_debates_and_proposals_enabled? diff --git a/app/models/widget/feed.rb b/app/models/widget/feed.rb index 4fc23a1dd..eacd79329 100644 --- a/app/models/widget/feed.rb +++ b/app/models/widget/feed.rb @@ -8,7 +8,7 @@ class Widget::Feed < ActiveRecord::Base end def setting - Setting.where(key: "feature.homepage.widgets.feeds.#{kind}").first + Setting.where(key: "homepage.widgets.feeds.#{kind}").first end def self.active diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 157e99b72..6823c2c80 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -71,7 +71,7 @@ section "Creating Settings" do Setting.create(key: "related_content_score_threshold", value: -0.3) Setting.create(key: "hot_score_period_in_days", value: 31) - Setting["feature.homepage.widgets.feeds.proposals"] = true - Setting["feature.homepage.widgets.feeds.debates"] = true - Setting["feature.homepage.widgets.feeds.processes"] = true + Setting.create(key: "homepage.widgets.feeds.proposals", value: "true") + Setting.create(key: "homepage.widgets.feeds.debates", value: "true") + Setting.create(key: "homepage.widgets.feeds.processes", value: "true") end diff --git a/db/seeds.rb b/db/seeds.rb index 581e5e932..3b012f406 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -115,9 +115,10 @@ Setting["map.zoom"] = 10 # Related content Setting["related_content_score_threshold"] = -0.3 -Setting["feature.homepage.widgets.feeds.proposals"] = true -Setting["feature.homepage.widgets.feeds.debates"] = true -Setting["feature.homepage.widgets.feeds.processes"] = true +# Homepage +Setting["homepage.widgets.feeds.proposals"] = true +Setting["homepage.widgets.feeds.debates"] = true +Setting["homepage.widgets.feeds.processes"] = true # Votes hot_score configuration Setting["hot_score_period_in_days"] = 31 diff --git a/spec/features/admin/homepage/homepage_spec.rb b/spec/features/admin/homepage/homepage_spec.rb index c62353283..d82f39d99 100644 --- a/spec/features/admin/homepage/homepage_spec.rb +++ b/spec/features/admin/homepage/homepage_spec.rb @@ -6,9 +6,9 @@ feature "Homepage" do admin = create(:administrator).user login_as(admin) - Setting["feature.homepage.widgets.feeds.proposals"] = false - Setting["feature.homepage.widgets.feeds.debates"] = false - Setting["feature.homepage.widgets.feeds.processes"] = false + Setting["homepage.widgets.feeds.proposals"] = false + Setting["homepage.widgets.feeds.debates"] = false + Setting["homepage.widgets.feeds.processes"] = false Setting["feature.user.recommendations"] = false end From 4df9a1a1b4df977584d9e7c4bd39601b9b44042b Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 12:49:50 +0100 Subject: [PATCH 09/10] Move HTML settings to content blocks settings page - Rename html settings keys - Show html settings next to content blocks page - Hide html settings from configuration tab --- .../site_customization/content_blocks_controller.rb | 2 ++ .../site_customization/content_blocks/index.html.erb | 2 ++ app/views/layouts/application.html.erb | 4 ++-- app/views/layouts/devise.html.erb | 2 ++ config/locales/en/settings.yml | 9 +++++---- config/locales/es/settings.yml | 9 +++++---- db/dev_seeds/settings.rb | 5 +++-- db/seeds.rb | 4 ++-- 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/site_customization/content_blocks_controller.rb b/app/controllers/admin/site_customization/content_blocks_controller.rb index 417291d51..eb6076dbe 100644 --- a/app/controllers/admin/site_customization/content_blocks_controller.rb +++ b/app/controllers/admin/site_customization/content_blocks_controller.rb @@ -9,6 +9,8 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati def index @content_blocks = SiteCustomization::ContentBlock.order(:name, :locale) @headings_content_blocks = Budget::ContentBlock.all + all_settings = Setting.all.group_by { |setting| setting.type } + @html_settings = all_settings["html"] end def create diff --git a/app/views/admin/site_customization/content_blocks/index.html.erb b/app/views/admin/site_customization/content_blocks/index.html.erb index 26579fd4c..1172e7f8b 100644 --- a/app/views/admin/site_customization/content_blocks/index.html.erb +++ b/app/views/admin/site_customization/content_blocks/index.html.erb @@ -6,6 +6,8 @@

    <%= t("admin.site_customization.content_blocks.index.title") %>

    +<%= render "admin/settings/settings_table", settings: @html_settings %> +

    <%= t("admin.site_customization.content_blocks.information") %>

    <%= t("admin.site_customization.content_blocks.about") %>

    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 84d8f6860..0166b2d0f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,10 +14,10 @@ type: "image/png" %> <%= content_for :social_media_meta_tags %> - <%= setting["per_page_code_head"].try(:html_safe) %> + <%= setting["html.per_page_code_head"].try(:html_safe) %> - <%= setting["per_page_code_body"].try(:html_safe) %> + <%= setting["html.per_page_code_body"].try(:html_safe) %>

    <%= setting["org_name"] %>

    diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb index 976261f53..368625e18 100644 --- a/app/views/layouts/devise.html.erb +++ b/app/views/layouts/devise.html.erb @@ -3,9 +3,11 @@ <%= render "layouts/common_head", default_title: "Gobierno abierto" %> <%= render "layouts/meta_tags" %> + <%= setting["html.per_page_code_head"].try(:html_safe) %> + <%= setting["html.per_page_code_body"].try(:html_safe) %>

    diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index b039d547b..21dd46f23 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -28,10 +28,6 @@ en: months_to_archive_proposals_description: "After this number of months the Proposals will be archived and will no longer be able to receive supports" email_domain_for_officials: "Email domain for public officials" email_domain_for_officials_description: "All users registered with this domain will have their account verified at registration" - per_page_code_head: "Code to be included on every page ()" - per_page_code_head_description: "This code will appear inside the label. Useful for entering custom scripts, analytics..." - per_page_code_body: "Code to be included on every page ()" - per_page_code_body_description: "This code will appear inside the label. Useful for entering custom scripts, analytics..." twitter_handle: "Twitter handle" twitter_handle_description: "If filled in it will appear in the footer" twitter_hashtag: "Twitter hashtag" @@ -126,3 +122,8 @@ en: budgets_description: "With participatory budgets, citizens decide which projects presented by their neighbours will receive a part of the budget" legislation: "Legislation" legislation_description: "In participatory processes, citizens are offered the opportunity to participate in the drafting and modification of regulations that affect the society and to give their opinion on certain actions that are planned to be carried out" + html: + per_page_code_head: "Code to be included on every page ()" + per_page_code_head_description: "This code will appear inside the label. Useful for entering custom scripts, analytics..." + per_page_code_body: "Code to be included on every page ()" + per_page_code_body_description: "This code will appear inside the label. Useful for entering custom scripts, analytics..." diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index c33e2f6f7..5f098045f 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -28,10 +28,6 @@ es: months_to_archive_proposals_description: "Pasado este número de meses las Propuestas se archivarán y ya no podrán recoger apoyos" email_domain_for_officials: "Dominio de email para cargos públicos" email_domain_for_officials_description: "Todos los usuarios registrados con este dominio tendrán su cuenta verificada al registrarse" - per_page_code_head: "Código a incluir en cada página ()" - per_page_code_head_description: "Esté código aparecerá dentro de la etiqueta . Útil para introducir scripts personalizados, analitycs..." - per_page_code_body: "Código a incluir en cada página ()" - per_page_code_body_description: "Esté código aparecerá dentro de la etiqueta . Útil para introducir scripts personalizados, analitycs..." twitter_handle: "Usuario de Twitter" twitter_handle_description: "Si está rellenado aparecerá en el pie de página" twitter_hashtag: "Hashtag para Twitter" @@ -126,3 +122,8 @@ es: budgets_description: "Con los presupuestos participativos la ciudadanía decide a qué proyectos presentados por los vecinos y vecinas va destinada una parte del presupuesto" legislation: "Legislación" legislation_description: "En los procesos participativos se ofrece a la ciudadanía la oportunidad de participar en la elaboración y modificación de normativa que afecta a la sociedad y de dar su opinión sobre ciertas actuaciones que se tiene previsto llevar a cabo" + html: + per_page_code_head: "Código a incluir en cada página ()" + per_page_code_head_description: "Esté código aparecerá dentro de la etiqueta . Útil para introducir scripts personalizados, analitycs..." + per_page_code_body: "Código a incluir en cada página ()" + per_page_code_body_description: "Esté código aparecerá dentro de la etiqueta . Útil para introducir scripts personalizados, analitycs..." diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 6823c2c80..c58bb8164 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -51,8 +51,9 @@ section "Creating Settings" do Setting.create(key: "feature.public_stats", value: "true") Setting.create(key: "feature.help_page", value: "true") - Setting.create(key: "per_page_code_head", value: "") - Setting.create(key: "per_page_code_body", value: "") + Setting.create(key: "html.per_page_code_head", value: "") + Setting.create(key: "html.per_page_code_body", value: "") + Setting.create(key: "comments_body_max_length", value: "1000") Setting.create(key: "mailer_from_name", value: "CONSUL") Setting.create(key: "mailer_from_address", value: "noreply@consul.dev") diff --git a/db/seeds.rb b/db/seeds.rb index 3b012f406..a2942ae35 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -41,10 +41,10 @@ Setting["months_to_archive_proposals"] = 12 Setting["email_domain_for_officials"] = "" # Code to be included at the top (inside ) of every page (useful for tracking) -Setting["per_page_code_head"] = "" +Setting["html.per_page_code_head"] = "" # Code to be included at the top (inside ) of every page -Setting["per_page_code_body"] = "" +Setting["html.per_page_code_body"] = "" # Social settings Setting["twitter_handle"] = nil From e04fd74cf1288c423386365a2f4bfbedc372553d Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 12:52:28 +0100 Subject: [PATCH 10/10] Add rake task to rename existing setting keys --- lib/tasks/settings.rake | 20 +++++++++ spec/lib/tasks/settings_spec.rb | 75 +++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/lib/tasks/settings.rake b/lib/tasks/settings.rake index 12f7e1385..3a241612d 100644 --- a/lib/tasks/settings.rake +++ b/lib/tasks/settings.rake @@ -55,4 +55,24 @@ namespace :settings do end end + desc "Rename existing settings" + task rename_setting_keys: :environment do + Setting.rename_key from: "map_latitude", to: "map.latitude" + Setting.rename_key from: "map_longitude", to: "map.longitude" + Setting.rename_key from: "map_zoom", to: "map.zoom" + + Setting.rename_key from: "feature.debates", to: "process.debates" + Setting.rename_key from: "feature.proposals", to: "process.proposals" + Setting.rename_key from: "feature.polls", to: "process.polls" + Setting.rename_key from: "feature.budgets", to: "process.budgets" + Setting.rename_key from: "feature.legislation", to: "process.legislation" + + Setting.rename_key from: "per_page_code_head", to: "html.per_page_code_head" + Setting.rename_key from: "per_page_code_body", to: "html.per_page_code_body" + + Setting.rename_key from: "feature.homepage.widgets.feeds.proposals", to: "homepage.widgets.feeds.proposals" + Setting.rename_key from: "feature.homepage.widgets.feeds.debates", to: "homepage.widgets.feeds.debates" + Setting.rename_key from: "feature.homepage.widgets.feeds.processes", to: "homepage.widgets.feeds.processes" + end + end diff --git a/spec/lib/tasks/settings_spec.rb b/spec/lib/tasks/settings_spec.rb index fbcc98d41..0ae74cc07 100644 --- a/spec/lib/tasks/settings_spec.rb +++ b/spec/lib/tasks/settings_spec.rb @@ -100,4 +100,79 @@ describe Setting do end + + describe "#rename_setting_keys" do + + let :run_rake_task do + Rake::Task["settings:rename_setting_keys"].reenable + Rake.application.invoke_task "settings:rename_setting_keys" + end + + let :old_keys do + %w[map_latitude map_longitude map_zoom feature.debates feature.proposals feature.polls + feature.budgets feature.legislation per_page_code_head per_page_code_body + feature.homepage.widgets.feeds.proposals feature.homepage.widgets.feeds.debates + feature.homepage.widgets.feeds.processes] + end + + let :new_keys do + %w[map.latitude map.longitude map.zoom process.debates process.proposals process.polls + process.budgets process.legislation html.per_page_code_head html.per_page_code_body + homepage.widgets.feeds.proposals homepage.widgets.feeds.debates + homepage.widgets.feeds.processes] + end + + context "with existing old settings" do + it "rename all settings keys keeping the same value" do + Setting.destroy_all + old_keys.each { |old_key| Setting[old_key] = "old value" } + + run_rake_task + + new_keys.each do |new_key| + expect(Setting[new_key]).to eq "old value" + end + + old_keys.each do |old_key| + expect(Setting.where(key: old_key)).not_to exist + end + end + end + + context "without existing old settings" do + it "initializes all settings with null value" do + Setting.destroy_all + + run_rake_task + + new_keys.each do |new_key| + expect(Setting[new_key]).to eq nil + end + + old_keys.each do |old_key| + expect(Setting.where(key: old_key)).not_to exist + end + end + end + + context "with already existing new settings" do + it "does not change the value of the new settings even if the old setting exist" do + Setting.destroy_all + old_keys.each { |old_key| Setting[old_key] = "old value" } + new_keys.each { |new_key| Setting[new_key] = "new value" } + + run_rake_task + + new_keys.each do |new_key| + expect(Setting[new_key]).to eq "new value" + end + + old_keys.each do |old_key| + expect(Setting.where(key: old_key)).not_to exist + end + end + end + + end + end