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

Merge branch '200/delete_tags_array' into 'master'

#200: Deletation of tags's array implemented on collection update and learning_object update.

See merge request !390
parents e28e8524 58118125
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ module TaggableController
# DELETE /v1/learning_objects/1/untagging
# DELETE /v1/learning_objects/1/untagging.json
def untagging
@owner.untag(taggable, tag_params[:name])
@owner.untag(taggable, with: [tag_params[:name]])
render json: taggable.tags, status: :ok
end
......
......@@ -9,7 +9,7 @@ class V1::CollectionsController < ApplicationController
include ::SubjectableController
include ::StageableController
before_action :authenticate_user!, only: [:create, :update, :destroy]
before_action :authenticate_user!, only: [:create, :update, :destroy, :tagging, :untagging]
before_action :set_collection, only: [:show, :update, :destroy, :add_object, :delete_object, :subjecting, :unsubjecting, :add_stages, :remove_stages]
before_action :set_new_collection, only: :index
before_action :authorize!, except: [:create, :tagging, :untagging, :follow, :unfollow, :download]
......@@ -107,7 +107,11 @@ class V1::CollectionsController < ApplicationController
end
def collection_associations(collection)
current_user.tag(collection, with: extra_params[:tags].map { |t| t['name'] }) unless extra_params[:tags].nil?
if extra_params[:tags] == []
current_user.untag(collection, with: @collection.tags.map { |t| t['name'] })
elsif !extra_params[:tags].nil?
current_user.tag(collection, with: extra_params[:tags].map { |t| t['name'] })
end
collection.add_subjects(ids: extra_params[:subjects]) unless extra_params[:subjects].nil?
collection.add_educational_stages(ids: extra_params[:educational_stages]) unless extra_params[:educational_stages].nil?
collection.add_items(extra_params[:items]) unless extra_params[:items].nil?
......
......@@ -10,7 +10,7 @@ class V1::LearningObjectsController < ApplicationController
include ::SubjectableController
include ::StageableController
before_action :authenticate_user!, only: [:create, :update, :destroy]
before_action :authenticate_user!, only: [:create, :update, :destroy, :tagging, :untagging]
before_action :set_learning_object, only: [:show, :update, :destroy, :subjecting, :unsubjecting, :add_stages, :remove_stages]
before_action :set_new_learning_object, only: :index
before_action :authorize!, except: [:create, :tagging, :untagging, :download]
......@@ -103,7 +103,11 @@ class V1::LearningObjectsController < ApplicationController
end
def learning_object_associations(learning_object)
current_user.tag(learning_object, with: extra_params[:tags].map { |t| t['name'] }) unless extra_params[:tags].nil?
if extra_params[:tags] == []
current_user.untag(learning_object, with: @learning_object.tags.map { |t| t['name'] })
elsif !extra_params[:tags].nil?
current_user.tag(learning_object, with: extra_params[:tags].map { |t| t['name'] })
end
learning_object.add_subjects(ids: extra_params[:subjects]) unless extra_params[:subjects].nil?
learning_object.add_educational_stages(ids: extra_params[:educational_stages]) unless extra_params[:educational_stages].nil?
end
......
......@@ -20,8 +20,10 @@ module Tagger
# Examples:
# tagger.untag(LearningObject.find(1), "Tag")
# tagger.untag(Collection.find(1), "Tag")
def untag(taggable, tag_name)
tag = Tag.find_by(name: tag_name)
Tagging.where(tagger: self, tag: tag, taggable: taggable).destroy_all
def untag(taggable, with: [])
with.each do |tag_name|
tag = Tag.find_by(name: tag_name)
Tagging.where(tagger: self, tag: tag, taggable: taggable).destroy_all
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