From 947b2bcb0d87375e2d06dfc214154d2cd9497086 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 27 Jun 2016 14:25:20 +0200 Subject: [PATCH 1/5] Adds user invites views on management --- .../management/user_invites_controller.rb | 9 +++++++++ app/views/management/_menu.html.erb | 11 +++++++---- app/views/management/user_invites/create.html.erb | 9 +++++++++ app/views/management/user_invites/new.html.erb | 12 ++++++++++++ config/locales/management.en.yml | 11 ++++++++++- config/locales/management.es.yml | 11 ++++++++++- config/routes.rb | 2 ++ 7 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 app/controllers/management/user_invites_controller.rb create mode 100644 app/views/management/user_invites/create.html.erb create mode 100644 app/views/management/user_invites/new.html.erb diff --git a/app/controllers/management/user_invites_controller.rb b/app/controllers/management/user_invites_controller.rb new file mode 100644 index 000000000..707759877 --- /dev/null +++ b/app/controllers/management/user_invites_controller.rb @@ -0,0 +1,9 @@ +class Management::UserInvitesController < Management::BaseController + + def new + end + + def create + end + +end diff --git a/app/views/management/_menu.html.erb b/app/views/management/_menu.html.erb index 00e3b0516..aa154212e 100644 --- a/app/views/management/_menu.html.erb +++ b/app/views/management/_menu.html.erb @@ -1,9 +1,5 @@
diff --git a/app/views/management/user_invites/create.html.erb b/app/views/management/user_invites/create.html.erb new file mode 100644 index 000000000..def83ef15 --- /dev/null +++ b/app/views/management/user_invites/create.html.erb @@ -0,0 +1,9 @@ +
+ <%= render 'shared/back_link' %> + +

<%= t('management.user_invites.create.title') %>

+ +
+ <%= t('management.user_invites.create.success_html') %> +
+
diff --git a/app/views/management/user_invites/new.html.erb b/app/views/management/user_invites/new.html.erb new file mode 100644 index 000000000..2779648d2 --- /dev/null +++ b/app/views/management/user_invites/new.html.erb @@ -0,0 +1,12 @@ +
+

<%= t('management.user_invites.new.title') %>

+ +
+ +

<%= t('management.user_invites.new.info') %>

+ +
+ +
+
+
diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 74a58ac26..8060ac2c5 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -49,9 +49,9 @@ en: create_spending_proposal: Create spending proposal print_spending_proposals: Print spending proposals support_spending_proposals: Support spending proposals - title: Management users: Users edit_user_accounts: Edit user account + user_invites: User's invites permissions: create_proposals: Create proposals debates: Engage in debates @@ -97,3 +97,12 @@ en: erase_account_confirm: Are you sure you want to erase the account? This action can not be undone erase_warning: This action can not be undone. Please make sure you want to erase this account. erase_submit: Delete account + user_invites: + new: + label: Emails + info: "Enter the emails separated by commas (',')" + submit: Send invites + title: User's invites + create: + success_html: COUNT invitations have been sent. + title: User's invites \ No newline at end of file diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index c4545e675..749a7f449 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -49,9 +49,9 @@ es: create_spending_proposal: Crear propuesta de inversión print_spending_proposals: Imprimir propts. de inversión support_spending_proposals: Apoyar propts. de inversión - title: Gestión users: Usuarios edit_user_accounts: Editar cuenta de usuario + user_invites: Invitaciones para usuarios permissions: create_proposals: Crear nuevas propuestas debates: Participar en debates @@ -97,3 +97,12 @@ es: erase_account_confirm: ¿Seguro que quieres borrar a este usuario? Esta acción no se puede deshacer erase_warning: Esta acción no se puede deshacer. Por favor asegurese de que quiere eliminar esta cuenta. erase_submit: Borrar cuenta + user_invites: + new: + label: Emails + info: "Introduce los emails separados por ','" + submit: Enviar invitaciones + title: Invitaciones para usuarios + create: + success_html: Se han enviado COUNT invitaciones. + title: Invitaciones para usuarios \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ed2ee34e4..37497268c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -235,6 +235,8 @@ Rails.application.routes.draw do resources :email_verifications, only: [:new, :create] + resources :user_invites, only: [:new, :create] + resources :users, only: [:new, :create] do collection do delete :logout From a2a2960867a58cc755dfb0cf8457e3af4662edac Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 27 Jun 2016 15:37:45 +0200 Subject: [PATCH 2/5] Adds mailer template for user invites --- app/views/mailer/user_invites.html.erb | 22 ++++++++++++++++++++++ config/locales/mailers.en.yml | 8 +++++++- config/locales/mailers.es.yml | 8 +++++++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 app/views/mailer/user_invites.html.erb diff --git a/app/views/mailer/user_invites.html.erb b/app/views/mailer/user_invites.html.erb new file mode 100644 index 000000000..3510a6c88 --- /dev/null +++ b/app/views/mailer/user_invites.html.erb @@ -0,0 +1,22 @@ + +

