diff --git a/.dockerignore b/.dockerignore index 948f23cb..31ea3800 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,4 @@ capybara-*.html /log/*.log* coverage -tmp +tmp/cache diff --git a/Gemfile b/Gemfile index ee618d15..a0787d72 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem 'doorkeeper', '~> 4' # Revise if this is needed after Rails 6.0 gem 'image_processing' +gem 'rails_admin' gem 'ancestry' gem 'api-pagination' gem 'api_cache' diff --git a/Gemfile.lock b/Gemfile.lock index 412dd46a..7c3e23f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,10 @@ GEM globalid (>= 0.3.6) activemodel (6.0.3.3) activesupport (= 6.0.3.3) + activemodel-serializers-xml (1.0.2) + activemodel (> 5.x) + activesupport (> 5.x) + builder (~> 3.1) activerecord (6.0.3.3) activemodel (= 6.0.3.3) activesupport (= 6.0.3.3) @@ -124,15 +128,14 @@ GEM parallel choice (0.2.0) coderay (1.1.3) - concurrent-ruby (1.1.7) + concurrent-ruby (1.1.8) connection_pool (2.2.2) countries (2.1.4) i18n_data (~> 0.8.0) money (~> 6.9) sixarm_ruby_unaccent (~> 1.1) unicode_utils (~> 1.4) - crack (0.4.5) - rexml + crack (0.4.4) crass (1.0.6) css_parser (1.7.0) addressable @@ -142,7 +145,7 @@ GEM activesupport diff-lcs (1.4.4) diffy (3.3.0) - docile (1.3.4) + docile (1.3.2) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) doorkeeper (4.4.3) @@ -161,12 +164,12 @@ GEM factory_bot_rails (6.1.0) factory_bot (~> 6.1.0) railties (>= 5.0.0) - faker (2.15.1) + faker (2.14.0) i18n (>= 1.6, < 2) faraday (0.15.4) multipart-post (>= 1.2, < 3) fast_blank (1.0.0) - ffi (1.14.2) + ffi (1.13.1) fog-aws (3.5.1) fog-core (~> 2.1) fog-json (~> 1.1) @@ -206,7 +209,7 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - haml (5.2.1) + haml (5.1.2) temple (>= 0.8.0) tilt hashdiff (1.0.1) @@ -225,6 +228,12 @@ GEM jbuilder (2.9.1) activesupport (>= 4.2.0) jmespath (1.4.0) + jquery-rails (4.4.0) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-ui-rails (6.0.1) + railties (>= 3.2.16) json (2.3.1) jwt (2.2.1) kaminari (1.2.1) @@ -239,10 +248,10 @@ GEM activerecord kaminari-core (= 1.2.1) kaminari-core (1.2.1) - listen (3.4.0) + listen (3.2.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.8.0) + loofah (2.9.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.2.8) @@ -273,6 +282,7 @@ GEM multipart-post (2.1.1) mustermann (1.0.3) nenv (0.3.0) + nested_form (0.3.2) net-scp (3.0.0) net-ssh (>= 2.6.5, < 7.0.0) net-ssh (6.1.0) @@ -293,10 +303,10 @@ GEM rack (>= 1.2, < 3) oj (3.7.12) oj_mimic_json (1.0.1) - parallel (1.20.1) - parallel_tests (3.4.0) + parallel (1.19.2) + parallel_tests (3.3.0) parallel - parser (3.0.0.0) + parser (2.7.1.5) ast (~> 2.4.1) pg (1.1.4) pg_search (2.2.0) @@ -324,7 +334,7 @@ GEM raabro (1.1.6) racc (1.5.2) rack (2.2.3) - rack-attack (6.3.1) + rack-attack (6.0.0) rack (>= 1.0, < 3) rack-cache (1.9.0) rack (>= 0.4) @@ -332,6 +342,9 @@ GEM rack (~> 2.0) rack-cors (1.0.5) rack (>= 1.6.0) + rack-pjax (1.1.0) + nokogiri (~> 1.5) + rack (>= 1.1) rack-protection (2.0.5) rack rack-test (1.1.0) @@ -366,6 +379,18 @@ GEM rails_12factor (0.0.3) rails_serve_static_assets rails_stdout_logging + rails_admin (2.0.2) + activemodel-serializers-xml (>= 1.0) + builder (~> 3.1) + haml (>= 4.0, < 6) + jquery-rails (>= 3.0, < 5) + jquery-ui-rails (>= 5.0, < 7) + kaminari (>= 0.14, < 2.0) + nested_form (~> 0.3) + rack-pjax (>= 0.7) + rails (>= 5.0, < 7) + remotipart (~> 1.3) + sassc-rails (>= 1.3, < 3) rails_serve_static_assets (0.0.5) rails_stdout_logging (0.0.5) railties (6.0.3.3) @@ -385,9 +410,10 @@ GEM rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) - rdoc (6.3.0) + rdoc (6.2.1) redis (4.2.2) - regexp_parser (2.0.3) + regexp_parser (1.8.0) + remotipart (1.4.4) responders (3.0.0) actionpack (>= 5.0) railties (>= 5.0) @@ -397,41 +423,41 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) rexml (3.2.4) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.2) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.1) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-rails (4.0.2) + rspec-support (~> 3.9.0) + rspec-rails (4.0.1) actionpack (>= 4.2) activesupport (>= 4.2) railties (>= 4.2) - rspec-core (~> 3.10) - rspec-expectations (~> 3.10) - rspec-mocks (~> 3.10) - rspec-support (~> 3.10) - rspec-support (3.10.1) - rubocop (1.8.0) + rspec-core (~> 3.9) + rspec-expectations (~> 3.9) + rspec-mocks (~> 3.9) + rspec-support (~> 3.9) + rspec-support (3.9.3) + rubocop (0.92.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) + regexp_parser (>= 1.7) rexml - rubocop-ast (>= 1.2.0, < 2.0) + rubocop-ast (>= 0.5.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.4.0) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (0.5.0) parser (>= 2.7.1.5) ruby-graphviz (1.2.5) rexml - ruby-progressbar (1.11.0) + ruby-progressbar (1.10.1) ruby-vips (2.0.14) ffi (~> 1.9) ruby2ruby (2.4.4) @@ -444,6 +470,14 @@ GEM rufus-scheduler (3.6.0) fugit (~> 1.1, >= 1.1.6) safe_yaml (1.0.5) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt sentry-raven (2.9.0) faraday (>= 0.7.6, < 1.0) sexp_processor (4.15.1) @@ -453,12 +487,10 @@ GEM rack (>= 1.5.0) rack-protection (>= 1.5.0) redis (>= 3.3.5, < 5) - simplecov (0.21.1) + simplecov (0.19.0) docile (~> 1.1) simplecov-html (~> 0.11) - simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) - simplecov_json_formatter (0.1.2) sinatra (2.0.5) mustermann (~> 1.0) rack (~> 2.0) @@ -478,27 +510,28 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sshkit (1.21.1) + sshkit (1.21.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) sshkit-sudo (0.1.0) sshkit (~> 1.8) stamp (0.6.0) temple (0.8.2) - terminal-table (1.6.0) - thor (1.0.1) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thor (1.1.0) thread_safe (0.3.6) tilt (2.0.10) - timecop (0.9.2) + timecop (0.9.1) tzinfo (1.2.9) thread_safe (~> 0.1) unf (0.1.4) unf_ext unf_ext (0.0.7.6) - unicode-display_width (2.0.0) + unicode-display_width (1.7.0) unicode_utils (1.4.0) vcr (6.0.0) - webmock (3.11.0) + webmock (3.9.1) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -567,6 +600,7 @@ DEPENDENCIES rails (= 6.0.3.3) rails-erd rails_12factor + rails_admin ransack rdoc redis diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 00000000..e69de29b diff --git a/config/application.rb b/config/application.rb index 7d7cc175..bdb7a594 100644 --- a/config/application.rb +++ b/config/application.rb @@ -78,6 +78,13 @@ class Application < Rails::Application end end + # Needed for rails_admin + config.middleware.use ActionDispatch::Cookies + config.middleware.use ActionDispatch::Flash + config.middleware.use Rack::MethodOverride + config.middleware.use ActionDispatch::Session::CookieStore, {:key=>"_smartcitizen_session"} + # end rails_admin + config.api_only = true end end diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb new file mode 100644 index 00000000..a21da7ac --- /dev/null +++ b/config/initializers/rails_admin.rb @@ -0,0 +1,52 @@ +RailsAdmin.config do |config| + + ### Popular gems integration + + ## == Devise == + # config.authenticate_with do + # warden.authenticate! scope: :user + # end + # config.current_user_method(&:current_user) + + config.authenticate_with do + authenticate_or_request_with_http_basic('Login required') do |username, password| + user = User.where(username: username).first + if user && user.authenticate(password) + user.is_admin? + else + false + end + end + end + + ## == 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/sferik/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 diff --git a/config/routes.rb b/config/routes.rb index a23621fe..c071b6fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,13 @@ require "sidekiq/web" Rails.application.routes.draw do + mount RailsAdmin::Engine => '/admin', as: 'rails_admin' + if Rails.env.production? Sidekiq::Web.use Rack::Auth::Basic do |username, password| username == ENV["sidekiq_username"] && password == ENV["sidekiq_password"] end end + mount Sidekiq::Web, at: "/sidekiq" api_version(module: "V0", path: {value: "v0"}, header: {name: "Accept", value: "application/vnd.smartcitizen; version=0"}, default: true, defaults: { format: :json }) do