Skip to content

Commit

Permalink
feature: Add Avo admin panel (#796)
Browse files Browse the repository at this point in the history
* feat: Install avo

* chore: Add avo resources

* chore: Add admin menu item

* linting

* feature: add Avo admin panel

* update Avo and remove locale files

* update to Avo 3

* add ransack

* add comment

* wip

* wip

* remove the dashboard

* tweaks

* lint

* remove searchable from default setup

* remove ransack

* rebased to main

* update gemfile.lock

* Update all Bundler dependencies (2023-12-10) (#1238)

* Update all Bundler dependencies (2023-12-13) (#1240)

* feat: Install avo

* chore: Add avo resources

* chore: Add admin menu item

* linting

* feature: add Avo admin panel

* update Avo and remove locale files

* update to Avo 3

* add ransack

* add comment

* wip

* wip

* remove the dashboard

* tweaks

* lint

* remove searchable from default setup

* remove ransack

* update gemfile.lock

* bundle update

* update to latest Avo version

* update time_zone field

* Update config/initializers/avo.rb

Co-authored-by: Jeremy Green <[email protected]>

* Update config/initializers/avo.rb

---------

Co-authored-by: Julian Rubisch <[email protected]>
Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
Co-authored-by: Jeremy Green <[email protected]>
  • Loading branch information
4 people authored Dec 14, 2023
1 parent cf0f335 commit bc8abc1
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ gem "devise"
gem "devise-two-factor"
gem "rqrcode"

# Admin panel
gem "avo", ">= 3.1.7"

group :development do
# Open any sent emails in your browser instead of having to setup an SMTP trap.
gem "letter_opener"
Expand Down
45 changes: 38 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ GEM
rails-html-sanitizer (~> 1.6)
active_hash (3.2.1)
activesupport (>= 5.0.0)
active_link_to (1.0.5)
actionpack
addressable
activejob (7.1.2)
activesupport (= 7.1.2)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -81,6 +84,22 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
ansi (1.5.0)
ast (2.4.2)
avo (3.1.7)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
activesupport (>= 6.1)
addressable
docile
dry-initializer
httparty
inline_svg
meta-tags
pagy
turbo-rails
turbo_power (~> 0.5.0)
view_component (>= 3.7.0)
zeitwerk (>= 2.6.12)
awesome_print (1.9.2)
aws-eventstream (1.3.0)
aws-partitions (1.865.0)
Expand Down Expand Up @@ -272,6 +291,7 @@ GEM
railties (>= 5)
drb (2.2.0)
ruby2_keywords
dry-initializer (3.1.1)
email_reply_parser (0.5.11)
erubi (1.12.0)
erubis (2.7.0)
Expand Down Expand Up @@ -309,14 +329,20 @@ GEM
http-cookie (1.0.5)
domain_name (~> 0.5)
http_accept_language (2.1.1)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
indefinite_article (0.2.5)
activesupport
io-console (0.7.0)
inline_svg (1.9.0)
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.6.0)
irb (1.10.1)
rdoc
reline (>= 0.3.8)
Expand Down Expand Up @@ -358,6 +384,8 @@ GEM
activesupport
prism (>= 0.14.0)
matrix (0.4.2)
meta-tags (2.19.0)
actionpack (>= 3.2.0, < 7.2)
method_source (1.0.0)
microscope (1.1.1)
activerecord (>= 4.1.0)
Expand All @@ -367,7 +395,6 @@ GEM
mime-types-data (3.2023.1205)
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
minitest-reporters (1.6.1)
ansi
Expand All @@ -392,10 +419,7 @@ GEM
netrc (0.11.0)
nice_partials (0.10.0)
actionview (>= 4.2.6)
nio4r (2.7.0)
nokogiri (1.15.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nio4r (2.5.9)
nokogiri (1.15.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.5-x86_64-linux)
Expand Down Expand Up @@ -627,6 +651,8 @@ GEM
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
turbo_power (0.5.0)
turbo-rails (~> 1.3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.1.4)
Expand All @@ -641,6 +667,10 @@ GEM
mail (>= 2.6.1)
simpleidn
version_gem (1.1.3)
view_component (3.8.0)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
Expand All @@ -661,11 +691,12 @@ GEM
PLATFORMS
arm64-darwin-21
arm64-darwin-22
ruby
arm64-darwin-23
x86_64-linux

DEPENDENCIES
active_hash
avo (>= 3.1.7)
aws-sdk-s3
bootsnap
bullet_train (= 1.6.22)
Expand Down
21 changes: 21 additions & 0 deletions app/avo/resources/invitation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Avo::Resources::Invitation < Avo::BaseResource
self.title = :email
self.includes = []
# self.search = {
# query: -> { query.ransack(id_eq: params[:q], email_cont: params[:q], m: "or").result(distinct: false) },
# item: -> {
# {
# title: record.email
# }
# }
# }

def fields
field :id, as: :id
field :email, as: :text
field :team, as: :belongs_to
field :from_membership, as: :belongs_to
field :membership, as: :has_one
field :uuid, as: :text
end
end
23 changes: 23 additions & 0 deletions app/avo/resources/membership.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Avo::Resources::Membership < Avo::BaseResource
self.title = :name
self.includes = []
# self.search = {
# query: -> { query.ransack(id_eq: params[:q], name_cont: params[:q], user_email_cont: params[:q], role_cont: params[:q], m: "or").result(distinct: false) },
# item: -> {
# {
# title: record.name,
# }
# }
# }

def fields
field :id, as: :id
field :name, as: :text, hide_on: :forms
field :user_email, as: :text
field :role_ids, as: :tags, suggestions: -> { [:admin, :editor] }, enforce_suggestions: true
field :user, as: :belongs_to
field :team, as: :belongs_to
field :invitation, as: :belongs_to
field :added_by, as: :belongs_to
end
end
24 changes: 24 additions & 0 deletions app/avo/resources/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Avo::Resources::Team < Avo::BaseResource
self.title = :name
self.includes = []
# self.search = {
# query: -> { query.ransack(id_eq: params[:q], name_cont: params[:q], slug_cont: params[:q], m: "or").result(distinct: false) },
# item: -> {
# {
# title: record.name
# }
# }
# }

def fields
field :id, as: :id
field :name, as: :text
field :slug, as: :text
field :being_destroyed, as: :boolean, hide_on: :forms
field :time_zone, as: :select, options: -> { view_context.time_zone_options_for_select(Avo::Current.user.time_zone, nil, ActiveSupport::TimeZone) }
field :locale, as: :text
field :users, as: :has_many, through: :memberships
field :memberships, as: :has_many
field :invitations, as: :has_many
end
end
24 changes: 24 additions & 0 deletions app/avo/resources/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Avo::Resources::User < Avo::BaseResource
self.title = :full_name
self.includes = []
# self.search = {
# query: -> { query.ransack(id_eq: params[:q], first_name_cont: params[:q], last_name_cont: params[:q], email_cont: params[:q], m: "or").result(distinct: false) },
# item: -> {
# {
# title: record.full_name,
# }
# }
# }

def fields
field :id, as: :id
field :email, as: :text
field :first_name, as: :text
field :last_name, as: :text
field :time_zone, as: :select, options: -> { view_context.time_zone_options_for_select(Avo::Current.user.time_zone, nil, ActiveSupport::TimeZone) }
field :current_team, as: :belongs_to

field :teams, as: :has_many, through: :teams
field :memberships, as: :has_many
end
end
4 changes: 4 additions & 0 deletions app/controllers/avo/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/2.0/controllers.html
class Avo::InvitationsController < Avo::ResourcesController
end
4 changes: 4 additions & 0 deletions app/controllers/avo/memberships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/2.0/controllers.html
class Avo::MembershipsController < Avo::ResourcesController
end
4 changes: 4 additions & 0 deletions app/controllers/avo/teams_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/2.0/controllers.html
class Avo::TeamsController < Avo::ResourcesController
end
4 changes: 4 additions & 0 deletions app/controllers/avo/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/2.0/controllers.html
class Avo::UsersController < Avo::ResourcesController
end
8 changes: 8 additions & 0 deletions app/views/account/shared/menu/_user_items.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
<% end %>
<% end %>
<% if current_user.developer? %>
<%= render 'account/shared/menu/item', url: main_app.avo_path, label: "Admin" do |p| %>
<% p.content_for :icon do %>
<i class="ti ti-key"></i>
<% end %>
<% end %>
<% end %>

<div data-turbo="false">
<%= render 'account/shared/menu/item', url: main_app.destroy_user_session_path, method: :delete, label: t('menus.main.labels.logout') do |p| %>
<% p.content_for :icon do %>
Expand Down
109 changes: 109 additions & 0 deletions config/initializers/avo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# For more information regarding these settings check out our docs https://docs.avohq.io
Avo.configure do |config|
## == Routing ==
config.root_path = "/admin/avo"
# used only when you have custom `map` configuration in your config.ru
# config.prefix_path = "/internal"

# Where should the user be redirected when visting the `/avo` url
# config.home_path = nil

## == Licensing ==
# config.license_key = ENV['AVO_LICENSE_KEY']

## == Set the context ==
config.set_context do
# Return a context object that gets evaluated in Avo::ApplicationController
end

## == Authentication ==
config.current_user_method = :current_user
# config.authenticate_with do
# end

## == Authorization ==
# config.authorization_methods = {
# index: 'index?',
# show: 'show?',
# edit: 'edit?',
# new: 'new?',
# update: 'update?',
# create: 'create?',
# destroy: 'destroy?',
# search: 'search?',
# }
# config.raise_error_on_missing_policy = false
# Change the authorization_client to :pundit when using the authorization feature
config.authorization_client = nil

## == Localization ==
# config.locale = 'en-US'

## == Resource options ==
# config.resource_controls_placement = :right
# config.model_resource_mapping = {}
# config.default_view_type = :table
# config.per_page = 24
# config.per_page_steps = [12, 24, 48, 72]
# config.via_per_page = 8
config.id_links_to_resource = true
# config.cache_resources_on_index_view = true
## permanent enable or disable cache_resource_filters, default value is false
# config.cache_resource_filters = false
## provide a lambda to enable or disable cache_resource_filters per user/resource.
# config.cache_resource_filters = ->(current_user:, resource:) { current_user.cache_resource_filters?}

## == Customization ==
config.app_name = -> { I18n.t "application.name" }
# config.timezone = 'UTC'
# config.currency = 'USD'
# config.hide_layout_when_printing = false
# config.full_width_container = false
# config.full_width_index_view = false
# config.search_debounce = 300
# config.view_component_path = "app/components"
# config.display_license_request_timeout_error = true
# config.disabled_features = []
# config.buttons_on_form_footers = true
# config.field_wrapper_layout = true

## == Branding ==
# config.branding = {
# colors: {
# background: "248 246 242",
# 100 => "#CEE7F8",
# 400 => "#399EE5",
# 500 => "#0886DE",
# 600 => "#066BB2",
# },
# chart_colors: ["#0B8AE2", "#34C683", "#2AB1EE", "#34C6A8"],
# logo: "/avo-assets/logo.png",
# logomark: "/avo-assets/logomark.png",
# placeholder: "/avo-assets/placeholder.svg",
# favicon: "/avo-assets/favicon.ico"
# }

## == Breadcrumbs ==
# config.display_breadcrumbs = true
# config.set_initial_breadcrumbs do
# add_breadcrumb "Home", '/avo'
# end

## == Menus ==
# config.main_menu = -> {
# section "Dashboards", icon: "dashboards" do
# all_dashboards
# end

# section "Resources", icon: "resources" do
# all_resources
# end

# section "Tools", icon: "tools" do
# all_tools
# end
# }
# config.profile_menu = -> {
# link "Profile", path: "/avo/profile", icon: "user-circle"
# }
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
draw "concerns"
draw "devise"
draw "sidekiq"
draw "avo"

# `collection_actions` is automatically super scaffolded to your routes file when creating certain objects.
# This is helpful to have around when working with shallow routes and complicated model namespacing. We don't use this
Expand Down
6 changes: 6 additions & 0 deletions config/routes/avo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Avo admin panel
if defined?(Avo::Engine)
authenticate :user, lambda { |u| u.developer? } do
mount Avo::Engine, at: Avo.configuration.root_path
end
end

0 comments on commit bc8abc1

Please sign in to comment.