Merge pull request #763 from AjuntamentdeBarcelona/make_consul_location_agnostic

Parameterize brand and social links
This commit is contained in:
Juanjo Bazán
2016-01-18 12:50:47 +01:00
27 changed files with 128 additions and 83 deletions

View File

@@ -53,7 +53,7 @@ class Users::ConfirmationsController < Devise::ConfirmationsController
private
def set_official_position
resource.add_official_position! (Setting.value_for 'official_level_1_name'), 1
resource.add_official_position! (Setting['official_level_1_name']), 1
end
end

View File

@@ -7,7 +7,7 @@ module AdminHelper
def official_level_options
options = [["",0]]
(1..5).each do |i|
options << [[t("admin.officials.level_#{i}"), Setting.value_for("official_level_#{i}_name")].compact.join(': '), i]
options << [[t("admin.officials.level_#{i}"), Setting["official_level_#{i}_name"]].compact.join(': '), i]
end
options
end

View File

@@ -75,7 +75,7 @@ class Debate < ActiveRecord::Base
end
def editable?
total_votes <= Setting.value_for('max_votes_for_debate_edit').to_i
total_votes <= Setting['max_votes_for_debate_edit'].to_i
end
def editable_by?(user)
@@ -93,8 +93,8 @@ class Debate < ActiveRecord::Base
return false unless user
total_votes <= 100 ||
!user.unverified? ||
Setting.value_for('max_ratio_anon_votes_on_debates').to_i == 100 ||
anonymous_votes_ratio < Setting.value_for('max_ratio_anon_votes_on_debates').to_i ||
Setting['max_ratio_anon_votes_on_debates'].to_i == 100 ||
anonymous_votes_ratio < Setting['max_ratio_anon_votes_on_debates'].to_i ||
user.voted_for?(self)
end

View File

@@ -80,7 +80,7 @@ class Proposal < ActiveRecord::Base
end
def editable?
total_votes <= Setting.value_for("max_votes_for_proposal_edit").to_i
total_votes <= Setting["max_votes_for_proposal_edit"].to_i
end
def editable_by?(user)
@@ -98,7 +98,7 @@ class Proposal < ActiveRecord::Base
end
def code
"#{Setting.value_for("proposal_code_prefix")}-#{created_at.strftime('%Y-%m')}-#{id}"
"#{Setting["proposal_code_prefix"]}-#{created_at.strftime('%Y-%m')}-#{id}"
end
def after_commented
@@ -129,7 +129,7 @@ class Proposal < ActiveRecord::Base
end
def self.votes_needed_for_success
Setting.value_for('votes_for_proposal_success').to_i
Setting['votes_for_proposal_success'].to_i
end
protected

View File

@@ -3,7 +3,16 @@ class Setting < ActiveRecord::Base
default_scope { order(id: :asc) }
def self.value_for(key)
class << self
def [](key)
where(key: key).pluck(:value).first
end
def []=(key, value)
setting = where(key: key).first || new(key: key)
setting.value = value
setting.save!
value
end
end
end

View File

@@ -202,7 +202,7 @@ class User < ActiveRecord::Base
end
def has_official_email?
domain = Setting.value_for 'email_domain_for_officials'
domain = Setting['email_domain_for_officials']
!email.blank? && ( (email.end_with? "@#{domain}") || (email.end_with? ".#{domain}") )
end

View File

@@ -11,7 +11,7 @@
<li class="name">
<%= link_to root_path do %>
<%= image_tag('header_logo_madrid.png', class: 'left', size: '96x96', alt: t("layouts.header.logo")) %>
<%= t("layouts.header.participation_html") %> <span>|</span> <span class="logo-site"><%= t("admin.dashboard.index.title") %></span>
<%= Setting['org_name'] %> <span>|</span> <span class="logo-site"><%= t("admin.dashboard.index.title") %></span>
<% end %>
</li>
<li class="toggle-topbar menu-icon"><a href="#"><span></span></a></li>

View File

