Merge pull request #1166 from consul/management-invitations
Management invitations
This commit is contained in:
13
app/controllers/management/user_invites_controller.rb
Normal file
13
app/controllers/management/user_invites_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Management::UserInvitesController < Management::BaseController
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
@emails = params[:emails].split
|
||||
@emails.each do |email|
|
||||
Mailer.user_invite(email).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -68,6 +68,12 @@ class Mailer < ApplicationMailer
|
||||
end
|
||||
end
|
||||
|
||||
def user_invite(email)
|
||||
I18n.with_locale(I18n.default_locale) do
|
||||
mail(to: email, subject: t('mailers.user_invite.subject', org_name: Setting["org_name"]))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def with_user(user, &block)
|
||||
|
||||
23
app/views/mailer/user_invite.html.erb
Normal file
23
app/views/mailer/user_invite.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<td style="padding-bottom: 20px; padding-left: 10px;">
|
||||
<h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;">
|
||||
<%= t('mailers.user_invite.title',
|
||||
org: Setting['org_name']) %>
|
||||
</h1>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t('mailers.user_invite.text',
|
||||
org: Setting['org_name']) %>
|
||||
</p>
|
||||
|
||||
<p style="text-align: center;">
|
||||
<%= 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 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t('mailers.user_invite.ignore') %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t('mailers.user_invite.thanks') %>
|
||||
</p>
|
||||
</td>
|
||||
@@ -1,9 +1,5 @@
|
||||
<div class="admin-sidebar">
|
||||
<ul id="admin_menu">
|
||||
<li>
|
||||
<%= link_to t("management.menu.title"), management_root_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "document_verifications" ||
|
||||
controller_name == "email_verifications" ||
|
||||
controller_name == "users" %>>
|
||||
@@ -61,5 +57,12 @@
|
||||
<%= t("management.menu.print_spending_proposals") %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<%= link_to new_management_user_invite_path do %>
|
||||
<span class="icon-letter"></span>
|
||||
<%= t("management.menu.user_invites") %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
9
app/views/management/user_invites/create.html.erb
Normal file
9
app/views/management/user_invites/create.html.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= render 'shared/back_link' %>
|
||||
|
||||
<h1><%= t('management.user_invites.create.title') %></h1>
|
||||
|
||||
<div class="callout success">
|
||||
<%= t('management.user_invites.create.success_html', count: @emails.count) %>
|
||||
</div>
|
||||
</div>
|
||||
12
app/views/management/user_invites/new.html.erb
Normal file
12
app/views/management/user_invites/new.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div class="small-12 medium-8 column">
|
||||
<h1><%= t('management.user_invites.new.title') %></h1>
|
||||
|
||||
<%= form_tag management_user_invites_path do %>
|
||||
<label><%= t('management.user_invites.new.label') %></label>
|
||||
<p class="note"><%= t('management.user_invites.new.info') %></p>
|
||||
<%= text_area_tag "emails", nil, rows: 5, placeholder: t('management.user_invites.new.info') %>
|
||||
<div class="small-12 medium-6">
|
||||
<input type="submit" name="" value="<%= t('management.user_invites.new.submit') %>", class="button hollow expanded">
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -45,4 +45,11 @@ 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 <strong>%{receiver}</strong> with the content:"
|
||||
title_html: "You have send a new private message to <strong>%{receiver}</strong> with the content:"
|
||||
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
|
||||
subject: "Invitation to %{org_name}"
|
||||
@@ -45,4 +45,11 @@ 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 <strong>%{receiver}</strong> con el siguiente contenido:"
|
||||
title_html: "Has enviado un nuevo mensaje privado a <strong>%{receiver}</strong> con el siguiente contenido:"
|
||||
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
|
||||
subject: "Invitación a %{org_name}"
|
||||
@@ -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: <strong>%{count} invitations</strong> have been sent.
|
||||
title: User's invites
|
||||
@@ -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 <strong>%{count} invitaciones</strong>.
|
||||
title: Invitaciones para usuarios
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
18
spec/features/user_invites_spec.rb
Normal file
18
spec/features/user_invites_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user