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

Feature/crud admin user #17

Merged
merged 10 commits into from Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -33,11 +33,13 @@ gem 'jbuilder'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

# Reduces boot times through caching; required in config/boot.rb
gem 'activeadmin', '~> 2.13', '>= 2.13.1'
gem 'bootsnap', require: false
gem 'byebug', '~> 11.1', '>= 11.1.3'
gem 'devise', '~> 4.8', '>= 4.8.1'
gem 'devise_token_auth', '>= 1.2.0', git: 'https://github.com/lynndylanhurley/devise_token_auth'
gem 'rack-cors', '~> 1.1', '>= 1.1.1'
gem 'sass-rails', '~> 6.0'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
Expand Down
58 changes: 58 additions & 0 deletions Gemfile.lock
Expand Up @@ -55,6 +55,15 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activeadmin (2.13.1)
arbre (~> 1.2, >= 1.2.1)
formtastic (>= 3.1, < 5.0)
formtastic_i18n (~> 0.4)
inherited_resources (~> 1.7)
jquery-rails (~> 4.2)
kaminari (~> 1.0, >= 1.2.1)
railties (>= 6.1, < 7.1)
ransack (>= 2.1.1, < 4)
activejob (7.0.2.4)
activesupport (= 7.0.2.4)
globalid (>= 0.3.6)
Expand All @@ -80,6 +89,9 @@ GEM
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
arbre (1.5.0)
activesupport (>= 3.0.0, < 7.1)
ruby2_keywords (>= 0.0.2, < 1.0)
ast (2.4.2)
bcrypt (3.1.18)
bindex (0.8.1)
Expand Down Expand Up @@ -121,20 +133,48 @@ GEM
railties (>= 5.0.0)
faker (2.21.0)
i18n (>= 1.8.11, < 2)
ffi (1.15.5)
formtastic (4.0.0)
actionpack (>= 5.2.0)
formtastic_i18n (0.7.0)
globalid (1.0.0)
activesupport (>= 5.0)
has_scope (0.8.0)
actionpack (>= 5.2)
activesupport (>= 5.2)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
importmap-rails (1.0.3)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
inherited_resources (1.13.1)
actionpack (>= 5.2, < 7.1)
has_scope (~> 0.6)
railties (>= 5.2, < 7.1)
responders (>= 2, < 4)
io-console (0.5.11)
irb (1.4.1)
reline (>= 0.3.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jquery-rails (4.5.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.6.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)
kwalify (0.7.2)
loofah (2.17.0)
crass (~> 1.0.2)
Expand Down Expand Up @@ -216,6 +256,10 @@ GEM
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
ransack (3.2.1)
activerecord (>= 6.1.5)
activesupport (>= 6.1.5)
i18n
reek (6.1.1)
kwalify (~> 0.7.0)
parser (~> 3.1.0)
Expand Down Expand Up @@ -263,7 +307,18 @@ GEM
rubocop-rootstrap (1.2)
rubocop (>= 0.72, < 2)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
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
selenium-webdriver (4.1.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
Expand All @@ -282,6 +337,7 @@ GEM
railties (>= 6.0.0)
strscan (3.0.1)
thor (1.2.1)
tilt (2.0.10)
timeout (0.2.0)
turbo-rails (1.0.1)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -312,6 +368,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
activeadmin (~> 2.13, >= 2.13.1)
annotate (~> 3.2)
bootsnap
byebug (~> 11.1, >= 11.1.3)
Expand All @@ -332,6 +389,7 @@ DEPENDENCIES
rspec-rails (~> 5.1, >= 5.1.2)
rubocop-rails (~> 2.15)
rubocop-rootstrap (~> 1.2)
sass-rails (~> 6.0)
selenium-webdriver
shoulda-matchers (~> 5.1)
sprockets-rails
Expand Down
27 changes: 27 additions & 0 deletions app/admin/admin_users.rb
@@ -0,0 +1,27 @@
ActiveAdmin.register AdminUser do
permit_params :email, :password, :password_confirmation

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
35 changes: 35 additions & 0 deletions app/admin/dashboard.rb
@@ -0,0 +1,35 @@
# 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
# content
end
end
1 change: 1 addition & 0 deletions app/assets/javascripts/active_admin.js
@@ -0,0 +1 @@
//= require active_admin/base
17 changes: 17 additions & 0 deletions 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; }
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
@@ -1,3 +1,2 @@
class ApplicationController < ActionController::Base
include DeviseTokenAuth::Concerns::SetUserByToken
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being removed? Don't we need to add it somewhere else?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a problem with active admin and this is already in the API controller.

https://github.com/LeandroSoria2/TargetApi/blob/develop/app/controllers/api/v1/api_controller.rb

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JulianPasquale It looks like including this line in the ApplicationController generates conflicts with active admin. He had another controller (ApiController) with this same DeviseTokenAuth inclusion already, which is the one he uses for endpoints, so he had to remove this line here in order to fix the issue he was having with active admin.

Here's a thread about the same issue Lean was having:

lynndylanhurley/devise_token_auth#47

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah so this is in the ApiController as well. If that's the case then it's ok to remove this 👍

end
24 changes: 24 additions & 0 deletions app/models/admin_user.rb
@@ -0,0 +1,24 @@
# == Schema Information
#
# Table name: admin_users
#
# id :bigint not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# 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
#
class AdminUser < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :validatable
end