docbrown/app/controllers/admin/invitations_controller.rb
Mac Siri ffe31cd5aa
Change default value for editor version (#14063)
* Create migration

* Remove explicit "v2" usages

* Fix broken spec

* Update spec/system/user_uses_the_editor_spec.rb

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
2021-06-28 14:08:14 -04:00

42 lines
1.3 KiB
Ruby

module Admin
class InvitationsController < Admin::ApplicationController
layout "admin"
def index
@invitations = User.where(registered: false).page(params[:page]).per(50)
end
def new; end
def create
email = params.dig(:user, :email)
name = params.dig(:user, :name)
if User.exists?(email: email.downcase, registered: true)
flash[:error] = "Invitation was not sent. There is already a registered user with the email: #{email}"
redirect_to admin_invitations_path
return
end
username = "#{name.downcase.tr(' ', '_').gsub(/[^0-9a-z ]/i, '')}_#{rand(1000)}"
User.invite!(email: email,
name: name,
username: username,
remote_profile_image_url: ::Users::ProfileImageGenerator.call,
saw_onboarding: false,
registered: false)
flash[:success] = "The invite has been sent to the user's email."
redirect_to admin_invitations_path
end
def destroy
@invitation = User.where(registered: false).find(params[:id])
if @invitation.destroy
flash[:success] = "The invitation has been deleted."
else
flash[:danger] = @invitation.errors_as_sentence
end
redirect_to admin_invitations_path
end
end
end