diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index d9510392..3f672110 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -83,16 +83,19 @@ class UsuariesController < ApplicationController # Enviar la invitación si es necesario y agregar al sitio invitaciones.each do |invitacion| attributes = { email: invitacion.address } + options = { skip_invitation: true } next if Usuarie.where(id: @site.roles.pluck(:usuarie_id)).find_by(attributes) - usuarie = Usuarie.find_by attributes.tap do |u| - u.send_devise_notification(:invitation_instructions, nil) + usuarie = Usuarie.find_by attributes + usuarie ||= Usuarie.invite!(attributes, nil, options).tap do |u| + u.generate_invitation_token! end - usuarie ||= Usuarie.invite! attributes - @site.roles.create(usuarie: usuarie, temporal: true, rol: invited_as) + + # XXX: La invitación tiene que ser enviada luego de crear el rol + usuarie.send(:send_devise_notification, :invitation_instructions, nil) end redirect_to site_usuaries_path(@site) diff --git a/app/views/devise/mailer/invitation_instructions.html.haml b/app/views/devise/mailer/invitation_instructions.html.haml index 3e8d26c1..4989cf64 100644 --- a/app/views/devise/mailer/invitation_instructions.html.haml +++ b/app/views/devise/mailer/invitation_instructions.html.haml @@ -19,4 +19,6 @@ - else %p= link_to t('devise.mailer.invitation_instructions.sign_in'), root_url(change_locale_to: @resource.lang) -%p= t('devise.mailer.invitation_instructions.ignore') + %p= t('devise.mailer.invitation_instructions.ignore') +- else + %p= link_to t('devise.mailer.invitation_instructions.sign_in'), root_url diff --git a/app/views/devise/mailer/invitation_instructions.text.haml b/app/views/devise/mailer/invitation_instructions.text.haml index 382e5a5b..a3e2d56d 100644 --- a/app/views/devise/mailer/invitation_instructions.text.haml +++ b/app/views/devise/mailer/invitation_instructions.text.haml @@ -16,8 +16,8 @@ = t('devise.mailer.invitation_instructions.accept_until', due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) + \ + = t('devise.mailer.invitation_instructions.ignore') - else = root_url(change_locale_to: @resource.lang) = t('devise.mailer.invitation_instructions.sign_in') -\ -= t('devise.mailer.invitation_instructions.ignore')