Skip to content
Snippets Groups Projects
Commit ad6d2312 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Merge branch 'dspace-sync' into 'master'

Dspace sync

See merge request portalmec/portalmec!483
parents e5369761 9398bb45
No related branches found
No related tags found
No related merge requests found
......@@ -59,16 +59,12 @@ class V1::UsersController < ApplicationController
# PUT/PATCH /v1/users/1
# PUT/PATCH /v1/users/1.json
def update
if user_params[:role_ids].blank? || current_user.is_admin?
if @user.update(user_params)
user_associations(@user)
if @user.update(user_params)
user_associations(@user)
render json: @user, status: :ok
else
render json: @user.errors, status: :unprocessable_entity
end
render json: @user, status: :ok
else
render status: :forbidden
render json: @user.errors, status: :unprocessable_entity
end
end
......@@ -183,7 +179,13 @@ class V1::UsersController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(
return params.require(:user).permit(*partner_allowed_params) if !current_user.nil? && current_user.is_partner?
return params.require(:user).permit(*admin_allowed_params) if !current_user.nil? && current_user.is_admin?
params.require(:user).permit(*user_allowed_params)
end
def user_allowed_params
[
:name,
:email,
:description,
......@@ -192,9 +194,22 @@ class V1::UsersController < ApplicationController
:password_confirmation,
:terms_of_service,
:avatar,
:cover,
:cover
]
end
def partner_allowed_params
user_allowed_params.push(*[
:dspace_url,
:dspace_handle,
dspace_sets: []
])
end
def admin_allowed_params
partner_allowed_params.push(*[
role_ids: []
)
])
end
def approve_params
......
......@@ -28,7 +28,7 @@ class UserSerializer < ActiveModel::Serializer
end
def email
object.email if (current_user != nil)&&(object.id == current_user.id || current_user.is_admin?)
object.email if is_current_user?
end
def learning_objects_count
......@@ -41,6 +41,22 @@ class UserSerializer < ActiveModel::Serializer
roles
end
def dspace_handle
object.dspace_handle if is_current_user?
end
def dspace_url
object.dspace_url if is_current_user?
end
def dspace_sets
object.dspace_sets if is_current_user?
end
def is_current_user?
(current_user != nil)&&(object.id == current_user.id || current_user.is_admin?)
end
attributes \
:id,
:email,
......@@ -54,6 +70,9 @@ class UserSerializer < ActiveModel::Serializer
:role_ids,
:institution_ids,
:avatar,
:dspace_url,
:dspace_handle,
:dspace_sets,
:likes_count,
:followed,
:complained,
......
class AddHandleToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :dspace_handle, :string
end
end
class AddDspaceInfoToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :dspace_url, :string
add_column :users, :dspace_sets, :text, array: true, default: []
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