Rolify has been added successfully to the system.
This commit is contained in:
parent
8343c3ae8a
commit
1d5646e61c
|
@ -0,0 +1,14 @@
|
|||
class Role < ApplicationRecord
|
||||
has_and_belongs_to_many :users, :join_table => :users_roles
|
||||
|
||||
belongs_to :resource,
|
||||
:polymorphic => true,
|
||||
:optional => true
|
||||
|
||||
|
||||
validates :resource_type,
|
||||
:inclusion => { :in => Rolify.resource_types },
|
||||
:allow_nil => true
|
||||
|
||||
scopify
|
||||
end
|
|
@ -1,3 +1,4 @@
|
|||
class User < ApplicationRecord
|
||||
rolify
|
||||
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
Rolify.configure do |config|
|
||||
# By default ORM adapter is ActiveRecord. uncomment to use mongoid
|
||||
# config.use_mongoid
|
||||
|
||||
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
|
||||
# config.use_dynamic_shortcuts
|
||||
|
||||
# Configuration to remove roles from database once the last resource is removed. Default is: true
|
||||
# config.remove_role_if_empty = false
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
class RolifyCreateRoles < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table(:roles) do |t|
|
||||
t.string :name
|
||||
t.references :resource, :polymorphic => true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table(:users_roles, :id => false) do |t|
|
||||
t.references :user
|
||||
t.references :role
|
||||
end
|
||||
|
||||
add_index(:roles, :name)
|
||||
add_index(:roles, [ :name, :resource_type, :resource_id ])
|
||||
add_index(:users_roles, [ :user_id, :role_id ])
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_04_02_214014) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_04_03_213530) do
|
||||
create_table "bank_accounts", force: :cascade do |t|
|
||||
t.string "institution_name"
|
||||
t.string "account_type"
|
||||
|
@ -149,6 +149,17 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_02_214014) do
|
|||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "roles", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "resource_type"
|
||||
t.integer "resource_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"
|
||||
t.index ["name"], name: "index_roles_on_name"
|
||||
t.index ["resource_type", "resource_id"], name: "index_roles_on_resource"
|
||||
end
|
||||
|
||||
create_table "service_contracts", force: :cascade do |t|
|
||||
t.integer "participant_id", null: false
|
||||
t.integer "vendor_id", null: false
|
||||
|
@ -173,6 +184,14 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_02_214014) do
|
|||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
end
|
||||
|
||||
create_table "users_roles", id: false, force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "role_id"
|
||||
t.index ["role_id"], name: "index_users_roles_on_role_id"
|
||||
t.index ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id"
|
||||
t.index ["user_id"], name: "index_users_roles_on_user_id"
|
||||
end
|
||||
|
||||
create_table "vendors", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "phone"
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name: MyString
|
||||
|
||||
two:
|
||||
name: MyString
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the "{}" from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
||||
|
|
Loading…
Reference in New Issue