diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 5ca18f60936..e8465893b5c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -82,7 +82,6 @@ //= require globalize //= require send_admin_notification_alert //= require modal_download -//= require settings //= require cookies //= require columns_selector //= require budget_edit_associations @@ -136,8 +135,7 @@ var initialize_modules = function() { App.Globalize.initialize(); App.SendAdminNotificationAlert.initialize(); App.ModalDownload.initialize(); - App.Settings.initialize(); - if ($("#js-columns-selector").length) { + if ( $('#js-columns-selector').length) { App.ColumnsSelector.initialize(); } App.BudgetEditAssociations.initialize(); diff --git a/app/assets/javascripts/foundation_extras.js b/app/assets/javascripts/foundation_extras.js index c6e344684ff..f1a87802750 100644 --- a/app/assets/javascripts/foundation_extras.js +++ b/app/assets/javascripts/foundation_extras.js @@ -17,6 +17,9 @@ $(window).trigger("resize"); $(document).on("page:before-unload", this.clearSticky); window.addEventListener("popstate", this.clearSticky, false); + $("#side_menu ul").on("down.zf.accordionMenu", function(e) { + Foundation.reInit($("[data-equalizer]")); + }); $(function() { if ($(window).width() < 620) { App.FoundationExtras.mobile_ui_init(); diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index d43db6130a3..e853f00d827 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -217,6 +217,13 @@ $sidebar-active: #f4fcd0; color: #fff; } + @include breakpoint(medium) { + td .enabled, + td .disabled { + padding: $line-height / 2 0; + } + } + th { background: $brand; color: #fff; diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index ad1a0dd0ba6..b7ede32fe30 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -23,3 +23,4 @@ @import "autocomplete_overrides"; @import "jquery-ui/sortable"; @import "leaflet"; +@import "wizard"; diff --git a/app/assets/stylesheets/wizard.scss b/app/assets/stylesheets/wizard.scss new file mode 100644 index 00000000000..8b356dd7d97 --- /dev/null +++ b/app/assets/stylesheets/wizard.scss @@ -0,0 +1,46 @@ +.wizard { + h3 { + margin-bottom: 0; + } + + h3, + .current-step { + display: inline-block; + padding: .7em 0; + } + + .current-step { + @include breakpoint(medium) { + margin-left: $line-height; + } + } + + .btn-back-step { + margin-right: $line-height; + } + + .btn-back-step i { + position: relative; + &:before { + position: absolute; + top: 2px; + left: -20px; + } + } + + .v-aligner { + display: flex; + align-items: center; + justify-content: center; + } + + .button { + margin-bottom: 0; + } + + @include breakpoint(small) { + input.button { + padding: 1em 0; + } + } +} diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index fdbc2b4d52d..565f31c73cb 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -8,29 +8,20 @@ class Admin::SettingsController < Admin::BaseController :poster_feature_short_title_setting, :poster_feature_description_setting def index - 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"] - @proposals_settings = all_settings["proposals"] - @remote_census_general_settings = all_settings["remote_census.general"] - @remote_census_request_settings = all_settings["remote_census.request"] - @remote_census_response_settings = all_settings["remote_census.response"] - @uploads_settings = all_settings["uploads"] + @settings_groups = ["configuration", "process", "feature", "map", "uploads", "proposals", "remote_census", "social", "advanced", "smtp", "regional", "sms"].freeze end def update @setting = Setting.find(params[:id]) @setting.update(settings_params) - redirect_to request_referer, notice: t("admin.settings.flash.updated") + redirect_to request.referer, notice: t("admin.settings.flash.updated") 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 - redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update") + redirect_to request.referer, notice: t("admin.settings.index.map.flash.update") end def update_content_types @@ -43,6 +34,12 @@ def update_content_types redirect_to admin_settings_path, notice: t("admin.settings.flash.updated") end + def show + @settings = settings_by_group(params[:id]) + + render params[:id] + end + private def settings_params @@ -53,8 +50,20 @@ def content_type_params params.permit(:jpg, :png, :gif, :pdf, :doc, :docx, :xls, :xlsx, :csv, :zip) end - def request_referer - return request.referer + params[:setting][:tab] if params[:setting][:tab] - request.referer + def settings_by_group(group) + all_settings = Setting.all.group_by { |setting| setting.type } + case group + when "remote_census" + [all_settings["remote_census.general"]] + [all_settings["remote_census.request"]] + [all_settings["remote_census.response"]] + when "social" + [all_settings["social.facebook"]] + [all_settings["social.twitter"]] + [all_settings["social.google"]] + when "advanced" + [all_settings["advanced.auth"]] + [all_settings["advanced.tracking"]] + when "regional" + [all_settings["regional.default_locale"]] + [all_settings["regional.available_locale"]] + [all_settings["regional.time_zone"]] + else + all_settings[group] + end end + end diff --git a/app/controllers/admin/wizards/installer_controller.rb b/app/controllers/admin/wizards/installer_controller.rb new file mode 100644 index 00000000000..50286c3eacc --- /dev/null +++ b/app/controllers/admin/wizards/installer_controller.rb @@ -0,0 +1,51 @@ +class Admin::Wizards::InstallerController < Admin::BaseController + layout "wizard" + + before_action :set_total_steps + before_action :set_settings, only: :show + + def new + end + + def show + render params[:id] + end + + private + + def set_total_steps + @total_steps = 7 + end + + def set_settings + case params[:id] + when "general_settings" + @settings = [Setting.find_by(key: "org_name"), + Setting.find_by(key: "min_age_to_participate")] + when "participation_process" + @settings = [[Setting.find_by(key: "process.debates"), + Setting.find_by(key: "process.proposals"), + Setting.find_by(key: "votes_for_proposal_success"), + Setting.find_by(key: "process.polls"), + Setting.find_by(key: "process.budgets")]] + when "map" + @settings = [[Setting.find_by(key: "feature.map"), + Setting.find_by(key: "map.latitude"), + Setting.find_by(key: "map.longitude"), + Setting.find_by(key: "map.zoom")]] + when "smtp" + @settings = [Setting.find_by(key: "feature.smtp_configuration"), + Setting.find_by(key: "smtp.address"), + Setting.find_by(key: "smtp.port"), + Setting.find_by(key: "smtp.domain"), + Setting.find_by(key: "smtp.username"), + Setting.find_by(key: "smtp.password"), + Setting.find_by(key: "smtp.authentication"), + Setting.find_by(key: "smtp.enable_starttls_auto")] + when "regional" + all_settings = Setting.all.group_by { |setting| setting.type } + @settings = [all_settings["regional.default_locale"]] + [all_settings["regional.available_locale"]] + [all_settings["regional.time_zone"]] + end + end + +end diff --git a/app/controllers/admin/wizards_controller.rb b/app/controllers/admin/wizards_controller.rb new file mode 100644 index 00000000000..5cc4bb959e7 --- /dev/null +++ b/app/controllers/admin/wizards_controller.rb @@ -0,0 +1,7 @@ +class Admin::WizardsController < Admin::BaseController + + def index + @wizards = ["installation"].freeze + end + +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ffe4f4f4a4d..7222ee702fa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base include HasFilters include HasOrders include AccessDeniedHandler + include RegionalSettings default_form_builder ConsulFormBuilder protect_from_forgery with: :exception @@ -28,12 +29,13 @@ class ApplicationController < ActionController::Base def authenticate_http_basic authenticate_or_request_with_http_basic do |username, password| - username == Rails.application.secrets.http_basic_username && password == Rails.application.secrets.http_basic_password + username == Retrocompatibility.calculate_value("advanced.auth.http_basic_username", "http_basic_username") && + password == Retrocompatibility.calculate_value("advanced.auth.http_basic_password", "http_basic_password") end end def http_basic_auth_site? - Rails.application.secrets.http_basic_auth + Retrocompatibility.calculate_value("advanced.auth.http_basic_auth", "http_basic_auth") end def verify_lock diff --git a/app/controllers/concerns/regional_settings.rb b/app/controllers/concerns/regional_settings.rb new file mode 100644 index 00000000000..290457cbed5 --- /dev/null +++ b/app/controllers/concerns/regional_settings.rb @@ -0,0 +1,14 @@ +module RegionalSettings + extend ActiveSupport::Concern + + included do + before_action :initialize_regional_settings + end + + private + + def initialize_regional_settings + Regional::Locales.load_default_and_available_locales + Regional::Timezone.load_timezone + end +end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 67edc4e2605..95cdcfcfb24 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -1,15 +1,15 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def twitter - sign_in_with :twitter_login, :twitter + sign_in_with :twitter end def facebook - sign_in_with :facebook_login, :facebook + sign_in_with :facebook end def google_oauth2 - sign_in_with :google_login, :google_oauth2 + sign_in_with :google_oauth2 end def after_sign_in_path_for(resource) @@ -22,8 +22,8 @@ def after_sign_in_path_for(resource) private - def sign_in_with(feature, provider) - raise ActionController::RoutingError.new("Not Found") unless Setting["feature.#{feature}"] + def sign_in_with(provider) + raise ActionController::RoutingError.new("Not Found") unless Setting["social.#{provider}.login"] auth = request.env["omniauth.auth"] diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 9f3a21c7e62..5dda01e5b54 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -48,7 +48,7 @@ def menu_profiles? def menu_settings? controllers_names = ["settings", "tags", "geozones", "images", "content_blocks", - "local_census_records", "imports"] + "local_census_records", "imports", "wizards"] controllers_names.include?(controller_name) && controller.class.parent != Admin::Poll::Questions::Answers end diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index d0f51f5f6be..394d799704a 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -53,8 +53,9 @@ def prepare_map_settings(map_location, editable, parent_class, investments_coord map_center_latitude: map_location_latitude(map_location), map_center_longitude: map_location_longitude(map_location), map_zoom: map_location_zoom(map_location), - map_tiles_provider: Rails.application.secrets.map_tiles_provider, - map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution, + map_tiles_provider: Retrocompatibility.calculate_value("map.tiles_provider", "map_tiles_provider"), + map_tiles_provider_attribution: Retrocompatibility.calculate_value("map.tiles_provider_attribution", + "map_tiles_provider_attribution"), marker_editable: editable, marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}", latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}", diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index 5d9ee2ebea8..88671f9b8a4 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -1,19 +1,62 @@ module SettingsHelper def feature?(name) - setting["feature.#{name}"].presence || setting["process.#{name}"].presence + setting["feature.#{name}"].presence || setting["process.#{name}"].presence || setting["social.#{name}"].presence end def setting @all_settings ||= Hash[Setting.all.map { |s| [s.key, s.value.presence] }] end - def display_setting_name(setting_name) - if setting_name == "setting" - t("admin.settings.setting_name") - else - t("admin.settings.#{setting_name}") + def is_feature?(setting) + social_feature?(setting) || + advanced_feature?(setting) || + smtp_feature?(setting) || + regional_feature?(setting) || + process_feature?(setting) || + map_feature?(setting) + end + + def social_feature?(setting) + key = setting.key.split(".") + key.first == "social" && key.last == "login" + end + + def advanced_feature?(setting) + setting.key == "advanced.auth.http_basic_auth" + end + + def smtp_feature?(setting) + setting.key == "smtp.enable_starttls_auto" || setting.key == "feature.smtp_configuration" + end + + def process_feature?(setting) + key = setting.key.split(".") + key.first == "process" + end + + def map_feature?(setting) + setting.key == "feature.map" + end + + def regional_feature?(setting) + key = setting.key.split(".") + key.first == "regional" && key.second == "available_locale" + end + + def options_for_default_locale + I18n.available_locales.map do |locale| + [name_for_locale(locale), locale] end end + def regional_setting?(setting) + setting.type.rpartition(".").first == "regional" + end + + def need_disable_language?(setting) + setting_locale = setting.key.rpartition(".").last.to_sym + setting_locale == I18n.default_locale || setting_locale == I18n.locale + end + end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 2788620705b..3e51b980e34 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -3,4 +3,9 @@ class ApplicationMailer < ActionMailer::Base helper :application default from: Proc.new { "#{Setting["mailer_from_name"]} <#{Setting["mailer_from_address"]}>" } layout "mailer" + before_action :set_smtp_settings + + def set_smtp_settings + SmtpConfiguration.set_configuration + end end diff --git a/app/mailers/devise_mailer.rb b/app/mailers/devise_mailer.rb index 89f2a76b6c9..ee7e45c3dbd 100644 --- a/app/mailers/devise_mailer.rb +++ b/app/mailers/devise_mailer.rb @@ -2,6 +2,11 @@ class DeviseMailer < Devise::Mailer helper :application, :settings include Devise::Controllers::UrlHelpers default template_path: "devise/mailer" + before_action :set_smtp_settings + + def set_smtp_settings + SmtpConfiguration.set_configuration + end protected diff --git a/app/models/setting.rb b/app/models/setting.rb index 3770aca1d13..992dfc3925f 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -8,9 +8,9 @@ def prefix end def type - if %w[feature process proposals map html homepage uploads].include? prefix + if %w[feature process proposals map html homepage uploads smtp sms].include? prefix prefix - elsif %w[remote_census].include? prefix + elsif %w[remote_census social advanced regional].include? prefix key.rpartition(".").first else "configuration" @@ -81,9 +81,6 @@ def mime_types def defaults { "feature.featured_proposals": nil, - "feature.facebook_login": true, - "feature.google_login": true, - "feature.twitter_login": true, "feature.public_stats": true, "feature.signature_sheets": true, "feature.user.recommendations": true, @@ -99,6 +96,16 @@ def defaults "feature.translation_interface": nil, "feature.remote_census": nil, "feature.valuation_comment_notification": true, + "feature.smtp_configuration": nil, + "social.facebook.login": true, + "social.facebook.key": nil, + "social.facebook.secret": nil, + "social.google.login": true, + "social.google.key": nil, + "social.google.secret": nil, + "social.twitter.login": true, + "social.twitter.key": nil, + "social.twitter.secret": nil, "homepage.widgets.feeds.debates": true, "homepage.widgets.feeds.processes": true, "homepage.widgets.feeds.proposals": true, @@ -109,6 +116,8 @@ def defaults "map.latitude": 51.48, "map.longitude": 0.0, "map.zoom": 10, + "map.tiles_provider": nil, + "map.tiles_provider_attribution": nil, "process.debates": true, "process.proposals": true, "process.polls": true, @@ -132,6 +141,48 @@ def defaults "uploads.documents.max_amount": 3, "uploads.documents.max_size": 3, "uploads.documents.content_types": "application/pdf", + "advanced.auth.http_basic_auth": nil, + "advanced.auth.http_basic_username": nil, + "advanced.auth.http_basic_password": nil, + "advanced.tracking.rollbar_server_token": nil, + # SMTP Configuration + "smtp.address": nil, + "smtp.port": nil, + "smtp.domain": nil, + "smtp.username": nil, + "smtp.password": nil, + "smtp.authentication": nil, + "smtp.enable_starttls_auto": nil, + # Languages and Time Zone + "regional.default_locale.key": "en", + "regional.available_locale.ar": true, + "regional.available_locale.bs": true, + "regional.available_locale.cs": true, + "regional.available_locale.da": true, + "regional.available_locale.de": true, + "regional.available_locale.el": true, + "regional.available_locale.en": true, + "regional.available_locale.es": true, + "regional.available_locale.fa": true, + "regional.available_locale.fr": true, + "regional.available_locale.gl": true, + "regional.available_locale.he": true, + "regional.available_locale.hr": true, + "regional.available_locale.id": true, + "regional.available_locale.it": true, + "regional.available_locale.nl": true, + "regional.available_locale.pl": true, + "regional.available_locale.pt-BR": true, + "regional.available_locale.ru": true, + "regional.available_locale.sl": true, + "regional.available_locale.sq": true, + "regional.available_locale.so": true, + "regional.available_locale.sv": true, + "regional.available_locale.tr": true, + "regional.available_locale.val": true, + "regional.available_locale.zh-CN": true, + "regional.available_locale.zh-TW": true, + "regional.time_zone.key": "Madrid", # Names for the moderation console, as a hint for moderators # to know better how to assign users with official positions "official_level_1_name": I18n.t("seeds.settings.official_level_1_name"), @@ -184,7 +235,10 @@ def defaults "remote_census.response.gender": "", "remote_census.response.name": "", "remote_census.response.surname": "", - "remote_census.response.valid": "" + "remote_census.response.valid": "", + "sms.endpoint": nil, + "sms.username": nil, + "sms.password": nil } end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 91245c0cf12..64d10194b40 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -1,5 +1,5 @@
<%= t("admin.settings.setting") %> | +<%= t("admin.settings.setting_status") %>/<%= t("admin.settings.setting_value") %> | +<%= t("admin.settings.setting_actions") %> | +||
---|---|---|---|---|
+ <%= t("settings.#{setting.key}") %>
+ + + <%= t("settings.#{setting.key}_description", default: t("admin.settings.no_description")) %> + + |
+
+ <% if is_feature?(setting) %>
+
+ <% if setting.enabled? %>
+
+
+ <%= t ("admin.settings.index.features.enabled") %>
+
+
+ <% else %>
+
+ <%= t("admin.settings.index.features.disabled") %>
+
+ <% end %>
+
+ <%= render "admin/settings/featured_settings_form", feature: setting %>
+
+ |
+ <% else %>
+
+ <%= form_for(setting, url: admin_setting_path(setting), html: { id: "edit_#{dom_id(setting)}"}) do |f| %>
+ <% if regional_setting?(setting) %>
+
+ <% if setting.key == "regional.time_zone.key" %>
+ <%= f.select :value, time_zone_options_for_select(Time.zone.name, ActiveSupport::TimeZone.all), label: false, id: dom_id(setting) %>
+ <% else %>
+ <%= f.select :value, options_for_select(options_for_default_locale, I18n.default_locale), label: false, id: dom_id(setting) %>
+ <% end %>
+
+ <% else %>
+ <%= f.text_area :value, label: false, id: dom_id(setting), lines: 1, class: "small-6 column" %>
+ <% end %>
+
+ <%= f.submit(t("admin.settings.index.update_setting"), class: "button hollow expanded") %>
+
+ <% end %>
+ |
+ <% end %>
+
<%= display_setting_name(setting_name) %> | +<%= t("admin.settings.setting_name") %> | <%= t("admin.settings.setting_value") %> |
---|---|---|
<%= t("settings.#{setting.key}") %>
@@ -19,11 +19,7 @@ <% if setting.content_type? %> <%= render "admin/settings/content_types_settings_form", setting: setting %> <% else %> - <% if defined?(tab) %> - <%= render "admin/settings/settings_form", setting: setting, tab: tab %> - <% else %> - <%= render "admin/settings/settings_form", setting: setting %> - <% end %> + <%= render "admin/settings/settings_form", setting: setting %> <% end %> |
<%= t("admin.settings.index.map.help") %>
diff --git a/app/views/admin/settings/process.html.erb b/app/views/admin/settings/process.html.erb new file mode 100644 index 00000000000..1a05d672e22 --- /dev/null +++ b/app/views/admin/settings/process.html.erb @@ -0,0 +1,4 @@ +<%= back_link_to admin_settings_path %> +<%= t("wizard.finish.description_html") %>
+ <%= link_to t("wizard.finish.btn_finish"), admin_root_path, class: "button" %> +<%= t("wizard.general_settings.description_html") %>
+ <%= render "admin/settings/settings_table", settings: @settings %> +<%= t("wizard.map.description_html") %>
+ <%#= render "admin/settings/settings_table", settings: @settings %> + <% @settings.each do |setting_group| %> + <%= render "admin/settings/mixed_settings_table", settings: setting_group %> + <% end %> +<%= t("admin.settings.index.map.help") %>
+ <%= render "admin/settings/map_form" %> +<%= t("wizard.new.description_html") %>
+ <%= link_to t("wizard.new.btn_start"), admin_wizards_installer_path(:general_settings), class: "button" %> +<%= t("wizard.partecipation_process.description_html") %>
+ <% @settings.each do |setting_group| %> + <%= render "admin/settings/mixed_settings_table", settings: setting_group %> + <% end %> +<%= t("wizard.regional.description_html") %>
+ <% @settings.each do |setting_group| %> +<%= t("wizard.smtp.description_html") %>
+ <%= render "admin/settings/mixed_settings_table", settings: @settings %> +