Booth invitation to invited users

User will enter email of users to invite to become booth responsible, which will create a user in User db with that email and a new booth request will be created.
This commit is contained in:
Rahul 2019-06-04 18:15:41 +05:30
parent 04c3859526
commit 29c15c5d93
6 changed files with 80 additions and 3 deletions

View file

@ -4,6 +4,7 @@ module Admin
class BoothsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
include Invitation
def index
@file_name = "booths_for_#{@conference.short_title}"
@ -38,6 +39,7 @@ module Admin
@booth.submitter = current_user
if @booth.save
booth_responsible_invite
redirect_to admin_conference_booths_path,
notice: 'Booth successfully created.'
else
@ -54,7 +56,7 @@ module Admin
@url = admin_conference_booth_path(@conference.short_title, @booth.id)
@booth.update_attributes(booth_params)
booth_responsible_invite
if @booth.save
redirect_to admin_conference_booths_path,
notice: "Successfully updated booth for #{@booth.title}."

View file

@ -5,6 +5,7 @@ class BoothsController < ApplicationController
load_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
skip_authorize_resource only: [:withdraw, :confirm, :restart]
include Invitation
def index
@booths = current_user.booths.where(conference_id: @conference.id).uniq
@ -22,6 +23,7 @@ class BoothsController < ApplicationController
@booth.submitter = current_user
if @booth.save
booth_responsible_invite
redirect_to conference_booths_path,
notice: 'Booth successfully created.'
else
@ -38,6 +40,7 @@ class BoothsController < ApplicationController
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.update_attributes(booth_params)
booth_responsible_invite
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully updated!'

View file

@ -0,0 +1,21 @@
module Invitation
extend ActiveSupport::Concern
def booth_responsible_invite
if booth_params[:invite_responsible]
emails_array = booth_params[:invite_responsible].split(',')
emails_array.each do |email|
new_user = User.find_by(email: email)
if new_user.nil?
User.invite!({ email: email }, current_user)
new_user = User.find_by(email: email)
end
if new_user && @booth.responsible_ids.exclude?(new_user.id)
BoothRequest.create(booth_id: @booth.id, user_id: new_user.id,
role: 'responsible')
end
end
end
end
end