Merge pull request #3387 from consul/admin_settings_improvement

Improve Admin settings section
This commit is contained in:
Julian Nicolas Herrero
2019-03-20 11:10:02 +01:00
committed by GitHub
57 changed files with 500 additions and 269 deletions

View File

@@ -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(){

View File

@@ -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()

View File

@@ -1,9 +1,11 @@
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"]
@participation_processes_settings = all_settings["process"]
@map_configuration_settings = all_settings["map"]
end
def update
@@ -13,9 +15,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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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?

View File

@@ -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)

View File

@@ -1,7 +1,7 @@
module SettingsHelper
def feature?(name)
setting["feature.#{name}"].presence
setting["feature.#{name}"].presence || setting["process.#{name}"].presence
end
def setting

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,3 @@
<h2><%= t("admin.settings.index.title") %></h2>
<%= render "settings_table", settings: @configuration_settings %>

View File

@@ -1,5 +1,3 @@
<h2><%= t("admin.settings.index.feature_flags") %></h2>
<table>
<thead>
<tr>
@@ -9,18 +7,18 @@
</tr>
</thead>
<tbody>
<% @feature_flags.each do |feature_flag| %>
<% features.each do |feature| %>
<tr>
<td class="small-8">
<strong><%= t("settings.#{feature_flag.key}") %></strong>
<strong><%= t("settings.#{feature.key}") %></strong>
<br>
<span class="small">
<%= t("settings.#{feature_flag.key}_description", default: t("admin.settings.no_description")) %>
<%= t("settings.#{feature.key}_description", default: t("admin.settings.no_description")) %>
</span>
</td>
<td>
<% if feature_flag.enabled? %>
<% if feature.enabled? %>
<span class="enabled">
<strong>
<%= t ("admin.settings.index.features.enabled") %>
@@ -34,11 +32,11 @@
</td>
<td class="text-right">
<%= 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 %>
</td>

View File

@@ -0,0 +1,3 @@
<h2><%= t("admin.settings.index.feature_flags") %></h2>
<%= render "featured_settings_table", features: @feature_settings %>

View File

@@ -11,6 +11,12 @@
<% end %>
</li>
<li class="tabs-title">
<%= link_to "#tab-participation-processes" do %>
<%= t("admin.settings.index.participation_processes") %>
<% end %>
</li>
<li class="tabs-title" id="features-tab">
<%= link_to "#tab-feature-flags" do %>
<%= t("admin.settings.index.feature_flags") %>

View File

@@ -1,8 +1,13 @@
<% if feature?(:map) %>
<h2><%= t("admin.settings.index.map.title") %></h2>
<%= render "settings_table", settings: @map_configuration_settings %>
<p><%= t("admin.settings.index.map.help") %></p>
<%= render "map_form" %>
<% else %>
<h3>No map to show.</h3>
<div class="callout primary">
<%= t("admin.settings.index.map.how_to_enable") %>
</div>
<% end %>

View File

@@ -2,14 +2,14 @@
<div class="small-12 column">
<div id="admin-map" class="map"
data-map
data-map-center-latitude="<%= Setting["map_latitude"] %>"
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"] %>
<div class="small-12 medium-6 large-4 margin-top">
<%= submit_tag t("admin.settings.index.map.form.submit"),

View File

@@ -0,0 +1,3 @@
<h2><%= t("admin.settings.index.participation_processes") %></h2>
<%= render "featured_settings_table", features: @participation_processes_settings %>

View File

@@ -1,5 +1,3 @@
<h2><%= t("admin.settings.index.title") %></h2>
<table>
<thead>
<tr>
@@ -8,7 +6,7 @@
</tr>
</thead>
<tbody>
<% @settings.each do |setting| %>
<% settings.each do |setting| %>
<tr>
<td class="small-6">
<strong><%= t("settings.#{setting.key}") %></strong>

View File

@@ -3,14 +3,18 @@
<%= render "filter_subnav" %>
<div class="tabs-panel is-active" id="tab-configuration">
<%= render "configuration" %>
<%= render "configuration_settings_tab" %>
</div>
<div class="tabs-panel" id="tab-participation-processes">
<%= render "participation_processes_tab" %>
</div>
<div class="tabs-panel" id="tab-feature-flags">
<%= render "feature_flags" %>
<%= render "features_tab" %>
</div>
<div class="tabs-panel" id="tab-map-configuration">
<%= render "map_configuration" %>
<%= render "map_configuration_tab" %>
</div>
</div>

View File

@@ -6,6 +6,8 @@
<h2 class="inline-block"><%= t("admin.site_customization.content_blocks.index.title") %></h2>
<%= render "admin/settings/settings_table", settings: @html_settings %>
<h3><%= t("admin.site_customization.content_blocks.information") %></h3>
<p><%= t("admin.site_customization.content_blocks.about") %></p>

View File

