Sha256: 414b47525abd715e105edbd3eca5ffa54208d6dcac172f8749b24db537e48870

Contents?: true

Size: 982 Bytes

Versions: 3

Compression:

Stored size: 982 Bytes

Contents

module Spotlight
  module Concerns
    ###
    # Mixin to be included into controllers that provides an action which
    # allows admins and curators to invite users and assign them a role.
    module UserInvitable
      def invite
        # skip_invitation stops the immediate delivery of the invitation
        user = Spotlight::Engine.user_class.invite!(email: invite_params[:user], skip_invitation: true)
        role = Spotlight::Role.create(resource: exhibit_or_site, user: user, role: invite_params[:role])
        if role.save
          user.deliver_invitation # now deliver it when we have saved the role
          redirect_to :back, notice: t(:'helpers.submit.invite.invited')
        else
          redirect_to :back, alert: t(:'helpers.submit.role.batch_error', count: 1)
        end
      end

      protected

      def invite_params
        params.permit(:user, :role)
      end

      def exhibit_or_site
        current_exhibit || @site
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blacklight-spotlight-0.23.0 app/controllers/spotlight/concerns/user_invitable.rb
blacklight-spotlight-0.22.0 app/controllers/spotlight/concerns/user_invitable.rb
blacklight-spotlight-0.21.0 app/controllers/spotlight/concerns/user_invitable.rb