+ <%= t('mailers.user_invites.title', + org: Setting['org_name']) %> +

+ +

+ <%= t('mailers.user_invites.text') %> +

+ +

+ <%= link_to t('mailers.user_invites.button'), new_user_registration_path, style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #004A83; border-radius: 6px; color: #fff !important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block; margin-left: 12px;" %> +

+ +

+ <%= t('mailers.user_invites.ignore') %> +

+ +

+ <%= t('mailers.user_invites.thanks') %> +

+ diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 17e3f6cf8..e17ccc68b 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -45,4 +45,10 @@ en: unsubscribe_account: My account direct_message_for_sender: subject: "You have send a new private message" - title_html: "You have send a new private message to %{receiver} with the content:" \ No newline at end of file + title_html: "You have send a new private message to %{receiver} with the content:" + user_invites: + ignore: "Please, if you have not requested this invite ignore this email." + text: "To start participating complete your registration in the Open Government Portal of the Madrid City Council." + thanks: "Thank you very much." + title: "Complete your registration in %{org}" + button: Complete registration \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 2a7a85013..48eade29f 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -45,4 +45,10 @@ es: unsubscribe_account: Mi cuenta direct_message_for_sender: subject: "Has enviado un nuevo mensaje privado" - title_html: "Has enviado un nuevo mensaje privado a %{receiver} con el siguiente contenido:" \ No newline at end of file + title_html: "Has enviado un nuevo mensaje privado a %{receiver} con el siguiente contenido:" + user_invites: + ignore: "Por favor, si no has solicitado esta invitación ignora este email." + text: "Para empezar a participar completa tu registro en el Portal de Gobierno Abierto del Ayuntamiento de Madrid." + thanks: "Muchas gracias." + title: "Completa tu registro en %{org}" + button: Completar registro \ No newline at end of file From 0bb948a0135e4583dd650b21a7c9cbf37492eff2 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 27 Jun 2016 16:01:03 +0200 Subject: [PATCH 3/5] Updates mailer texts --- app/views/mailer/user_invites.html.erb | 3 ++- config/locales/mailers.en.yml | 6 +++--- config/locales/mailers.es.yml | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/views/mailer/user_invites.html.erb b/app/views/mailer/user_invites.html.erb index 3510a6c88..6d02022d3 100644 --- a/app/views/mailer/user_invites.html.erb +++ b/app/views/mailer/user_invites.html.erb @@ -5,7 +5,8 @@

- <%= t('mailers.user_invites.text') %> + <%= t('mailers.user_invites.text', + org: Setting['org_name']) %>

diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index e17ccc68b..6a14540be 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -47,8 +47,8 @@ en: subject: "You have send a new private message" title_html: "You have send a new private message to %{receiver} with the content:" user_invites: - ignore: "Please, if you have not requested this invite ignore this email." - text: "To start participating complete your registration in the Open Government Portal of the Madrid City Council." + ignore: "If you have not requested this invitation don't worry, you can ignore this email." + text: "Thank you for applying to join %{org}! In seconds you can start to decide the city you want, just fill the form below:" thanks: "Thank you very much." - title: "Complete your registration in %{org}" + title: "Welcome to %{org}" button: Complete registration \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 48eade29f..86d591134 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -47,8 +47,8 @@ es: subject: "Has enviado un nuevo mensaje privado" title_html: "Has enviado un nuevo mensaje privado a %{receiver} con el siguiente contenido:" user_invites: - ignore: "Por favor, si no has solicitado esta invitación ignora este email." - text: "Para empezar a participar completa tu registro en el Portal de Gobierno Abierto del Ayuntamiento de Madrid." + ignore: "Si no has solicitado esta invitación no te preocupes, puedes ignorar este correo." + text: "¡Gracias por solicitar unirte a %{org}! En unos segundos podrás empezar a decidir la ciudad que quieres, sólo tienes que rellenar el siguiente formulario:" thanks: "Muchas gracias." - title: "Completa tu registro en %{org}" + title: "Bienvenido a %{org}" button: Completar registro \ No newline at end of file From 745de9bb7775686d721956212c62936e07fd65e6 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 27 Jun 2016 23:31:47 +0200 Subject: [PATCH 4/5] sends invitation email to users --- .../management/user_invites_controller.rb | 4 ++++ app/mailers/mailer.rb | 4 ++++ ..._invites.html.erb => user_invite.html.erb} | 10 ++++----- .../management/user_invites/create.html.erb | 2 +- .../management/user_invites/new.html.erb | 6 ++--- config/locales/mailers.en.yml | 5 +++-- config/locales/mailers.es.yml | 5 +++-- config/locales/management.en.yml | 2 +- config/locales/management.es.yml | 2 +- spec/features/emails_spec.rb | 22 +++++++++++++++++++ spec/features/user_invites_spec.rb | 18 +++++++++++++++ 11 files changed, 65 insertions(+), 15 deletions(-) rename app/views/mailer/{user_invites.html.erb => user_invite.html.erb} (55%) create mode 100644 spec/features/user_invites_spec.rb diff --git a/app/controllers/management/user_invites_controller.rb b/app/controllers/management/user_invites_controller.rb index 707759877..b022e6a86 100644 --- a/app/controllers/management/user_invites_controller.rb +++ b/app/controllers/management/user_invites_controller.rb @@ -4,6 +4,10 @@ class Management::UserInvitesController < Management::BaseController end def create + @emails = params[:emails].split + @emails.each do |email| + Mailer.user_invite(email).deliver_later + end end end diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index d987e34cc..55229ab72 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -68,6 +68,10 @@ class Mailer < ApplicationMailer end end + def user_invite(email) + mail(to: email, subject: t('mailers.user_invite.subject', org_name: Setting["org_name"])) + end + private def with_user(user, &block) diff --git a/app/views/mailer/user_invites.html.erb b/app/views/mailer/user_invite.html.erb similarity index 55% rename from app/views/mailer/user_invites.html.erb rename to app/views/mailer/user_invite.html.erb index 6d02022d3..43b95626c 100644 --- a/app/views/mailer/user_invites.html.erb +++ b/app/views/mailer/user_invite.html.erb @@ -1,23 +1,23 @@

