Skip to content
Snippets Groups Projects
Commit 8d91943d authored by Lucas Gabriel Lima's avatar Lucas Gabriel Lima
Browse files

add checking of users permitions in taggable_controller

parent c73afe12
No related branches found
No related tags found
No related merge requests found
...@@ -3,19 +3,20 @@ module TaggableController ...@@ -3,19 +3,20 @@ module TaggableController
included do included do
before_action :authenticate_user!, only: [:tagging, :untagging] before_action :authenticate_user!, only: [:tagging, :untagging]
before_action :set_owner, only: [:tagging, :untagging]
end end
# POST /v1/learning_objects/1/tagging # POST /v1/learning_objects/1/tagging
# POST /v1/learning_objects/1/tagging.json # POST /v1/learning_objects/1/tagging.json
def tagging def tagging
current_user.tag(taggable, with: [tag_params[:name]]) @owner.tag(taggable, with: [tag_params[:name]])
render json: taggable, status: :created render json: taggable, status: :created
end end
# DELETE /v1/learning_objects/1/untagging # DELETE /v1/learning_objects/1/untagging
# DELETE /v1/learning_objects/1/untagging.json # DELETE /v1/learning_objects/1/untagging.json
def untagging def untagging
current_user.untag(taggable, tag_params[:name]) @owner.untag(taggable, tag_params[:name])
render json: taggable, status: :ok render json: taggable, status: :ok
end end
...@@ -26,7 +27,21 @@ module TaggableController ...@@ -26,7 +27,21 @@ module TaggableController
end end
def tag_params def tag_params
params.require(:tag).permit(:name) params.require(:tag).permit(:name, :owner_id, :owner_type)
end
def set_owner
if current_user.is_admin?
@owner = tag_params[:owner_type].constantize.find(tag_params[:owner_id])
else
if tag_params[:owner_type] == 'Institution'
if Institution.find(tag_params[:owner_id]).users.include? current_user
@owner = Institution.find(tag_params[:owner_id])
end
else
@owner = current_user
end
end
end end
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