From 12b80cc7961a72b3f792d0ea64eb88c4b85f632e Mon Sep 17 00:00:00 2001 From: lucas podesta Date: Tue, 3 Sep 2024 18:19:46 -0300 Subject: [PATCH 1/4] activeadmin added --- Gemfile | 2 + Gemfile.lock | 77 +++- app/admin/admin_users.rb | 30 ++ app/admin/dashboard.rb | 34 ++ app/assets/javascripts/active_admin.js | 1 + app/assets/stylesheets/active_admin.scss | 17 + app/models/admin_user.rb | 27 ++ config/initializers/active_admin.rb | 354 ++++++++++++++++++ config/routes.rb | 2 + ...0240903211621_devise_create_admin_users.rb | 43 +++ ...0903211623_create_active_admin_comments.rb | 18 + db/schema.rb | 28 +- db/seeds.rb | 1 + spec/factories/admin_users.rb | 25 ++ spec/models/admin_user_spec.rb | 26 ++ 15 files changed, 678 insertions(+), 7 deletions(-) create mode 100644 app/admin/admin_users.rb create mode 100644 app/admin/dashboard.rb create mode 100644 app/assets/javascripts/active_admin.js create mode 100644 app/assets/stylesheets/active_admin.scss create mode 100644 app/models/admin_user.rb create mode 100644 config/initializers/active_admin.rb create mode 100644 db/migrate/20240903211621_devise_create_admin_users.rb create mode 100644 db/migrate/20240903211623_create_active_admin_comments.rb create mode 100644 spec/factories/admin_users.rb create mode 100644 spec/models/admin_user_spec.rb diff --git a/Gemfile b/Gemfile index 8a7d438..9b82c01 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ ruby file: '.ruby-version' gem 'rails', '~> 7.2' +gem 'activeadmin', '~> 3.2', '>= 3.2.4' gem 'aws-sdk-s3', '~> 1.122' gem 'blueprinter', '~> 1.0', '>= 1.0.2' gem 'bootsnap', '~> 1.18', '>= 1.18.3', require: false @@ -18,6 +19,7 @@ gem 'puma', '~> 6.4', '>= 6.4.2' gem 'rack-cors', '~> 2.0', '>= 2.0.2' gem 'redis', '~> 5.2' gem 'ruby-vips', '~> 2.2', '>= 2.2.1' +gem 'sassc-rails', '~> 2.1', '>= 2.1.2' gem 'sidekiq', '~> 7.3' gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] gem 'warped', '~> 1.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index e0731c7..bea7185 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,6 +45,16 @@ GEM erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) + activeadmin (3.2.4) + arbre (~> 1.2, >= 1.2.1) + csv + formtastic (>= 3.1) + formtastic_i18n (>= 0.4) + inherited_resources (~> 1.7) + jquery-rails (>= 4.2) + kaminari (>= 1.2.1) + railties (>= 6.1) + ransack (>= 4.0) activejob (7.2.0) activesupport (= 7.2.0) globalid (>= 0.3.6) @@ -76,6 +86,9 @@ GEM annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) + arbre (1.7.0) + activesupport (>= 3.0.0) + ruby2_keywords (>= 0.0.2) ast (2.4.2) aws-eventstream (1.3.0) aws-partitions (1.963.0) @@ -108,6 +121,7 @@ GEM concurrent-ruby (1.3.4) connection_pool (2.4.1) crass (1.0.6) + csv (3.3.0) date (3.3.4) debug (1.9.2) irb (~> 1.10) @@ -158,18 +172,45 @@ GEM ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-linux-gnu) ffi (1.17.0-x86_64-linux-musl) + formtastic (5.0.0) + actionpack (>= 6.0.0) + formtastic_i18n (0.7.0) globalid (1.2.1) activesupport (>= 6.1) + has_scope (0.8.2) + actionpack (>= 5.2) + activesupport (>= 5.2) i18n (1.14.5) concurrent-ruby (~> 1.0) + inherited_resources (1.14.0) + actionpack (>= 6.0) + has_scope (>= 0.6) + railties (>= 6.0) + responders (>= 2) io-console (0.7.2) irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) jmespath (1.6.2) + jquery-rails (4.6.0) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) json (2.7.2) jwt (2.8.2) base64 + 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) language_server-protocol (3.17.0.3) launchy (3.0.1) addressable (~> 2.8) @@ -223,16 +264,16 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.1) - rack (3.1.7) + rack (2.2.9) rack-cors (2.0.2) rack (>= 2.0.0) - rack-session (2.0.0) - rack (>= 3.0.0) + rack-session (1.0.2) + rack (< 3) rack-test (2.1.0) rack (>= 1.3) - rackup (2.1.0) - rack (>= 3) - webrick (~> 1.8) + rackup (1.0.0) + rack (< 3) + webrick rails (7.2.0) actioncable (= 7.2.0) actionmailbox (= 7.2.0) @@ -264,6 +305,10 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.2.1) + ransack (4.2.1) + activerecord (>= 6.1.5) + activesupport (>= 6.1.5) + i18n rdoc (6.7.0) psych (>= 4.0.0) redis (5.2.0) @@ -317,6 +362,15 @@ GEM ruby-vips (2.2.2) ffi (~> 1.12) logger + ruby2_keywords (0.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 securerandom (0.3.1) shoulda-matchers (6.3.1) activesupport (>= 5.2.0) @@ -332,9 +386,18 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) + sprockets (3.7.3) + base64 + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + sprockets (>= 3.0.0) stringio (3.1.1) strscan (3.1.0) thor (1.3.1) + tilt (2.4.0) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) @@ -374,6 +437,7 @@ PLATFORMS x86_64-linux-musl DEPENDENCIES + activeadmin (~> 3.2, >= 3.2.4) annotate (~> 3.2) aws-sdk-s3 (~> 1.122) blueprinter (~> 1.0, >= 1.0.2) @@ -397,6 +461,7 @@ DEPENDENCIES rubocop (~> 1.64, >= 1.64.1) rubocop-rails (~> 2.25, >= 2.25.1) ruby-vips (~> 2.2, >= 2.2.1) + sassc-rails (~> 2.1, >= 2.1.2) shoulda-matchers (~> 6.2) sidekiq (~> 7.3) simplecov (~> 0.22.0) diff --git a/app/admin/admin_users.rb b/app/admin/admin_users.rb new file mode 100644 index 0000000..8aefa82 --- /dev/null +++ b/app/admin/admin_users.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +ActiveAdmin.register AdminUser do + permit_params :email, :password, :password_confirmation + + remove_filter :email, :encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at + index do + selectable_column + id_column + column :email + column :current_sign_in_at + column :sign_in_count + column :created_at + actions + end + + filter :email + filter :current_sign_in_at + filter :sign_in_count + filter :created_at + + form do |f| + f.inputs do + f.input :email + f.input :password + f.input :password_confirmation + end + f.actions + end +end diff --git a/app/admin/dashboard.rb b/app/admin/dashboard.rb new file mode 100644 index 0000000..21064f9 --- /dev/null +++ b/app/admin/dashboard.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +ActiveAdmin.register_page 'Dashboard' do + menu priority: 1, label: proc { I18n.t('active_admin.dashboard') } + + content title: proc { I18n.t('active_admin.dashboard') } do + div class: 'blank_slate_container', id: 'dashboard_default_message' do + span class: 'blank_slate' do + span I18n.t('active_admin.dashboard_welcome.welcome') + small I18n.t('active_admin.dashboard_welcome.call_to_action') + end + end + + # Here is an example of a simple dashboard with columns and panels. + # + # columns do + # column do + # panel "Recent Posts" do + # ul do + # Post.recent(5).map do |post| + # li link_to(post.title, admin_post_path(post)) + # end + # end + # end + # end + + # column do + # panel "Info" do + # para "Welcome to ActiveAdmin." + # end + # end + # end + end +end diff --git a/app/assets/javascripts/active_admin.js b/app/assets/javascripts/active_admin.js new file mode 100644 index 0000000..d2b66c5 --- /dev/null +++ b/app/assets/javascripts/active_admin.js @@ -0,0 +1 @@ +//= require active_admin/base diff --git a/app/assets/stylesheets/active_admin.scss b/app/assets/stylesheets/active_admin.scss new file mode 100644 index 0000000..41c27b3 --- /dev/null +++ b/app/assets/stylesheets/active_admin.scss @@ -0,0 +1,17 @@ +// Sass variable overrides must be declared before loading up Active Admin's styles. +// +// To view the variables that Active Admin provides, take a look at +// `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the +// Active Admin source. +// +// For example, to change the sidebar width: +// $sidebar-width: 242px; + +// Active Admin's got SASS! +@import "active_admin/mixins"; +@import "active_admin/base"; + +// Overriding any non-variable Sass must be done after the fact. +// For example, to change the default status-tag color: +// +// .status_tag { background: #6090DB; } diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb new file mode 100644 index 0000000..f6ba433 --- /dev/null +++ b/app/models/admin_user.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class AdminUser < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, + :recoverable, :rememberable, :validatable +end + +# == Schema Information +# +# Table name: admin_users +# +# id :bigint not null, primary key +# email :string default(""), not null +# encrypted_password :string default(""), not null +# remember_created_at :datetime +# reset_password_sent_at :datetime +# reset_password_token :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_admin_users_on_email (email) UNIQUE +# index_admin_users_on_reset_password_token (reset_password_token) UNIQUE +# diff --git a/config/initializers/active_admin.rb b/config/initializers/active_admin.rb new file mode 100644 index 0000000..933c057 --- /dev/null +++ b/config/initializers/active_admin.rb @@ -0,0 +1,354 @@ +# frozen_string_literal: true + +ActiveAdmin.setup do |config| + # == Site Title + # + # Set the title that is displayed on the main layout + # for each of the active admin pages. + # + config.site_title = 'Rails Api' + + # Set the link url for the title. For example, to take + # users to your main site. Defaults to no link. + # + # config.site_title_link = "/" + + # Set an optional image to be displayed for the header + # instead of a string (overrides :site_title) + # + # Note: Aim for an image that's 21px high so it fits in the header. + # + # config.site_title_image = "logo.png" + + # == Load Paths + # + # By default Active Admin files go inside app/admin/. + # You can change this directory. + # + # eg: + # config.load_paths = [File.join(Rails.root, 'app', 'ui')] + # + # Or, you can also load more directories. + # Useful when setting namespaces with users that are not your main AdminUser entity. + # + # eg: + # config.load_paths = [ + # File.join(Rails.root, 'app', 'admin'), + # File.join(Rails.root, 'app', 'cashier') + # ] + + # == Default Namespace + # + # Set the default namespace each administration resource + # will be added to. + # + # eg: + # config.default_namespace = :hello_world + # + # This will create resources in the HelloWorld module and + # will namespace routes to /hello_world/* + # + # To set no namespace by default, use: + # config.default_namespace = false + # + # Default: + # config.default_namespace = :admin + # + # You can customize the settings for each namespace by using + # a namespace block. For example, to change the site title + # within a namespace: + # + # config.namespace :admin do |admin| + # admin.site_title = "Custom Admin Title" + # end + # + # This will ONLY change the title for the admin section. Other + # namespaces will continue to use the main "site_title" configuration. + + # == User Authentication + # + # Active Admin will automatically call an authentication + # method in a before filter of all controller actions to + # ensure that there is a currently logged in admin user. + # + # This setting changes the method which Active Admin calls + # within the application controller. + config.authentication_method = :authenticate_admin_user! + + # == User Authorization + # + # Active Admin will automatically call an authorization + # method in a before filter of all controller actions to + # ensure that there is a user with proper rights. You can use + # CanCanAdapter or make your own. Please refer to documentation. + # config.authorization_adapter = ActiveAdmin::CanCanAdapter + + # In case you prefer Pundit over other solutions you can here pass + # the name of default policy class. This policy will be used in every + # case when Pundit is unable to find suitable policy. + # config.pundit_default_policy = "MyDefaultPunditPolicy" + + # If you wish to maintain a separate set of Pundit policies for admin + # resources, you may set a namespace here that Pundit will search + # within when looking for a resource's policy. + # config.pundit_policy_namespace = :admin + + # You can customize your CanCan Ability class name here. + # config.cancan_ability_class = "Ability" + + # You can specify a method to be called on unauthorized access. + # This is necessary in order to prevent a redirect loop which happens + # because, by default, user gets redirected to Dashboard. If user + # doesn't have access to Dashboard, he'll end up in a redirect loop. + # Method provided here should be defined in application_controller.rb. + # config.on_unauthorized_access = :access_denied + + # == Current User + # + # Active Admin will associate actions with the current + # user performing them. + # + # This setting changes the method which Active Admin calls + # (within the application controller) to return the currently logged in user. + config.current_user_method = :current_admin_user + + # == Logging Out + # + # Active Admin displays a logout link on each screen. These + # settings configure the location and method used for the link. + # + # This setting changes the path where the link points to. If it's + # a string, the strings is used as the path. If it's a Symbol, we + # will call the method to return the path. + # + # Default: + config.logout_link_path = :destroy_admin_user_session_path + + # This setting changes the http method used when rendering the + # link. For example :get, :delete, :put, etc.. + # + # Default: + # config.logout_link_method = :get + + # == Root + # + # Set the action to call for the root path. You can set different + # roots for each namespace. + # + # Default: + # config.root_to = 'dashboard#index' + + # == Admin Comments + # + # This allows your users to comment on any resource registered with Active Admin. + # + # You can completely disable comments: + # config.comments = false + # + # You can change the name under which comments are registered: + # config.comments_registration_name = 'AdminComment' + # + # You can change the order for the comments and you can change the column + # to be used for ordering: + # config.comments_order = 'created_at ASC' + # + # You can disable the menu item for the comments index page: + # config.comments_menu = false + # + # You can customize the comment menu: + # config.comments_menu = { parent: 'Admin', priority: 1 } + + # == Batch Actions + # + # Enable and disable Batch Actions + # + config.batch_actions = true + + # == Controller Filters + # + # You can add before, after and around filters to all of your + # Active Admin resources and pages from here. + # + # config.before_action :do_something_awesome + + # == Attribute Filters + # + # You can exclude possibly sensitive model attributes from being displayed, + # added to forms, or exported by default by ActiveAdmin + # + config.filter_attributes = %i[encrypted_password password password_confirmation] + + # == Localize Date/Time Format + # + # Set the localize format to display dates and times. + # To understand how to localize your app with I18n, read more at + # https://guides.rubyonrails.org/i18n.html + # + # You can run `bin/rails runner 'puts I18n.t("date.formats")'` to see the + # available formats in your application. + # + config.localize_format = :long + + # == Setting a Favicon + # + # config.favicon = 'favicon.ico' + + # == Meta Tags + # + # Add additional meta tags to the head element of active admin pages. + # + # Add tags to all pages logged in users see: + # config.meta_tags = { author: 'My Company' } + + # By default, sign up/sign in/recover password pages are excluded + # from showing up in search engine results by adding a robots meta + # tag. You can reset the hash of meta tags included in logged out + # pages: + # config.meta_tags_for_logged_out_pages = {} + + # == Removing Breadcrumbs + # + # Breadcrumbs are enabled by default. You can customize them for individual + # resources or you can disable them globally from here. + # + # config.breadcrumb = false + + # == Create Another Checkbox + # + # Create another checkbox is disabled by default. You can customize it for individual + # resources or you can enable them globally from here. + # + # config.create_another = true + + # == Register Stylesheets & Javascripts + # + # We recommend using the built in Active Admin layout and loading + # up your own stylesheets / javascripts to customize the look + # and feel. + # + # To load a stylesheet: + # config.register_stylesheet 'my_stylesheet.css' + # + # You can provide an options hash for more control, which is passed along to stylesheet_link_tag(): + # config.register_stylesheet 'my_print_stylesheet.css', media: :print + # + # To load a javascript file: + # config.register_javascript 'my_javascript.js' + + # == CSV options + # + # Set the CSV builder separator + # config.csv_options = { col_sep: ';' } + # + # Force the use of quotes + # config.csv_options = { force_quotes: true } + + # == Menu System + # + # You can add a navigation menu to be used in your application, or configure a provided menu + # + # To change the default utility navigation to show a link to your website & a logout btn + # + # config.namespace :admin do |admin| + # admin.build_menu :utility_navigation do |menu| + # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank } + # admin.add_logout_button_to_menu menu + # end + # end + # + # If you wanted to add a static menu item to the default menu provided: + # + # config.namespace :admin do |admin| + # admin.build_menu :default do |menu| + # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: "_blank" } + # end + # end + + # == Download Links + # + # You can disable download links on resource listing pages, + # or customize the formats shown per namespace/globally + # + # To disable/customize for the :admin namespace: + # + # config.namespace :admin do |admin| + # + # # Disable the links entirely + # admin.download_links = false + # + # # Only show XML & PDF options + # admin.download_links = [:xml, :pdf] + # + # # Enable/disable the links based on block + # # (for example, with cancan) + # admin.download_links = proc { can?(:view_download_links) } + # + # end + + # == Pagination + # + # Pagination is enabled by default for all resources. + # You can control the default per page count for all resources here. + # + # config.default_per_page = 30 + # + # You can control the max per page count too. + # + # config.max_per_page = 10_000 + + # == Filters + # + # By default the index screen includes a "Filters" sidebar on the right + # hand side with a filter for each attribute of the registered model. + # You can enable or disable them for all resources here. + # + # config.filters = true + # + # By default the filters include associations in a select, which means + # that every record will be loaded for each association (up + # to the value of config.maximum_association_filter_arity). + # You can enabled or disable the inclusion + # of those filters by default here. + # + # config.include_default_association_filters = true + + # config.maximum_association_filter_arity = 256 # default value of :unlimited will change to 256 in a future version + # config.filter_columns_for_large_association = [ + # :display_name, + # :full_name, + # :name, + # :username, + # :login, + # :title, + # :email, + # ] + # config.filter_method_for_large_association = '_start' + + # == Head + # + # You can add your own content to the site head like analytics. Make sure + # you only pass content you trust. + # + # config.head = ''.html_safe + + # == Footer + # + # By default, the footer shows the current Active Admin version. You can + # override the content of the footer here. + # + # config.footer = 'my custom footer text' + + # == Sorting + # + # By default ActiveAdmin::OrderClause is used for sorting logic + # You can inherit it with own class and inject it for all resources + # + # config.order_clause = MyOrderClause + + # == Webpacker + # + # By default, Active Admin uses Sprocket's asset pipeline. + # You can switch to using Webpacker here. + # + # config.use_webpacker = true +end diff --git a/config/routes.rb b/config/routes.rb index d34e308..9cc8233 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true Rails.application.routes.draw do + devise_for :admin_users, ActiveAdmin::Devise.config + ActiveAdmin.routes(self) get 'up' => 'rails/health#show', as: :rails_health_check defaults format: :html do diff --git a/db/migrate/20240903211621_devise_create_admin_users.rb b/db/migrate/20240903211621_devise_create_admin_users.rb new file mode 100644 index 0000000..4bf91b0 --- /dev/null +++ b/db/migrate/20240903211621_devise_create_admin_users.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +class DeviseCreateAdminUsers < ActiveRecord::Migration[7.2] + def change + create_table :admin_users do |t| + ## Database authenticatable + t.string :email, null: false, default: '' + t.string :encrypted_password, null: false, default: '' + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + # t.integer :sign_in_count, default: 0, null: false + # t.datetime :current_sign_in_at + # t.datetime :last_sign_in_at + # t.string :current_sign_in_ip + # t.string :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + t.timestamps null: false + end + + add_index :admin_users, :email, unique: true + add_index :admin_users, :reset_password_token, unique: true + # add_index :admin_users, :confirmation_token, unique: true + # add_index :admin_users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20240903211623_create_active_admin_comments.rb b/db/migrate/20240903211623_create_active_admin_comments.rb new file mode 100644 index 0000000..e8cbf67 --- /dev/null +++ b/db/migrate/20240903211623_create_active_admin_comments.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateActiveAdminComments < ActiveRecord::Migration[7.2] + def self.up + create_table :active_admin_comments do |t| + t.string :namespace + t.text :body + t.references :resource, polymorphic: true + t.references :author, polymorphic: true + t.timestamps + end + add_index :active_admin_comments, [:namespace] + end + + def self.down + drop_table :active_admin_comments + end +end diff --git a/db/schema.rb b/db/schema.rb index 1e8f2ec..2da4413 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,10 +10,24 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2023_11_24_152822) do +ActiveRecord::Schema[7.2].define(version: 2024_09_03_211623) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "active_admin_comments", force: :cascade do |t| + t.string "namespace" + t.text "body" + t.string "resource_type" + t.bigint "resource_id" + t.string "author_type" + t.bigint "author_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author" + t.index ["namespace"], name: "index_active_admin_comments_on_namespace" + t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource" + end + create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -42,6 +56,18 @@ t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end + create_table "admin_users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_admin_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true + end + create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false diff --git a/db/seeds.rb b/db/seeds.rb index 6533326..c86db72 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,3 +7,4 @@ # # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) # Character.create(name: "Luke", movie: movies.first) +AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') if Rails.env.development? \ No newline at end of file diff --git a/spec/factories/admin_users.rb b/spec/factories/admin_users.rb new file mode 100644 index 0000000..aec4e1b --- /dev/null +++ b/spec/factories/admin_users.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :admin_user do + end +end + +# == Schema Information +# +# Table name: admin_users +# +# id :bigint not null, primary key +# email :string default(""), not null +# encrypted_password :string default(""), not null +# remember_created_at :datetime +# reset_password_sent_at :datetime +# reset_password_token :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_admin_users_on_email (email) UNIQUE +# index_admin_users_on_reset_password_token (reset_password_token) UNIQUE +# diff --git a/spec/models/admin_user_spec.rb b/spec/models/admin_user_spec.rb new file mode 100644 index 0000000..afa6091 --- /dev/null +++ b/spec/models/admin_user_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe AdminUser, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end + +# == Schema Information +# +# Table name: admin_users +# +# id :bigint not null, primary key +# email :string default(""), not null +# encrypted_password :string default(""), not null +# remember_created_at :datetime +# reset_password_sent_at :datetime +# reset_password_token :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_admin_users_on_email (email) UNIQUE +# index_admin_users_on_reset_password_token (reset_password_token) UNIQUE +# From b937abdcde9e120d39f82fea23637a08dead4fc4 Mon Sep 17 00:00:00 2001 From: lucas podesta Date: Tue, 3 Sep 2024 19:22:09 -0300 Subject: [PATCH 2/4] admin_user_spec added and rubocop fixes --- app/admin/admin_users.rb | 1 + db/seeds.rb | 2 +- spec/factories/admin_users.rb | 2 ++ spec/models/admin_user_spec.rb | 8 +++++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/admin/admin_users.rb b/app/admin/admin_users.rb index 8aefa82..9e27699 100644 --- a/app/admin/admin_users.rb +++ b/app/admin/admin_users.rb @@ -4,6 +4,7 @@ permit_params :email, :password, :password_confirmation remove_filter :email, :encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at + index do selectable_column id_column diff --git a/db/seeds.rb b/db/seeds.rb index c86db72..17c8e57 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,4 +7,4 @@ # # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) # Character.create(name: "Luke", movie: movies.first) -AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') if Rails.env.development? \ No newline at end of file +AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') if Rails.env.development? diff --git a/spec/factories/admin_users.rb b/spec/factories/admin_users.rb index aec4e1b..b483bb0 100644 --- a/spec/factories/admin_users.rb +++ b/spec/factories/admin_users.rb @@ -2,6 +2,8 @@ FactoryBot.define do factory :admin_user do + sequence(:email) { |n| "admin#{n}@3maccounting.ca" } + password { Faker::Internet.password(min_length: 6) } end end diff --git a/spec/models/admin_user_spec.rb b/spec/models/admin_user_spec.rb index afa6091..feaefc5 100644 --- a/spec/models/admin_user_spec.rb +++ b/spec/models/admin_user_spec.rb @@ -3,7 +3,13 @@ require 'rails_helper' RSpec.describe AdminUser, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + describe 'validations' do + subject { build(:admin_user) } + + it { is_expected.to validate_presence_of(:email) } + it { is_expected.to validate_uniqueness_of(:email).case_insensitive } + it { is_expected.to validate_presence_of(:password) } + end end # == Schema Information From fe41ca290eb974647a59892b6e6669601a3ef663 Mon Sep 17 00:00:00 2001 From: lucas podesta Date: Wed, 4 Sep 2024 11:17:22 -0300 Subject: [PATCH 3/4] arctic_admin added --- .gitignore | 2 ++ Gemfile | 3 +++ Gemfile.lock | 12 +++++++++--- app/assets/config/manifest.js | 0 app/assets/javascripts/active_admin.js | 2 +- app/assets/stylesheets/active_admin.scss | 2 +- config/initializers/active_admin.rb | 9 +++++++-- package.json | 6 ++++++ yarn.lock | 13 +++++++++++++ 9 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 app/assets/config/manifest.js create mode 100644 package.json create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore index 72959d2..d7973f8 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,5 @@ # Ignore all .pem files *.pem + +/node_modules diff --git a/Gemfile b/Gemfile index 9b82c01..88d1d89 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ ruby file: '.ruby-version' gem 'rails', '~> 7.2' gem 'activeadmin', '~> 3.2', '>= 3.2.4' +gem 'arctic_admin', '~> 4.3', '>= 4.3.1' gem 'aws-sdk-s3', '~> 1.122' gem 'blueprinter', '~> 1.0', '>= 1.0.2' gem 'bootsnap', '~> 1.18', '>= 1.18.3', require: false @@ -21,6 +22,8 @@ gem 'redis', '~> 5.2' gem 'ruby-vips', '~> 2.2', '>= 2.2.1' gem 'sassc-rails', '~> 2.1', '>= 2.1.2' gem 'sidekiq', '~> 7.3' +gem 'sprockets', '~> 4.2', '>= 4.2.1' + gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] gem 'warped', '~> 1.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index bea7185..050938e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,6 +89,9 @@ GEM arbre (1.7.0) activesupport (>= 3.0.0) ruby2_keywords (>= 0.0.2) + arctic_admin (4.3.1) + activeadmin (>= 1.1.0, < 4.0) + font-awesome-sass (~> 6.0) ast (2.4.2) aws-eventstream (1.3.0) aws-partitions (1.963.0) @@ -172,6 +175,8 @@ GEM ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-linux-gnu) ffi (1.17.0-x86_64-linux-musl) + font-awesome-sass (6.5.2) + sassc (~> 2.0) formtastic (5.0.0) actionpack (>= 6.0.0) formtastic_i18n (0.7.0) @@ -386,10 +391,9 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - sprockets (3.7.3) - base64 + sprockets (4.2.1) concurrent-ruby (~> 1.0) - rack (> 1, < 3) + rack (>= 2.2.4, < 4) sprockets-rails (3.5.2) actionpack (>= 6.1) activesupport (>= 6.1) @@ -439,6 +443,7 @@ PLATFORMS DEPENDENCIES activeadmin (~> 3.2, >= 3.2.4) annotate (~> 3.2) + arctic_admin (~> 4.3, >= 4.3.1) aws-sdk-s3 (~> 1.122) blueprinter (~> 1.0, >= 1.0.2) bootsnap (~> 1.18, >= 1.18.3) @@ -465,6 +470,7 @@ DEPENDENCIES shoulda-matchers (~> 6.2) sidekiq (~> 7.3) simplecov (~> 0.22.0) + sprockets (~> 4.2, >= 4.2.1) tzinfo-data warped (~> 1.0.0) diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/active_admin.js b/app/assets/javascripts/active_admin.js index d2b66c5..a79b4c7 100644 --- a/app/assets/javascripts/active_admin.js +++ b/app/assets/javascripts/active_admin.js @@ -1 +1 @@ -//= require active_admin/base +//= require arctic_admin/base diff --git a/app/assets/stylesheets/active_admin.scss b/app/assets/stylesheets/active_admin.scss index 41c27b3..69138a0 100644 --- a/app/assets/stylesheets/active_admin.scss +++ b/app/assets/stylesheets/active_admin.scss @@ -9,7 +9,7 @@ // Active Admin's got SASS! @import "active_admin/mixins"; -@import "active_admin/base"; +@import "arctic_admin/base"; // Overriding any non-variable Sass must be done after the fact. // For example, to change the default status-tag color: diff --git a/config/initializers/active_admin.rb b/config/initializers/active_admin.rb index 933c057..1e22b00 100644 --- a/config/initializers/active_admin.rb +++ b/config/initializers/active_admin.rb @@ -6,7 +6,7 @@ # Set the title that is displayed on the main layout # for each of the active admin pages. # - config.site_title = 'Rails Api' + config.site_title = 'GoGrow Api' # Set the link url for the title. For example, to take # users to your main site. Defaults to no link. @@ -198,7 +198,10 @@ # Add additional meta tags to the head element of active admin pages. # # Add tags to all pages logged in users see: - # config.meta_tags = { author: 'My Company' } + # + + meta_tags_options = { viewport: 'width=device-width, initial-scale=1' } + config.meta_tags = meta_tags_options # By default, sign up/sign in/recover password pages are excluded # from showing up in search engine results by adding a robots meta @@ -206,6 +209,8 @@ # pages: # config.meta_tags_for_logged_out_pages = {} + config.meta_tags_for_logged_out_pages = meta_tags_options + # == Removing Breadcrumbs # # Breadcrumbs are enabled by default. You can customize them for individual diff --git a/package.json b/package.json new file mode 100644 index 0000000..17b3e1e --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "@fortawesome/fontawesome-free": "^6.6.0", + "arctic_admin": "^4.3.1" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..10c7972 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,13 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@fortawesome/fontawesome-free@^6.6.0": + version "6.6.0" + resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-6.6.0.tgz#0e984f0f2344ee513c185d87d77defac4c0c8224" + integrity sha512-60G28ke/sXdtS9KZCpZSHHkCbdsOGEhIUGlwq6yhY74UpTiToIh8np7A8yphhM4BWsvNFtIvLpi4co+h9Mr9Ow== + +arctic_admin@^4.3.1: + version "4.3.1" + resolved "https://registry.yarnpkg.com/arctic_admin/-/arctic_admin-4.3.1.tgz#276fb2fcfb4eca219e350e427e36d330a597833e" + integrity sha512-2z5HHVobZZCWgJiWelG/RG4pnbo+iXTAOCEcAC6TBSI4LI7u8h1ugBkYgg9IF15jFh7Z8j2c1Qw7gxrCH0wgkQ== From e0150941500b45f17c3edc3f85dbdcf44ad195d5 Mon Sep 17 00:00:00 2001 From: lucas podesta Date: Mon, 9 Sep 2024 20:17:36 -0300 Subject: [PATCH 4/4] pr comments --- app/admin/admin_users.rb | 15 +++++++-------- app/models/application_record.rb | 4 ++++ spec/factories/admin_users.rb | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/admin/admin_users.rb b/app/admin/admin_users.rb index 9e27699..b56c82a 100644 --- a/app/admin/admin_users.rb +++ b/app/admin/admin_users.rb @@ -3,22 +3,21 @@ ActiveAdmin.register AdminUser do permit_params :email, :password, :password_confirmation - remove_filter :email, :encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at - index do selectable_column id_column column :email - column :current_sign_in_at - column :sign_in_count column :created_at actions end - filter :email - filter :current_sign_in_at - filter :sign_in_count - filter :created_at + show do + attributes_table do + row :id + row :email + row :created_at + end + end form do |f| f.inputs do diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 08dc537..903e357 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -2,4 +2,8 @@ class ApplicationRecord < ActiveRecord::Base primary_abstract_class + + def self.ransackable_attributes(auth_object = nil) + authorizable_ransackable_attributes + end end diff --git a/spec/factories/admin_users.rb b/spec/factories/admin_users.rb index b483bb0..4f7b464 100644 --- a/spec/factories/admin_users.rb +++ b/spec/factories/admin_users.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :admin_user do - sequence(:email) { |n| "admin#{n}@3maccounting.ca" } + email { Faker::Internet.email } password { Faker::Internet.password(min_length: 6) } end end