From 886a384c4460683e9165579582ede00729a2c0dc Mon Sep 17 00:00:00 2001 From: Chris Zhu Date: Tue, 18 Feb 2025 18:05:02 -0800 Subject: [PATCH] added login as feature --- app/avo/config.rb | 5 +++++ app/avo/resources/cluster.rb | 2 +- app/controllers/avo/tools_controller.rb | 6 ++++++ app/views/avo/resource_tools/_user.html.erb | 12 +++--------- config/routes.rb | 1 + 5 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 app/avo/config.rb diff --git a/app/avo/config.rb b/app/avo/config.rb new file mode 100644 index 00000000..1151506b --- /dev/null +++ b/app/avo/config.rb @@ -0,0 +1,5 @@ +class Avo::Config + def self.button_css + "button-component inline-flex flex-grow-0 items-center font-semibold leading-6 fill-current whitespace-nowrap transition duration-100 transform transition duration-100 cursor-pointer disabled:cursor-not-allowed disabled:opacity-60 data-[disabled='true']:opacity-60 justify-center border active:outline active:outline-1 rounded bg-primary-500 text-white border-primary-500 hover:bg-primary-600 hover:border-primary-600 active:border-primary-600 active:outline-primary-600 active:bg-primary-600 px-3 py-1.5 text-sm" + end +end diff --git a/app/avo/resources/cluster.rb b/app/avo/resources/cluster.rb index ad4ddabc..7735e303 100644 --- a/app/avo/resources/cluster.rb +++ b/app/avo/resources/cluster.rb @@ -8,7 +8,7 @@ class Avo::Resources::Cluster < Avo::BaseResource def fields field :id, as: :id field :name, as: :text - field :status, as: :select, options: Cluster.statuses.keys.map { |status| [status.humanize, status] } + field :status, as: :select, options: Cluster.statuses.keys.map { |status| [ status.humanize, status ] } field :account, as: :belongs_to field :add_ons, as: :has_many field :projects, as: :has_many diff --git a/app/controllers/avo/tools_controller.rb b/app/controllers/avo/tools_controller.rb index a3c4cd6f..5608720e 100644 --- a/app/controllers/avo/tools_controller.rb +++ b/app/controllers/avo/tools_controller.rb @@ -3,4 +3,10 @@ class Avo::ToolsController < Avo::ApplicationController @page_title = "Dashboard" add_breadcrumb "Dashboard" end + + def login_as + user = User.find(params[:id]) + sign_in(user) + redirect_to root_path + end end diff --git a/app/views/avo/resource_tools/_user.html.erb b/app/views/avo/resource_tools/_user.html.erb index 547a0671..cf58fbc8 100644 --- a/app/views/avo/resource_tools/_user.html.erb +++ b/app/views/avo/resource_tools/_user.html.erb @@ -10,15 +10,9 @@

Manage User

- -

- You can edit this file here app/views/avo/resource_tools/_user.html.erb. -

- -

- The resource tool configuration file should be here app/avo/resource_tools/user.rb. -

- + <%= form_with url: login_as_path(@resource.record.id), method: :post, data: { turbo: false } do |f| %> + <%= f.submit "Login As", class: Avo::Config.button_css %> + <% end %> <% # In this partial you have access to the following variables: # tool diff --git a/config/routes.rb b/config/routes.rb index eeacec9c..41696e1b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ Rails.application.routes.draw do Avo::Engine.routes.draw do # This route is not protected, secure it with authentication if needed. get "dashboard", to: "tools#dashboard", as: :dashboard + post "login_as/:id", to: "tools#login_as", as: :login_as end end resources :accounts, only: [ :create ] do