From 1f28e97c2e5929a85150dddcfe018fc16ceb88ad Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 11 Sep 2015 13:04:43 +0200 Subject: [PATCH 01/11] filters reset to page 1. Fixes #445 --- app/views/debates/index.html.erb | 2 +- app/views/shared/_filter_subnav.html.erb | 2 +- spec/features/debates_spec.rb | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index f0db765d2..c0c78ade4 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -30,7 +30,7 @@ <% @valid_orders.each do |order| %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 98e326322..98afaeb4f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/es.yml b/config/locales/es.yml index 9d968eb59..6becb32f2 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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 From 8bf71e818b1daf690e9f296dde88b57edc359ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 11 Sep 2015 14:39:43 +0200 Subject: [PATCH 03/11] adds verification status methods to user --- lib/verification.rb | 12 ++++++++++++ spec/models/user_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/lib/verification.rb b/lib/verification.rb index 1e2f7be81..67b0f4422 100644 --- a/lib/verification.rb +++ b/lib/verification.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 801702cae..e8e710dd0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 From bc86d813025621d39e0c4406bc26fb9db0bf1458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Fri, 11 Sep 2015 14:40:42 +0200 Subject: [PATCH 04/11] adds verification controller --- app/controllers/verification_controller.rb | 31 ++++++++++++++++++++++ config/locales/verification.en.yml | 5 +++- config/locales/verification.es.yml | 3 +++ config/routes.rb | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/controllers/verification_controller.rb diff --git a/app/controllers/verification_controller.rb b/app/controllers/verification_controller.rb new file mode 100644 index 000000000..6d1945af4 --- /dev/null +++ b/app/controllers/verification_controller.rb @@ -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 \ No newline at end of file diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml index a333f78d7..267138b5b 100644 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -93,4 +93,7 @@ en: phone_title: "Phones" use_another_phone: "Use another phone" form: - submit_button: "Send code" \ No newline at end of file + 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!" diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml index 6c86abcfc..fc7bd884b 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -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" diff --git a/config/routes.rb b/config/routes.rb index aa596fc25..e434d71e8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] From 66c2813664bf0bf6d1db7f68653cf727f6b67924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 11 Sep 2015 14:41:12 +0200 Subject: [PATCH 05/11] adds specs --- .../verification/verification_path_spec.rb | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 spec/features/verification/verification_path_spec.rb diff --git a/spec/features/verification/verification_path_spec.rb b/spec/features/verification/verification_path_spec.rb new file mode 100644 index 000000000..dc9f244a1 --- /dev/null +++ b/spec/features/verification/verification_path_spec.rb @@ -0,0 +1,77 @@ +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 +end \ No newline at end of file From eabcbb3ef789fb6adf9d2c3252633fdfaa0638c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 11 Sep 2015 14:41:27 +0200 Subject: [PATCH 06/11] fixes I18n string --- config/locales/es.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/es.yml b/config/locales/es.yml index 9d968eb59..e10386bac 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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 tu email está confirmada pero no hemos verificado tus datos todavía." + instructions_2_html: "Hemos detectado que tu dirección de email está confirmada pero no hemos verificado tus datos todavía." instructions_3_html: "Sin verificar tus datos el acceso que tienes es limitado. 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)" From eb276b917ae07b1420e53771571a27ba5fb21ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 11 Sep 2015 14:41:51 +0200 Subject: [PATCH 07/11] changes link in account page to verification path --- app/views/account/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 413a0e892..d580052e2 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -10,9 +10,9 @@ <%= t("account.show.verified_account") %>

<% 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 %> From 58a780bac5554a70de8d2624e57e91105627f745 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 11 Sep 2015 16:31:24 +0200 Subject: [PATCH 08/11] reverts postgres extension until permissions enabled at server level --- app/models/debate.rb | 2 +- db/migrate/20150910185110_add_unaccent_extension.rb | 9 --------- db/schema.rb | 4 +--- spec/features/debates_spec.rb | 4 ++-- 4 files changed, 4 insertions(+), 15 deletions(-) delete mode 100644 db/migrate/20150910185110_add_unaccent_extension.rb diff --git a/app/models/debate.rb b/app/models/debate.rb index c30bc7b8d..f1e9a621e 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -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? diff --git a/db/migrate/20150910185110_add_unaccent_extension.rb b/db/migrate/20150910185110_add_unaccent_extension.rb deleted file mode 100644 index d23af95d0..000000000 --- a/db/migrate/20150910185110_add_unaccent_extension.rb +++ /dev/null @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 274192ccb..fde03fe30 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index bcddab7a4..edb5c2725 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -439,10 +439,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 From 129666860699947f89981a1e5050be867c86a142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 11 Sep 2015 16:44:00 +0200 Subject: [PATCH 09/11] changes links to verification process --- app/views/debates/_votes.html.erb | 2 +- app/views/welcome/welcome.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/debates/_votes.html.erb b/app/views/debates/_votes.html.erb index c5704b34a..5f38b1e7a 100644 --- a/app/views/debates/_votes.html.erb +++ b/app/views/debates/_votes.html.erb @@ -31,7 +31,7 @@ <% elsif !user_signed_in? %> diff --git a/app/views/welcome/welcome.html.erb b/app/views/welcome/welcome.html.erb index fa49f9218..965edb795 100644 --- a/app/views/welcome/welcome.html.erb +++ b/app/views/welcome/welcome.html.erb @@ -4,7 +4,7 @@

<%= t("welcome.welcome.instructions_3_html") %>

<%= 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" %>

<%= link_to t("welcome.welcome.go_to_index"), From f517d7f410937e6b1f4c2b16b70ad88fa4f94242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 11 Sep 2015 16:44:52 +0200 Subject: [PATCH 10/11] adds before action for verified users --- app/controllers/application_controller.rb | 4 ++++ app/controllers/verification/email_controller.rb | 1 + app/controllers/verification/letter_controller.rb | 1 + .../verification/residence_controller.rb | 1 + app/controllers/verification/sms_controller.rb | 1 + .../verification/verified_user_controller.rb | 1 + .../verification/verification_path_spec.rb | 14 ++++++++++++++ 7 files changed, 23 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f71ebf723..aa6da3a80 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/verification/email_controller.rb b/app/controllers/verification/email_controller.rb index cb7542c80..017269095 100644 --- a/app/controllers/verification/email_controller.rb +++ b/app/controllers/verification/email_controller.rb @@ -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 diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index 15d408a5f..e1e23903b 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -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 diff --git a/app/controllers/verification/residence_controller.rb b/app/controllers/verification/residence_controller.rb index df24454e6..f5a826058 100644 --- a/app/controllers/verification/residence_controller.rb +++ b/app/controllers/verification/residence_controller.rb @@ -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 diff --git a/app/controllers/verification/sms_controller.rb b/app/controllers/verification/sms_controller.rb index 87604f726..09e4840a7 100644 --- a/app/controllers/verification/sms_controller.rb +++ b/app/controllers/verification/sms_controller.rb @@ -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 diff --git a/app/controllers/verification/verified_user_controller.rb b/app/controllers/verification/verified_user_controller.rb index bf2bc65fb..6964a2bd5 100644 --- a/app/controllers/verification/verified_user_controller.rb +++ b/app/controllers/verification/verified_user_controller.rb @@ -1,5 +1,6 @@ class Verification::VerifiedUserController < ApplicationController before_action :authenticate_user! + before_action :verify_verified! skip_authorization_check def show diff --git a/spec/features/verification/verification_path_spec.rb b/spec/features/verification/verification_path_spec.rb index dc9f244a1..2967f5e2f 100644 --- a/spec/features/verification/verification_path_spec.rb +++ b/spec/features/verification/verification_path_spec.rb @@ -74,4 +74,18 @@ feature 'Verification path' do 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 \ No newline at end of file From ea8c7e25cd258267e7eadea02406ea1d17396b29 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 11 Sep 2015 17:05:38 +0200 Subject: [PATCH 11/11] updates sms text --- lib/sms_api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sms_api.rb b/lib/sms_api.rb index 9192f2178..e3a7c6ff2 100644 --- a/lib/sms_api.rb +++ b/lib/sms_api.rb @@ -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