- <%= t('mailers.user_invites.title', + <%= t('mailers.user_invite.title', org: Setting['org_name']) %>

- <%= t('mailers.user_invites.text', + <%= t('mailers.user_invite.text', org: Setting['org_name']) %>

- <%= link_to t('mailers.user_invites.button'), new_user_registration_path, style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #004A83; border-radius: 6px; color: #fff !important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block; margin-left: 12px;" %> + <%= link_to t('mailers.user_invite.button'), new_user_registration_url, style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #004A83; border-radius: 6px; color: #fff !important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block; margin-left: 12px;" %>

- <%= t('mailers.user_invites.ignore') %> + <%= t('mailers.user_invite.ignore') %>

- <%= t('mailers.user_invites.thanks') %> + <%= t('mailers.user_invite.thanks') %>

diff --git a/app/views/management/user_invites/create.html.erb b/app/views/management/user_invites/create.html.erb index def83ef15..3d573532f 100644 --- a/app/views/management/user_invites/create.html.erb +++ b/app/views/management/user_invites/create.html.erb @@ -4,6 +4,6 @@

<%= t('management.user_invites.create.title') %>

- <%= t('management.user_invites.create.success_html') %> + <%= t('management.user_invites.create.success_html', count: @emails.count) %>
diff --git a/app/views/management/user_invites/new.html.erb b/app/views/management/user_invites/new.html.erb index 2779648d2..a49a84538 100644 --- a/app/views/management/user_invites/new.html.erb +++ b/app/views/management/user_invites/new.html.erb @@ -1,12 +1,12 @@

<%= t('management.user_invites.new.title') %>

-
+ <%= form_tag management_user_invites_path do %>

<%= t('management.user_invites.new.info') %>

- + <%= text_area_tag "emails", nil, rows: 5, placeholder: t('management.user_invites.new.info') %>
-
+ <% end %>
diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 6a14540be..9362b3202 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -46,9 +46,10 @@ en: direct_message_for_sender: subject: "You have send a new private message" title_html: "You have send a new private message to %{receiver} with the content:" - user_invites: + user_invite: ignore: "If you have not requested this invitation don't worry, you can ignore this email." text: "Thank you for applying to join %{org}! In seconds you can start to decide the city you want, just fill the form below:" thanks: "Thank you very much." title: "Welcome to %{org}" - button: Complete registration \ No newline at end of file + button: Complete registration + subject: "Invitation to %{org_name}" \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 86d591134..75523cf6c 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -46,9 +46,10 @@ es: direct_message_for_sender: subject: "Has enviado un nuevo mensaje privado" title_html: "Has enviado un nuevo mensaje privado a %{receiver} con el siguiente contenido:" - user_invites: + user_invite: ignore: "Si no has solicitado esta invitación no te preocupes, puedes ignorar este correo." text: "¡Gracias por solicitar unirte a %{org}! En unos segundos podrás empezar a decidir la ciudad que quieres, sólo tienes que rellenar el siguiente formulario:" thanks: "Muchas gracias." title: "Bienvenido a %{org}" - button: Completar registro \ No newline at end of file + button: Completar registro + subject: "Invitación a %{org_name}" \ No newline at end of file diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 8060ac2c5..a0fffbde4 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -104,5 +104,5 @@ en: submit: Send invites title: User's invites create: - success_html: COUNT invitations have been sent. + success_html: %{count} invitations have been sent. title: User's invites \ No newline at end of file diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 749a7f449..e5ee1c074 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -104,5 +104,5 @@ es: submit: Enviar invitaciones title: Invitaciones para usuarios create: - success_html: Se han enviado COUNT invitaciones. + success_html: Se han enviado %{count} invitaciones. title: Invitaciones para usuarios \ No newline at end of file diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index f793b5bb7..dcc90ca27 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -231,4 +231,26 @@ feature 'Emails' do end + context "User invites" do + + scenario "Send an invitation" do + login_as_manager + visit new_management_user_invite_path + + fill_in "emails", with: "john@example.com, ana@example.com, isable@example.com" + click_button "Send invites" + + expect(page).to have_content "3 invitations have been sent." + + expect(unread_emails_for("john@example.com").count).to eq 1 + expect(unread_emails_for("ana@example.com").count).to eq 1 + expect(unread_emails_for("isable@example.com").count).to eq 1 + + email = open_last_email + expect(email).to have_subject("Invitation to Consul") + expect(email).to have_body_text(/#{new_user_registration_path}/) + end + + end + end diff --git a/spec/features/user_invites_spec.rb b/spec/features/user_invites_spec.rb new file mode 100644 index 000000000..5627b0b7e --- /dev/null +++ b/spec/features/user_invites_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +feature 'User invites' do + + background do + login_as_manager + end + + scenario "Send invitations" do + visit new_management_user_invite_path + + fill_in "emails", with: "john@example.com, ana@example.com, isable@example.com" + click_button "Send invites" + + expect(page).to have_content "3 invitations have been sent." + end + +end \ No newline at end of file From ad1720ba02ab7248f36c7924872e14c7cce1bcd2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 27 Jun 2016 23:38:23 +0200 Subject: [PATCH 5/5] uses applications's default locale --- app/mailers/mailer.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 55229ab72..ad87359af 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -69,7 +69,9 @@ class Mailer < ApplicationMailer end def user_invite(email) - mail(to: email, subject: t('mailers.user_invite.subject', org_name: Setting["org_name"])) + I18n.with_locale(I18n.default_locale) do + mail(to: email, subject: t('mailers.user_invite.subject', org_name: Setting["org_name"])) + end end private