@@ -53,22 +53,30 @@
</div>
<div class="small-12 medium-3 column social">
<%= link_to "https://twitter.com/abriendomadrid", target: "_blank", title: t("social.twitter") do %>
<% if Setting['twitter_handle'] %>
<%= link_to "https://twitter.com/#{Setting['twitter_handle']}", target: "_blank", title: t("social.twitter") do %>
<span class="sr-only"><%= t("social.twitter") %></span>
<i class="icon-twitter"></i>
<% end %>
<%= link_to "https://www.facebook.com/Abriendo-Madrid-1475577616080350/", target: "_blank", title: t("social.facebook") do %>
<% end %>
<% if Setting['facebook_handle'] %>
<%= link_to "https://www.facebook.com/#{Setting['facebook_handle']}/", target: "_blank", title: t("social.facebook") do %>
<span class="sr-only"><%= t("social.facebook") %></span>
<i class="icon-facebook"></i>
<% end %>
<%= link_to "/blog", target: "_blank", title: t("social.blog") do %>
<% end %>
<% if Setting['blog_url'] %>
<%= link_to Setting['blog_url'], target: "_blank", title: t("social.blog") do %>
<span class="sr-only"><%= t("social.blog") %></span>
<i class="icon-blog"></i>
<% end %>
<%= link_to "https://www.youtube.com/channel/UCFmaChI9quIY7lwHplnacfg", target: "_blank", title: t("social.youtube") do %>
<% end %>
<% if Setting['youtube_handle'] %>
<%= link_to "https://www.youtube.com/#{Setting['youtube_handle']}", target: "_blank", title: t("social.youtube") do %>
<span class="sr-only"><%= t("social.youtube") %></span>
<i class="icon-youtube"></i>
<% end %>
<% end %>
</div>
</div>
</div>

View File

@@ -3,7 +3,7 @@
<div class="row">
<%= render "shared/locale_switcher" %>
<div class="external-links">
<%= link_to t("layouts.header.participation_html"), root_path, class: ("selected" unless current_page?("/opendata")) %>&nbsp;|
<%= link_to Setting['org_name'], root_path, class: ("selected" unless current_page?("/opendata")) %>&nbsp;|
<%= link_to t("layouts.header.external_link_transparency"), t("layouts.header.external_link_transparency_url") %>&nbsp;|
<%= link_to t("layouts.header.external_link_opendata"), "/opendata", class: ("selected" if current_page?("/opendata")) %>
</div>
@@ -21,7 +21,7 @@
<%= t("layouts.header.open_gov", open: "#{t('layouts.header.open')}") %> <span>|</span>
<span class="logo-site"><%= t("layouts.header.open_data") %></span>
<% else %>
<%= t("layouts.header.participation_html") %>
<%= Setting['org_name'] %>
<% end %>
<% end %>
</li>
@@ -39,9 +39,11 @@
<%= link_to t("layouts.header.proposals"), proposals_path, class: ("active" if controller_name == "proposals") %>
<%= link_to t("layouts.header.spending_proposals"), spending_proposals_path, class: ("active" if controller_name == "spending_proposals") %>
<%= link_to t("layouts.header.more_information"), page_path('more_information'), class: ("active" if current_page?("/more_information")) %>
<%= link_to t("layouts.header.external_link_blog_url"), target: "_blank" do %>
<% if Setting['blog_url'] %>
<%= link_to Setting['blog_url'], target: "_blank" do %>
<%= t("layouts.header.external_link_blog") %>
<small><i class="icon-external"></i></small>
<i class="icon-external"></i>
<% end %>
<% end %>
</div>
<div class="small-12 medium-3 column">

View File

@@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title><%= content_for?(:title) ? yield(:title) : "Gobierno abierto" %></title>
<title><%= content_for?(:title) ? yield(:title) : Setting['org_name'] %></title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "vendor/modernizr" %>
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
@@ -16,7 +16,7 @@
type: "image/png" %>
<%= content_for :social_media_meta_tags %>
<%= Setting.value_for(:per_page_code).try(:html_safe) %>
<%= Setting['per_page_code'].try(:html_safe) %>
</head>
<body>

View File

@@ -14,7 +14,7 @@
<tr>
<td style="border-bottom: 1px solid #dadfe1; padding: 20px 0;">
<a href="#" target="_blank">
<%= image_tag('logo_email_gobierno_abierto.png', style: "border: 0; display: block; width: 100%;max-width: 370px", alt: "Ayuntamiento de Madrid - Participación ciudadana, transparencia y gobierno abierto") %>
<%= image_tag('logo_email_gobierno_abierto.png', style: "border: 0; display: block; width: 100%;max-width: 370px", alt: Setting['org_name']) %>
</a>
</td>
</tr>
@@ -31,7 +31,7 @@
<tr>
<td style="text-align: center; border-top: 1px solid #dadfe1; padding-top: 20px;">
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; margin: 0;padding: 0;line-height: 1.5em;color: #797f7f; font-size: 12px;">
Ayuntamiento de Madrid</p>
<%= Setting['org_name'] %></p>
</td>
</tr>
</tbody>

View File

@@ -29,7 +29,7 @@
<li class="name">
<%= link_to management_root_path do %>
<%= image_tag('header_logo_madrid.png', class: 'left', size: '96x96') %>
<%= t("layouts.header.participation_html") %> <span>|</span> <span class="logo-site"><%= t("management.dashboard.index.title") %></span>
<%= Setting['org_name'] %> <span>|</span> <span class="logo-site"><%= t("management.dashboard.index.title") %></span>
<% end %>
</li>
<li class="toggle-topbar menu-icon"><a href="#"><span></span></a></li>

View File

@@ -35,8 +35,10 @@
<% end %>
<% if voted_for?(@featured_proposals_votes, proposal) %>
<% if Setting['twitter_handle'] %>
<div class="share-supported">
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: "AbriendoMadrid") %>
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: Setting['twitter_handle']) %>
</div>
<% end %>
<% end %>
</div>

View File

@@ -51,9 +51,9 @@
</div>
<% end %>
<% if voted_for?(@proposal_votes, proposal) %>
<% if voted_for?(@proposal_votes, proposal) && Setting['twitter_handle'] %>
<div class="share-supported">
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: "AbriendoMadrid") %>
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: Setting['twitter_handle']) %>
</div>
<% end %>
</div>

View File

@@ -6,11 +6,15 @@
<meta name="twitter:image" content="<%= image_url '/social-media-icon.png' %>" />
<!-- Facebook OG -->
<meta id="ogtitle" property="og:title" content="<%= social_title %>"/>
<meta property="article:publisher" content="http://decide.madrid.es"/>
<meta property="article:author" content="https://www.facebook.com/Ayuntamiento-de-Madrid-770904446353931"/>
<% if Setting['url'] %>
<meta property="article:publisher" content=Setting['url']/>
<% end %>
<% if Setting['facebook_handle'] %>
<meta property="article:author" content="https://www.facebook.com/#{Setting['facebook_handle']}"/>
<% end %>
<meta property="og:type" content="article"/>
<meta id="ogurl" property="og:url" content="<%= social_url %>"/>
<meta id="ogimage" property="og:image" content="<%= image_url '/social-media-icon.png' %>"/>
<meta property="og:site_name" content="Madrid Participación"/>
<meta property="og:site_name" content="<%= Setting['org_name'] %>"/>
<meta id="ogdescription" property="og:description" content="<%= social_description %>"/>
<meta property="fb:app_id" content="1662598980652932"/>

View File

@@ -184,7 +184,6 @@ en:
administration: Administration
debates: Debates
external_link_blog: Blog
external_link_blog_url: "/blog"
external_link_opendata: Open data
external_link_opendata_url: http://datos.madrid.es
external_link_transparency: Transparency
@@ -204,7 +203,6 @@ en:
open_city_title: Love the city, and it will become a city you love.
open_data: Open data
open_gov: Open government
participation_html: Madrid Decide
proposals: Proposals
see_all: See proposals
spending_proposals: Spending proposals

View File

@@ -184,7 +184,6 @@ es:
administration: Administrar
debates: Debates
external_link_blog: Blog
external_link_blog_url: "/blog"
external_link_opendata: Datos abiertos
external_link_opendata_url: http://datos.madrid.es
external_link_transparency: Transparencia
@@ -204,7 +203,6 @@ es:
open_city_title: La ciudad que quieres será la ciudad que quieras.
open_data: Datos abiertos
open_gov: Gobierno %{open}
participation_html: Madrid Decide
proposals: Propuestas
see_all: Ver propuestas
spending_proposals: Presupuestos ciudadanos

View File

