Skip to content

Commit

Permalink
Merge pull request #53 from TelosLabs/43-basic-admin-panel-setup
Browse files Browse the repository at this point in the history
AVO Basic setup
  • Loading branch information
Sergio-e authored Jul 24, 2024
2 parents 0cb9ea9 + 906aeca commit 4be8a39
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ gem "action_policy", "~> 0.7.0"
# Authentication
gem "bcrypt", "~> 3.1.20"

# Admin
gem "avo", ">= 3.2.1"

# Other
gem "bootsnap", require: false
gem "inline_svg"
gem "puma", ">= 5.0"
gem "ransack"
gem "rqrcode", "~> 2.0"
gem "tzinfo-data", platforms: %i[windows jruby]
gem "validates_timeliness", "~> 7.0.0.beta1"

Expand Down
40 changes: 40 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
active_link_to (1.0.5)
actionpack
addressable
activejob (7.1.3.4)
activesupport (= 7.1.3.4)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -86,6 +89,21 @@ GEM
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
ast (2.4.2)
avo (3.10.6)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
activesupport (>= 6.1)
addressable
docile
inline_svg
literal (~> 0.2)
meta-tags
pagy (>= 7.0.0)
turbo-rails (>= 2.0.0)
turbo_power (>= 0.6.0)
view_component (>= 3.7.0)
zeitwerk (>= 2.6.12)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
Expand Down Expand Up @@ -128,6 +146,7 @@ GEM
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (5.0.0)
chunky_png (1.4.0)
coderay (1.1.3)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
Expand Down Expand Up @@ -238,6 +257,7 @@ GEM
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
lint_roller (1.1.0)
literal (0.2.1)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -248,6 +268,8 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
meta-tags (2.22.0)
actionpack (>= 6.0.0, < 8.1)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.24.0)
Expand All @@ -272,6 +294,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.6-x86_64-linux)
racc (~> 1.4)
pagy (8.6.3)
parallel (1.25.1)
parser (3.3.3.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -340,6 +363,10 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
ransack (4.2.0)
activerecord (>= 6.1.5)
activesupport (>= 6.1.5)
i18n
rdoc (6.7.0)
psych (>= 4.0.0)
reek (6.3.0)
Expand All @@ -353,6 +380,10 @@ GEM
rexml (3.3.2)
strscan
rouge (4.3.0)
rqrcode (2.2.0)
chunky_png (~> 1.0)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand Down Expand Up @@ -468,12 +499,18 @@ GEM
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
turbo_power (0.6.2)
turbo-rails (>= 1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
validates_timeliness (7.0.0.beta2)
activemodel (>= 7.0.0, < 8)
timeliness (>= 0.3.10, < 1)
view_component (3.13.0)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
virtus (2.0.0)
axiom-types (~> 0.1)
coercible (~> 1.0)
Expand Down Expand Up @@ -501,6 +538,7 @@ DEPENDENCIES
action_policy (~> 0.7.0)
activerecord-enhancedsqlite3-adapter (~> 0.8.0)
annotate
avo (>= 3.2.1)
bcrypt (~> 3.1.20)
better_errors
binding_of_caller
Expand All @@ -526,6 +564,8 @@ DEPENDENCIES
rack-mini-profiler
rails (~> 7.1.3, >= 7.1.3.4)
rails-controller-testing
ransack
rqrcode (~> 2.0)
rspec-instafail
rspec-rails
rspec-retry
Expand Down
17 changes: 17 additions & 0 deletions app/avo/resources/profile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Avo::Resources::Profile < Avo::BaseResource
self.visible_on_sidebar = false

def fields
field :id, as: :id
field :uuid, as: :text, readonly: true
field :name, as: :text
field :bio, as: :text
field :location, as: :text
field :github_url, as: :text
field :linkedin_url, as: :text
field :twitter_url, as: :text
field :is_public, as: :boolean
field :profileable_type, as: :text
field :profileable_id, as: :text
end
end
20 changes: 20 additions & 0 deletions app/avo/resources/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Avo::Resources::User < Avo::BaseResource
self.includes = [:profile]
self.search = {
query: -> { query.ransack(email_cont: params[:q], m: "or").result(distinct: false) },
item: -> do
{
title: "[#{record.id}] #{record.email}"
}
end
}

def fields
field :id, as: :id
field :profile, as: :has_one
field :email, as: :text
field :role, as: :select, options: User.roles, include_blank: true
field :mail_notifications_enabled, as: :boolean
field :in_app_notifications_enabled, as: :boolean
end
end
2 changes: 2 additions & 0 deletions app/controllers/avo/base_resources_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Avo::BaseResourcesController < Avo::ResourcesController
end
2 changes: 2 additions & 0 deletions app/controllers/avo/profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Avo::ProfilesController < Avo::BaseResourcesController
end
2 changes: 2 additions & 0 deletions app/controllers/avo/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Avo::UsersController < Avo::BaseResourcesController
end
6 changes: 6 additions & 0 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class RegistrationsController < ApplicationController
allow_unauthenticated_access

before_action :redirect_if_signed_in

def new
@user = User.new
end
Expand All @@ -21,4 +23,8 @@ def create
def registration_params
params.require(:user).permit(:email, :password, :password_confirmation)
end

def redirect_if_signed_in
redirect_to root_path if user_signed_in?
end
end
6 changes: 6 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class SessionsController < ApplicationController
allow_unauthenticated_access only: [:new, :create]

before_action :redirect_if_signed_in, only: [:new, :create]

def new
@user = User.new
end
Expand All @@ -26,4 +28,8 @@ def destroy
def session_params
params.require(:user).permit(:email, :password)
end

def redirect_if_signed_in
redirect_to root_path if user_signed_in?
end
end
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class User < ApplicationRecord
validates :password_digest, presence: true
validates :password, length: {minimum: 8}, if: -> { password.present? }

enum role: {user: "user", admin: "admin"}

generates_token_for :password_reset, expires_in: PASSWORD_RESET_EXPIRATION do
password_salt&.last(10)
end

def self.ransackable_attributes(_auth_object = nil)
%w[email]
end
end
Loading

0 comments on commit 4be8a39

Please sign in to comment.