move recruiter to admin/candidate

This commit is contained in:
Mark Moser
2016-09-22 13:30:30 -05:00
parent 47d7188a2f
commit 9078c463f4
25 changed files with 383 additions and 327 deletions

View File

@ -0,0 +1,70 @@
# frozen_string_literal: true
module Admin
class CandidateController < AdminController
before_action :collect_quizzes, except: [:login, :auth]
def index
@candidates = policy_scope current_recruiter.candidates
end
def new
authorize Candidate
@candidate = Candidate.new
render :new
end
def create
authorize Candidate
@candidate = Candidate.create(candidate_params.merge(recruiter_id: current_recruiter.id))
if @candidate.persisted?
send_notifications @candidate
redirect_to admin_candidate_path,
flash: { success: "Sucessfully created candidate #{@candidate.name}" }
else
flash[:error] = "Failed to save candidate."
render :new
end
end
def edit
authorize Candidate
@candidate = Candidate.find_by(id: params[:id])
end
def update
authorize Candidate
@candidate = Candidate.find_by(id: params[:id])
@candidate.update(candidate_params)
if @candidate.save
redirect_to admin_candidate_path, flash: { success: "#{@candidate.name} updated!" }
else
flash[:error] = "Failed to save candidate."
render :edit
end
end
def resend_welcome
authorize Candidate
candidate = Candidate.find_by(id: params[:id])
CandidateMailer.welcome(candidate).deliver_later
render json: { message: "Email queued!" }.to_json
end
private
def candidate_params
params.require(:candidate).permit(:name, :email, :experience, :quiz_id)
end
def collect_quizzes
@quizzes ||= Quiz.order(:name)
end
def send_notifications candidate
CandidateMailer.welcome(candidate).deliver_later
RecruiterMailer.candidate_created(candidate).deliver_later
end
end
end

View File

@ -1,80 +0,0 @@
# frozen_string_literal: true
class RecruiterController < ApplicationController
before_action :authorize_recruiter, except: [:login, :auth]
before_action :collect_quizzes, except: [:login, :auth]
def index
@candidates = current_recruiter.candidates
end
def new
@candidate = Candidate.new
render :new
end
def create
@candidate = Candidate.create(candidate_params.merge(recruiter_id: current_recruiter.id))
if @candidate.persisted?
CandidateMailer.welcome(@candidate).deliver_later
RecruiterMailer.candidate_created(@candidate).deliver_later
redirect_to recruiter_path, flash: { success: "Sucessfully created candidate #{@candidate.name}" }
else
flash[:error] = "Failed to save candidate."
render :new
end
end
def edit
@candidate = Candidate.find_by(id: params[:id])
end
def update
@candidate = Candidate.find_by(id: params[:id])
@candidate.update(candidate_params)
if @candidate.save
redirect_to recruiter_path, flash: { success: "#{@candidate.name} updated!" }
else
flash[:error] = "Failed to save candidate."
render :edit
end
end
def login
redirect_to recruiter_path unless current_recruiter.nil?
end
def auth
recruiter = User.find_by(email: auth_params[:email], role: %w(admin recruiter))
if recruiter && recruiter.authenticate(auth_params[:password])
session[:user] = recruiter.to_i
redirect_to recruiter_path
else
redirect_to recruiter_login_path,
flash: { error: "Sorry, incorrect email or password. Please try again." }
end
end
def logout
reset_session
redirect_to recruiter_login_path
end
def resend_welcome
candidate = Candidate.find_by(id: params[:id])
CandidateMailer.welcome(candidate).deliver_later
render json: { message: "Email queued!" }.to_json
end
private
def candidate_params
params.require(:candidate).permit(:name, :email, :experience, :quiz_id)
end
def collect_quizzes
@quizzes ||= Quiz.order(:name)
end
end