Sha256: e4295fc853c60ee0374269c00fa4fb252da005d258be8e0824efb0d7ff233776

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module Decidim
  module Devise
    # This controller customizes the behaviour of Devise::Invitiable.
    class InvitationsController < ::Devise::InvitationsController
      include Decidim::DeviseControllers
      include NeedsTosAccepted

      before_action :configure_permitted_parameters

      # We don't users to create invitations, so we just redirect them to the
      # homepage.
      def authenticate_inviter!
        redirect_to root_path
      end

      # 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.
      def after_accept_path_for(resource)
        params[:invite_redirect] || after_sign_in_path_for(resource)
      end

      # When a managed user accepts the invitation is promoted to non-managed user.
      def accept_resource
        resource = resource_class.accept_invitation!(update_resource_params)
        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
        resource
      end

      protected

      def configure_permitted_parameters
        devise_parameter_sanitizer.permit(:accept_invitation, keys: [:nickname, :tos_agreement, :newsletter_notifications])
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-core-0.18.1 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.17.2 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.18.0 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.17.1 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.16.1 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.17.0 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.16.0 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.15.2 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.15.1 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.15.0 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.14.4 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.14.3 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.14.2 app/controllers/decidim/devise/invitations_controller.rb
decidim-core-0.14.1 app/controllers/decidim/devise/invitations_controller.rb