@@ -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) %>
</head>
<body class="<%= yield (:body_class) %>">
<%= setting["per_page_code_body"].try(:html_safe) %>
<%= setting["html.per_page_code_body"].try(:html_safe) %>
<h1 class="show-for-sr"><%= setting["org_name"] %></h1>

View File

@@ -3,9 +3,11 @@
<head>
<%= render "layouts/common_head", default_title: "Gobierno abierto" %>
<%= render "layouts/meta_tags" %>
<%= setting["html.per_page_code_head"].try(:html_safe) %>
</head>
<body class="auth-page">
<%= setting["html.per_page_code_body"].try(:html_safe) %>
<div class="wrapper">
<div class="auth-image small-12 medium-3 column">
<h1 class="logo margin">

View File

@@ -29,7 +29,7 @@
<%= link_to t("management.menu.support_proposals"), management_proposals_path %>
</li>
<% if Setting["feature.budgets"] %>
<% if Setting["process.budgets"] %>
<li <%= "class=is-active" if menu_create_investments? %>>
<%= link_to t("management.menu.create_budget_investment"), create_investments_management_budgets_path %>
</li>
@@ -42,7 +42,7 @@
</ul>
</li>
<% if Setting["feature.budgets"] %>
<% if Setting["process.budgets"] %>
<li <%= "class=is-active" if menu_print_investments? %>>
<%= link_to print_investments_management_budgets_path do %>
<span class="icon-print"></span>

View File

@@ -1175,6 +1175,7 @@ en:
index:
title: Configuration settings
update_setting: Update
participation_processes: "Participation processes"
feature_flags: Features
features:
enabled: "Feature enabled"
@@ -1188,6 +1189,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

View File

@@ -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 (<head>)"
per_page_code_head_description: "This code will appear inside the <head> label. Useful for entering custom scripts, analytics..."
per_page_code_body: "Code to be included on every page (<body>)"
per_page_code_body_description: "This code will appear inside the <body> 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"
@@ -52,12 +48,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"
@@ -76,26 +66,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:
@@ -124,3 +104,26 @@ 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"
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"
html:
per_page_code_head: "Code to be included on every page (<head>)"
per_page_code_head_description: "This code will appear inside the <head> label. Useful for entering custom scripts, analytics..."
per_page_code_body: "Code to be included on every page (<body>)"
per_page_code_body_description: "This code will appear inside the <body> label. Useful for entering custom scripts, analytics..."

View File

@@ -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"
@@ -1187,6 +1188,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

View File

@@ -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 (<head>)"
per_page_code_head_description: "Esté código aparecerá dentro de la etiqueta <head>. Útil para introducir scripts personalizados, analitycs..."
per_page_code_body: "Código a incluir en cada página (<body>)"
per_page_code_body_description: "Esté código aparecerá dentro de la etiqueta <body>. Ú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"
@@ -52,12 +48,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"
@@ -76,26 +66,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:
@@ -124,3 +104,26 @@ 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"
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"
html:
per_page_code_head: "Código a incluir en cada página (<head>)"
per_page_code_head_description: "Esté código aparecerá dentro de la etiqueta <head>. Útil para introducir scripts personalizados, analitycs..."
per_page_code_body: "Código a incluir en cada página (<body>)"
per_page_code_body_description: "Esté código aparecerá dentro de la etiqueta <body>. Útil para introducir scripts personalizados, analitycs..."

View File

@@ -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

View File

@@ -26,31 +26,34 @@ 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")
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: "")
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")
@@ -59,9 +62,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)
@@ -69,7 +72,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

View File

@@ -41,10 +41,10 @@ Setting["months_to_archive_proposals"] = 12
Setting["email_domain_for_officials"] = ""
# Code to be included at the top (inside <head>) 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 <body>) of every page
Setting["per_page_code_body"] = ""
Setting["html.per_page_code_body"] = ""
# Social settings
Setting["twitter_handle"] = nil
@@ -65,22 +65,25 @@ 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
Setting["feature.user.skip_verification"] = "true"
Setting["feature.community"] = true
Setting["feature.map"] = nil
Setting["feature.allow_images"] = true
@@ -105,18 +108,17 @@ 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
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
# 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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
@@ -22,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"
@@ -36,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"
@@ -66,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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -17,11 +17,7 @@ feature "Admin legislation questions" do
context "Feature flag" do
background do
Setting["feature.legislation"] = nil
end
after do
Setting["feature.legislation"] = true
Setting["process.legislation"] = nil
end
scenario "Disabled with a feature flag" do

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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) }

View File

@@ -12,12 +12,10 @@ 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)
Setting["feature.budgets"] = true
end
scenario "Hiding an investment", :js do

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -409,16 +409,13 @@ 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")
Setting["feature.debates"] = true
Setting["feature.budgets"] = true
end
end

View File

@@ -12,12 +12,10 @@ 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)
Setting["feature.budgets"] = true
end
scenario "Display link to valuation section" do

View File

@@ -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

View File

@@ -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

View File

@@ -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