-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up ActiveAdmin for user management with admin role access
- Loading branch information
1 parent
934832b
commit 47f08a1
Showing
23 changed files
with
655 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2024-10-21 12:41:10 UTC using RuboCop version 1.67.0. | ||
# on 2024-10-22 20:34:39 UTC using RuboCop version 1.67.0. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 1 | ||
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. | ||
# AllowedMethods: refine | ||
Metrics/BlockLength: | ||
Max: 43 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
ActiveAdmin.register User do | ||
permit_params :first_name, :last_name, :email, :role, :password, :password_confirmation | ||
|
||
filter :first_name_cont, as: :string | ||
filter :last_name_cont, as: :string | ||
filter :email | ||
filter :created_at | ||
|
||
index do | ||
selectable_column | ||
id_column | ||
column :first_name | ||
column :last_name | ||
column :email | ||
column :role | ||
column :created_at | ||
column :updated_at | ||
actions | ||
end | ||
|
||
show do | ||
attributes_table do | ||
row :id | ||
row :first_name | ||
row :last_name | ||
row :email | ||
row :role | ||
row :created_at | ||
row :updated_at | ||
end | ||
end | ||
|
||
form do |f| | ||
f.inputs "User Details" do | ||
f.input :first_name | ||
f.input :last_name | ||
f.input :email | ||
f.input :role, as: :select, collection: User.roles.keys | ||
if f.object.new_record? | ||
f.input :password | ||
f.input :password_confirmation | ||
else | ||
f.input :password, hint: I18n.t("active_admin.hints.password") | ||
f.input :password_confirmation, hint: I18n.t("active_admin.hints.password") | ||
end | ||
end | ||
f.actions | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
//= require active_admin/base | ||
//= require activeadmin_addons/all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@import 'activeadmin_addons/all'; | ||
// 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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class User < ApplicationRecord | ||
# Include default devise modules. Others available are: | ||
# :confirmable, :lockable, :timeoutable, :trackable, and :omniauthable | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :validatable | ||
|
||
enum :role, { user: 0, admin: 1 } | ||
|
||
validates :first_name, :last_name, :email, presence: true | ||
|
||
def self.ransackable_attributes(_auth_object = nil) | ||
%w[first_name last_name email role] | ||
end | ||
|
||
def password_required? | ||
new_record? || password.present? || password_confirmation.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.