added login as feature

This commit is contained in:
Chris Zhu
2025-02-18 18:05:02 -08:00
parent 42918e9ebe
commit 886a384c44
5 changed files with 16 additions and 10 deletions

5
app/avo/config.rb Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -10,15 +10,9 @@
<div class="flex flex-col p-4 min-h-24">
<div class="space-y-4">
<h3>Manage User</h3>
<p>
You can edit this file here <code class='p-1 rounded bg-gray-500 text-white text-sm'>app/views/avo/resource_tools/_user.html.erb</code>.
</p>
<p>
The resource tool configuration file should be here <code class='p-1 rounded bg-gray-500 text-white text-sm'>app/avo/resource_tools/user.rb</code>.
</p>
<%= 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

View File

@@ -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