Skip to content

Commit

Permalink
refactor: plugins reporting and versions hiding (#3287)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Oct 1, 2024
1 parent 701a608 commit 134de10
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 10 deletions.
8 changes: 8 additions & 0 deletions app/controllers/avo/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,13 @@ def choose_layout
"avo/application"
end
end

def authenticate_developer_or_admin!
raise_404 unless Avo::Current.user_is_developer? || Avo::Current.user_is_admin?
end

def raise_404
raise ActionController::RoutingError.new "No route matches"
end
end
end
6 changes: 6 additions & 0 deletions app/controllers/avo/debug_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

module Avo
class DebugController < ApplicationController
before_action :authenticate_developer_or_admin!

def status
respond_to do |format|
format.html { render :status }
format.text { render :status }
end
end

def send_to_hq
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/avo/private_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Avo
class PrivateController < ApplicationController
before_action :authenticate_developer_or_admin!

def design
@page_title = "Design [Private]"
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/avo/debug/status.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<ul>
<li>Avo <%= Avo::VERSION %></li>
<% Avo.plugin_manager.plugins.each do |plugin| %>
<li><%= plugin.klass.name %> - <%= plugin.klass.version %></li>
<li><%= plugin.name %> - <%= plugin.version %></li>
<% end %>
</ul>
</div>
Expand Down
6 changes: 6 additions & 0 deletions app/views/avo/debug/status.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- Avo version: <%= Avo::VERSION %> -->
<!-- Rails version: <%= Rails::VERSION::STRING %> -->
<!-- Environment: <%= Rails.env %> -->
<!-- License ID: <%= Avo.license.id %> -->
<!-- License valid?: <%= Avo.license.valid ? "valid" : "invalid" %> -->
<!-- Plugins: <%= Avo.plugin_manager.to_s %> -->
6 changes: 0 additions & 6 deletions app/views/layouts/avo/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@
<%= render partial: "avo/partials/alerts" %>
<%= render partial: "avo/partials/scripts" %>
<%= render partial: "avo/partials/confirm_dialog" %>
<!-- Avo version: <%= Avo::VERSION %> -->
<!-- Rails version: <%= Rails::VERSION::STRING %> -->
<!-- Environment: <%= Rails.env %> -->
<!-- License ID: <%= Avo.license.id %> -->
<!-- License valid?: <%= Avo.license.valid ? "valid" : "invalid" %> -->
<!-- Plugins: <%= Avo.plugin_manager.to_s %> -->
</body>
</html>
<!-- ✨ Built with Avo • https://www.avohq.io/ -->
6 changes: 6 additions & 0 deletions lib/avo/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ class Plugin
attr_reader :name
attr_reader :priority

delegate :version, :namespace, :engine, to: :class

def initialize(*, name:, priority:, **, &block)
@name = name
@priority = priority
end

def to_s
"#{name}-#{version}"
end

class << self
def name
return gemspec.name if gemspec.present?
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/plugin_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def register_tool
def as_json(*arg)
plugins.map do |plugin|
{
klass: plugin.klass.to_s,
klass: plugin.to_s,
priority: plugin.priority,
}
end
end

def to_s
plugins.map do |plugin|
plugin.klass.to_s
plugin.to_s
end.join(",")
rescue
"Failed to fetch plugins."
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/avo/templates/initializer/avo.tt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Avo.configure do |config|
# }

## == Customization ==
config.click_row_to_view_record = true
# config.app_name = 'Avocadelicious'
# config.timezone = 'UTC'
# config.currency = 'USD'
Expand All @@ -114,7 +115,6 @@ Avo.configure do |config|
# config.buttons_on_form_footers = true
# config.field_wrapper_layout = true
# config.resource_parent_controller = "Avo::ResourcesController"
# config.click_row_to_view_record = false

## == Branding ==
# config.branding = {
Expand Down

0 comments on commit 134de10

Please sign in to comment.