remove Role entity and set language to pt-BR

This commit is contained in:
João Geonizeli
2022-07-26 14:40:46 -03:00
parent 9db59c071f
commit e24449adbc
22 changed files with 221 additions and 79 deletions

View File

@@ -10,6 +10,7 @@
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# roles :string default([]), is an Array
# created_at :datetime not null
# updated_at :datetime not null
#
@@ -19,21 +20,31 @@
# index_users_on_reset_password_token (reset_password_token) UNIQUE
#
class User < ApplicationRecord
extend Enumerize
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:validatable,
:omniauthable,
omniauth_providers: [:google_oauth2]
has_and_belongs_to_many :roles
enumerize :roles,
multiple: true,
default: :teacher,
in: %i[admin nde coordinator center_director pro_rector teacher]
validates :name, presence: true
roles.values.each do |role|
define_method "#{role}?" do
roles.include?(role)
end
end
def self.from_omniauth(email, avatar_url)
@user = User.find_by!(email: email)
@user.update(avatar_url: avatar_url)
@user
User.find_by(email: email).tap do |user|
user.update(avatar_url: avatar_url) unless user.nil?
end
end
end