Devise/Devise_invitable: 如何跳过挂起的邀请控件

Devise/Devise_invitable: How to skip the pending invitations control

我有一个 Rails/Mongoid 应用程序,它使用 devise 和 devise_invitable gem,在一个特殊场景中,用户 has_and_belongs_to_many 组。这在应用程序中意味着用户可以被其他用户邀请到一个或多个组。我正在使用 devise_invitable 处理新用户和现有用户的邀请。

我遇到问题的场景是当用户已经注册并确认其帐户,并且可能已经被邀请加入一个组时,被邀请加入另一个组。在这种情况下,系统会像往常一样发送新邀请,但不会为现有用户创建新邀请。

如果用户确认邀请,一切正常,但我遇到的问题是,除非用户确认,否则 he/she 将无法再次登录到他的用户帐户,因为它将收到警报:

You have a pending invitation, accept it to finish creating your account.

所以我想知道我应该怎么做或者我应该在 Devise/Devise_invitable 上重写什么以便在尝试以已经确认但已经确认的用户身份登录时跳过该控件待处理的邀请。

我的用户模型是这个:

class User
  include Mongoid::Document
  include Mongoid::Attributes::Dynamic
  include Mongoid::Timestamps
  include Mongoid::Userstamp::User

  devise :invitable, :encryptable, :database_authenticatable, :registerable, :lockable, :recoverable, :confirmable, :rememberable, :trackable, :validatable, :timeoutable

has_and_belongs_to_many :groups

谢谢!

好的,我在 devise_invitable ticket 我打开的地方得到了帮助。

实现我所要求的方法是覆盖用户模型上的 this method。因此,即使 he/she 有待处理的邀请也允许已确认用户登录的解决方案如下:

class User
  ...
  def block_from_invitation?
    #If the user has not been confirmed yet, we let the usual controls work
    if confirmed_at.blank?
      return invited_to_sign_up?
    else #if the user was confirmed, we let them in (will decide to accept or decline invitation from the dashboard)
      return false
    end
  end
  ...
end

希望对以后的其他人有所帮助。