Class: Decidim::Devise::InvitationsController

Inherits:
Devise::InvitationsController
  • Object
show all
Includes:
Decidim::DeviseControllers, NeedsTosAccepted
Defined in:
app/controllers/decidim/devise/invitations_controller.rb

Overview

This controller customizes the behaviour of Devise::Invitiable.

Instance Method Summary collapse

Instance Method Details

#accept_resourceObject

When a managed user accepts the invitation is promoted to non-managed user.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/decidim/devise/invitations_controller.rb', line 26

def accept_resource
  resource = resource_class.accept_invitation!(update_resource_params)

  if resource.valid? && resource.invitation_accepted?
    resource.update!(newsletter_notifications_at: Time.current) if update_resource_params[:newsletter_notifications]
    resource.update!(managed: false) if resource.managed?
    resource.update!(accepted_tos_version: resource.organization.tos_version)
    Decidim::Gamification.increment_score(resource.invited_by, :invitations) if resource.invited_by
  end

  resource
end

#after_accept_path_for(resource) ⇒ Object

Overwrite the method that returns the path after a user accepts an invitation. Using the param ‘invite_redirect` we can redirect the user to a custom path after it has accepted the invitation.



21
22
23
# File 'app/controllers/decidim/devise/invitations_controller.rb', line 21

def after_accept_path_for(resource)
  params[:invite_redirect] || (resource)
end

#authenticate_inviter!Object

We don’t users to create invitations, so we just redirect them to the homepage.



14
15
16
# File 'app/controllers/decidim/devise/invitations_controller.rb', line 14

def authenticate_inviter!
  redirect_to root_path
end