diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 9e9cac71..28513e63 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -96,6 +96,12 @@ class UsuariesController < ApplicationController # XXX: La invitación tiene que ser enviada luego de crear el rol if role.persisted? + # Si es una cuenta manual que no está confirmada aun, + # aprovechar para reconfirmarla. + if !usuarie.confirmed? && !usuarie.created_by_invite? + usuarie.generate_confirmation_token! + end + usuarie.deliver_invitation else raise ArgumentError, role.errors.full_messages diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index ef13239b..e25a6785 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -51,9 +51,9 @@ class Usuarie < ApplicationRecord end # Les usuaries necesitan link de invitación si no tenían cuenta - # o todavía no la confirmaron + # y todavía no aceptaron la invitación anterior. def needs_invitation_link? - (created_by_invite? && !invitation_accepted?) || !confirmed? + created_by_invite? && !invitation_accepted? end private diff --git a/app/views/devise/mailer/invitation_instructions.html.haml b/app/views/devise/mailer/invitation_instructions.html.haml index 1cdcb2a9..6370ed1a 100644 --- a/app/views/devise/mailer/invitation_instructions.html.haml +++ b/app/views/devise/mailer/invitation_instructions.html.haml @@ -18,5 +18,9 @@ format: :'devise.mailer.invitation_instructions.accept_until_format')) %p= t('devise.mailer.invitation_instructions.ignore') +- elsif !@resource.confirmed? && @resource.confirmation_token + = confirmation_url(@resource, confirmation_token: @token, change_locale_to: @resource.lang) + \ + = 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 eab021ef..719c7cd2 100644 --- a/app/views/devise/mailer/invitation_instructions.text.haml +++ b/app/views/devise/mailer/invitation_instructions.text.haml @@ -18,6 +18,10 @@ format: :'devise.mailer.invitation_instructions.accept_until_format')) \ = t('devise.mailer.invitation_instructions.ignore') +- elsif !@resource.confirmed? && @resource.confirmation_token + = confirmation_url(@resource, confirmation_token: @token, change_locale_to: @resource.lang) + \ + = t('devise.mailer.invitation_instructions.ignore') - else = root_url(change_locale_to: @resource.lang) = t('devise.mailer.invitation_instructions.sign_in')