@@ -1,3 +1,4 @@
# coding: utf-8
# Default admin user (change password after first deploy to a server!)
if Administrator.count == 0 && !Rails.env.test?
admin = User.create!(username: 'admin', email: 'admin@madrid.es', password: '12345678', password_confirmation: '12345678', confirmed_at: Time.now, terms_of_service: "1")
@@ -6,30 +7,45 @@ end
# Names for the moderation console, as a hint for moderators
# to know better how to assign users with official positions
Setting.create(key: 'official_level_1_name', value: 'Empleados públicos')
Setting.create(key: 'official_level_2_name', value: 'Organización Municipal')
Setting.create(key: 'official_level_3_name', value: 'Directores generales')
Setting.create(key: 'official_level_4_name', value: 'Concejales')
Setting.create(key: 'official_level_5_name', value: 'Alcaldesa')
Setting["official_level_1_name"] = "Empleados públicos"
Setting["official_level_2_name"] = "Organización Municipal"
Setting["official_level_3_name"] = "Directores generales"
Setting["official_level_4_name"] = "Concejales"
Setting["official_level_5_name"] = "Alcaldesa"
# Max percentage of allowed anonymous votes on a debate
Setting.create(key: 'max_ratio_anon_votes_on_debates', value: '50')
Setting["max_ratio_anon_votes_on_debates"] = 50
# Max votes where a debate is still editable
Setting.create(key: 'max_votes_for_debate_edit', value: '1000')
Setting["max_votes_for_debate_edit"] = 1000
# Max votes where a proposal is still editable
Setting.create(key: 'max_votes_for_proposal_edit', value: '1000')
Setting["max_votes_for_proposal_edit"] = 1000
# Prefix for the Proposal codes
Setting.create(key: 'proposal_code_prefix', value: 'MAD')
Setting["proposal_code_prefix"] = 'MAD'
# Number of votes needed for proposal success
Setting.create(key: 'votes_for_proposal_success', value: '53726')
Setting["votes_for_proposal_success"] = 53726
# Users with this email domain will automatically be marked as level 1 officials
# Emails under the domain's subdomains will also be included
Setting.create(key: 'email_domain_for_officials', value: '')
Setting["email_domain_for_officials"] = ''
# Code to be included at the top (header) of every page (useful for tracking)
Setting.create(key: 'per_page_code', value: '')
Setting['per_page_code'] = ''
# Social settings
Setting["twitter_handle"] = nil
Setting["facebook_handle"] = nil
Setting["youtube_handle"] = nil
Setting["blog_url"] = nil
# Public-facing URL of the app.
Setting["url"] = "http://example.com"
# Consul installation's organization name
Setting["org_name"] = "Consul"
# Consul installation place name (City, Country...)
Setting["place_name"] = "Consul-land"

View File

@@ -7,7 +7,7 @@ namespace :users do
desc "Assigns official level to users with the officials' email domain"
task check_for_official_emails: :environment do
domain = Setting.value_for 'email_domain_for_officials'
domain = Setting['email_domain_for_officials']
# We end the task if there is no email domain configured
if !domain.blank?
@@ -15,7 +15,7 @@ namespace :users do
# The real check will be done by check_if_official_email, however.
User.where('official_level = 0 and email like ?', "%#{domain}").find_each do |user|
if user.has_official_email?
user.add_official_position! (Setting.value_for 'official_level_1_name'), 1
user.add_official_position! (Setting['official_level_1_name']), 1
puts "#{user.username} (#{user.email}) is now a level-1 official."
end
end

View File

@@ -24,7 +24,7 @@ describe DebatesController do
describe "Vote with too many anonymous votes" do
it 'should allow vote if user is allowed' do
Setting.find_by(key: "max_ratio_anon_votes_on_debates").update(value: 100)
Setting["max_ratio_anon_votes_on_debates"] = 100
debate = create(:debate)
sign_in create(:user)
@@ -34,7 +34,7 @@ describe DebatesController do
end
it 'should not allow vote if user is not allowed' do
Setting.find_by(key: "max_ratio_anon_votes_on_debates").update(value: 0)
Setting["max_ratio_anon_votes_on_debates"] = 0
debate = create(:debate, cached_votes_total: 1000)
sign_in create(:user)

View File

@@ -1,3 +1,4 @@
# coding: utf-8
require 'rails_helper'
feature 'Debates' do
@@ -255,7 +256,7 @@ feature 'Debates' do
scenario 'Update should not be posible if debate is not editable' do
debate = create(:debate)
Setting.find_by(key: "max_votes_for_debate_edit").update(value: 2)
Setting["max_votes_for_debate_edit"] = 2
3.times { create(:vote, votable: debate) }
expect(debate).to_not be_editable

View File

