Merge branch 'master' into whenever-355

This commit is contained in:
kikito
2015-09-11 17:28:41 +02:00
28 changed files with 255 additions and 50 deletions

View File

@@ -305,7 +305,7 @@
.panel {
border-radius: 0;
box-shadow: 0px 1px 3px 0 $border;
margin-bottom: rem-calc(12);
margin-bottom: rem-calc(4);
min-height: rem-calc(192);
padding-top: rem-calc(12);

View File

@@ -259,7 +259,7 @@ h6 {
.footer {
background: #DEE0E2;
border-top: rem-calc(10) solid $brand;
border-top: rem-calc(6) solid $brand;
}
// 04. Header
@@ -330,8 +330,14 @@ header {
}
.icon-external {
color: #D01A6C;
font-size: rem-calc(12);
opacity: .5;
@media (min-width: $small-breakpoint) {
position: absolute;
right: -18px;
top: 3px;
}
}
.selected {
@@ -398,6 +404,7 @@ header {
color: white;
height: rem-calc(48);
max-width: 1170px !important;
padding: 0 rem-calc(12);
@media (min-width: $small-breakpoint) {
height: rem-calc(96);
@@ -543,9 +550,11 @@ header {
li:not(.has-form) a:not(.button) {
background: none;
color: white;
padding: 0 rem-calc(6);
@media (min-width: $small-breakpoint) {
line-height: $line-height*4;
padding: 0 rem-calc(12);
}
&:hover {
@@ -569,6 +578,10 @@ header {
color: white;
font-size: rem-calc(14);
.row {
padding: 0 rem-calc(12);
}
a {
color: white;
@@ -725,7 +738,7 @@ footer {
color: white;
&.info {
background: $brand;
background: rgba(0,0,0,.5);
}
}
@@ -1045,11 +1058,7 @@ img.initialjs-avatar {
h2 {
display: inline-block;
font-size: rem-calc(24);
margin: rem-calc(24) 0 rem-calc(12);
@media (min-width: $small-breakpoint) {
margin: rem-calc(24) 0;
}
margin-left: rem-calc(-17);
}
select {
@@ -1061,8 +1070,12 @@ img.initialjs-avatar {
padding: rem-calc(12);
width: auto;
@media (max-width: $small) {
margin-left: rem-calc(-17);
}
@media (min-width: $small-breakpoint) {
margin: 0 rem-calc(6) rem-calc(24);
margin: 0 0 rem-calc(24) rem-calc(12);
}
optgroup {
@@ -1077,6 +1090,18 @@ img.initialjs-avatar {
}
}
}
.debates-order {
text-align: left;
@media (min-width: $small-breakpoint) {
text-align: right;
}
select {
margin-left: 0;
}
}
}
.search-results {

View File

@@ -96,4 +96,8 @@ class ApplicationController < ActionController::Base
redirect_to new_residence_path, alert: t('verification.residence.alert.unconfirmed_residency')
end
end
def verify_verified!
redirect_to(account_path, notice: t('verification.redirect_notices.already_verified')) if current_user.level_three_verified?
end
end

View File

@@ -1,5 +1,6 @@
class Verification::EmailController < ApplicationController
before_action :authenticate_user!
before_action :verify_verified!
before_action :set_verified_user, only: :create
skip_authorization_check

View File

@@ -2,6 +2,7 @@ class Verification::LetterController < ApplicationController
before_action :authenticate_user!
before_action :verify_resident!
before_action :verify_phone!
before_action :verify_verified!
before_action :verify_lock
skip_authorization_check

View File

@@ -1,5 +1,6 @@
class Verification::ResidenceController < ApplicationController
before_action :authenticate_user!
before_action :verify_verified!
before_action :verify_lock, only: [:new, :create]
skip_authorization_check

View File

@@ -1,6 +1,7 @@
class Verification::SmsController < ApplicationController
before_action :authenticate_user!
before_action :verify_resident!
before_action :verify_verified!
before_action :verify_lock, only: [:new, :create]
before_action :set_phone, only: :create

View File

@@ -1,5 +1,6 @@
class Verification::VerifiedUserController < ApplicationController
before_action :authenticate_user!
before_action :verify_verified!
skip_authorization_check
def show

View File

@@ -0,0 +1,31 @@
class VerificationController < ApplicationController
before_action :authenticate_user!
before_action :verify_lock
skip_authorization_check
def show
redirect_to next_step_path[:path], notice: next_step_path[:notice]
end
private
def next_step_path(user = current_user)
if user.level_three_verified?
{ path: account_path, notice: t('verification.redirect_notices.already_verified') }
elsif user.verification_letter_sent?
{ path: edit_letter_path }
elsif user.level_two_verified?
{ path: new_letter_path }
elsif user.verification_sms_sent?
{ path: edit_sms_path }
elsif user.verification_email_sent?
{ path: verified_user_path, notice: t('verification.redirect_notices.email_already_sent') }
elsif user.residence_verified?
{ path: verified_user_path }
else
{ path: new_residence_path }
end
end
end

View File

@@ -138,7 +138,7 @@ class Debate < ActiveRecord::Base
end
def self.search(terms)
terms.present? ? where("unaccent(title) ILIKE unaccent(?) OR unaccent(description) ILIKE unaccent(?)", "%#{terms}%", "%#{terms}%") : none
terms.present? ? where("title ILIKE ? OR description ILIKE ?", "%#{terms}%", "%#{terms}%") : none
end
def conflictive?

View File

@@ -10,9 +10,9 @@
<%= t("account.show.verified_account") %>
</p>
<% elsif current_user.level_two_verified? %>
<%= link_to t("account.show.finish_verification"), new_letter_path, class: "button radius small success right" %>
<%= link_to t("account.show.finish_verification"), verification_path, class: "button radius small success right" %>
<% else %>
<%= link_to t("account.show.verify_my_account"), new_residence_path, class: "button radius small success right" %>
<%= link_to t("account.show.verify_my_account"), verification_path, class: "button radius small success right" %>
<% end %>
</span>
</div>

View File

@@ -1,5 +1,5 @@
<% cache [locale_and_user_status, debate, @debate_votes[debate.id]] do %>
<div id="<%= dom_id(debate) %>" class="debate">
<div id="<%= dom_id(debate) %>" class="debate clear">
<div class="panel">
<div class="row">

View File

@@ -31,7 +31,7 @@
<div class="anonymous-votes" style='display:none'>
<p>
<%= t("votes.anonymous",
verify_account: link_to(t("votes.verify_account"), new_residence_path )).html_safe %>
verify_account: link_to(t("votes.verify_account"), verification_path )).html_safe %>
</p>
</div>
<% elsif !user_signed_in? %>

View File

@@ -3,34 +3,35 @@
<div class="wrap row">
<div id="debates" class="debates-list small-12 medium-9 column js-order-<%= @order.dasherize %>">
<div class="filters">
<div class="small-12 medium-8 column">
<div class="small-12 medium-7 column">
<% if @search_terms %>
<h2>
<h2 class="margin-top">
<%= page_entries_info @debates %>
<%= t("debates.index.search_results", count: @debates.size, search_term: @search_terms) %>
</h2>
<% elsif @tag_filter %>
<h2>
<h2 class="margin-top">
<%= page_entries_info @debates %>
<%= t("debates.index.filter_topic", count: @debates.size, topic: @tag_filter) %>
</h2>
<% end %>
</div>
<div class="inline-block <%= 'right' if (@tag_filter || @search_terms) %>">
<% if @tag_filter || @search_terms %>
<h6 class="inline-block">
<%= t("debates.index.select_order") %>
</h6>
<% else %>
<h2 class="inline-block">
<%= t("debates.index.select_order_long") %>
</h2>
<% end %>
<% if @tag_filter || @search_terms %>
<div class="small-12 medium-5 margin-top inline-block debates-order">
<h6 class="inline-block">
<%= t("debates.index.select_order") %>
</h6>
<% else %>
<div class="small-12 column margin-top inline-block">
<h2 class="inline-block">
<%= t("debates.index.select_order_long") %>
</h2>
<% end %>
<form class="inline-block">
<select class="js-location-changer" name="order-selector">
<% @valid_orders.each do |order| %>
<option <%= 'selected' if order == @order %>
value='<%= current_path_with_query_params(order: order) %>'>
value='<%= current_path_with_query_params(order: order, page: 1) %>'>
<%= t("debates.index.orders.#{order}") %>
</option>
<% end %>

View File

@@ -11,7 +11,7 @@
<dd class="active"><%= t("#{i18n_namespace}.filters.#{filter}") %></dd>
<% else %>
<dd><%= link_to t("#{i18n_namespace}.filters.#{filter}"),
current_path_with_query_params(filter: filter) %></dd>
current_path_with_query_params(filter: filter, page: 1) %></dd>
<% end %>
<% end %>
</dl>

View File

@@ -4,7 +4,7 @@
<p><%= t("welcome.welcome.instructions_3_html") %></p>
<p>
<%= link_to t("welcome.welcome.verify_account"),
new_residence_path, class: "button large success radius margin-top expand" %>
verification_path, class: "button large success radius margin-top expand" %>
</p>
<p class="text-center">
<%= link_to t("welcome.welcome.go_to_index"),

View File

@@ -189,7 +189,7 @@ en:
debate: "secret code did not match with the image"
shared:
tags_cloud:
tags: Topics
tags: Trend
flag: Flag as inappropriate
unflag: Undo flag
collective: Collective

View File

@@ -189,7 +189,7 @@ es:
debate: "el código secreto no coincide con la imagen"
shared:
tags_cloud:
tags: Temas
tags: Tendencias
flag: Denunciar como inapropiado
unflag: Deshacer denuncia
collective: Colectivo
@@ -211,7 +211,7 @@ es:
welcome:
title: Verificación de cuenta
instructions_1_html: "Bienvenido a la página de participación ciudadana"
instructions_2_html: "Hemos detectado que <b>tu email está confirmada pero no hemos verificado tus datos todavía</b>."
instructions_2_html: "Hemos detectado que <b>tu dirección de email está confirmada pero no hemos verificado tus datos todavía</b>."
instructions_3_html: "Sin verificar tus datos <b>el acceso que tienes es limitado</b>. Verificarlos ahora te permitirá, por ejemplo, apoyar propuestas ciudadanas."
verify_account: "Verificar mi cuenta"
go_to_index: "Quiero entrar como un usuario no verificado (acceso limitado)"

View File

@@ -93,4 +93,7 @@ en:
phone_title: "Phones"
use_another_phone: "Use another phone"
form:
submit_button: "Send code"
submit_button: "Send code"
redirect_notices:
email_already_sent: "We already sent you a confirmation email, if you have not received it you can try resend it here"
already_verified: "You are a verified user!"

View File

@@ -94,3 +94,6 @@ es:
use_another_phone: "Utilizar otro teléfono"
form:
submit_button: "Enviar código"
redirect_notices:
email_already_sent: "Ya te enviamos un email con un enlace de confirmación, si no lo encuentras puedes solicitar aquí que te lo reenviemos"
already_verified: "Tu cuenta ya está verificada"

View File

@@ -46,6 +46,7 @@ Rails.application.routes.draw do
end
resource :account, controller: "account", only: [:show, :update]
resource :verification, controller: "verification", only: [:show]
scope module: :verification do
resource :residence, controller: "residence", only: [:new, :create]

View File

@@ -1,9 +0,0 @@
class AddUnaccentExtension < ActiveRecord::Migration
def up
execute "CREATE EXTENSION IF NOT EXISTS unaccent"
end
def down
execute "DROP EXTENSION unaccent"
end
end

View File

@@ -11,11 +11,10 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150910185110) do
ActiveRecord::Schema.define(version: 20150910152734) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "unaccent"
create_table "addresses", force: :cascade do |t|
t.integer "user_id"
@@ -259,7 +258,6 @@ ActiveRecord::Schema.define(version: 20150910185110) do
t.datetime "letter_requested_at"
t.datetime "confirmed_hide_at"
t.string "letter_verification_code"
t.integer "letter_verification_tries", default: 0
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree

View File

@@ -25,7 +25,7 @@ class SMSApi
def request(phone, code)
{ autorizacion: authorization,
destinatarios: { destinatario: phone },
texto_mensaje: "Código de verificación: #{code}",
texto_mensaje: "Clave para verificarte: #{code}. Gobierno Abierto - Ayuntamiento de Madrid",
solicita_notificacion: "All" }
end

View File

@@ -1,5 +1,17 @@
module Verification
def verification_email_sent?
email_verification_token.present?
end
def verification_sms_sent?
unconfirmed_phone.present? && sms_confirmation_code.present?
end
def verification_letter_sent?
letter_requested_at.present? && letter_verification_code.present?
end
def residence_verified?
residence_verified_at.present?
end

View File

@@ -384,6 +384,7 @@ feature 'Debates' do
end
expect(current_url).to include('order=hot_score')
expect(current_url).to include('page=1')
end
scenario 'Debates are ordered by most commented', :js do
@@ -400,6 +401,7 @@ feature 'Debates' do
end
expect(current_url).to include('order=most_commented')
expect(current_url).to include('page=1')
end
scenario 'Debates are ordered by newest', :js do
@@ -416,6 +418,7 @@ feature 'Debates' do
end
expect(current_url).to include('order=created_at')
expect(current_url).to include('page=1')
end
scenario 'Debates are ordered randomly', :js do
@@ -432,6 +435,7 @@ feature 'Debates' do
debates_second_time = find("#debates.js-order-random").text
expect(debates_first_time).to_not eq(debates_second_time)
expect(current_url).to include('page=1')
end
end
@@ -439,10 +443,10 @@ feature 'Debates' do
debate1 = create(:debate, title: "Show me what you got")
debate2 = create(:debate, title: "Get Schwifty")
debate3 = create(:debate)
debate4 = create(:debate, description: "Schwíftÿ in here")
debate4 = create(:debate, description: "Schwifty in here")
visit debates_path
fill_in "search", with: "Schwìfty"
fill_in "search", with: "Schwifty"
click_button "Search"
within("#debates") do

View File

@@ -0,0 +1,91 @@
require 'rails_helper'
feature 'Verification path' do
scenario "User is verified" do
user = create(:user, verified_at: Time.now)
login_as(user)
visit verification_path
expect(current_path).to eq account_path
expect(page).to have_content 'You are a verified user!'
end
scenario "User requested a letter" do
user = create(:user, confirmed_phone: "623456789", residence_verified_at: Time.now,
letter_requested_at: Time.now, letter_verification_code: "666")
login_as(user)
visit verification_path
expect(current_path).to eq edit_letter_path
end
scenario "User is level two verified" do
user = create(:user, residence_verified_at: Time.now, confirmed_phone: "666666666")
login_as(user)
visit verification_path
expect(current_path).to eq new_letter_path
end
scenario "User received a verification sms" do
user = create(:user, residence_verified_at: Time.now, unconfirmed_phone: "666666666", sms_confirmation_code: "666")
login_as(user)
visit verification_path
expect(current_path).to eq edit_sms_path
end
scenario "User received verification email" do
user = create(:user, letter_requested_at: Time.now, letter_verification_code: "666")
login_as(user)
visit verification_path
verification_redirect = current_path
visit verified_user_path
expect(current_path).to eq verification_redirect
end
scenario "User has verified residence" do
user = create(:user, residence_verified_at: Time.now)
login_as(user)
visit verification_path
verification_redirect = current_path
visit verified_user_path
expect(current_path).to eq verification_redirect
end
scenario "User has not started verification process" do
user = create(:user)
login_as(user)
visit verification_path
expect(current_path).to eq new_residence_path
end
scenario "A verified user can not access verification pages" do
user = create(:user, verified_at: Time.now)
login_as(user)
verification_paths = [new_residence_path, verified_user_path, edit_sms_path, new_letter_path, edit_letter_path]
verification_paths.each do |step_path|
visit step_path
expect(current_path).to eq account_path
expect(page).to have_content 'You are a verified user!'
end
end
end

View File

@@ -304,6 +304,42 @@ describe User do
user = create(:user, verified_at: Time.now, confirmed_phone: "123456789", residence_verified_at: Time.now)
expect(user.unverified?).to eq(false)
end
it "verification_email_sent? is true only if user has email_verification_token" do
user = create(:user, email_verification_token: "xxxxxxx")
expect(user.verification_email_sent?).to eq(true)
user = create(:user, email_verification_token: nil)
expect(user.verification_email_sent?).to eq(false)
end
it "verification_sms_sent? is true only if user has unconfirmed_phone and sms_confirmation_code" do
user = create(:user, unconfirmed_phone: "666666666", sms_confirmation_code: "666")
expect(user.verification_sms_sent?).to eq(true)
user = create(:user, unconfirmed_phone: nil, sms_confirmation_code: "666")
expect(user.verification_sms_sent?).to eq(false)
user = create(:user, unconfirmed_phone: "666666666", sms_confirmation_code: nil)
expect(user.verification_sms_sent?).to eq(false)
user = create(:user, unconfirmed_phone: nil, sms_confirmation_code: nil)
expect(user.verification_sms_sent?).to eq(false)
end
it "verification_letter_sent? is true only if user has letter_requested_at and letter_verification_code" do
user = create(:user, letter_requested_at: Time.now, letter_verification_code: "666")
expect(user.verification_letter_sent?).to eq(true)
user = create(:user, letter_requested_at: nil, letter_verification_code: "666")
expect(user.verification_letter_sent?).to eq(false)
user = create(:user, letter_requested_at: Time.now, letter_verification_code: nil)
expect(user.verification_letter_sent?).to eq(false)
user = create(:user, letter_requested_at: nil, letter_verification_code: nil)
expect(user.verification_letter_sent?).to eq(false)
end
end
describe "cache" do