docbrown/app/controllers/admin/invitations_controller.rb
Julianna Tetreault a6aabb2149
Give Admins Ability to Delete Invitations (#10959)
* WIP: Gives Admins the ability to delete invitations from /admin/invitations

* Refactors #destroy to properly delete invites, redirect, & display messages

* Adds additional flash message and makes existing messages more explicit

* Adds spec to test the deletion of invitations in admin/invitations
2020-10-20 12:07:36 -04:00

36 lines
1.1 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)
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,
editor_version: :v2,
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