diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 34fb069056991b3218a95e186444c1cb0c3d034c..60173d6e8f1ff6b79de3741f0f4a00b3220e0ad9 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -96,7 +96,9 @@ class CollectionsController < ApplicationController @collection = nil if @collection == 'all' @collections = current_user.associated_collections - @collections.select! { |c| c.id != @collection.id } unless @collection.blank? + @collections.select! do |c| + (!@collection.blank? && c.id != @collection.id) || !include_learning_objects?(c) + end @type = params[:type] unless @type.blank? @@ -138,7 +140,7 @@ class CollectionsController < ApplicationController next unless collection.user_own?(current_user) @learning_objects.each do |learning_object| - collection.learning_objects << learning_object + collection.learning_objects << learning_object unless collection.learning_objects.include? learning_object end collection.save end @@ -171,6 +173,13 @@ class CollectionsController < ApplicationController private + def include_learning_objects?(collection) + @learning_objects.each do |lo| + return true if collection.learning_objects.include? lo + end + false + end + def check_collection_privacy!(collection) if collection.private? && !collection.user_own?(current_user) redirect_to :root, notice: 'Está é uma coleção privada.'