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

Added dspace info to User with Role partner

parent 0be8d194
Branches
Tags
No related merge requests found
...@@ -59,7 +59,6 @@ class V1::UsersController < ApplicationController ...@@ -59,7 +59,6 @@ class V1::UsersController < ApplicationController
# PUT/PATCH /v1/users/1 # PUT/PATCH /v1/users/1
# PUT/PATCH /v1/users/1.json # PUT/PATCH /v1/users/1.json
def update def update
if user_params[:role_ids].blank? || current_user.is_admin?
if @user.update(user_params) if @user.update(user_params)
user_associations(@user) user_associations(@user)
...@@ -67,9 +66,6 @@ class V1::UsersController < ApplicationController ...@@ -67,9 +66,6 @@ class V1::UsersController < ApplicationController
else else
render json: @user.errors, status: :unprocessable_entity render json: @user.errors, status: :unprocessable_entity
end end
else
render status: :forbidden
end
end end
# DELETE /v1/users/1 # DELETE /v1/users/1
...@@ -162,7 +158,13 @@ class V1::UsersController < ApplicationController ...@@ -162,7 +158,13 @@ class V1::UsersController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def user_params 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, :name,
:email, :email,
:description, :description,
...@@ -171,9 +173,22 @@ class V1::UsersController < ApplicationController ...@@ -171,9 +173,22 @@ class V1::UsersController < ApplicationController
:password_confirmation, :password_confirmation,
:terms_of_service, :terms_of_service,
:avatar, :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: [] role_ids: []
) ])
end end
def approve_params def approve_params
......
...@@ -28,7 +28,7 @@ class UserSerializer < ActiveModel::Serializer ...@@ -28,7 +28,7 @@ class UserSerializer < ActiveModel::Serializer
end end
def email def email
object.email if (current_user != nil)&&(object.id == current_user.id || current_user.is_admin?) object.email if is_current_user?
end end
def learning_objects_count def learning_objects_count
...@@ -41,6 +41,22 @@ class UserSerializer < ActiveModel::Serializer ...@@ -41,6 +41,22 @@ class UserSerializer < ActiveModel::Serializer
roles roles
end 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 \ attributes \
:id, :id,
:email, :email,
...@@ -54,6 +70,9 @@ class UserSerializer < ActiveModel::Serializer ...@@ -54,6 +70,9 @@ class UserSerializer < ActiveModel::Serializer
:role_ids, :role_ids,
:institution_ids, :institution_ids,
:avatar, :avatar,
:dspace_url,
:dspace_handle,
:dspace_sets,
:likes_count, :likes_count,
:followed, :followed,
:complained, :complained,
......
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.
Please register or to comment