Skip to content
Snippets Groups Projects
Commit 3a7fa706 authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec into paginate-publisher

parents 777d547d c997309a
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@ class ApplicationController < ActionController::API
protected
def configure_permitted_parameters
registration_params = [:name, :email, :description, :avatar, :cover, :password, :password_confirmation, :current_password, :terms_of_service]
registration_params = [:name, :email, :description, :teacher_id, :birthday, :avatar, :cover, :password, :password_confirmation, :current_password, :terms_of_service]
devise_parameter_sanitizer.permit :sign_up, keys: registration_params
devise_parameter_sanitizer.permit :account_update, keys: registration_params
end
......
......@@ -61,7 +61,6 @@ class V1::UsersController < ApplicationController
def update
if @user.update(user_params)
user_associations(@user)
render json: @user, status: :ok
else
render json: @user.errors, status: :unprocessable_entity
......@@ -195,7 +194,9 @@ class V1::UsersController < ApplicationController
:password_confirmation,
:terms_of_service,
:avatar,
:cover
:cover,
:teacher_id,
:birthday
]
end
......
......@@ -68,5 +68,9 @@ class Role < ApplicationRecord
def self.partner
find_by(name: 'partner') || create!(name: 'partner')
end
def self.publisher
find_by(name: 'publisher') || create!(name: 'publisher')
end
end
......@@ -88,6 +88,7 @@ class User < ApplicationRecord
has_many :applications
after_create :default_role
before_save :verify_teacher_id
after_save :verify_dspace_info
has_attached_file :avatar, styles: { medium: '300x300>', thumb: '60x60>' }, default_url: ''
......@@ -288,6 +289,24 @@ class User < ApplicationRecord
end
end
def verify_teacher_id
return true if (changed & ["teacher_id", "birthday"]).empty?
params = {
filter: "teacher:#{teacher_id},day: #{birthday.day},month:#{birthday.month},year:#{birthday.year},min_year:2017"
}
uri = URI("https://simcaq.c3sl.ufpr.br/api/v1/verify_teacher")
uri.query = URI.encode_www_form(params)
response = JSON.parse(Net::HTTP.get(uri))
if !response['result'].blank?
roles << Role.publisher
return true
end
errors.add(:INEP, "Dados do INEP incorretos")
return false
end
def activity_owner
self
end
......
......@@ -28,7 +28,7 @@ class UserDeviseSerializer < ActiveModel::Serializer
end
attributes :id, :email, :provider, :avatar_file_name, :avatar_content_type, :uid, :name, :submitter_request, :avatar_file_size, :avatar_updated_at,
attributes :id, :email, :teacher_id, :birthday, :provider, :avatar_file_name, :avatar_content_type, :uid, :name, :submitter_request, :avatar_file_size, :avatar_updated_at,
:bookmarks_count, :user_category_id, :score, :follows_count, :deleted_at, :description, :likes_count,
:learning_objects_count, :collections_count, :cover_file_name, :cover_content_type, :cover_file_size, :cover_updated_at
has_many :roles
......
......@@ -53,6 +53,10 @@ class UserSerializer < ActiveModel::Serializer
object.dspace_sets if is_current_user?
end
def teacher_id
object.teacher_id if is_current_user?
end
def is_current_user?
(current_user != nil)&&(object.id == current_user.id || current_user.is_admin?)
end
......@@ -60,6 +64,8 @@ class UserSerializer < ActiveModel::Serializer
attributes \
:id,
:email,
:teacher_id,
:birthday,
:provider,
:name,
:description,
......
class AddTeacherIdToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :teacher_id, :string
end
end
class AddBirthdayToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :birthday, :datetime
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment