From bbce73f12a4e8271aa55e62bfc97372872ea6954 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 30 Sep 2015 20:53:02 +0200 Subject: [PATCH 01/43] Adds i18n entry: error.messages.user_not_found --- config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 67a805059..c71652799 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,8 @@ en: locale: English + errors: + messages: + user_not_found: "User not found" layouts: header: external_link_transparency: Transparency diff --git a/config/locales/es.yml b/config/locales/es.yml index ae1e57b0a..9280f83db 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,5 +1,8 @@ es: locale: "Español" + errors: + messages: + user_not_found: "No se encontró el usuario" layouts: header: external_link_transparency: Transparencia From c24eebed3ca9988a5fc6f0c02869c281bf5aed19 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 30 Sep 2015 20:53:36 +0200 Subject: [PATCH 02/43] Modifies the way dev_seeds verifies users Previously level 3 users did not have level 2 info --- db/dev_seeds.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 1a809d905..ab17701c5 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -50,9 +50,10 @@ end (1..40).each do |i| user = create_user("user#{i}@madrid.es") level = [1,2,3].sample - if level == 2 then - user.update(residence_verified_at: Time.now, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: Faker::Number.number(10) ) - elsif level == 3 then + if level >= 2 then + user.update(residence_verified_at: Time.now, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: Faker::Number.number(10), document_type: "1" ) + end + if level == 3 then user.update(verified_at: Time.now, document_number: Faker::Number.number(10) ) end end From b5a483087102f6e0e44f18eaa36cee7364083f08 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 30 Sep 2015 20:53:57 +0200 Subject: [PATCH 03/43] Adds User.by_document scope --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/user.rb b/app/models/user.rb index dd8c725be..b24354fa2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,6 +40,7 @@ class User < ActiveRecord::Base scope :organizations, -> { joins(:organization) } scope :officials, -> { where("official_level > 0") } scope :for_render, -> { includes(:organization) } + scope :by_document, -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) } def self.find_for_oauth(auth, signed_in_resource = nil) # Get the identity and user if they exist From 78d6f5e53a5b6e26ad9545aebab54d5c17116752 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 30 Sep 2015 21:00:42 +0200 Subject: [PATCH 04/43] Adds a half-done implementation of on_site_verifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Things missing: * Implement models/verification/on_site#send_verification_email * Implement the “create new user” path * Tests --- .../on_site_verifications_controller.rb | 55 +++++++++++++++++++ .../user_verification_controller.rb | 25 +++++++++ app/models/verification/on_site.rb | 53 ++++++++++++++++++ .../already_verified.html.erb | 25 +++++++++ .../on_site_verifications/email_sent.html.erb | 28 ++++++++++ .../existing_user.html.erb | 31 +++++++++++ .../on_site_verifications/index.html.erb | 22 ++++++++ .../invalid_document.html.erb | 27 +++++++++ .../on_site_verifications/new.html.erb | 29 ++++++++++ .../on_site_verifications/verified.html.erb | 25 +++++++++ config/locales/management.es.yml | 41 ++++++++++++++ config/routes.rb | 7 +++ 12 files changed, 368 insertions(+) create mode 100644 app/controllers/management/on_site_verifications_controller.rb create mode 100644 app/controllers/management/user_verification_controller.rb create mode 100644 app/models/verification/on_site.rb create mode 100644 app/views/management/on_site_verifications/already_verified.html.erb create mode 100644 app/views/management/on_site_verifications/email_sent.html.erb create mode 100644 app/views/management/on_site_verifications/existing_user.html.erb create mode 100644 app/views/management/on_site_verifications/index.html.erb create mode 100644 app/views/management/on_site_verifications/invalid_document.html.erb create mode 100644 app/views/management/on_site_verifications/new.html.erb create mode 100644 app/views/management/on_site_verifications/verified.html.erb create mode 100644 config/locales/management.es.yml diff --git a/app/controllers/management/on_site_verifications_controller.rb b/app/controllers/management/on_site_verifications_controller.rb new file mode 100644 index 000000000..f71218829 --- /dev/null +++ b/app/controllers/management/on_site_verifications_controller.rb @@ -0,0 +1,55 @@ +class Management::OnSiteVerificationsController < ActionController::Base + + def index + @verification_on_site = Verification::OnSite.new() + end + + def check + @verification_on_site = Verification::OnSite.new(verification_on_site_params) + + if @verification_on_site.valid? + if @verification_on_site.verified? + render :verified + elsif @verification_on_site.user? + render :new + elsif @verification_on_site.in_census? + render :existing_user + else + render :invalid_document + end + else + render :index + end + end + + def create + @verification_on_site = Verification::OnSite.new(verification_on_site_params) + @verification_on_site.verify + render :verified + end + + def send_email + @verification_on_site = Verification::OnSite.new(verification_on_site_with_email_params) + @verification_on_site.should_validate_email = true + + if @verification_on_site.valid? + @verification_on_site.send_verification_email + render :email_sent + else + render :existing_user + end + end + + private + + def verification_on_site_params + params.require(:verification_on_site).permit(:document_type, :document_number) + end + + def verification_on_site_with_email_params + params.require(:verification_on_site).permit(:document_type, :document_number, :email) + end +end + + + diff --git a/app/controllers/management/user_verification_controller.rb b/app/controllers/management/user_verification_controller.rb new file mode 100644 index 000000000..4693be1c8 --- /dev/null +++ b/app/controllers/management/user_verification_controller.rb @@ -0,0 +1,25 @@ +class Management::OnSiteVerificationController < ActionController::Base + + def new + + end + + def create + + verification = Verification::OnSite() + + end + + + def invalid_document + + end + + def user_exists + + end + + def + + + end diff --git a/app/models/verification/on_site.rb b/app/models/verification/on_site.rb new file mode 100644 index 000000000..8eaab0013 --- /dev/null +++ b/app/models/verification/on_site.rb @@ -0,0 +1,53 @@ +class Verification::OnSite + include ActiveModel::Model + + attr_accessor :document_type + attr_accessor :document_number + attr_accessor :email + attr_accessor :should_validate_email + + validates :document_type, :document_number, presence: true + validate :validate_email, if: :should_validate_email + + def user + @user ||= + User.where(email: email).first || + User.by_document(document_type, document_number).first + end + + def user? + user.present? + end + + def in_census? + CensusApi.new.call(document_type, document_number).valid? + end + + def verified? + user? && user.level_three_verified? + end + + def verify + user.update(verified_at: Time.now) if user? + end + + def send_verification_email + # FIXME + # Should assign document_number here? + # Should send verification email here? + end + + def validate_email + if email.blank? + errors.add(:email, I18n.t('errors.messages.blank')) + elsif email !~ Devise.email_regexp + errors.add(:email, I18n.t('errors.messages.invalid')) + elsif !user? + errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user? + end + end + +end + + + diff --git a/app/views/management/on_site_verifications/already_verified.html.erb b/app/views/management/on_site_verifications/already_verified.html.erb new file mode 100644 index 000000000..60b81566c --- /dev/null +++ b/app/views/management/on_site_verifications/already_verified.html.erb @@ -0,0 +1,25 @@ + + +
+ <%= t("management.users.already_verified") %> +
+ +
+ +

<%= t("management.users.census_success_info") %>

+ +
    +
  • <%= t("management.users.user_permission_debates") %>
  • +
  • <%= t("management.users.user_permission_proposal") %>
  • +
  • <%= t("management.users.user_permission_support_proposal") %>
  • +
  • <%= t("management.users.user_permission_votes") %>
  • +
+ +
+ +<%= t("management.print_info") %> diff --git a/app/views/management/on_site_verifications/email_sent.html.erb b/app/views/management/on_site_verifications/email_sent.html.erb new file mode 100644 index 000000000..721d81524 --- /dev/null +++ b/app/views/management/on_site_verifications/email_sent.html.erb @@ -0,0 +1,28 @@ + + + + +
+ <%= t("management.users.email_sent") %> +
+ +
+ +

<%= t("management.users.census_success_info") %>

+ +
    +
  • <%= t("management.users.user_permission_debates") %>
  • +
  • <%= t("management.users.user_permission_proposal") %>
  • +
  • <%= t("management.users.user_permission_support_proposal") %>
  • +
  • <%= t("management.users.user_permission_votes") %>
  • +
+ +
+ +<%= t("management.print_info") %> + diff --git a/app/views/management/on_site_verifications/existing_user.html.erb b/app/views/management/on_site_verifications/existing_user.html.erb new file mode 100644 index 000000000..ac271f07a --- /dev/null +++ b/app/views/management/on_site_verifications/existing_user.html.erb @@ -0,0 +1,31 @@ + + +
+ <%= t("management.users.census_success") %> +
+ +
    +
  • + <%= t("management.users.has_account") %> + +

    <%= t("management.users.has_account_note") %>

    + + <%= form_for @verification_on_site, url: send_email_management_on_site_verifications_path do |f| %> + <%= f.hidden_field :document_type %> + <%= f.hidden_field :document_number %> + <%= f.text_field :email, label: false, placeholder: t('management.users.has_account_placeholder') %> + <%= f.submit t("management.users.has_account_send_email"), class: "button success radius" %> + <% end %> +
  • + +
  • + <%= t("management.users.has_not_account") %> + +

    + <%= t("management.users.create_user") %> +

    +
  • +
diff --git a/app/views/management/on_site_verifications/index.html.erb b/app/views/management/on_site_verifications/index.html.erb new file mode 100644 index 000000000..e20d7573b --- /dev/null +++ b/app/views/management/on_site_verifications/index.html.erb @@ -0,0 +1,22 @@ +

<%= t("management.verification_on_sites.title") %>

+ +
+
+ <%= form_for @verification_on_site, url: check_management_on_site_verifications_path do |f| %> +
+ <%= f.select(:document_type, + [[humanize_document_type("1"), 1], + [humanize_document_type("2"), 2], + [humanize_document_type("3"), 3]], + label: t("management.document_type_label")) %> +
+
+ <%= f.text_field :document_number, + placeholder: t('management.document_number'), + label: t("management.document_number") + %> +
+ <%= f.submit t("management.check") %> + <% end %> +
+
diff --git a/app/views/management/on_site_verifications/invalid_document.html.erb b/app/views/management/on_site_verifications/invalid_document.html.erb new file mode 100644 index 000000000..c95d3c01e --- /dev/null +++ b/app/views/management/on_site_verifications/invalid_document.html.erb @@ -0,0 +1,27 @@ + + +
+ <%= t("management.users.census_error") %> +
+ +
+ +

<%= t("management.users.census_error_info") %>

+ +
    +
  • <%= t("management.users.user_permission_debates") %>
  • +
  • <%= t("management.users.user_permission_proposal") %>
  • +
  • <%= t("management.users.user_permission_support_proposal") %>
  • +
  • <%= t("management.users.user_permission_votes") %>
  • +
+ +

+ <%= t("management.users.has_not_account_html", + url: link_to(t("management.users.portal_url"), t("management.users.portal_url"), + target: "_blank")).html_safe %> +

+ +
diff --git a/app/views/management/on_site_verifications/new.html.erb b/app/views/management/on_site_verifications/new.html.erb new file mode 100644 index 000000000..cc7d6e914 --- /dev/null +++ b/app/views/management/on_site_verifications/new.html.erb @@ -0,0 +1,29 @@ + + +
+ <%= t("management.users.census_success_account") %> +
+ +
+ +

<%= t("management.users.census_success_info") %>

+ +
    +
  • <%= t("management.users.user_permission_debates") %>
  • +
  • <%= t("management.users.user_permission_proposal") %>
  • +
  • <%= t("management.users.user_permission_support_proposal") %>
  • +
  • <%= t("management.users.user_permission_votes") %>
  • +
+ + <%= form_for @verification_on_site, url: management_on_site_verifications_path do |f| %> + <%= f.hidden_field :document_type %> + <%= f.hidden_field :document_number %> + <%= f.submit t("management.users.verify"), class: "button success radius" %> + <% end %> + +
diff --git a/app/views/management/on_site_verifications/verified.html.erb b/app/views/management/on_site_verifications/verified.html.erb new file mode 100644 index 000000000..60b81566c --- /dev/null +++ b/app/views/management/on_site_verifications/verified.html.erb @@ -0,0 +1,25 @@ + + +
+ <%= t("management.users.already_verified") %> +
+ +
+ +

<%= t("management.users.census_success_info") %>

+ +
    +
  • <%= t("management.users.user_permission_debates") %>
  • +
  • <%= t("management.users.user_permission_proposal") %>
  • +
  • <%= t("management.users.user_permission_support_proposal") %>
  • +
  • <%= t("management.users.user_permission_votes") %>
  • +
+ +
+ +<%= t("management.print_info") %> diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml new file mode 100644 index 000000000..30a9515da --- /dev/null +++ b/config/locales/management.es.yml @@ -0,0 +1,41 @@ +es: + management: + print: "Imprimir" + print_info: "Imprimir esta información" + username_label: "Nombre de usuario" + email_label: "Email" + check: "Comprobar" + document_number: "Número de documento" + document_type_label: "Tipo de documento" + on_site_verifications: + title: "Gestionar usuario" + + users: + title: "Gestionar usuario" + census_error: "Este documento no está registrado en el Padrón Municipal de Madrid." + census_error_info: "Las personas no empadronadas en Madrid pueden participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" + census_success: "Este documento está en el registro del padrón municipal, pero todavía no tiene una cuenta de usuario asociada. Elige una de las opciones siguientes:" + census_success_info: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" + census_success_account: "Compruebe que los datos anteriores son correctos para proceder a verificar la cuenta completamente." + user_permission_debates: "Participar en debates" + user_permission_proposal: "Crear nuevas propuestas" + user_permission_support_proposal: "Apoyar propuestas" + user_permission_votes: "Participar en las votaciones finales" + has_not_account_html: "Para crear un usuario entre en %{url} y haga clic en la opción 'Registrarse' en la parte superior derecha de la pantalla." + portal_url: "http://decide.madrid.es" + already_verified: "Esta cuenta de usuario ya está verificada." + has_account: "Si la persona ya ha creado una cuenta de usuario en la web" + has_not_account: "Si la persona todavía no ha creado una cuenta de usuario en la web" + has_account_note: "Introduce el email con el que creó la cuenta:" + has_account_placeholder: "Introduce el email de registro" + has_account_send_email: "Enviar email de verificación" + email_sent: "Para terminar de verificar esta cuenta es necesario que haga clic en el enlace que le hemos enviado a la dirección de correo que figura arriba. Este paso es necesario para confirmar que dicha cuenta de usuario es suya." + create_user: "Crear nueva cuenta de usuario" + create_user_info: "Procedemos a crear un usuario con la siguiente información:" + create_user_submit: "Crear usuario" + create_user_success_html: + "Le hemos mandado un correo electrónico a la dirección de correo anterior para verificar que es suya. + Le recomendamos cambiar la contraseña en su primer uso. Para ello entre en %{url} con su usuario y contraseña, + acceda a la sección 'Mi cuenta' y haga clic en el botón 'Cambiar datos de acceso'" + verify: "Verificar usuario" + diff --git a/config/routes.rb b/config/routes.rb index 2103c0fce..f512a47f5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -165,6 +165,13 @@ Rails.application.routes.draw do namespace :management do + resources :on_site_verifications, only: [:index, :new, :create] do + collection do + post :check + post :send_email + end + end + end # Example of regular route: From 988304e3dfb5e6d02285c198bc42e90997564238 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 1 Oct 2015 14:17:11 +0200 Subject: [PATCH 05/43] Dashboard for management --- app/controllers/management/dashboard_controller.rb | 6 ++++++ config/routes.rb | 1 + 2 files changed, 7 insertions(+) create mode 100644 app/controllers/management/dashboard_controller.rb diff --git a/app/controllers/management/dashboard_controller.rb b/app/controllers/management/dashboard_controller.rb new file mode 100644 index 000000000..abb605341 --- /dev/null +++ b/app/controllers/management/dashboard_controller.rb @@ -0,0 +1,6 @@ +class Management::DashboardController < Management::BaseController + + def index + end + +end diff --git a/config/routes.rb b/config/routes.rb index f512a47f5..8c798ed49 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -164,6 +164,7 @@ Rails.application.routes.draw do end namespace :management do + root to: "dashboard#index" resources :on_site_verifications, only: [:index, :new, :create] do collection do From 4bb02ff564267004910755e1b18ef8dac20e0812 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 1 Oct 2015 14:18:11 +0200 Subject: [PATCH 06/43] Separate into two concerns: onsite verification + onsite verification emails --- .../on_site_verification_emails_controller.rb | 25 ++++++++++++++ .../on_site_verifications_controller.rb | 20 ++--------- app/models/verification/on_site.rb | 23 +------------ app/models/verification/on_site_email.rb | 34 +++++++++++++++++++ app/views/management/_menu.html.erb | 14 ++++++++ app/views/management/dashboard/index.html.erb | 3 ++ .../new.html.erb} | 9 ++--- .../sent.html.erb} | 10 +++--- .../on_site_verifications/index.html.erb | 2 +- config/locales/management.es.yml | 6 +++- config/routes.rb | 4 ++- 11 files changed, 98 insertions(+), 52 deletions(-) create mode 100644 app/controllers/management/on_site_verification_emails_controller.rb create mode 100644 app/models/verification/on_site_email.rb create mode 100644 app/views/management/_menu.html.erb create mode 100644 app/views/management/dashboard/index.html.erb rename app/views/management/{on_site_verifications/existing_user.html.erb => on_site_verification_emails/new.html.erb} (71%) rename app/views/management/{on_site_verifications/email_sent.html.erb => on_site_verification_emails/sent.html.erb} (67%) diff --git a/app/controllers/management/on_site_verification_emails_controller.rb b/app/controllers/management/on_site_verification_emails_controller.rb new file mode 100644 index 000000000..52fb8b279 --- /dev/null +++ b/app/controllers/management/on_site_verification_emails_controller.rb @@ -0,0 +1,25 @@ +class Management::OnSiteVerificationEmailsController < Management::BaseController + + def new + @verification_on_site_email = Verification::OnSiteEmail.new(verification_on_site_email_params) + end + + def create + @verification_on_site_email = Verification::OnSiteEmail.new(verification_on_site_email_params) + + if @verification_on_site_email.valid? + @verification_on_site_email.send_email + render :sent + else + render :new + end + end + + private + + def verification_on_site_email_params + params.require(:verification_on_site_email).permit(:document_type, :document_number, :email) + end + +end + diff --git a/app/controllers/management/on_site_verifications_controller.rb b/app/controllers/management/on_site_verifications_controller.rb index f71218829..46409c869 100644 --- a/app/controllers/management/on_site_verifications_controller.rb +++ b/app/controllers/management/on_site_verifications_controller.rb @@ -1,4 +1,4 @@ -class Management::OnSiteVerificationsController < ActionController::Base +class Management::OnSiteVerificationsController < Management::BaseController def index @verification_on_site = Verification::OnSite.new() @@ -13,7 +13,7 @@ class Management::OnSiteVerificationsController < ActionController::Base elsif @verification_on_site.user? render :new elsif @verification_on_site.in_census? - render :existing_user + redirect_to new_management_on_site_verification_email_path(verification_on_site_email: verification_on_site_params) else render :invalid_document end @@ -28,27 +28,13 @@ class Management::OnSiteVerificationsController < ActionController::Base render :verified end - def send_email - @verification_on_site = Verification::OnSite.new(verification_on_site_with_email_params) - @verification_on_site.should_validate_email = true - - if @verification_on_site.valid? - @verification_on_site.send_verification_email - render :email_sent - else - render :existing_user - end - end - private def verification_on_site_params params.require(:verification_on_site).permit(:document_type, :document_number) end - def verification_on_site_with_email_params - params.require(:verification_on_site).permit(:document_type, :document_number, :email) - end + end diff --git a/app/models/verification/on_site.rb b/app/models/verification/on_site.rb index 8eaab0013..f7c3c20e7 100644 --- a/app/models/verification/on_site.rb +++ b/app/models/verification/on_site.rb @@ -3,16 +3,11 @@ class Verification::OnSite attr_accessor :document_type attr_accessor :document_number - attr_accessor :email - attr_accessor :should_validate_email validates :document_type, :document_number, presence: true - validate :validate_email, if: :should_validate_email def user - @user ||= - User.where(email: email).first || - User.by_document(document_type, document_number).first + @user = User.by_document(document_type, document_number).first end def user? @@ -31,22 +26,6 @@ class Verification::OnSite user.update(verified_at: Time.now) if user? end - def send_verification_email - # FIXME - # Should assign document_number here? - # Should send verification email here? - end - - def validate_email - if email.blank? - errors.add(:email, I18n.t('errors.messages.blank')) - elsif email !~ Devise.email_regexp - errors.add(:email, I18n.t('errors.messages.invalid')) - elsif !user? - errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user? - end - end - end diff --git a/app/models/verification/on_site_email.rb b/app/models/verification/on_site_email.rb new file mode 100644 index 000000000..abe61d4f7 --- /dev/null +++ b/app/models/verification/on_site_email.rb @@ -0,0 +1,34 @@ +class Verification::OnSiteEmail + include ActiveModel::Model + + attr_accessor :document_type + attr_accessor :document_number + attr_accessor :email + + validates :document_type, :document_number, presence: true + validate :validate_email + + def user + @user ||= User.where(email: email).first + end + + def user? + user.present? + end + + def send_email + # FIXME + # Should assign document_number here? + # Should send verification email here? + end + + def validate_email + if email.blank? + errors.add(:email, I18n.t('errors.messages.blank')) + elsif email !~ Devise.email_regexp + errors.add(:email, I18n.t('errors.messages.invalid')) + elsif !user? + errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user? + end + end +end diff --git a/app/views/management/_menu.html.erb b/app/views/management/_menu.html.erb new file mode 100644 index 000000000..74c5151d4 --- /dev/null +++ b/app/views/management/_menu.html.erb @@ -0,0 +1,14 @@ + diff --git a/app/views/management/dashboard/index.html.erb b/app/views/management/dashboard/index.html.erb new file mode 100644 index 000000000..8fc1b6100 --- /dev/null +++ b/app/views/management/dashboard/index.html.erb @@ -0,0 +1,3 @@ +
+

<%= t("management.dashboard.index.title") %>

+
diff --git a/app/views/management/on_site_verifications/existing_user.html.erb b/app/views/management/on_site_verification_emails/new.html.erb similarity index 71% rename from app/views/management/on_site_verifications/existing_user.html.erb rename to app/views/management/on_site_verification_emails/new.html.erb index ac271f07a..bafc1e11d 100644 --- a/app/views/management/on_site_verifications/existing_user.html.erb +++ b/app/views/management/on_site_verification_emails/new.html.erb @@ -1,6 +1,6 @@
@@ -13,10 +13,11 @@

<%= t("management.users.has_account_note") %>

- <%= form_for @verification_on_site, url: send_email_management_on_site_verifications_path do |f| %> + <%= form_for @verification_on_site_email, url: management_on_site_verification_emails_path do |f| %> <%= f.hidden_field :document_type %> <%= f.hidden_field :document_number %> <%= f.text_field :email, label: false, placeholder: t('management.users.has_account_placeholder') %> + <%= f.submit t("management.users.has_account_send_email"), class: "button success radius" %> <% end %> @@ -25,7 +26,7 @@ <%= t("management.users.has_not_account") %>

- <%= t("management.users.create_user") %> + <%= t("management.print_info") %>

diff --git a/app/views/management/on_site_verifications/email_sent.html.erb b/app/views/management/on_site_verification_emails/sent.html.erb similarity index 67% rename from app/views/management/on_site_verifications/email_sent.html.erb rename to app/views/management/on_site_verification_emails/sent.html.erb index 721d81524..d3aa3035d 100644 --- a/app/views/management/on_site_verifications/email_sent.html.erb +++ b/app/views/management/on_site_verification_emails/sent.html.erb @@ -1,12 +1,10 @@ - -
<%= t("management.users.email_sent") %>
diff --git a/app/views/management/on_site_verifications/index.html.erb b/app/views/management/on_site_verifications/index.html.erb index e20d7573b..41f62bd70 100644 --- a/app/views/management/on_site_verifications/index.html.erb +++ b/app/views/management/on_site_verifications/index.html.erb @@ -1,4 +1,4 @@ -

<%= t("management.verification_on_sites.title") %>

+

<%= t("management.users.title") %>

diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 30a9515da..d59126973 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -7,9 +7,13 @@ es: check: "Comprobar" document_number: "Número de documento" document_type_label: "Tipo de documento" + menu: + on_site_verifications: "Usuarios" on_site_verifications: title: "Gestionar usuario" - + dashboard: + index: + title: "Gestión" users: title: "Gestionar usuario" census_error: "Este documento no está registrado en el Padrón Municipal de Madrid." diff --git a/config/routes.rb b/config/routes.rb index 8c798ed49..ca8ee1e12 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -169,10 +169,12 @@ Rails.application.routes.draw do resources :on_site_verifications, only: [:index, :new, :create] do collection do post :check - post :send_email end end + resources :on_site_verification_emails, only: [:new, :create] + + end # Example of regular route: From 1fe850b6dc0147f04b3a48cc5057be3b76f5e4a1 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 1 Oct 2015 19:27:04 +0200 Subject: [PATCH 07/43] Renaming of management validations --- .../document_verifications_controller.rb | 41 +++++++++++++++++++ .../email_verifications_controller.rb | 25 +++++++++++ .../on_site_verification_emails_controller.rb | 25 ----------- .../on_site_verifications_controller.rb | 41 ------------------- .../{on_site.rb => management/document.rb} | 2 +- .../{on_site_email.rb => management/email.rb} | 2 +- app/views/management/_menu.html.erb | 5 ++- .../index.html.erb | 5 ++- .../invalid_document.html.erb | 4 +- .../new.html.erb | 10 ++--- .../verified.html.erb | 8 ++-- .../new.html.erb | 8 ++-- .../sent.html.erb | 8 ++-- .../already_verified.html.erb | 25 ----------- config/routes.rb | 6 +-- 15 files changed, 97 insertions(+), 118 deletions(-) create mode 100644 app/controllers/management/document_verifications_controller.rb create mode 100644 app/controllers/management/email_verifications_controller.rb delete mode 100644 app/controllers/management/on_site_verification_emails_controller.rb delete mode 100644 app/controllers/management/on_site_verifications_controller.rb rename app/models/verification/{on_site.rb => management/document.rb} (92%) rename app/models/verification/{on_site_email.rb => management/email.rb} (95%) rename app/views/management/{on_site_verifications => document_verifications}/index.html.erb (81%) rename app/views/management/{on_site_verifications => document_verifications}/invalid_document.html.erb (83%) rename app/views/management/{on_site_verifications => document_verifications}/new.html.erb (65%) rename app/views/management/{on_site_verifications => document_verifications}/verified.html.erb (68%) rename app/views/management/{on_site_verification_emails => email_verifications}/new.html.erb (74%) rename app/views/management/{on_site_verification_emails => email_verifications}/sent.html.erb (67%) delete mode 100644 app/views/management/on_site_verifications/already_verified.html.erb diff --git a/app/controllers/management/document_verifications_controller.rb b/app/controllers/management/document_verifications_controller.rb new file mode 100644 index 000000000..17ae484d9 --- /dev/null +++ b/app/controllers/management/document_verifications_controller.rb @@ -0,0 +1,41 @@ +class Management::DocumentVerificationsController < Management::BaseController + + def index + @document_verification = Verification::Management::Document.new() + end + + def check + @document_verification = Verification::Management::Document.new(document_verification_params) + + if @document_verification.valid? + if @document_verification.verified? + render :verified + elsif @document_verification.user? + render :new + elsif @document_verification.in_census? + redirect_to new_management_email_verification_path(email_verification: document_verification_params) + else + render :invalid_document + end + else + render :index + end + end + + def create + @document_verification = Verification::Management::Document.new(document_verification_params) + @document_verification.verify + render :verified + end + + private + + def document_verification_params + params.require(:document_verification).permit(:document_type, :document_number) + end + + +end + + + diff --git a/app/controllers/management/email_verifications_controller.rb b/app/controllers/management/email_verifications_controller.rb new file mode 100644 index 000000000..7d2fa604f --- /dev/null +++ b/app/controllers/management/email_verifications_controller.rb @@ -0,0 +1,25 @@ +class Management::EmailVerificationsController < Management::BaseController + + def new + @email_verification = Verification::Management::Email.new(email_verification_params) + end + + def create + @email_verification = Verification::Email.new(email_verification_params) + + if @email_verification.valid? + @email_verification.send_email + render :sent + else + render :new + end + end + + private + + def email_verification_params + params.require(:email_verification).permit(:document_type, :document_number, :email) + end + +end + diff --git a/app/controllers/management/on_site_verification_emails_controller.rb b/app/controllers/management/on_site_verification_emails_controller.rb deleted file mode 100644 index 52fb8b279..000000000 --- a/app/controllers/management/on_site_verification_emails_controller.rb +++ /dev/null @@ -1,25 +0,0 @@ -class Management::OnSiteVerificationEmailsController < Management::BaseController - - def new - @verification_on_site_email = Verification::OnSiteEmail.new(verification_on_site_email_params) - end - - def create - @verification_on_site_email = Verification::OnSiteEmail.new(verification_on_site_email_params) - - if @verification_on_site_email.valid? - @verification_on_site_email.send_email - render :sent - else - render :new - end - end - - private - - def verification_on_site_email_params - params.require(:verification_on_site_email).permit(:document_type, :document_number, :email) - end - -end - diff --git a/app/controllers/management/on_site_verifications_controller.rb b/app/controllers/management/on_site_verifications_controller.rb deleted file mode 100644 index 46409c869..000000000 --- a/app/controllers/management/on_site_verifications_controller.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Management::OnSiteVerificationsController < Management::BaseController - - def index - @verification_on_site = Verification::OnSite.new() - end - - def check - @verification_on_site = Verification::OnSite.new(verification_on_site_params) - - if @verification_on_site.valid? - if @verification_on_site.verified? - render :verified - elsif @verification_on_site.user? - render :new - elsif @verification_on_site.in_census? - redirect_to new_management_on_site_verification_email_path(verification_on_site_email: verification_on_site_params) - else - render :invalid_document - end - else - render :index - end - end - - def create - @verification_on_site = Verification::OnSite.new(verification_on_site_params) - @verification_on_site.verify - render :verified - end - - private - - def verification_on_site_params - params.require(:verification_on_site).permit(:document_type, :document_number) - end - - -end - - - diff --git a/app/models/verification/on_site.rb b/app/models/verification/management/document.rb similarity index 92% rename from app/models/verification/on_site.rb rename to app/models/verification/management/document.rb index f7c3c20e7..69ab1affc 100644 --- a/app/models/verification/on_site.rb +++ b/app/models/verification/management/document.rb @@ -1,4 +1,4 @@ -class Verification::OnSite +class Verification::Management::Document include ActiveModel::Model attr_accessor :document_type diff --git a/app/models/verification/on_site_email.rb b/app/models/verification/management/email.rb similarity index 95% rename from app/models/verification/on_site_email.rb rename to app/models/verification/management/email.rb index abe61d4f7..0f9842caf 100644 --- a/app/models/verification/on_site_email.rb +++ b/app/models/verification/management/email.rb @@ -1,4 +1,4 @@ -class Verification::OnSiteEmail +class Verification::Management::Email include ActiveModel::Model attr_accessor :document_type diff --git a/app/views/management/_menu.html.erb b/app/views/management/_menu.html.erb index 74c5151d4..dd0558e83 100644 --- a/app/views/management/_menu.html.erb +++ b/app/views/management/_menu.html.erb @@ -4,8 +4,9 @@ <%= link_to t("management.dashboard.index.title"), management_root_path %> -
  • > - <%= link_to management_on_site_verifications_path do %> +
  • > + <%= link_to management_document_verifications_path do %> <%= t("management.menu.on_site_verifications") %> <% end %> diff --git a/app/views/management/on_site_verifications/index.html.erb b/app/views/management/document_verifications/index.html.erb similarity index 81% rename from app/views/management/on_site_verifications/index.html.erb rename to app/views/management/document_verifications/index.html.erb index 41f62bd70..d87b83b06 100644 --- a/app/views/management/on_site_verifications/index.html.erb +++ b/app/views/management/document_verifications/index.html.erb @@ -2,7 +2,10 @@
    - <%= form_for @verification_on_site, url: check_management_on_site_verifications_path do |f| %> + <%= form_for(@document_verification, + as: :document_verification, + url: check_management_document_verifications_path) do |f| %> +
    <%= f.select(:document_type, [[humanize_document_type("1"), 1], diff --git a/app/views/management/on_site_verifications/invalid_document.html.erb b/app/views/management/document_verifications/invalid_document.html.erb similarity index 83% rename from app/views/management/on_site_verifications/invalid_document.html.erb rename to app/views/management/document_verifications/invalid_document.html.erb index c95d3c01e..d662b6c08 100644 --- a/app/views/management/on_site_verifications/invalid_document.html.erb +++ b/app/views/management/document_verifications/invalid_document.html.erb @@ -1,6 +1,6 @@
    diff --git a/app/views/management/on_site_verifications/new.html.erb b/app/views/management/document_verifications/new.html.erb similarity index 65% rename from app/views/management/on_site_verifications/new.html.erb rename to app/views/management/document_verifications/new.html.erb index cc7d6e914..ad9623107 100644 --- a/app/views/management/on_site_verifications/new.html.erb +++ b/app/views/management/document_verifications/new.html.erb @@ -1,8 +1,8 @@
    @@ -20,7 +20,7 @@
  • <%= t("management.users.user_permission_votes") %>
  • - <%= form_for @verification_on_site, url: management_on_site_verifications_path do |f| %> + <%= form_for @document_verification, url: management_on_site_verifications_path do |f| %> <%= f.hidden_field :document_type %> <%= f.hidden_field :document_number %> <%= f.submit t("management.users.verify"), class: "button success radius" %> diff --git a/app/views/management/on_site_verifications/verified.html.erb b/app/views/management/document_verifications/verified.html.erb similarity index 68% rename from app/views/management/on_site_verifications/verified.html.erb rename to app/views/management/document_verifications/verified.html.erb index 60b81566c..dae7ce17a 100644 --- a/app/views/management/on_site_verifications/verified.html.erb +++ b/app/views/management/document_verifications/verified.html.erb @@ -1,8 +1,8 @@
    diff --git a/app/views/management/on_site_verification_emails/new.html.erb b/app/views/management/email_verifications/new.html.erb similarity index 74% rename from app/views/management/on_site_verification_emails/new.html.erb rename to app/views/management/email_verifications/new.html.erb index bafc1e11d..d6987cf26 100644 --- a/app/views/management/on_site_verification_emails/new.html.erb +++ b/app/views/management/email_verifications/new.html.erb @@ -1,6 +1,6 @@
    @@ -13,7 +13,9 @@

    <%= t("management.users.has_account_note") %>

    - <%= form_for @verification_on_site_email, url: management_on_site_verification_emails_path do |f| %> + <%= form_for @email_verification, + as: :email_verification, + url: management_email_verifications_path do |f| %> <%= f.hidden_field :document_type %> <%= f.hidden_field :document_number %> <%= f.text_field :email, label: false, placeholder: t('management.users.has_account_placeholder') %> diff --git a/app/views/management/on_site_verification_emails/sent.html.erb b/app/views/management/email_verifications/sent.html.erb similarity index 67% rename from app/views/management/on_site_verification_emails/sent.html.erb rename to app/views/management/email_verifications/sent.html.erb index d3aa3035d..470e9c292 100644 --- a/app/views/management/on_site_verification_emails/sent.html.erb +++ b/app/views/management/email_verifications/sent.html.erb @@ -1,8 +1,8 @@
    diff --git a/app/views/management/on_site_verifications/already_verified.html.erb b/app/views/management/on_site_verifications/already_verified.html.erb deleted file mode 100644 index 60b81566c..000000000 --- a/app/views/management/on_site_verifications/already_verified.html.erb +++ /dev/null @@ -1,25 +0,0 @@ - - -
    - <%= t("management.users.already_verified") %> -
    - -
    - -

    <%= t("management.users.census_success_info") %>

    - -
      -
    • <%= t("management.users.user_permission_debates") %>
    • -
    • <%= t("management.users.user_permission_proposal") %>
    • -
    • <%= t("management.users.user_permission_support_proposal") %>
    • -
    • <%= t("management.users.user_permission_votes") %>
    • -
    - -
    - -<%= t("management.print_info") %> diff --git a/config/routes.rb b/config/routes.rb index ca8ee1e12..50d8283d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -166,15 +166,13 @@ Rails.application.routes.draw do namespace :management do root to: "dashboard#index" - resources :on_site_verifications, only: [:index, :new, :create] do + resources :document_verifications, only: [:index, :new, :create] do collection do post :check end end - resources :on_site_verification_emails, only: [:new, :create] - - + resources :email_verifications, only: [:new, :create] end # Example of regular route: From 3786d9d67f99a0056b2fc955195b5cd3cdff2eb2 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 13:19:57 +0200 Subject: [PATCH 08/43] Fixes typo --- app/controllers/management/email_verifications_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/management/email_verifications_controller.rb b/app/controllers/management/email_verifications_controller.rb index 7d2fa604f..00276eb51 100644 --- a/app/controllers/management/email_verifications_controller.rb +++ b/app/controllers/management/email_verifications_controller.rb @@ -5,7 +5,7 @@ class Management::EmailVerificationsController < Management::BaseController end def create - @email_verification = Verification::Email.new(email_verification_params) + @email_verification = Verification::Management::Email.new(email_verification_params) if @email_verification.valid? @email_verification.send_email From 75721ab186c16a57bbb96f00bf9a87565cb3b94b Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 13:20:44 +0200 Subject: [PATCH 09/43] Implements Verification::Management::Email#save + refactors --- .../email_verifications_controller.rb | 3 +- app/models/verification/management/email.rb | 42 +++++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/controllers/management/email_verifications_controller.rb b/app/controllers/management/email_verifications_controller.rb index 00276eb51..182fac2e2 100644 --- a/app/controllers/management/email_verifications_controller.rb +++ b/app/controllers/management/email_verifications_controller.rb @@ -7,8 +7,7 @@ class Management::EmailVerificationsController < Management::BaseController def create @email_verification = Verification::Management::Email.new(email_verification_params) - if @email_verification.valid? - @email_verification.send_email + if @email_verification.save render :sent else render :new diff --git a/app/models/verification/management/email.rb b/app/models/verification/management/email.rb index 0f9842caf..ffb1d704a 100644 --- a/app/models/verification/management/email.rb +++ b/app/models/verification/management/email.rb @@ -5,8 +5,9 @@ class Verification::Management::Email attr_accessor :document_number attr_accessor :email - validates :document_type, :document_number, presence: true - validate :validate_email + validates :document_type, :document_number, :email, presence: true + validates :email, format: { with: Devise.email_regexp }, allow_blank: true + validate :validate_user def user @user ||= User.where(email: email).first @@ -16,19 +17,34 @@ class Verification::Management::Email user.present? end - def send_email - # FIXME - # Should assign document_number here? - # Should send verification email here? + def save + return false unless valid? + + plain_token, encrypted_token = Devise.token_generator.generate(User, :email_verification_token) + user.update(email_verification_token: plain_token) + Mailer.email_verification(user, email, encrypted_token).deliver_later + true end - def validate_email - if email.blank? - errors.add(:email, I18n.t('errors.messages.blank')) - elsif email !~ Devise.email_regexp - errors.add(:email, I18n.t('errors.messages.invalid')) - elsif !user? - errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user? + def already_verified? + user? && user.level_three_verified? + end + + def document_number_mismatch? + user? && user.document_number.present? && + (user.document_number != document_number || user.document_type != document_type) + end + + def validate_user + return if errors.count > 0 + errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user? + if already_verified? + errors.add(:email, I18n.t('management.users.already_verified')) + elsif document_number_mismatch? + errors.add(:email, + I18n.t('management.users.document_mismatch', + document_type: ApplicationController.helpers.humanize_document_type(user.document_type), + document_number: user.document_number)) end end end From fa19490991b03be7d2106e598490b8306311e61d Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 13:21:01 +0200 Subject: [PATCH 10/43] Adds extra error message to mL --- config/locales/management.es.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index d59126973..37b1d1df0 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -34,6 +34,7 @@ es: has_account_placeholder: "Introduce el email de registro" has_account_send_email: "Enviar email de verificación" email_sent: "Para terminar de verificar esta cuenta es necesario que haga clic en el enlace que le hemos enviado a la dirección de correo que figura arriba. Este paso es necesario para confirmar que dicha cuenta de usuario es suya." + document_mismatch: "Ese email corresponde a un usuario que ya tiene asociado el documento %{document_number}(%{document_type})" create_user: "Crear nueva cuenta de usuario" create_user_info: "Procedemos a crear un usuario con la siguiente información:" create_user_submit: "Crear usuario" From 5069f86eb9f95f07e4290a7f5bac75c6f3114eeb Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 18:36:40 +0200 Subject: [PATCH 11/43] Skips the welcome screen when the user is verifying via email --- app/controllers/users/sessions_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index c93b61c80..6700785e5 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -1,11 +1,18 @@ class Users::SessionsController < Devise::SessionsController def after_sign_in_path_for(resource) - if resource.show_welcome_screen? + if stored_path_allows_welcome_screen? && resource.show_welcome_screen? welcome_path else root_path end end + private + + def stored_path_allows_welcome_screen? + stored_path = session[stored_location_key_for(resource)] + stored_path[0..5] != "/email" + end + end From fc11a3b41b0195b68006a8aef00ba387f43e8885 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 18:37:15 +0200 Subject: [PATCH 12/43] Restores the usage of the stored path instead of forcing root path after every login --- app/controllers/users/sessions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 6700785e5..eab624559 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -4,7 +4,7 @@ class Users::SessionsController < Devise::SessionsController if stored_path_allows_welcome_screen? && resource.show_welcome_screen? welcome_path else - root_path + super end end From 8a1b01e985800efc5fd3e32a543bebc2825a0901 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 18:37:53 +0200 Subject: [PATCH 13/43] Adds unconfirmed_document_number to user via migration --- ...add_unconfirmed_document_number_to_user.rb | 5 ++++ db/schema.rb | 25 ++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20151002144206_add_unconfirmed_document_number_to_user.rb diff --git a/db/migrate/20151002144206_add_unconfirmed_document_number_to_user.rb b/db/migrate/20151002144206_add_unconfirmed_document_number_to_user.rb new file mode 100644 index 000000000..7a00acb91 --- /dev/null +++ b/db/migrate/20151002144206_add_unconfirmed_document_number_to_user.rb @@ -0,0 +1,5 @@ +class AddUnconfirmedDocumentNumberToUser < ActiveRecord::Migration + def change + add_column :users, :unconfirmed_document_number, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 97ad0ab97..3a84bc7b6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150930082311) do +ActiveRecord::Schema.define(version: 20151002144206) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -267,30 +267,30 @@ ActiveRecord::Schema.define(version: 20150930082311) do add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" - t.boolean "email_on_comment", default: false - t.boolean "email_on_comment_reply", default: false - t.string "phone_number", limit: 30 + t.boolean "email_on_comment", default: false + t.boolean "email_on_comment_reply", default: false + t.string "phone_number", limit: 30 t.string "official_position" - t.integer "official_level", default: 0 + t.integer "official_level", default: 0 t.datetime "hidden_at" t.string "sms_confirmation_code" - t.string "username", limit: 60 + t.string "username", limit: 60 t.string "document_number" t.string "document_type" t.datetime "residence_verified_at" @@ -302,7 +302,8 @@ ActiveRecord::Schema.define(version: 20150930082311) do t.datetime "letter_requested_at" t.datetime "confirmed_hide_at" t.string "letter_verification_code" - t.integer "failed_census_calls_count", default: 0 + t.integer "failed_census_calls_count", default: 0 + t.string "unconfirmed_document_number" end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree From 9e05a3283c5387bde85115104cd6128f9041e3ef Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 18:40:24 +0200 Subject: [PATCH 14/43] Includes the document number and type in the verification email --- app/mailers/mailer.rb | 5 ++++- app/models/verification/management/email.rb | 2 +- app/views/mailer/email_verification.html.erb | 6 ++++++ config/locales/mailers.en.yml | 1 + config/locales/mailers.es.yml | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 8ce28060c..bf646019a 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -1,6 +1,7 @@ class Mailer < ApplicationMailer helper :text_with_links helper :mailer + helper :user def comment(comment) @comment = comment @@ -16,10 +17,12 @@ class Mailer < ApplicationMailer mail(to: @recipient.email, subject: t('mailers.reply.subject')) if @commentable.present? && @recipient.present? end - def email_verification(user, recipient, token) + def email_verification(user, recipient, token, document_type, document_number) @user = user @recipient = recipient @token = token + @document_type = document_type + @document_number = document_number mail(to: @recipient, subject: t('mailers.email_verification.subject')) end diff --git a/app/models/verification/management/email.rb b/app/models/verification/management/email.rb index ffb1d704a..37d37be90 100644 --- a/app/models/verification/management/email.rb +++ b/app/models/verification/management/email.rb @@ -22,7 +22,7 @@ class Verification::Management::Email plain_token, encrypted_token = Devise.token_generator.generate(User, :email_verification_token) user.update(email_verification_token: plain_token) - Mailer.email_verification(user, email, encrypted_token).deliver_later + Mailer.email_verification(user, email, encrypted_token, document_type, document_number).deliver_later true end diff --git a/app/views/mailer/email_verification.html.erb b/app/views/mailer/email_verification.html.erb index e86e7b7ce..040fb76ba 100644 --- a/app/views/mailer/email_verification.html.erb +++ b/app/views/mailer/email_verification.html.erb @@ -9,6 +9,12 @@ t('mailers.email_verification.click_here_to_verify'), email_url(email_verification_token: @token))) %>

    + +

    + <%= t("mailers.email_verification.instructions_2_html", + document_type: humanize_document_type(@document_type), + document_number: @document_number) %> +

    <%= t("mailers.email_verification.thanks") %>

    diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 030dc13de..52852832c 100644 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -15,5 +15,6 @@ en: title: Please verify yourself instructions_html: "We need to verify you using this email, which we got from the Census. %{verification_link}" click_here_to_verify: "Please click here to verify yourself" + instructions_html_2: "This email will verify your account with %{document_type} %{document_number}. If these don't belong to you, please don't click on the previous link and ignore this email." thanks: "Thanks" diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 1ca753ab5..bf8b276e1 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -15,4 +15,5 @@ es: title: Verifica tu cuenta con el siguiente enlace instructions_html: "Para terminar de verificar tu cuenta de usuario en el Portal de Gobierno Abierto del Ayuntamiento de Madrid, necesitamos que pulses %{verification_link}." click_here_to_verify: "en este enlace" + instructions_2_html: "Este email es para verificar tu cuenta con %{document_type} %{document_number}. Si esos no son tus datos, por favor no pulses el enlace anterior e ignora este email." thanks: "Muchas gracias." From 967bfc5b311f5897c7b4d33393adcbf6646b911e Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 18:40:56 +0200 Subject: [PATCH 15/43] Moves the humanize_document_type helper to a new helper file called user --- app/helpers/admin_helper.rb | 13 +------------ app/helpers/user_helper.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 app/helpers/user_helper.rb diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 1c72fedbf..faf9b2302 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -12,21 +12,10 @@ module AdminHelper options end - def humanize_document_type(document_type) - case document_type - when "1" - t "verification.residence.new.document_type.spanish_id" - when "2" - t "verification.residence.new.document_type.passport" - when "3" - t "verification.residence.new.document_type.residence_card" - end - end - private def namespace controller.class.parent.name.downcase end -end \ No newline at end of file +end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 000000000..9fe2a801d --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,12 @@ +module UserHelper + def humanize_document_type(document_type) + case document_type + when "1" + t "verification.residence.new.document_type.spanish_id" + when "2" + t "verification.residence.new.document_type.passport" + when "3" + t "verification.residence.new.document_type.residence_card" + end + end +end From 3ed5c269e41a44b61220c85bdd03528cf470f488 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 18:44:15 +0200 Subject: [PATCH 16/43] Adds unconfirmed_document_number into email verifications It also makes sure that when a user is considered level 3 is also considered residence-verified. --- app/controllers/verification/email_controller.rb | 8 ++++++-- app/models/verification/management/email.rb | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/controllers/verification/email_controller.rb b/app/controllers/verification/email_controller.rb index 017269095..122d2ed84 100644 --- a/app/controllers/verification/email_controller.rb +++ b/app/controllers/verification/email_controller.rb @@ -6,7 +6,11 @@ class Verification::EmailController < ApplicationController def show if Verification::Email.find(current_user, params[:email_verification_token]) - current_user.update(verified_at: Time.now) + + current_user.update(verified_at: Time.now, + document_number: current_user.document_number || current_user.unconfirmed_document_number, + residence_verified_at: current_user.residence_verified_at || Time.now) + redirect_to account_path, notice: t('verification.email.show.flash.success') else redirect_to verified_user_path, alert: t('verification.email.show.alert.failure') @@ -33,4 +37,4 @@ class Verification::EmailController < ApplicationController def verified_user_params params.require(:verified_user).permit(:id) end -end \ No newline at end of file +end diff --git a/app/models/verification/management/email.rb b/app/models/verification/management/email.rb index 37d37be90..7cd815dd5 100644 --- a/app/models/verification/management/email.rb +++ b/app/models/verification/management/email.rb @@ -21,7 +21,11 @@ class Verification::Management::Email return false unless valid? plain_token, encrypted_token = Devise.token_generator.generate(User, :email_verification_token) - user.update(email_verification_token: plain_token) + + user.update(document_type: document_type, + unconfirmed_document_number: document_number, + email_verification_token: plain_token) + Mailer.email_verification(user, email, encrypted_token, document_type, document_number).deliver_later true end From 9ddc9c57b7b9df492a304284c5436b778cd20e36 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Oct 2015 18:44:28 +0200 Subject: [PATCH 17/43] Do not show the welcome screen to administrators --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index b24354fa2..80e2de195 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -159,7 +159,7 @@ class User < ActiveRecord::Base end def show_welcome_screen? - sign_in_count == 1 && unverified? && !organization + sign_in_count == 1 && unverified? && !organization && !administrator? end private From 6f799ae32e9a6fe96bcfd8e0acab47a64cd69408 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 5 Oct 2015 11:49:15 +0200 Subject: [PATCH 18/43] Extracts common elements out of management views --- app/views/management/_account_info.html.erb | 8 +++++ .../management/_user_permissions.html.erb | 20 ++++++++++++ .../invalid_document.html.erb | 30 ++++++----------- .../document_verifications/new.html.erb | 32 ++++++------------- .../document_verifications/verified.html.erb | 22 +++---------- .../email_verifications/new.html.erb | 5 +-- .../email_verifications/sent.html.erb | 26 ++++----------- 7 files changed, 58 insertions(+), 85 deletions(-) create mode 100644 app/views/management/_account_info.html.erb create mode 100644 app/views/management/_user_permissions.html.erb diff --git a/app/views/management/_account_info.html.erb b/app/views/management/_account_info.html.erb new file mode 100644 index 000000000..fae1179d1 --- /dev/null +++ b/app/views/management/_account_info.html.erb @@ -0,0 +1,8 @@ + diff --git a/app/views/management/_user_permissions.html.erb b/app/views/management/_user_permissions.html.erb new file mode 100644 index 000000000..c77cab17c --- /dev/null +++ b/app/views/management/_user_permissions.html.erb @@ -0,0 +1,20 @@ +<% + # Parameters: + # message: A string explaining the permissions + # permissions: An array of symbols containing the permissions + # (can be :debates, :proposal, :support_proposal, :votes) +%> +
    + +

    <%= message %>

    + +
      + <% [:debates, :proposal, :support_proposal, :votes].each do |permission| %> +
    • + + <%= t("management.users.user_permission_#{permission}") %> +
    • + <% end %> +
    + +
    diff --git a/app/views/management/document_verifications/invalid_document.html.erb b/app/views/management/document_verifications/invalid_document.html.erb index d662b6c08..42e2e63c0 100644 --- a/app/views/management/document_verifications/invalid_document.html.erb +++ b/app/views/management/document_verifications/invalid_document.html.erb @@ -1,27 +1,15 @@ - +<%= render 'management/account_info.html', verification: @document_verification %>
    <%= t("management.users.census_error") %>
    -
    +<%= render 'management/user_permissions', + message: t("management.users.census_error_info"), + permissions: [:debates, :proposal] %> -

    <%= t("management.users.census_error_info") %>

    - -
      -
    • <%= t("management.users.user_permission_debates") %>
    • -
    • <%= t("management.users.user_permission_proposal") %>
    • -
    • <%= t("management.users.user_permission_support_proposal") %>
    • -
    • <%= t("management.users.user_permission_votes") %>
    • -
    - -

    - <%= t("management.users.has_not_account_html", - url: link_to(t("management.users.portal_url"), t("management.users.portal_url"), - target: "_blank")).html_safe %> -

    - -
    +

    + <%= t("management.users.has_not_account_html", + url: link_to(t("management.users.portal_url"), t("management.users.portal_url"), + target: "_blank")).html_safe %> +

    diff --git a/app/views/management/document_verifications/new.html.erb b/app/views/management/document_verifications/new.html.erb index ad9623107..f263ecbca 100644 --- a/app/views/management/document_verifications/new.html.erb +++ b/app/views/management/document_verifications/new.html.erb @@ -1,29 +1,15 @@ - +<%= render 'management/account_info.html', verification: @document_verification %>
    <%= t("management.users.census_success_account") %>
    -
    +<%= render 'management/user_permissions', + message: t("management.users.census_success_info"), + permissions: [:debates, :proposal, :support_proposal] %> -

    <%= t("management.users.census_success_info") %>

    - -
      -
    • <%= t("management.users.user_permission_debates") %>
    • -
    • <%= t("management.users.user_permission_proposal") %>
    • -
    • <%= t("management.users.user_permission_support_proposal") %>
    • -
    • <%= t("management.users.user_permission_votes") %>
    • -
    - - <%= form_for @document_verification, url: management_on_site_verifications_path do |f| %> - <%= f.hidden_field :document_type %> - <%= f.hidden_field :document_number %> - <%= f.submit t("management.users.verify"), class: "button success radius" %> - <% end %> - -
    +<%= form_for @document_verification, url: management_on_site_verifications_path do |f| %> + <%= f.hidden_field :document_type %> + <%= f.hidden_field :document_number %> + <%= f.submit t("management.users.verify"), class: "button success radius" %> +<% end %> diff --git a/app/views/management/document_verifications/verified.html.erb b/app/views/management/document_verifications/verified.html.erb index dae7ce17a..40ea294fa 100644 --- a/app/views/management/document_verifications/verified.html.erb +++ b/app/views/management/document_verifications/verified.html.erb @@ -1,25 +1,11 @@ - +<%= render 'management/account_info.html', verification: @document_verification %>
    <%= t("management.users.already_verified") %>
    -
    - -

    <%= t("management.users.census_success_info") %>

    - -
      -
    • <%= t("management.users.user_permission_debates") %>
    • -
    • <%= t("management.users.user_permission_proposal") %>
    • -
    • <%= t("management.users.user_permission_support_proposal") %>
    • -
    • <%= t("management.users.user_permission_votes") %>
    • -
    - -
    +<%= render 'management/user_permissions', + message: t("management.users.census_success_info"), + permissions: [:debates, :proposal, :support_proposal] %> <%= t("management.print_info") %> diff --git a/app/views/management/email_verifications/new.html.erb b/app/views/management/email_verifications/new.html.erb index d6987cf26..782110cf5 100644 --- a/app/views/management/email_verifications/new.html.erb +++ b/app/views/management/email_verifications/new.html.erb @@ -1,7 +1,4 @@ - +<%= render 'management/account_info.html', verification: @email_verification %>
    <%= t("management.users.census_success") %> diff --git a/app/views/management/email_verifications/sent.html.erb b/app/views/management/email_verifications/sent.html.erb index 470e9c292..6b0c3da8a 100644 --- a/app/views/management/email_verifications/sent.html.erb +++ b/app/views/management/email_verifications/sent.html.erb @@ -1,26 +1,14 @@ - +<%= render 'management/account_info.html', verification: @email_verification %>
    <%= t("management.users.email_sent") %>
    -
    +<%= render 'management/user_permissions', + message: t("management.users.census_success_info"), + permissions: [:debates, :proposal, :support_proposal, :votes] %> -

    <%= t("management.users.census_success_info") %>

    - -
      -
    • <%= t("management.users.user_permission_debates") %>
    • -
    • <%= t("management.users.user_permission_proposal") %>
    • -
    • <%= t("management.users.user_permission_support_proposal") %>
    • -
    • <%= t("management.users.user_permission_votes") %>
    • -
    - -
    - -<%= t("management.print_info") %> +

    + <%= t("management.print_info") %> +

    From 93f4bfcc4b06849e600b17e932c0368ab6c48e7a Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 5 Oct 2015 19:38:58 +0200 Subject: [PATCH 19/43] Lots of renaming in management.en & es.yml --- config/locales/management.en.yml | 35 +++++++++++++++++++++++++ config/locales/management.es.yml | 45 ++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 config/locales/management.en.yml diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml new file mode 100644 index 000000000..b63d1c648 --- /dev/null +++ b/config/locales/management.en.yml @@ -0,0 +1,35 @@ +en: + management: + print: "Print" + print_info: "Print this info" + username_label: "User name" + email_label: "Email" + check: "Check" + document_number: "Document number" + document_type_label: "Document type" + menu: + document_verifications: "Users" + dashboard: + index: + title: "Management" + permissions: + debates: "Engage in debates" + create_proposals: "Create proposals" + support_proposals: "Support proposals" + vote_proposals: "Vote proposals" + document_verifications: + please_check_account_data: "Please check that the account data above are correct." + already_verified: "This user account is already verified." + in_census_has_following_permissions: "This user can participate in the website with the following permissions:" + not_in_census: "This document is not registered in Madrid." + not_in_census_info: "Citizens not in the Census can participate in the website with the following permissions:" + has_no_account_html: "In order to create an account, go to %{link} and click in 'Register' in the upper-left part of the screen." + verify: "Verify" + email_verifications: + document_found_in_census: "This document was found in the census, but it has no user account associated to it. Please choose one of the following options:" + if_existing_account: "If the person has already a user account created in the website," + introduce_email: "Please introduce the email used on the account:" + email_placeholder: "Write the email this person used to create his or her account" + send_email: "Send verification email" + email_sent_instructions: "In order to completely verify this user, it is necessary that the user clicks on a link which we have sent to the email address above. This step is needed in order to confirm that the address belongs to him." + if_no_existing_account: "If this person has not created an account yet" diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 37b1d1df0..92cb9a43c 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -9,31 +9,37 @@ es: document_type_label: "Tipo de documento" menu: on_site_verifications: "Usuarios" - on_site_verifications: title: "Gestionar usuario" dashboard: index: title: "Gestión" + permissions: + debates: "Participar en debates" + create_proposals: "Crear nuevas propuestas" + support_proposals: "Apoyar propuestas" + vote_proposals: "Participar en las votaciones finales" + document_verifications: + please_check_account_data: "Compruebe que los datos anteriores son correctos para proceder a verificar la cuenta completamente." + already_verified: "Esta cuenta de usuario ya está verificada." + in_census_has_following_permissions: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" + not_in_census: "Este documento no está registrado en el Padrón Municipal de Madrid." + not_in_census_info: "Las personas no empadronadas en Madrid pueden participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" + has_no_account_html: "Para crear un usuario entre en %{link} y haga clic en la opción 'Registrarse' en la parte superior derecha de la pantalla." + verify: "Verificar usuario" + email_verifications: + document_found_in_census: "Este documento está en el registro del padrón municipal, pero todavía no tiene una cuenta de usuario asociada. Elige una de las opciones siguientes:" + if_existing_account: "Si la persona ya ha creado una cuenta de usuario en la web" + introduce_email: "Introduce el email con el que creó la cuenta:" + email_placeholder: "Introduce el email de registro" + send_email: "Enviar email de verificación" + if_no_existing_account: "Si la persona todavía no ha creado una cuenta de usuario en la web" + email_sent_instructions: "Para terminar de verificar esta cuenta es necesario que haga clic en el enlace que le hemos enviado a la dirección de correo que figura arriba. Este paso es necesario para confirmar que dicha cuenta de usuario es suya." + + users: title: "Gestionar usuario" - census_error: "Este documento no está registrado en el Padrón Municipal de Madrid." - census_error_info: "Las personas no empadronadas en Madrid pueden participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" - census_success: "Este documento está en el registro del padrón municipal, pero todavía no tiene una cuenta de usuario asociada. Elige una de las opciones siguientes:" - census_success_info: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" - census_success_account: "Compruebe que los datos anteriores son correctos para proceder a verificar la cuenta completamente." - user_permission_debates: "Participar en debates" - user_permission_proposal: "Crear nuevas propuestas" - user_permission_support_proposal: "Apoyar propuestas" - user_permission_votes: "Participar en las votaciones finales" - has_not_account_html: "Para crear un usuario entre en %{url} y haga clic en la opción 'Registrarse' en la parte superior derecha de la pantalla." - portal_url: "http://decide.madrid.es" - already_verified: "Esta cuenta de usuario ya está verificada." - has_account: "Si la persona ya ha creado una cuenta de usuario en la web" - has_not_account: "Si la persona todavía no ha creado una cuenta de usuario en la web" - has_account_note: "Introduce el email con el que creó la cuenta:" - has_account_placeholder: "Introduce el email de registro" - has_account_send_email: "Enviar email de verificación" - email_sent: "Para terminar de verificar esta cuenta es necesario que haga clic en el enlace que le hemos enviado a la dirección de correo que figura arriba. Este paso es necesario para confirmar que dicha cuenta de usuario es suya." + + document_mismatch: "Ese email corresponde a un usuario que ya tiene asociado el documento %{document_number}(%{document_type})" create_user: "Crear nueva cuenta de usuario" create_user_info: "Procedemos a crear un usuario con la siguiente información:" @@ -42,5 +48,4 @@ es: "Le hemos mandado un correo electrónico a la dirección de correo anterior para verificar que es suya. Le recomendamos cambiar la contraseña en su primer uso. Para ello entre en %{url} con su usuario y contraseña, acceda a la sección 'Mi cuenta' y haga clic en el botón 'Cambiar datos de acceso'" - verify: "Verificar usuario" From 8d950a5862ed57c3eaacaaf337e0478c6e6529f7 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 5 Oct 2015 19:39:20 +0200 Subject: [PATCH 20/43] includes the document type when creating a level 2 and level 3 user via a factory --- spec/factories.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/factories.rb b/spec/factories.rb index fac81f1c9..5558bf949 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -18,11 +18,13 @@ FactoryGirl.define do unconfirmed_phone "611111111" confirmed_phone "611111111" sms_confirmation_code "1234" + document_type "1" document_number "12345678Z" end trait :level_three do verified_at Time.now + document_type "1" document_number "12345678Z" end From 5e327f0ae0b74347886cc4a49ad80f6547bd1fbf Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 5 Oct 2015 19:40:10 +0200 Subject: [PATCH 21/43] Applies the same renaming done in management.yml to the views --- app/views/management/_user_permissions.html.erb | 4 ++-- .../document_verifications/invalid_document.html.erb | 12 ++++++------ .../management/document_verifications/new.html.erb | 12 +++++++----- .../document_verifications/verified.html.erb | 6 +++--- .../management/email_verifications/new.html.erb | 12 ++++++------ .../management/email_verifications/sent.html.erb | 6 +++--- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/views/management/_user_permissions.html.erb b/app/views/management/_user_permissions.html.erb index c77cab17c..8b17605ea 100644 --- a/app/views/management/_user_permissions.html.erb +++ b/app/views/management/_user_permissions.html.erb @@ -9,10 +9,10 @@

    <%= message %>

      - <% [:debates, :proposal, :support_proposal, :votes].each do |permission| %> + <% [:debates, :create_proposals, :support_proposals, :vote_proposals].each do |permission| %>
    • - <%= t("management.users.user_permission_#{permission}") %> + <%= t("management.permissions.#{permission}") %>
    • <% end %>
    diff --git a/app/views/management/document_verifications/invalid_document.html.erb b/app/views/management/document_verifications/invalid_document.html.erb index 42e2e63c0..a3ae68c52 100644 --- a/app/views/management/document_verifications/invalid_document.html.erb +++ b/app/views/management/document_verifications/invalid_document.html.erb @@ -1,15 +1,15 @@ <%= render 'management/account_info.html', verification: @document_verification %>
    - <%= t("management.users.census_error") %> + <%= t("management.document_verifications.not_in_census") %>
    <%= render 'management/user_permissions', - message: t("management.users.census_error_info"), - permissions: [:debates, :proposal] %> + message: t("management.document_verifications.not_in_census_info"), + permissions: [:debates, :create_proposals] %>

    - <%= t("management.users.has_not_account_html", - url: link_to(t("management.users.portal_url"), t("management.users.portal_url"), - target: "_blank")).html_safe %> + <%= t("management.document_verifications.has_no_account_html", + link: link_to('http://decide.madrid.es', 'http://decide.madrid.es'), + target: "_blank") %>

    diff --git a/app/views/management/document_verifications/new.html.erb b/app/views/management/document_verifications/new.html.erb index f263ecbca..b6be34d7c 100644 --- a/app/views/management/document_verifications/new.html.erb +++ b/app/views/management/document_verifications/new.html.erb @@ -1,15 +1,17 @@ <%= render 'management/account_info.html', verification: @document_verification %>
    - <%= t("management.users.census_success_account") %> + <%= t("management.document_verifications.please_check_account_data") %>
    <%= render 'management/user_permissions', - message: t("management.users.census_success_info"), - permissions: [:debates, :proposal, :support_proposal] %> + message: t("management.document_verifications.in_census_has_following_permissions"), + permissions: [:debates, :create_proposals, :support_proposals] %> -<%= form_for @document_verification, url: management_on_site_verifications_path do |f| %> +<%= form_for @document_verification, + as: :document_verification, + url: management_document_verifications_path do |f| %> <%= f.hidden_field :document_type %> <%= f.hidden_field :document_number %> - <%= f.submit t("management.users.verify"), class: "button success radius" %> + <%= f.submit t("management.document_verifications.verify"), class: "button success radius" %> <% end %> diff --git a/app/views/management/document_verifications/verified.html.erb b/app/views/management/document_verifications/verified.html.erb index 40ea294fa..3c72a5a45 100644 --- a/app/views/management/document_verifications/verified.html.erb +++ b/app/views/management/document_verifications/verified.html.erb @@ -1,11 +1,11 @@ <%= render 'management/account_info.html', verification: @document_verification %>
    - <%= t("management.users.already_verified") %> + <%= t("management.document_verifications.already_verified") %>
    <%= render 'management/user_permissions', - message: t("management.users.census_success_info"), - permissions: [:debates, :proposal, :support_proposal] %> + message: t("management.document_verifications.in_census_has_following_permissions"), + permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %> <%= t("management.print_info") %> diff --git a/app/views/management/email_verifications/new.html.erb b/app/views/management/email_verifications/new.html.erb index 782110cf5..87bcb1fe0 100644 --- a/app/views/management/email_verifications/new.html.erb +++ b/app/views/management/email_verifications/new.html.erb @@ -1,28 +1,28 @@ <%= render 'management/account_info.html', verification: @email_verification %>
    - <%= t("management.users.census_success") %> + <%= t("management.email_verifications.document_found_in_census") %>
    • - <%= t("management.users.has_account") %> + <%= t("management.email_verifications.if_existing_account") %> -

      <%= t("management.users.has_account_note") %>

      +

      <%= t("management.email_verifications.introduce_email") %>

      <%= form_for @email_verification, as: :email_verification, url: management_email_verifications_path do |f| %> <%= f.hidden_field :document_type %> <%= f.hidden_field :document_number %> - <%= f.text_field :email, label: false, placeholder: t('management.users.has_account_placeholder') %> + <%= f.text_field :email, label: false, placeholder: t('management.email_verifications.email_placeholder') %> - <%= f.submit t("management.users.has_account_send_email"), class: "button success radius" %> + <%= f.submit t("management.email_verifications.send_email"), class: "button success radius" %> <% end %>
    • - <%= t("management.users.has_not_account") %> + <%= t("management.emails_verifications.if_no_existing_account") %>

      <%= t("management.print_info") %> diff --git a/app/views/management/email_verifications/sent.html.erb b/app/views/management/email_verifications/sent.html.erb index 6b0c3da8a..6917d0ddd 100644 --- a/app/views/management/email_verifications/sent.html.erb +++ b/app/views/management/email_verifications/sent.html.erb @@ -1,12 +1,12 @@ <%= render 'management/account_info.html', verification: @email_verification %>

      - <%= t("management.users.email_sent") %> + <%= t("management.email_verifications.email_sent_instructions") %>
      <%= render 'management/user_permissions', - message: t("management.users.census_success_info"), - permissions: [:debates, :proposal, :support_proposal, :votes] %> + message: t("management.email_verifications.document_found_in_census"), + permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %>

      <%= t("management.print_info") %> From 8423da58a11729f80159f49c6815ff9b31c3cd65 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 5 Oct 2015 19:40:27 +0200 Subject: [PATCH 22/43] Feature specs for management/document_verifications --- .../management/document_verifications_spec.rb | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 spec/features/management/document_verifications_spec.rb diff --git a/spec/features/management/document_verifications_spec.rb b/spec/features/management/document_verifications_spec.rb new file mode 100644 index 000000000..8a5411eca --- /dev/null +++ b/spec/features/management/document_verifications_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +feature 'DocumentVerifications' do + + scenario 'Verifying a level 3 user shows an "already verified" page' do + user = create(:user, :level_three) + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: user.document_number + click_button 'Check' + + expect(page).to have_content "already verified" + end + + scenario 'Verifying a level 2 user displays the verification form' do + + user = create(:user, :level_two) + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: user.document_number + click_button 'Check' + + expect(page).to have_content "Vote proposals" + + click_button 'Verify' + + expect(page).to have_content "already verified" + + expect(user.reload).to be_level_three_verified + end + + scenario 'Verifying a user which does not exist and is not in the census shows an error' do + + expect_any_instance_of(Verification::Management::Document).to receive(:in_census?).and_return(false) + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: "inexisting" + click_button 'Check' + + expect(page).to have_content "This document is not registered" + end + + scenario 'Verifying a user which does exists in the census but not in the db redirects allows sending an email' do + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: '1234' + click_button 'Check' + + expect(page).to have_content "Please introduce the email used on the account" + end + +end From 615527b5329716c5f8fa0927b52869557365fc22 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Oct 2015 18:02:25 +0200 Subject: [PATCH 23/43] adds specs for verification/management/email.rb --- .../verification/management/email_spec.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 spec/models/verification/management/email_spec.rb diff --git a/spec/models/verification/management/email_spec.rb b/spec/models/verification/management/email_spec.rb new file mode 100644 index 000000000..d303367bb --- /dev/null +++ b/spec/models/verification/management/email_spec.rb @@ -0,0 +1,49 @@ +require 'rails_helper' + +describe Verification::Management::Email do + + describe "#user" do + subject { described_class.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com") } + it "returns nil/false when the user does not exist" do + expect(subject.user).to be_nil + expect(subject.user?).to_not be + end + end + + describe "validations" do + it "is not valid if the user does not exist" do + expect(described_class.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com")).to_not be_valid + end + + it "is not valid if the user is already level 3" do + user = create(:user, :level_three) + expect(described_class.new(document_type: "1", document_number: "1234", email: user.email)).to_not be_valid + end + + it "is not valid if the user already has a different document number" do + user = create(:user, document_number: "1234", document_type: "1") + expect(described_class.new(document_type: "1", document_number: "5678", email: user.email)).to_not be_valid + end + end + + describe "#save" do + it "does nothing if not valid" do + expect(described_class.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com").save).to eq(false) + end + + it "updates the user and sends an email" do + user = create(:user) + validation = described_class.new(document_type: "1", document_number: "1234", email: user.email) + + mail = double(:mail) + + allow(validation).to receive(:user).and_return user + expect(mail).to receive(:deliver_later) + expect(Devise.token_generator).to receive(:generate).with(User, :email_verification_token).and_return(["1","2"]) + expect(user).to receive(:update).with(document_type: "1", unconfirmed_document_number: "1234", email_verification_token: "1") + expect(Mailer).to receive(:email_verification).with(user, user.email, "2", "1", "1234").and_return(mail) + + validation.save + end + end +end From 984ecd80f4e9cd1d8ec03e2d8ed8f0921607d141 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Oct 2015 18:48:57 +0200 Subject: [PATCH 24/43] Fixes issue when a user does login without stored path --- app/controllers/users/sessions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index eab624559..5fe2c78a3 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -12,7 +12,7 @@ class Users::SessionsController < Devise::SessionsController def stored_path_allows_welcome_screen? stored_path = session[stored_location_key_for(resource)] - stored_path[0..5] != "/email" + stored_path && stored_path[0..5] != "/email" end end From bc841a4799500e244d1760b9a633715fd75bb1af Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Oct 2015 18:50:54 +0200 Subject: [PATCH 25/43] Adds test for Management::EmailVerifications --- .../management/email_verifications_spec.rb | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spec/features/management/email_verifications_spec.rb diff --git a/spec/features/management/email_verifications_spec.rb b/spec/features/management/email_verifications_spec.rb new file mode 100644 index 000000000..335738e3a --- /dev/null +++ b/spec/features/management/email_verifications_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +feature 'EmailVerifications' do + + scenario 'Verifying a level 1 user via email' do + + user = create(:user) + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: '1234' + click_button 'Check' + + expect(page).to have_content "Please introduce the email used on the account" + + fill_in 'email_verification_email', with: user.email + click_button 'Send verification email' + + expect(page).to have_content("In order to completely verify this user, it is necessary that the user clicks on a link") + + user.reload + + login_as(user) + + sent_token = /.*email_verification_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] + visit email_path(email_verification_token: sent_token) + + expect(page).to have_content "You are now a verified user" + + expect(page).to_not have_link "Verify my account" + expect(page).to have_content "Verified account" + + expect(user.reload.document_number).to eq('1234') + expect(user).to be_level_three_verified + + end +end + + + From d5d5e683d17e68555ceb43a79f2773a52b2bfd32 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Oct 2015 19:39:59 +0200 Subject: [PATCH 26/43] Refactors account_info partial --- app/models/verification/management/document.rb | 2 ++ app/models/verification/management/email.rb | 2 ++ app/views/management/_account_info.html.erb | 12 +++++++----- .../document_verifications/invalid_document.html.erb | 2 +- .../management/document_verifications/new.html.erb | 2 +- .../document_verifications/verified.html.erb | 2 +- .../management/email_verifications/new.html.erb | 2 +- .../management/email_verifications/sent.html.erb | 2 +- 8 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/models/verification/management/document.rb b/app/models/verification/management/document.rb index 69ab1affc..6c9a8897f 100644 --- a/app/models/verification/management/document.rb +++ b/app/models/verification/management/document.rb @@ -6,6 +6,8 @@ class Verification::Management::Document validates :document_type, :document_number, presence: true + delegate :username, :email, to: :user, allow_nil: true + def user @user = User.by_document(document_type, document_number).first end diff --git a/app/models/verification/management/email.rb b/app/models/verification/management/email.rb index 7cd815dd5..9863b05d6 100644 --- a/app/models/verification/management/email.rb +++ b/app/models/verification/management/email.rb @@ -9,6 +9,8 @@ class Verification::Management::Email validates :email, format: { with: Devise.email_regexp }, allow_blank: true validate :validate_user + delegate :username, to: :user, allow_nil: true + def user @user ||= User.where(email: email).first end diff --git a/app/views/management/_account_info.html.erb b/app/views/management/_account_info.html.erb index fae1179d1..972398e89 100644 --- a/app/views/management/_account_info.html.erb +++ b/app/views/management/_account_info.html.erb @@ -1,8 +1,10 @@

      diff --git a/app/views/management/document_verifications/invalid_document.html.erb b/app/views/management/document_verifications/invalid_document.html.erb index a3ae68c52..d5e1b78fe 100644 --- a/app/views/management/document_verifications/invalid_document.html.erb +++ b/app/views/management/document_verifications/invalid_document.html.erb @@ -1,4 +1,4 @@ -<%= render 'management/account_info.html', verification: @document_verification %> +<%= render 'management/account_info.html', account: @document_verification %>
      <%= t("management.document_verifications.not_in_census") %> diff --git a/app/views/management/document_verifications/new.html.erb b/app/views/management/document_verifications/new.html.erb index b6be34d7c..be2d3a1c5 100644 --- a/app/views/management/document_verifications/new.html.erb +++ b/app/views/management/document_verifications/new.html.erb @@ -1,4 +1,4 @@ -<%= render 'management/account_info.html', verification: @document_verification %> +<%= render 'management/account_info.html', account: @document_verification %>
      <%= t("management.document_verifications.please_check_account_data") %> diff --git a/app/views/management/document_verifications/verified.html.erb b/app/views/management/document_verifications/verified.html.erb index 3c72a5a45..99ddb4202 100644 --- a/app/views/management/document_verifications/verified.html.erb +++ b/app/views/management/document_verifications/verified.html.erb @@ -1,4 +1,4 @@ -<%= render 'management/account_info.html', verification: @document_verification %> +<%= render 'management/account_info.html', account: @document_verification %>
      <%= t("management.document_verifications.already_verified") %> diff --git a/app/views/management/email_verifications/new.html.erb b/app/views/management/email_verifications/new.html.erb index 87bcb1fe0..4b8b0130b 100644 --- a/app/views/management/email_verifications/new.html.erb +++ b/app/views/management/email_verifications/new.html.erb @@ -1,4 +1,4 @@ -<%= render 'management/account_info.html', verification: @email_verification %> +<%= render 'management/account_info.html', account: @email_verification %>
      <%= t("management.email_verifications.document_found_in_census") %> diff --git a/app/views/management/email_verifications/sent.html.erb b/app/views/management/email_verifications/sent.html.erb index 6917d0ddd..cc368c0db 100644 --- a/app/views/management/email_verifications/sent.html.erb +++ b/app/views/management/email_verifications/sent.html.erb @@ -1,4 +1,4 @@ -<%= render 'management/account_info.html', verification: @email_verification %> +<%= render 'management/account_info.html', account: @email_verification %>
      <%= t("management.email_verifications.email_sent_instructions") %> From 131982c8e9b0ec847573231acd71ac188dd9f1b6 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Oct 2015 19:43:34 +0200 Subject: [PATCH 27/43] Moves translations from one namespace to another --- app/models/verification/management/email.rb | 4 ++-- config/locales/management.en.yml | 3 +++ config/locales/management.es.yml | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/verification/management/email.rb b/app/models/verification/management/email.rb index 9863b05d6..5b7593673 100644 --- a/app/models/verification/management/email.rb +++ b/app/models/verification/management/email.rb @@ -45,10 +45,10 @@ class Verification::Management::Email return if errors.count > 0 errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user? if already_verified? - errors.add(:email, I18n.t('management.users.already_verified')) + errors.add(:email, I18n.t('management.email_verifications.already_verified')) elsif document_number_mismatch? errors.add(:email, - I18n.t('management.users.document_mismatch', + I18n.t('management.email_verifications.document_mismatch', document_type: ApplicationController.helpers.humanize_document_type(user.document_type), document_number: user.document_number)) end diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index b63d1c648..d0084264b 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -18,6 +18,7 @@ en: support_proposals: "Support proposals" vote_proposals: "Vote proposals" document_verifications: + title: "User management" please_check_account_data: "Please check that the account data above are correct." already_verified: "This user account is already verified." in_census_has_following_permissions: "This user can participate in the website with the following permissions:" @@ -33,3 +34,5 @@ en: send_email: "Send verification email" email_sent_instructions: "In order to completely verify this user, it is necessary that the user clicks on a link which we have sent to the email address above. This step is needed in order to confirm that the address belongs to him." if_no_existing_account: "If this person has not created an account yet" + document_mismatch: "This email belongs to a user which already has an associated id: %{document_number}(%{document_type})" + already_verified: "This user account is already verified." diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 92cb9a43c..68581a906 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -19,6 +19,7 @@ es: support_proposals: "Apoyar propuestas" vote_proposals: "Participar en las votaciones finales" document_verifications: + title: "Gestión de usuarios" please_check_account_data: "Compruebe que los datos anteriores son correctos para proceder a verificar la cuenta completamente." already_verified: "Esta cuenta de usuario ya está verificada." in_census_has_following_permissions: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" @@ -41,6 +42,7 @@ es: document_mismatch: "Ese email corresponde a un usuario que ya tiene asociado el documento %{document_number}(%{document_type})" + already_verified: "Esta cuenta de usuario ya está verificada." create_user: "Crear nueva cuenta de usuario" create_user_info: "Procedemos a crear un usuario con la siguiente información:" create_user_submit: "Crear usuario" From 6cfb23bc40fa652b875286afa27fe0c92328ee90 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Oct 2015 19:45:09 +0200 Subject: [PATCH 28/43] Fixes typo --- app/views/management/email_verifications/new.html.erb | 2 +- config/locales/management.es.yml | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/views/management/email_verifications/new.html.erb b/app/views/management/email_verifications/new.html.erb index 4b8b0130b..52e20a525 100644 --- a/app/views/management/email_verifications/new.html.erb +++ b/app/views/management/email_verifications/new.html.erb @@ -22,7 +22,7 @@
    • - <%= t("management.emails_verifications.if_no_existing_account") %> + <%= t("management.email_verifications.if_no_existing_account") %>

      <%= t("management.print_info") %> diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 68581a906..ad6550552 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -35,19 +35,14 @@ es: send_email: "Enviar email de verificación" if_no_existing_account: "Si la persona todavía no ha creado una cuenta de usuario en la web" email_sent_instructions: "Para terminar de verificar esta cuenta es necesario que haga clic en el enlace que le hemos enviado a la dirección de correo que figura arriba. Este paso es necesario para confirmar que dicha cuenta de usuario es suya." - - - users: - title: "Gestionar usuario" - - document_mismatch: "Ese email corresponde a un usuario que ya tiene asociado el documento %{document_number}(%{document_type})" already_verified: "Esta cuenta de usuario ya está verificada." + users: create_user: "Crear nueva cuenta de usuario" create_user_info: "Procedemos a crear un usuario con la siguiente información:" create_user_submit: "Crear usuario" create_user_success_html: "Le hemos mandado un correo electrónico a la dirección de correo anterior para verificar que es suya. - Le recomendamos cambiar la contraseña en su primer uso. Para ello entre en %{url} con su usuario y contraseña, + Le recomendamos cambiar la contraseña en su primer uso. Para ello entre en %{link} con su usuario y contraseña, acceda a la sección 'Mi cuenta' y haga clic en el botón 'Cambiar datos de acceso'" From b6aaad87af41ca24d52849db71b28500609a6504 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Oct 2015 20:18:17 +0200 Subject: [PATCH 29/43] Adds a user controller for management --- app/models/user.rb | 7 +++ .../document_verifications/index.html.erb | 2 +- .../email_verifications/new.html.erb | 2 +- app/views/management/users/new.html.erb | 25 +++++++++++ app/views/management/users/show.html.erb | 9 ++++ config/locales/management.en.yml | 8 ++++ config/routes.rb | 2 + spec/features/management/users_spec.rb | 45 +++++++++++++++++++ 8 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 app/views/management/users/new.html.erb create mode 100644 app/views/management/users/show.html.erb create mode 100644 spec/features/management/users_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb index 80e2de195..f5a05e3ba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,6 +35,8 @@ class User < ActiveRecord::Base accepts_nested_attributes_for :organization, update_only: true + attr_accessor :skip_password_validation + scope :administrators, -> { joins(:administrators) } scope :moderators, -> { joins(:moderator) } scope :organizations, -> { joins(:organization) } @@ -162,6 +164,11 @@ class User < ActiveRecord::Base sign_in_count == 1 && unverified? && !organization && !administrator? end + def password_required? + return false if skip_password_validation + super + end + private def validate_username_length diff --git a/app/views/management/document_verifications/index.html.erb b/app/views/management/document_verifications/index.html.erb index d87b83b06..20d7724b4 100644 --- a/app/views/management/document_verifications/index.html.erb +++ b/app/views/management/document_verifications/index.html.erb @@ -1,4 +1,4 @@ -

      <%= t("management.users.title") %>

      +

      <%= t("management.document_verifications.title") %>

      diff --git a/app/views/management/email_verifications/new.html.erb b/app/views/management/email_verifications/new.html.erb index 52e20a525..b8094a2b1 100644 --- a/app/views/management/email_verifications/new.html.erb +++ b/app/views/management/email_verifications/new.html.erb @@ -25,7 +25,7 @@ <%= t("management.email_verifications.if_no_existing_account") %>

      - <%= t("management.print_info") %> + <%= link_to t('management.users.create_user'), new_management_user_path(user: params[:email_verification]), class: "button warning radius" %>

    diff --git a/app/views/management/users/new.html.erb b/app/views/management/users/new.html.erb new file mode 100644 index 000000000..1188b7872 --- /dev/null +++ b/app/views/management/users/new.html.erb @@ -0,0 +1,25 @@ +<%= render 'management/account_info.html', account: @user %> + +

    <%= t("management.users.create_user_info") %>

    + +<%= render 'management/user_permissions', + message: t("management.document_verifications.in_census_has_following_permissions"), + permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %> + +
    +
    + <%= form_for @user, url: management_users_path do |f| %> + <%= f.hidden_field :document_type %> + <%= f.hidden_field :document_number %> + <%= f.text_field :username, + label: t('management.username_label'), + placeholder: t('management.username_label') %> + <%= f.text_field :email, + label: t('management.email_label'), + placeholder: t('management.email_label') %> + + <%= f.submit t("management.users.create_user_submit"), class: "button success radius" %> + <% end %> +
    +
    + diff --git a/app/views/management/users/show.html.erb b/app/views/management/users/show.html.erb new file mode 100644 index 000000000..ce4257bea --- /dev/null +++ b/app/views/management/users/show.html.erb @@ -0,0 +1,9 @@ +<%= render 'management/account_info.html', account: @user %> + +

    <%= t("management.users.create_user_success_html", + link: link_to("http://decide.madrid.es", "http://decide.madrid.es", target: "_blank")) %> +

    + +<%= render 'management/user_permissions', + message: t("management.document_verifications.in_census_has_following_permissions"), + permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %> diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index d0084264b..1d7f64a30 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -36,3 +36,11 @@ en: if_no_existing_account: "If this person has not created an account yet" document_mismatch: "This email belongs to a user which already has an associated id: %{document_number}(%{document_type})" already_verified: "This user account is already verified." + users: + create_user: "Create a new account" + create_user_info: "We will create an account with the following data:" + create_user_submit: "Create user" + create_user_success_html: + "We have sent an email to the email address used to create the account in order to verify that it belongs to him. + We recommend changing the password on the first login. In order to do that go to %{link} with your user and password, + and enter the 'My account / Change access data' section" diff --git a/config/routes.rb b/config/routes.rb index 50d8283d2..c4828414b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -173,6 +173,8 @@ Rails.application.routes.draw do end resources :email_verifications, only: [:new, :create] + + resources :users, only: [:new, :create] end # Example of regular route: diff --git a/spec/features/management/users_spec.rb b/spec/features/management/users_spec.rb new file mode 100644 index 000000000..9b648f6ee --- /dev/null +++ b/spec/features/management/users_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +feature 'users' do + + scenario 'Creating a level 3 user from scratch' do + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: '1234' + click_button 'Check' + + expect(page).to have_content "Please introduce the email used on the account" + + click_link 'Create a new account' + + fill_in 'user_username', with: 'pepe' + fill_in 'user_email', with: 'pepe@gmail.com' + + click_button 'Create user' + + expect(page).to have_content "We have sent an email" + + user = User.find_by_email('pepe@gmail.com') + + expect(user).to be_level_three_verified + expect(user).to be_residence_verified + expect(user).to_not be_confirmed + + sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] + visit user_confirmation_path(confirmation_token: sent_token) + + expect(page).to have_content "Confirming the account with email" + + fill_in 'user_password', with: '12345678' + fill_in 'user_password_confirmation', with: '12345678' + + click_button 'Confirm' + + expect(user.reload).to be_confirmed + + expect(page).to have_content "Your email address has been successfully confirmed." + end +end + + + From 5f74528f12eee58549cc1791546014cb0d7941d3 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Oct 2015 20:18:54 +0200 Subject: [PATCH 30/43] Modifies devise so that unconfirmed users w/o password can set it when confirming their account --- .../management/users_controller.rb | 25 +++++++++++ .../users/confirmations_controller.rb | 45 +++++++++++++++++++ app/views/devise/confirmations/new.html.erb | 15 +++++-- app/views/devise/confirmations/show.html.erb | 34 ++++++++++++++ config/locales/activerecord.en.yml | 6 +++ config/locales/activerecord.es.yml | 6 +++ config/locales/devise_views.en.yml | 14 ++++-- config/locales/devise_views.es.yml | 14 ++++-- config/routes.rb | 6 +++ 9 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 app/controllers/management/users_controller.rb create mode 100644 app/controllers/users/confirmations_controller.rb create mode 100644 app/views/devise/confirmations/show.html.erb diff --git a/app/controllers/management/users_controller.rb b/app/controllers/management/users_controller.rb new file mode 100644 index 000000000..bb6766c70 --- /dev/null +++ b/app/controllers/management/users_controller.rb @@ -0,0 +1,25 @@ +class Management::UsersController < Management::BaseController + def new + @user = User.new(user_params) + end + + def create + @user = User.new(user_params) + @user.skip_password_validation = true + @user.terms_of_service = '1' + @user.residence_verified_at = Time.now + @user.verified_at = Time.now + + if @user.save then + render :show + else + render :new + end + end + + private + + def user_params + params.require(:user).permit(:document_type, :document_number, :username, :email) + end +end diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb new file mode 100644 index 000000000..484cdcd7a --- /dev/null +++ b/app/controllers/users/confirmations_controller.rb @@ -0,0 +1,45 @@ +class Users::ConfirmationsController < Devise::ConfirmationsController + + # PATCH /resource/confirmation + def update + self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token]) + + if resource.encrypted_password.blank? + resource.assign_attributes(resource_params) + + if resource.valid? # password is set correctly + resource.save + resource.confirm + set_flash_message(:notice, :confirmed) if is_flashing_format? + sign_in_and_redirect(resource_name, resource) + else + render :show + end + else + resource.errors.add(:email, :password_already_set) + respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new } + end + end + + # GET /resource/confirmation?confirmation_token=abcdef + def show + self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token]) + + if resource.encrypted_password.blank? + respond_with_navigational(resource){ render :show } + elsif resource.errors.empty? + resource.confirm + set_flash_message(:notice, :confirmed) if is_flashing_format? + respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } + else + respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new } + end + end + + protected + + def resource_params + params.require(resource_name).permit(:password, :password_confirmation) + end + +end diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index 722609134..f552272e2 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -1,16 +1,23 @@ -<% provide :title do %><%= t("devise_views.confirmations.title") %><% end %> -

    <%= t("devise_views.confirmations.title") %>

    +<% provide :title do %><%= t("devise_views.confirmations.new.title") %><% end %> +

    <%= t("devise_views.confirmations.new.title") %>

    <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> <%= render 'shared/errors', resource: resource %>
    - <%= f.email_field :email, autofocus: true, placeholder: t("devise_views.confirmations.email_label"), value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> + <%= f.email_field :email, autofocus: true, placeholder: t("devise_views.confirmations.new.email_label"), value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
    + <% if @requires_password %> +

    <%= f.password_field :password %>

    +

    <%= f.password_field :password_confirmation %>

    + <% end %> + + <%= hidden_field_tag :confirmation_token,@confirmation_token %> +
    - <%= f.submit(t("devise_views.confirmations.submit"), class: "button radius expand") %> + <%= f.submit(t("devise_views.confirmations.new.submit"), class: "button radius expand") %>
    <% end %> diff --git a/app/views/devise/confirmations/show.html.erb b/app/views/devise/confirmations/show.html.erb new file mode 100644 index 000000000..88a3a6292 --- /dev/null +++ b/app/views/devise/confirmations/show.html.erb @@ -0,0 +1,34 @@ +<% provide :title do %><%= t("devise_views.confirmations.show.title") %><% end %> +

    <%= t("devise_views.confirmations.show.title") %>

    + +

    <%= t('devise_views.confirmations.show.instructions_html', email: resource.email) %>

    + +<%= form_for(resource, + as: resource_name, + url: update_user_confirmation_path, + html: { method: :patch }) do |f| %> + +

    <%= t('devise_views.confirmations.show.please_set_password') %>

    + + <%= render 'shared/errors', resource: resource %> + +
    +
    + <%= f.password_field :password, + autofocus: true, + label: t('devise_views.confirmations.show.new_password_label') %> +
    +
    + <%= f.password_field :password_confirmation, + label: t('devise_views.confirmations.show.new_password_confirmation_label') %> +
    +
    + + <%= hidden_field_tag :confirmation_token, params[:confirmation_token] %> + +
    + <%= f.submit(t("devise_views.confirmations.show.submit"), class: "button radius expand") %> +
    +<% end %> + +<%= render "devise/shared/links" %> diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 303bd5ded..06cb48980 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -1,5 +1,11 @@ en: activerecord: + errors: + models: + user: + attributes: + email: + password_already_set: "This user already has a password" models: activity: Activity comment: Comment diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 3ba5e7cca..89fba981c 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -1,5 +1,11 @@ es: activerecord: + errors: + models: + user: + attributes: + email: + password_already_set: "Este usuario ya tiene una clave asociada" models: activity: one: actividad diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml index 39136e18a..2c04d3ce8 100644 --- a/config/locales/devise_views.en.yml +++ b/config/locales/devise_views.en.yml @@ -1,9 +1,17 @@ en: devise_views: confirmations: - title: "Resend confirmation instructions" - email_label: Email - submit: "Resend confirmation" + new: + title: "Resend confirmation instructions" + email_label: Email + submit: "Resend confirmation" + show: + title: "Confirm my account" + instructions_html: "Confirming the account with email %{email}" + please_set_password: "Please choose your new pasword (it will allow you to login with the email above)" + new_password_label: "New access password" + new_password_confirmation_label: "Repeat access password" + submit: "Confirm" mailer: confirmation_instructions: title: "Welcome to open government portal" diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml index 54e23911c..f2ca13215 100644 --- a/config/locales/devise_views.es.yml +++ b/config/locales/devise_views.es.yml @@ -1,9 +1,17 @@ es: devise_views: confirmations: - title: "Reenviar instrucciones de confirmación" - email_label: Email - submit: "Reenviar instrucciones" + new: + title: "Reenviar instrucciones de confirmación" + email_label: Email + submit: "Reenviar instrucciones" + show: + title: "Confirmar mi cuenta" + instructions_html: "Vamos a proceder a confirmar la cuenta con el email %{email}" + please_set_password: "Por favor introduce una nueva clave de acceso para su cuenta (te permitirá hacer login con el email de más arriba)" + new_password_label: "Nueva clave de acceso" + new_password_confirmation_label: "Repite la clave de nuevo" + submit: "Confirmar" mailer: confirmation_instructions: title: "Te damos la bienvenida al Portal de Gobierno Abierto del Ayuntamiento de Madrid" diff --git a/config/routes.rb b/config/routes.rb index c4828414b..173f27264 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,13 @@ Rails.application.routes.draw do + + as :user do + match '/user/confirmation' => 'users/confirmations#update', :via => :patch, :as => :update_user_confirmation + end + devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions', + confirmations: 'users/confirmations', omniauth_callbacks: 'users/omniauth_callbacks' } devise_for :organizations, class_name: 'User', From d351daedd435081a36bb459fc3198198dd5ad115 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 8 Oct 2015 15:19:11 +0200 Subject: [PATCH 31/43] Adds document_number-related constraints to User --- app/models/user.rb | 7 +++++++ spec/models/user_spec.rb | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index f5a05e3ba..f652a8f9c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,6 +25,7 @@ class User < ActiveRecord::Base validates :username, presence: true, unless: :organization? validates :username, uniqueness: true, unless: :organization? + validates :document_number, uniqueness: { scope: :document_type }, allow_nil: true validate :validate_username_length validates :official_level, inclusion: {in: 0..5} @@ -44,6 +45,8 @@ class User < ActiveRecord::Base scope :for_render, -> { includes(:organization) } scope :by_document, -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) } + before_validation :clean_document_number + def self.find_for_oauth(auth, signed_in_resource = nil) # Get the identity and user if they exist identity = Identity.find_for_oauth(auth) @@ -171,6 +174,10 @@ class User < ActiveRecord::Base private + def clean_document_number + self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank? + end + def validate_username_length validator = ActiveModel::Validations::LengthValidator.new( attributes: :username, diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 29b239da9..14f20ad1d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -287,4 +287,19 @@ describe User do end + describe "document_number" do + it "should upcase document number" do + user = User.new({document_number: "x1234567z"}) + user.valid? + expect(user.document_number).to eq("X1234567Z") + end + + it "should remove all characters except numbers and letters" do + user = User.new({document_number: " 12.345.678 - B"}) + user.valid? + expect(user.document_number).to eq("12345678B") + end + + end + end From 10de596a94a3b32d56e87dd10bf5442366d4b920 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 8 Oct 2015 15:19:28 +0200 Subject: [PATCH 32/43] Adds missing parameter for confirmations --- app/controllers/users/confirmations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 484cdcd7a..12c8b4eba 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -39,7 +39,7 @@ class Users::ConfirmationsController < Devise::ConfirmationsController protected def resource_params - params.require(resource_name).permit(:password, :password_confirmation) + params.require(resource_name).permit(:password, :password_confirmation, :email) end end From ffe06729c1fe36aba64942a8eee51626a9e38b80 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 8 Oct 2015 15:20:06 +0200 Subject: [PATCH 33/43] Changes message when the user is created by managers --- app/views/management/users/show.html.erb | 4 +--- config/locales/management.en.yml | 6 +++--- config/locales/management.es.yml | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/views/management/users/show.html.erb b/app/views/management/users/show.html.erb index ce4257bea..48e563e36 100644 --- a/app/views/management/users/show.html.erb +++ b/app/views/management/users/show.html.erb @@ -1,8 +1,6 @@ <%= render 'management/account_info.html', account: @user %> -

    <%= t("management.users.create_user_success_html", - link: link_to("http://decide.madrid.es", "http://decide.madrid.es", target: "_blank")) %> -

    +

    <%= t("management.users.create_user_success_html", email: @user.email) %>

    <%= render 'management/user_permissions', message: t("management.document_verifications.in_census_has_following_permissions"), diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 1d7f64a30..b1712018f 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -41,6 +41,6 @@ en: create_user_info: "We will create an account with the following data:" create_user_submit: "Create user" create_user_success_html: - "We have sent an email to the email address used to create the account in order to verify that it belongs to him. - We recommend changing the password on the first login. In order to do that go to %{link} with your user and password, - and enter the 'My account / Change access data' section" + "We have sent an email to the email address %{email} in order to verify that it belongs to this user. + It contains a link they have to click. Then they will have to set their access password before being able + to log in to the website" diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index ad6550552..48a6881a0 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -42,7 +42,7 @@ es: create_user_info: "Procedemos a crear un usuario con la siguiente información:" create_user_submit: "Crear usuario" create_user_success_html: - "Le hemos mandado un correo electrónico a la dirección de correo anterior para verificar que es suya. - Le recomendamos cambiar la contraseña en su primer uso. Para ello entre en %{link} con su usuario y contraseña, - acceda a la sección 'Mi cuenta' y haga clic en el botón 'Cambiar datos de acceso'" + "Hemos enviado un correo electrónico a %{email} para verificar que es suya. + El correo enviado contiene un link que el usuario deberá pulsar. Entonces podrá seleccionar + una clave de acceso, y entrar en la web de participación." From 26072eebeb009aedfe4becde55cb2afcddaff002 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 8 Oct 2015 15:24:21 +0200 Subject: [PATCH 34/43] adds management styles --- app/assets/stylesheets/admin.scss | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 94b128e4c..37fc2291c 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -4,6 +4,7 @@ // 02. Sidebar // 03. List elements // 04. Stats +// 05. Management // // 01. Global styles @@ -272,3 +273,37 @@ body.admin { } } } + +// 05. Management +// - - - - - - - - - - - - - - - - - - - - - - - - - + +.postfix { + height: rem-calc(48); + line-height: rem-calc(48); +} + +.user-permissions { + + ul { + list-style-type: none; + margin-left: 0; + + li { + font-size: rem-calc(14); + margin-bottom: rem-calc(12); + + span { + color: $text-medium; + font-size: rem-calc(12); + } + + .icon-check { + color: $check; + } + + .icon-x { + color: $delete; + } + } + } +} From 4c7dcbed3900b49b202586a954de8ad009ad59e9 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 8 Oct 2015 16:26:41 +0200 Subject: [PATCH 35/43] Fixes welcome specs and adds a couple more tests --- app/controllers/users/sessions_controller.rb | 2 +- spec/features/welcome_spec.rb | 26 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 5fe2c78a3..bbab5371a 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -12,7 +12,7 @@ class Users::SessionsController < Devise::SessionsController def stored_path_allows_welcome_screen? stored_path = session[stored_location_key_for(resource)] - stored_path && stored_path[0..5] != "/email" + stored_path.nil? || stored_path[0..5] != "/email" end end diff --git a/spec/features/welcome_spec.rb b/spec/features/welcome_spec.rb index cef26e035..f75eadd0c 100644 --- a/spec/features/welcome_spec.rb +++ b/spec/features/welcome_spec.rb @@ -10,6 +10,24 @@ feature "Welcome screen" do expect(current_path).to eq(welcome_path) end + scenario 'a regular user does not see it when coing to /email' do + + plain, encrypted = Devise.token_generator.generate(User, :email_verification_token) + + user = create(:user, email_verification_token: plain) + + visit email_path(email_verification_token: encrypted) + + fill_in 'user_email', with: user.email + fill_in 'user_password', with: user.password + + click_button 'Log in' + + expect(page).to have_content("You are now a verified user") + + expect(current_path).to eq(account_path) + end + scenario 'it is not shown more than once' do user = create(:user, sign_in_count: 2) @@ -42,4 +60,12 @@ feature "Welcome screen" do expect(current_path).to eq(proposals_path) end + scenario 'is not shown to administrators' do + administrator = create(:administrator) + + login_through_form_as(administrator.user) + + expect(current_path).to eq(proposals_path) + end + end From 37592d8fa52a5224747ddb3cfb0aec70512abd66 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 8 Oct 2015 17:19:29 +0200 Subject: [PATCH 36/43] Fixes i18n failures --- app/views/management/_menu.html.erb | 7 ++++--- config/locales/mailers.en.yml | 2 +- config/locales/management.en.yml | 4 ++-- config/locales/management.es.yml | 5 ++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/views/management/_menu.html.erb b/app/views/management/_menu.html.erb index dd0558e83..6493f8a66 100644 --- a/app/views/management/_menu.html.erb +++ b/app/views/management/_menu.html.erb @@ -1,14 +1,15 @@