mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Add role to users
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
class User < ApplicationRecord
|
||||
enum role: [:user, :moderator, :admin]
|
||||
after_initialize :set_default_role, if: :new_record?
|
||||
|
||||
def set_default_role
|
||||
self.role ||= :user
|
||||
end
|
||||
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :validatable,
|
||||
:confirmable
|
||||
|
||||
5
db/migrate/20190818191513_add_role_to_users.rb
Normal file
5
db/migrate/20190818191513_add_role_to_users.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddRoleToUsers < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :users, :role, :integer
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_08_18_162602) do
|
||||
ActiveRecord::Schema.define(version: 2019_08_18_191513) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -27,6 +27,7 @@ ActiveRecord::Schema.define(version: 2019_08_18_162602) do
|
||||
t.string "unconfirmed_email"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.integer "role"
|
||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
|
||||
Reference in New Issue
Block a user