aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/my/agent_controller.rb
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2020-10-09 12:48:13 +0200
committerhellekin <hellekin@cepheide.org>2020-10-09 12:50:16 +0200
commit383a840c50ca8f6df19677e93357e9dc6c0e043c (patch)
tree3597f5ee2a92b551a01ac207f440ae85bcb3d9c6 /app/controllers/my/agent_controller.rb
parentdd9e0691acae3eb63bdfbc8665eb3f8ce516536d (diff)
downloadincommon-map-383a840c50ca8f6df19677e93357e9dc6c0e043c.tar.gz
Enable switching Agent
Switching current Agent can help with roles and resource access. Go to your dashboard by clicking the avatar. Select agent and hit "Select"
Diffstat (limited to 'app/controllers/my/agent_controller.rb')
-rw-r--r--app/controllers/my/agent_controller.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/controllers/my/agent_controller.rb b/app/controllers/my/agent_controller.rb
new file mode 100644
index 0000000..ac761b7
--- /dev/null
+++ b/app/controllers/my/agent_controller.rb
@@ -0,0 +1,29 @@
+class My::AgentController < ApplicationController
+ # PATCH /my/current_agent
+ def switch
+ response_status = :unprocessable_entity
+ new_agent = current_user.agents.find(params[:agent][:id])
+ Rails.logger.info "CURRENT_AGENT #{session[:current_agent]} -> #{new_agent.name}"
+ if new_agent.present?
+ session[:current_agent] = new_agent.name
+ @current_agent = new_agent
+ response_status = :ok
+ respond_to do |format|
+ format.html { redirect_to my_dashboard_url, notice: "L'Agent est maintenant #{new_agent.name}." }
+ format.json { render json: { current_agent: session[:current_agent] }, status: response_status }
+ end
+ else
+ respond_to do |format|
+ format.html { redirect_to my_dashboard_url, notice: "L'Agent est toujours le meme..." }
+ format.json { render json: { current_agent: session[:current_agent] }, status: response_status }
+ end
+ end
+
+ end
+
+ private
+
+ def agent_params
+ params.require(:agent).permit(:id)
+ end
+end