sends invitation email to users

This commit is contained in:
rgarcia
2016-06-27 23:31:47 +02:00
parent 0bb948a013
commit 745de9bb77
11 changed files with 65 additions and 15 deletions

View File

@@ -4,6 +4,10 @@ class Management::UserInvitesController < Management::BaseController
end end
def create def create
@emails = params[:emails].split
@emails.each do |email|
Mailer.user_invite(email).deliver_later
end
end end
end end

View File

@@ -68,6 +68,10 @@ class Mailer < ApplicationMailer
end end
end end
def user_invite(email)
mail(to: email, subject: t('mailers.user_invite.subject', org_name: Setting["org_name"]))
end
private private
def with_user(user, &block) def with_user(user, &block)

View File

@@ -1,23 +1,23 @@
<td style="padding-bottom: 20px; padding-left: 10px;"> <td style="padding-bottom: 20px; padding-left: 10px;">
<h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;"> <h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;">
<%= t('mailers.user_invites.title', <%= t('mailers.user_invite.title',
org: Setting['org_name']) %> org: Setting['org_name']) %>
</h1> </h1>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;"> <p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.user_invites.text', <%= t('mailers.user_invite.text',
org: Setting['org_name']) %> org: Setting['org_name']) %>
</p> </p>
<p style="text-align: center;"> <p style="text-align: center;">
<%= 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;" %>
</p> </p>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;"> <p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.user_invites.ignore') %> <%= t('mailers.user_invite.ignore') %>
</p> </p>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;"> <p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.user_invites.thanks') %> <%= t('mailers.user_invite.thanks') %>
</p> </p>
</td> </td>

View File

@@ -4,6 +4,6 @@
<h1><%= t('management.user_invites.create.title') %></h1> <h1><%= t('management.user_invites.create.title') %></h1>
<div class="callout success"> <div class="callout success">
<%= t('management.user_invites.create.success_html') %> <%= t('management.user_invites.create.success_html', count: @emails.count) %>
</div> </div>
</div> </div>

View File

@@ -1,12 +1,12 @@
<div class="small-12 medium-8 column"> <div class="small-12 medium-8 column">
<h1><%= t('management.user_invites.new.title') %></h1> <h1><%= t('management.user_invites.new.title') %></h1>
<form> <%= form_tag management_user_invites_path do %>
<label><%= t('management.user_invites.new.label') %></label> <label><%= t('management.user_invites.new.label') %></label>
<p class="note"><%= t('management.user_invites.new.info') %></p> <p class="note"><%= t('management.user_invites.new.info') %></p>
<textarea placeholder="<%= t('management.user_invites.new.info') %>" rows="5"></textarea> <%= text_area_tag "emails", nil, rows: 5, placeholder: t('management.user_invites.new.info') %>
<div class="small-12 medium-6"> <div class="small-12 medium-6">
<input type="submit" name="" value="<%= t('management.user_invites.new.submit') %>", class="button hollow expanded"> <input type="submit" name="" value="<%= t('management.user_invites.new.submit') %>", class="button hollow expanded">
</div> </div>
</form> <% end %>
</div> </div>

View File

@@ -46,9 +46,10 @@ en:
direct_message_for_sender: direct_message_for_sender:
subject: "You have send a new private message" subject: "You have send a new private message"
title_html: "You have send a new private message to <strong>%{receiver}</strong> with the content:" title_html: "You have send a new private message to <strong>%{receiver}</strong> with the content:"
user_invites: user_invite:
ignore: "If you have not requested this invitation don't worry, you can ignore this email." 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:" 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." thanks: "Thank you very much."
title: "Welcome to %{org}" title: "Welcome to %{org}"
button: Complete registration button: Complete registration
subject: "Invitation to %{org_name}"

View File

@@ -46,9 +46,10 @@ es:
direct_message_for_sender: direct_message_for_sender:
subject: "Has enviado un nuevo mensaje privado" subject: "Has enviado un nuevo mensaje privado"
title_html: "Has enviado un nuevo mensaje privado a <strong>%{receiver}</strong> con el siguiente contenido:" title_html: "Has enviado un nuevo mensaje privado a <strong>%{receiver}</strong> con el siguiente contenido:"
user_invites: user_invite:
ignore: "Si no has solicitado esta invitación no te preocupes, puedes ignorar este correo." 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:" 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." thanks: "Muchas gracias."
title: "Bienvenido a %{org}" title: "Bienvenido a %{org}"
button: Completar registro button: Completar registro
subject: "Invitación a %{org_name}"

View File

@@ -104,5 +104,5 @@ en:
submit: Send invites submit: Send invites
title: User's invites title: User's invites
create: create:
success_html: <strong>COUNT invitations</strong> have been sent. success_html: <strong>%{count} invitations</strong> have been sent.
title: User's invites title: User's invites

View File

@@ -104,5 +104,5 @@ es:
submit: Enviar invitaciones submit: Enviar invitaciones
title: Invitaciones para usuarios title: Invitaciones para usuarios
create: create:
success_html: Se han enviado <strong>COUNT invitaciones</strong>. success_html: Se han enviado <strong>%{count} invitaciones</strong>.
title: Invitaciones para usuarios title: Invitaciones para usuarios

View File

@@ -231,4 +231,26 @@ feature 'Emails' do
end 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 end

View File

@@ -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