* 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
36 lines
1.1 KiB
Ruby
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
|