diff --git a/.rubocop.yml b/.rubocop.yml index 1e38f2f9..a42adca8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -32,7 +32,7 @@ Metrics/MethodLength: - 'app/controllers/invitadxs_controller.rb' - 'app/controllers/i18n_controller.rb' - 'app/controllers/collaborations_controller.rb' - + - 'app/controllers/usuaries_controller.rb' Metrics/BlockLength: Exclude: diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 7ed088e6..529d8be5 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -82,13 +82,20 @@ class UsuariesController < ApplicationController # TODO: Enviar invitación igual! Podemos no usar el Mailer de # DeviseInvitations y usar uno propio que contenga texto y se # envíe de todas formas. - usuarie = Usuarie.invite! email: invitacion.address + usuarie = Usuarie.invite! email: invitacion.address, + skip_invitation: true # No invitar al sitio si ya estaba en la lista! - next if @site.invitade?(usuarie) || @site.usuarie?(usuarie) + # + # XXX: En este caso no estamos enviando ninguna invitación + next if usuarie.sites.exists? @site.id @site.roles << Rol.create(usuarie: usuarie, site: @site, temporal: true, rol: invited_as) + + # Invitamos después de crear el rol para que el correo de + # invitación pueda recibir el sitio. + usuarie.deliver_invitation end redirect_to site_usuaries_path(@site) diff --git a/app/views/devise/mailer/invitation_instructions.haml b/app/views/devise/mailer/invitation_instructions.haml index f2f42219..74551234 100644 --- a/app/views/devise/mailer/invitation_instructions.haml +++ b/app/views/devise/mailer/invitation_instructions.haml @@ -1,5 +1,6 @@ +- binding.pry %p= t("devise.mailer.invitation_instructions.hello", email: @resource.email) -%p= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) +%p= t("devise.mailer.invitation_instructions.someone_invited_you", url: @resource.sites.first.name) %p= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token) - if @resource.invitation_due_at %p= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) diff --git a/app/views/devise/mailer/invitation_instructions.text.haml b/app/views/devise/mailer/invitation_instructions.text.haml index a9d23d3f..e45dcefe 100644 --- a/app/views/devise/mailer/invitation_instructions.text.haml +++ b/app/views/devise/mailer/invitation_instructions.text.haml @@ -1,5 +1,5 @@ = t("devise.mailer.invitation_instructions.hello", email: @resource.email) -= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) += t("devise.mailer.invitation_instructions.someone_invited_you", url: @resource.sites.first.name) = accept_invitation_url(@resource, invitation_token: @token) - if @resource.invitation_due_at = t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format'))