Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic rails admin config -- need to fix multitenancy + allowing administration to happen on a per subdomain basis #1623

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ gem "strong_migrations"
gem "simple_calendar", "~> 3.0"

gem "icalendar", "~> 2.9"

gem "rails_admin", "~> 3.1"
26 changes: 25 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ GEM
globalid (>= 0.3.6)
activemodel (6.1.5)
activesupport (= 6.1.5)
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
activerecord (6.1.5)
activemodel (= 6.1.5)
activesupport (= 6.1.5)
Expand Down Expand Up @@ -266,6 +270,18 @@ GEM
json (2.5.1)
jsonapi-serializer (2.2.0)
activesupport (>= 4.2)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
kramdown (2.4.0)
rexml
listen (3.5.1)
Expand Down Expand Up @@ -299,6 +315,7 @@ GEM
multi_xml (0.6.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nested_form (0.3.2)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
Expand Down Expand Up @@ -358,6 +375,12 @@ GEM
rails-i18n (7.0.6)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
rails_admin (3.1.2)
activemodel-serializers-xml (>= 1.0)
kaminari (>= 0.14, < 2.0)
nested_form (~> 0.3)
rails (>= 6.0, < 8)
turbo-rails (~> 1.0)
railties (6.1.5)
actionpack (= 6.1.5)
activesupport (= 6.1.5)
Expand Down Expand Up @@ -558,6 +581,7 @@ DEPENDENCIES
rack-mini-profiler (~> 3.0)
rails (~> 6.1.5)
rails-controller-testing
rails_admin (~> 3.1)
ransack
recaptcha
redis-namespace (~> 1.8)
Expand Down Expand Up @@ -587,7 +611,7 @@ DEPENDENCIES
will_paginate

RUBY VERSION
ruby 3.0.0p0
ruby 2.6.6p146

BUNDLED WITH
2.1.4
2 changes: 2 additions & 0 deletions app/javascript/packs/rails_admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "rails_admin/src/rails_admin/base";
import "../stylesheets/rails_admin.scss";
1 change: 1 addition & 0 deletions app/javascript/stylesheets/rails_admin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "rails_admin/src/rails_admin/styles/base";
47 changes: 47 additions & 0 deletions config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
RailsAdmin.config do |config|
config.asset_source = :webpacker

### Popular gems integration

config.authenticate_with do
warden.authenticate! scope: :user
end
config.current_user_method(&:current_user)

## == Devise ==
# config.authenticate_with do
# warden.authenticate! scope: :user
# end
# config.current_user_method(&:current_user)

## == CancanCan ==
# config.authorize_with :cancancan

## == Pundit ==
# config.authorize_with :pundit

## == PaperTrail ==
# config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0

### More at https://github.com/railsadminteam/rails_admin/wiki/Base-configuration

## == Gravatar integration ==
## To disable Gravatar integration in Navigation Bar set to false
# config.show_gravatar = true

config.actions do
dashboard # mandatory
index # mandatory
new
export
bulk_delete
show
edit
delete
show_in_app

## With an audit adapter, you can add:
# history_index
# history_show
end
end
34 changes: 34 additions & 0 deletions config/initializers/rails_admin_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Rails.application.config.to_prepare do
RailsAdmin::ApplicationController.class_eval do
before_action :switch_tenant

def switch_tenant
Apartment::Tenant.switch!(Apartment::Tenant.current)
end

# def reload_rails_admin
# Rails.application.eager_load!
# excluded_models = ApplicationRecord.descendants.map { |m| m.name unless m.base_class.table_exists? }.compact
# puts "Excluded models: #{excluded_models}"

# RailsAdmin::Config.reset
# RailsAdmin.config do |config|
# config.excluded_models = excluded_models

# config.actions do
# dashboard
# index
# new
# export
# bulk_delete
# show
# edit
# delete
# show_in_app
# end
# end
# end

end
end

4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def self.matches?(request)
post '/users/sign_in/otp' => 'users/otp/sessions#create'
end
# system admin panel authentication (ensure public schema as well)
get 'sysadmin', to: 'admin/subdomain_requests#index'
# get 'sysadmin', to: 'admin/subdomain_requests#index'
mount RailsAdmin::Engine => '/sysadmin', as: 'rails_admin'

namespace :admin do
authenticate :user, lambda { |u| u.global_admin? } do
mount Sidekiq::Web => '/sidekiq'
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"moment": "^2.29.4",
"popper.js": "^1.16.1",
"rails-erb-loader": "^5.5.2",
"rails_admin": "3.1.2",
"select2": "^4.1.0-rc.0",
"sortablejs": "^1.14.0",
"stimulus": "^3.2.1",
Expand All @@ -35,5 +36,8 @@
"node": "14.x || 10.x",
"yarn": "1.22.x",
"npm": "6.14.x"
},
"resolutions": {
"rails_admin/@fortawesome/fontawesome-free": "^5.15.0"
}
}
77 changes: 77 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading