remove Role entity and set language to pt-BR
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
ActiveAdmin.register Role do
|
||||
permit_params :name
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
ActiveAdmin.register User do
|
||||
permit_params :email, :name, role_ids: []
|
||||
permit_params :email, :name, roles: []
|
||||
|
||||
index do
|
||||
selectable_column
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
before_action :authenticate_user!
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ module Users
|
||||
else
|
||||
session['devise.google_data'] = request.env['omniauth.auth'].except('extra')
|
||||
|
||||
redirect_to new_user_registration_url, alert: 'User not found.'
|
||||
redirect_to new_user_session_url, alert: 'User not found.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,9 +9,5 @@ module Types
|
||||
field :email, String, null: false
|
||||
field :roles, [Enums::RoleEnum], null: false
|
||||
field :avatar_url, String, null: true
|
||||
|
||||
def roles
|
||||
object.roles.map(&:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,6 +11,7 @@ import { classNames } from '../../utils';
|
||||
import { DashboardRoutePaths, QuestionRoutePaths, SessionRoutePaths } from '../../routes'
|
||||
import { turnOff } from '../../services/store/unsavedChanges';
|
||||
import { CurrentUserAvatar } from "../CurrentUserAvatar";
|
||||
import { localFetch } from '../../utils/localFetch';
|
||||
|
||||
const UserMenu: FC = () => {
|
||||
const { user } = useCurrentUser();
|
||||
@@ -21,8 +22,14 @@ const UserMenu: FC = () => {
|
||||
|
||||
const doLogout = () => {
|
||||
setConfirmLogout(false)
|
||||
|
||||
dispatch(turnOff())
|
||||
history.push('/')
|
||||
|
||||
localFetch('/users/sign_out', {
|
||||
method: 'DELETE'
|
||||
}).then(() => {
|
||||
window.location.href = '/'
|
||||
})
|
||||
}
|
||||
|
||||
const handleLogout = () => {
|
||||
|
||||
24
app/javascript/utils/localFetch.ts
Normal file
24
app/javascript/utils/localFetch.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
type LocalFetch = typeof fetch
|
||||
|
||||
export const localFetch: LocalFetch = (input, init) => {
|
||||
const { headers, ...rest } = init ?? {}
|
||||
|
||||
const crfsToken = document
|
||||
.querySelector("[name='csrf-token']")
|
||||
?.getAttribute('content')
|
||||
|
||||
if (!crfsToken) {
|
||||
throw new Error('CSRF token not found')
|
||||
}
|
||||
|
||||
const customInt: RequestInit = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': crfsToken,
|
||||
...(headers ?? {}),
|
||||
},
|
||||
...rest,
|
||||
}
|
||||
|
||||
return fetch(input, customInt)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: roles
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_roles_on_name (name) UNIQUE
|
||||
#
|
||||
class Role < ApplicationRecord
|
||||
has_and_belongs_to_many :users
|
||||
|
||||
validates :name, presence: true, uniqueness: true
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -6,7 +6,7 @@ class ApplicationPolicy
|
||||
def initialize(user, record)
|
||||
@user = user
|
||||
@record = record
|
||||
@roles = user.roles.map { |r| r.name.to_sym }
|
||||
@roles = user.roles
|
||||
end
|
||||
|
||||
def is?(role)
|
||||
|
||||
Reference in New Issue
Block a user