From 11e503061cf3dde80bdf5100fe268ecc9fbbdb2d Mon Sep 17 00:00:00 2001 From: f Date: Mon, 20 Mar 2023 17:22:40 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20enviar=20invitaci=C3=B3n=20sin=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Usuarie#deliver_invitation además generaba un token cuando no era necesario y esto es lo que hacía que les usuaries quedaran flotando. --- app/controllers/usuaries_controller.rb | 5 ++++- .../mailer/invitation_instructions.html.haml | 17 +++++++++------- .../mailer/invitation_instructions.text.haml | 20 +++++++++++-------- config/locales/devise_invitable.en.yml | 1 + config/locales/devise_invitable.es.yml | 1 + 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 2dd3ea99..7621489e 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -86,7 +86,10 @@ class UsuariesController < ApplicationController next if Usuarie.where(id: @site.roles.pluck(:usuarie_id)).find_by(attributes) - usuarie = Usuarie.find_by attributes + usuarie = Usuarie.find_by(attributes).tap do |u| + u.send(:send_devise_notification, :invitation_instructions, nil) + end + usuarie ||= Usuarie.invite! attributes @site.roles.create(usuarie: usuarie, temporal: true, rol: invited_as) diff --git a/app/views/devise/mailer/invitation_instructions.html.haml b/app/views/devise/mailer/invitation_instructions.html.haml index 74193878..e1fe6812 100644 --- a/app/views/devise/mailer/invitation_instructions.html.haml +++ b/app/views/devise/mailer/invitation_instructions.html.haml @@ -8,12 +8,15 @@ %h1= site.title %p= site.description -%p= link_to t('devise.mailer.invitation_instructions.accept'), - accept_invitation_url(@resource, invitation_token: @token) +- if @resource.created_by_invite? + %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')) + - 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')) -%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 16a9f0a8..353f2a12 100644 --- a/app/views/devise/mailer/invitation_instructions.text.haml +++ b/app/views/devise/mailer/invitation_instructions.text.haml @@ -9,11 +9,15 @@ \ = site.description \ -= 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')) -\ -= t('devise.mailer.invitation_instructions.ignore') +- if @resource.created_by_invite? + = 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')) + \ + = t('devise.mailer.invitation_instructions.ignore') +- else + = root_url(change_locale_to: @resource.lang) + = t('devise.mailer.invitation_instructions.sign_in') diff --git a/config/locales/devise_invitable.en.yml b/config/locales/devise_invitable.en.yml index f6bfee40..39238140 100644 --- a/config/locales/devise_invitable.en.yml +++ b/config/locales/devise_invitable.en.yml @@ -23,6 +23,7 @@ en: accept: "Accept invitation" accept_until: "This invitation will be due in %{due_date}." ignore: "If you don't want to accept the invitation, please ignore this email. Your account won't be created until you access the link above and set your password." + sign_in: "Sign in to your account to accept or decline the invitation." time: formats: devise: diff --git a/config/locales/devise_invitable.es.yml b/config/locales/devise_invitable.es.yml index 144d6df6..e83a703c 100644 --- a/config/locales/devise_invitable.es.yml +++ b/config/locales/devise_invitable.es.yml @@ -23,6 +23,7 @@ es: accept: "Aceptar la invitación" accept_until: "La invitación vencerá el %{due_date}." ignore: "Si no querés aceptar la invitación, por favor ignora este correo. Tu cuenta no será creada hasta que aceptes la invitación y configures una contraseña." + sign_in: "Iniciá sesión con tu cuenta para aceptar o rechazar la invitación." time: formats: devise: