Chatwoot/app/controllers/api/v1/agents_controller.rb
Pranav Raj Sreepuram 2a34255e0b Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com>
Co-authored-by: Manoj <manojmj92@gmail.com>
Co-authored-by: Nithin <webofnithin@gmail.com>
2019-08-14 15:18:44 +05:30

52 lines
940 B
Ruby

class Api::V1::AgentsController < Api::BaseController
before_action :fetch_agent, except: [:create, :index]
before_action :check_authorization
before_action :build_agent, only: [:create]
def index
render json: agents
end
def destroy
@agent.destroy
head :ok
end
def update
@agent.update_attributes!(agent_params)
render json: @agent
end
def create
@agent.save!
render json: @agent
end
private
def check_authorization
authorize(User)
end
def fetch_agent
@agent = agents.find(params[:id])
end
def build_agent
@agent = agents.new(new_agent_params)
end
def agent_params
params.require(:agent).permit(:email, :name, :role)
end
def new_agent_params
time = Time.now.to_i
params.require(:agent).permit(:email, :name, :role).merge!(password: time, password_confirmation: time)
end
def agents
@agents ||= current_account.users
end
end