@@ -1,3 +1,4 @@
# coding: utf-8
require 'rails_helper'
feature 'Proposals' do
@@ -342,7 +343,7 @@ feature 'Proposals' do
scenario 'Update should not be posible if proposal is not editable' do
proposal = create(:proposal)
Setting.find_by(key: "max_votes_for_proposal_edit").update(value: 10)
Setting["max_votes_for_proposal_edit"] = 10
11.times { create(:vote, votable: proposal) }
expect(proposal).to_not be_editable

View File

@@ -304,7 +304,7 @@ feature 'Votes' do
user = create(:user)
debate = create(:debate)
Setting.find_by(key: "max_ratio_anon_votes_on_debates").update(value: 50)
Setting["max_ratio_anon_votes_on_debates"] = 50
debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)
login_as(user)

View File

@@ -1,3 +1,4 @@
# coding: utf-8
require 'rails_helper'
describe Debate do
@@ -82,7 +83,7 @@ describe Debate do
describe "#editable?" do
let(:debate) { create(:debate) }
before(:each) { Setting.find_by(key: "max_votes_for_debate_edit").update(value: 3) }
before(:each) { Setting["max_votes_for_debate_edit"] = 3 }
it "should be true if debate has no votes yet" do
expect(debate.total_votes).to eq(0)
@@ -104,7 +105,7 @@ describe Debate do
describe "#editable_by?" do
let(:debate) { create(:debate) }
before(:each) { Setting.find_by(key: "max_votes_for_debate_edit").update(value: 1) }
before(:each) { Setting["max_votes_for_debate_edit"] = 1 }
it "should be true if user is the author and debate is editable" do
expect(debate.editable_by?(debate.author)).to be true
@@ -124,7 +125,7 @@ describe Debate do
let(:debate) { create(:debate) }
before(:each) do
Setting.find_by(key: "max_ratio_anon_votes_on_debates").update(value: 50)
Setting["max_ratio_anon_votes_on_debates"] = 50
end
it "should be true for level two verified users" do
@@ -160,7 +161,7 @@ describe Debate do
let(:debate) { create(:debate) }
before(:each) do
Setting.find_by(key: "max_ratio_anon_votes_on_debates").update(value: 50)
Setting["max_ratio_anon_votes_on_debates"] = 50
end
describe "from level two verified users" do

View File

@@ -1,3 +1,4 @@
# coding: utf-8
require 'rails_helper'
describe Proposal do
@@ -134,14 +135,14 @@ describe Proposal do
end
it "should have a code" do
Setting.find_by(key: "proposal_code_prefix").update(value: "TEST")
Setting["proposal_code_prefix"] = "TEST"
proposal = create(:proposal)
expect(proposal.code).to eq "TEST-#{proposal.created_at.strftime('%Y-%m')}-#{proposal.id}"
end
describe "#editable?" do
let(:proposal) { create(:proposal) }
before(:each) {Setting.find_by(key: "max_votes_for_proposal_edit").update(value: 5)}
before(:each) {Setting["max_votes_for_proposal_edit"] = 5}
it "should be true if proposal has no votes yet" do
expect(proposal.total_votes).to eq(0)

View File

@@ -1,15 +1,19 @@
require 'rails_helper'
describe Setting do
it "should be accesible by key" do
create(:setting, key: "Important Setting", value: "42")
expect(Setting.value_for("Important Setting")).to eq("42")
before do
Setting["official_level_1_name"] = 'Stormtrooper'
end
it "should be nil if key does not exist" do
expect(Setting.value_for("Undefined key")).to be_nil
it "should return the overriden setting" do
expect(Setting['official_level_1_name']).to eq('Stormtrooper')
end
it "should should return nil" do
expect(Setting['undefined_key']).to eq(nil)
end
it "should persist a setting on the db" do
expect(Setting.where(key: 'official_level_1_name', value: 'Stormtrooper')).to exist
end
end

View File

@@ -250,7 +250,7 @@ describe User do
it "checks if the mail address has the officials domain" do
# We will use empleados.madrid.es as the officials' domain
# Subdomains are also accepted
Setting.find_by(key: 'email_domain_for_officials').update(value: 'officials.madrid.es')
Setting['email_domain_for_officials'] = 'officials.madrid.es'
user1 = create(:user, email: "john@officials.madrid.es", confirmed_at: Time.now)
user2 = create(:user, email: "john@yes.officials.madrid.es", confirmed_at: Time.now)