From 7e972f0d84be1f92e97cffdea326544196afe6a9 Mon Sep 17 00:00:00 2001 From: donrestarone Date: Sat, 28 Oct 2023 10:16:54 -0400 Subject: [PATCH] basic rails admin config -- need to fix multitenancy + allowing administration to happen on a per subdomain basis --- Gemfile | 2 + Gemfile.lock | 26 ++++++- app/javascript/packs/rails_admin.js | 2 + app/javascript/stylesheets/rails_admin.scss | 1 + config/initializers/rails_admin.rb | 47 +++++++++++ config/initializers/rails_admin_controller.rb | 34 ++++++++ config/routes.rb | 4 +- package.json | 4 + yarn.lock | 77 +++++++++++++++++++ 9 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 app/javascript/packs/rails_admin.js create mode 100644 app/javascript/stylesheets/rails_admin.scss create mode 100755 config/initializers/rails_admin.rb create mode 100644 config/initializers/rails_admin_controller.rb diff --git a/Gemfile b/Gemfile index c2cbb5f11..c4c245b5f 100644 --- a/Gemfile +++ b/Gemfile @@ -128,3 +128,5 @@ gem "strong_migrations" gem "simple_calendar", "~> 3.0" gem "icalendar", "~> 2.9" + +gem "rails_admin", "~> 3.1" diff --git a/Gemfile.lock b/Gemfile.lock index 0b0451feb..15b068918 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -587,7 +611,7 @@ DEPENDENCIES will_paginate RUBY VERSION - ruby 3.0.0p0 + ruby 2.6.6p146 BUNDLED WITH 2.1.4 diff --git a/app/javascript/packs/rails_admin.js b/app/javascript/packs/rails_admin.js new file mode 100644 index 000000000..63c31b597 --- /dev/null +++ b/app/javascript/packs/rails_admin.js @@ -0,0 +1,2 @@ +import "rails_admin/src/rails_admin/base"; +import "../stylesheets/rails_admin.scss"; diff --git a/app/javascript/stylesheets/rails_admin.scss b/app/javascript/stylesheets/rails_admin.scss new file mode 100644 index 000000000..8ca6f865f --- /dev/null +++ b/app/javascript/stylesheets/rails_admin.scss @@ -0,0 +1 @@ +@import "rails_admin/src/rails_admin/styles/base"; diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb new file mode 100755 index 000000000..d17ef9e83 --- /dev/null +++ b/config/initializers/rails_admin.rb @@ -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 \ No newline at end of file diff --git a/config/initializers/rails_admin_controller.rb b/config/initializers/rails_admin_controller.rb new file mode 100644 index 000000000..735fe481b --- /dev/null +++ b/config/initializers/rails_admin_controller.rb @@ -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 + diff --git a/config/routes.rb b/config/routes.rb index 820cc3185..29b581ada 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/package.json b/package.json index 24e501864..143693c86 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/yarn.lock b/yarn.lock index bc4680988..cff26d395 100644 --- a/yarn.lock +++ b/yarn.lock @@ -811,6 +811,13 @@ dependencies: regenerator-runtime "^0.13.4" +"@babel/runtime@^7.16.7": + version "7.23.2" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.2.tgz#062b0ac103261d68a966c4c7baf2ae3e62ec3885" + integrity sha512-mM8eg4yl5D6i3lu2QKPuPH4FArvJ8KhTofbE7jwMUv9KX5mBvwPAqnV3MlyBNqdp9RyRKP6Yck8TrfYrPvX3bg== + dependencies: + regenerator-runtime "^0.14.0" + "@babel/template@^7.12.13": version "7.12.13" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.13.tgz#530265be8a2589dbb37523844c5bcb55947fb327" @@ -848,6 +855,11 @@ resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7" integrity sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw== +"@fortawesome/fontawesome-free@>=5.15.0 <7.0.0": + version "6.4.2" + resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-6.4.2.tgz#36b6a9cb5ffbecdf89815c94d0c0ffa489ac5ecb" + integrity sha512-m5cPn3e2+FDCOgi1mz0RexTUvvQibBebOUlUlW0+YrMjDTPkiJ6VTKukA1GRsvRw+12KyJndNjj0O4AgTxm2Pg== + "@hotwired/stimulus-webpack-helpers@^1.0.0": version "1.0.1" resolved "https://registry.yarnpkg.com/@hotwired/stimulus-webpack-helpers/-/stimulus-webpack-helpers-1.0.1.tgz#4cd74487adeca576c9865ac2b9fe5cb20cef16dd" @@ -858,6 +870,14 @@ resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.2.1.tgz#e3de23623b0c52c247aba4cd5d530d257008676b" integrity sha512-HGlzDcf9vv/EQrMJ5ZG6VWNs8Z/xMN+1o2OhV1gKiSG6CqZt5MCBB1gRg5ILiN3U0jEAxuDTNPRfBcnZBDmupQ== +"@hotwired/turbo-rails@^7.1.0": + version "7.3.0" + resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-7.3.0.tgz#422c21752509f3edcd6c7b2725bbe9e157815f51" + integrity sha512-fvhO64vp/a2UVQ3jue9WTc2JisMv9XilIC7ViZmXAREVwiQ2S4UC7Go8f9A1j4Xu7DBI6SbFdqILk5ImqVoqyA== + dependencies: + "@hotwired/turbo" "^7.3.0" + "@rails/actioncable" "^7.0" + "@hotwired/turbo-rails@^7.1.3": version "7.1.3" resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-7.1.3.tgz#a4e04ecb800a06e7f9aa6e298170fa4580b74216" @@ -871,6 +891,11 @@ resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.1.0.tgz#27e44e0e3dc5bd1d4bda0766d579cf5a14091cd7" integrity sha512-Q8kGjqwPqER+CtpQudbH+3Zgs2X4zb6pBAlr6NsKTXadg45pAOvxI9i4QpuHbwSzR2+x87HUm+rot9F/Pe8rxA== +"@hotwired/turbo@^7.3.0": + version "7.3.0" + resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.3.0.tgz#2226000fff1aabda9fd9587474565c9929dbf15d" + integrity sha512-Dcu+NaSvHLT7EjrDrkEmH4qET2ZJZ5IcCWmNXxNQTBwlnE5tBZfN6WxZ842n5cHV52DH/AKNirbPBtcEXDLW4g== + "@npmcli/move-file@^1.0.1": version "1.1.2" resolved "https://registry.yarnpkg.com/@npmcli/move-file/-/move-file-1.1.2.tgz#1a82c3e372f7cae9253eb66d72543d6b8685c674" @@ -879,6 +904,11 @@ mkdirp "^1.0.4" rimraf "^3.0.2" +"@popperjs/core@^2.11.0": + version "2.11.8" + resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f" + integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A== + "@rails/actioncable@^6.0.0": version "6.1.3" resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.1.3.tgz#c8a67ec4d22ecd6931f7ebd98143fddbc815419a" @@ -908,6 +938,11 @@ resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.1.3.tgz#90ef26caa0925492b1a3b1495db09cfbe49e745e" integrity sha512-9mip5o+LVouWAqLMNJWhxda+D5uP+4RziNECgOGJlL6k3rc5SC/ljCHpV9Cym4i3oeGZkpZJ2tu4frCwt84kzQ== +"@rails/ujs@^6.1.4-1": + version "6.1.7" + resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.1.7.tgz#b09dc5b2105dd267e8374c47e4490240451dc7f6" + integrity sha512-0e7WQ4LE/+LEfW2zfAw9ppsB6A8RmxbdAUPAF++UT80epY+7emuQDkKXmaK0a9lp6An50RvzezI0cIQjp1A58w== + "@rails/webpacker@5.2.1": version "5.2.1" resolved "https://registry.yarnpkg.com/@rails/webpacker/-/webpacker-5.2.1.tgz#87cdbd4af2090ae2d74bdc51f6f04717d907c5b3" @@ -1582,6 +1617,11 @@ bootstrap@^4.6.0: resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-4.6.0.tgz#97b9f29ac98f98dfa43bf7468262d84392552fd7" integrity sha512-Io55IuQY3kydzHtbGvQya3H+KorS/M9rSNyfCGCg9WZ4pyT/lCxIlpJgG1GXW/PswzC84Tr2fBYi+7+jFVQQBw== +bootstrap@^5.1.3: + version "5.3.2" + resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-5.3.2.tgz#97226583f27aae93b2b28ab23f4c114757ff16ae" + integrity sha512-D32nmNWiQHo94BKHLmOrdjlL05q1c8oxbtBphQFb9Z5to6eGRDCm0QgeaZ4zFBHzfg2++rqa2JkqCcxDy0sH0g== + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -3139,6 +3179,11 @@ findup-sync@^3.0.0: micromatch "^3.0.4" resolve-dir "^1.0.1" +flatpickr@^4.6.9: + version "4.6.13" + resolved "https://registry.yarnpkg.com/flatpickr/-/flatpickr-4.6.13.tgz#8a029548187fd6e0d670908471e43abe9ad18d94" + integrity sha512-97PMG/aywoYpB4IvbvUJi0RQi8vearvU0oov1WW3k0WZPBMrTQVqekSX5CjSG/M4Q3i6A/0FKXC7RyAoAUUSPw== + flatted@^3.0.4: version "3.1.1" resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469" @@ -4139,11 +4184,23 @@ jest-worker@^26.5.0: merge-stream "^2.0.0" supports-color "^7.0.0" +jquery-ui@^1.12.1: + version "1.13.2" + resolved "https://registry.yarnpkg.com/jquery-ui/-/jquery-ui-1.13.2.tgz#de03580ae6604773602f8d786ad1abfb75232034" + integrity sha512-wBZPnqWs5GaYJmo1Jj0k/mrSkzdQzKDwhXNtHKcBdAcKVxMM3KNYFq+iJ2i1rwiG53Z8M4mTn3Qxrm17uH1D4Q== + dependencies: + jquery ">=1.8.0 <4.0.0" + jquery@>=1.10: version "3.6.3" resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.3.tgz#23ed2ffed8a19e048814f13391a19afcdba160e6" integrity sha512-bZ5Sy3YzKo9Fyc8wH2iIQK4JImJ6R0GWI9kL1/k7Z91ZBNgkRXE6U0JfHIizZbort8ZunhSI3jw9I6253ahKfg== +"jquery@>=1.8.0 <4.0.0": + version "3.7.1" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.7.1.tgz#083ef98927c9a6a74d05a6af02806566d16274de" + integrity sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg== + jquery@^3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470" @@ -6157,6 +6214,21 @@ rails-erb-loader@^5.5.2: loader-utils "^1.1.0" lodash.defaults "^4.2.0" +rails_admin@3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/rails_admin/-/rails_admin-3.1.2.tgz#00d6d85b7a00c89c69b5dbf5f1f4620702626504" + integrity sha512-uIQHN27lBvlav6s5ppmOtVxKN8GIxyhHuDFc9ZbvWgFknR4zgG4/xEUGzKzQ9R34AEsfZ/t8cZbvtvgj+aXp4A== + dependencies: + "@babel/runtime" "^7.16.7" + "@fortawesome/fontawesome-free" ">=5.15.0 <7.0.0" + "@hotwired/turbo-rails" "^7.1.0" + "@popperjs/core" "^2.11.0" + "@rails/ujs" "^6.1.4-1" + bootstrap "^5.1.3" + flatpickr "^4.6.9" + jquery "^3.6.0" + jquery-ui "^1.12.1" + randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" @@ -6274,6 +6346,11 @@ regenerator-runtime@^0.13.4, regenerator-runtime@^0.13.7: resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55" integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew== +regenerator-runtime@^0.14.0: + version "0.14.0" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz#5e19d68eb12d486f797e15a3c6a918f7cec5eb45" + integrity sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA== + regenerator-transform@^0.14.2: version "0.14.5" resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.5.tgz#c98da154683671c9c4dcb16ece736517e1b7feb4"