diff --git a/Gemfile b/Gemfile index cfcb968b1c9b7c34a1f224931644c280ebe7a814..e5e60aa5254284f3cf381721504cd78ab1e1d225 100644 --- a/Gemfile +++ b/Gemfile @@ -134,7 +134,7 @@ gem 'gitlab' gem 'pundit' # elasticsearch integration -gem 'searchkick', '~> 1.3.6' +gem 'searchkick' # enable/disable features by enviroments gem 'feature' diff --git a/Gemfile.lock b/Gemfile.lock index f97d5f9128b3660afd5c71726d93f55fab402077..173c4cd951d54bccc257cfe0eb887dc348f045c8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,7 +44,7 @@ GEM erubis (~> 2.7.0) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - active_model_serializers (0.10.5) + active_model_serializers (0.10.6) actionpack (>= 4.1, < 6) activemodel (>= 4.1, < 6) case_transform (>= 0.2) @@ -58,14 +58,14 @@ GEM activemodel (= 5.0.0.1) activesupport (= 5.0.0.1) arel (~> 7.0) - activerecord-import (0.17.2) + activerecord-import (0.18.2) activerecord (>= 3.2) activesupport (5.0.0.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) - acts_as_list (0.9.4) + acts_as_list (0.9.5) activerecord (>= 3.0) addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) @@ -124,8 +124,8 @@ GEM dm-validations (~> 1.2.0) data_objects (0.10.17) addressable (~> 2.1) - database_cleaner (1.5.3) - dawnscanner (1.6.7) + database_cleaner (1.6.1) + dawnscanner (1.6.8) cvss data_mapper dm-sqlite-adapter @@ -137,7 +137,7 @@ GEM sqlite3 sys-uname terminal-table - debug_inspector (0.0.2) + debug_inspector (0.0.3) derailed_benchmarks (1.3.2) benchmark-ips (~> 2) get_process_mem (~> 0) @@ -194,12 +194,12 @@ GEM dm-core (~> 1.2.0) do_sqlite3 (0.10.17) data_objects (= 0.10.17) - elasticsearch (5.0.3) - elasticsearch-api (= 5.0.3) - elasticsearch-transport (= 5.0.3) - elasticsearch-api (5.0.3) + elasticsearch (5.0.4) + elasticsearch-api (= 5.0.4) + elasticsearch-transport (= 5.0.4) + elasticsearch-api (5.0.4) multi_json - elasticsearch-transport (5.0.3) + elasticsearch-transport (5.0.4) faraday multi_json equalizer (0.0.11) @@ -218,7 +218,7 @@ GEM feature (1.4.0) ffi (1.9.18) flamegraph (0.9.5) - flay (2.8.1) + flay (2.9.0) erubis (~> 2.7.0) path_expander (~> 1.0) ruby_parser (~> 3.0) @@ -228,17 +228,17 @@ GEM ruby_parser (~> 3.1, > 3.1.0) sexp_processor (~> 4.8) get_process_mem (0.2.1) - gitlab (3.7.0) - httparty (~> 0.13.0) - terminal-table - globalid (0.3.7) - activesupport (>= 4.1.0) - haml (4.0.7) + gitlab (4.0.0) + httparty + terminal-table (= 1.7.1) + globalid (0.4.0) + activesupport (>= 4.2.0) + haml (5.0.1) + temple (>= 0.8.0) tilt hashie (3.5.5) heapy (0.1.2) - httparty (0.13.7) - json (~> 1.8) + httparty (0.14.0) multi_xml (>= 0.5.2) i18n (0.8.1) ice_nine (0.11.2) @@ -255,7 +255,7 @@ GEM logger-colors (1.0.0) loofah (2.0.3) nokogiri (>= 1.5.9) - mail (2.6.4) + mail (2.6.5) mime-types (>= 1.16, < 4) memory_profiler (0.9.8) method_source (0.8.2) @@ -267,7 +267,7 @@ GEM open4 (~> 1.3.4) rake mini_portile2 (2.1.0) - minitest (5.10.1) + minitest (5.10.2) minitest-reporters (1.1.14) ansi builder @@ -277,9 +277,10 @@ GEM multi_xml (0.6.0) multipart-post (2.0.0) mustache (1.0.5) + mustermann (1.0.0) net-http-persistent (2.9.4) nio4r (1.2.1) - nokogiri (1.7.1) + nokogiri (1.7.2) mini_portile2 (~> 2.1.0) oauth (0.5.1) oauth2 (1.3.1) @@ -309,7 +310,7 @@ GEM rack open4 (1.3.4) orm_adapter (0.5.0) - paper_trail (6.0.2) + paper_trail (7.0.2) activerecord (>= 4.0, < 5.2) request_store (~> 1.1) paperclip (5.1.0) @@ -320,7 +321,7 @@ GEM mimemagic (~> 0.3.0) parser (2.4.0.0) ast (~> 2.2) - path_expander (1.0.1) + path_expander (1.0.2) pg (0.20.0) phantomjs (2.1.1.0) powerpack (0.1.1) @@ -334,13 +335,13 @@ GEM puma (3.8.2) pundit (1.1.0) activesupport (>= 3.0.0) - rack (2.0.1) + rack (2.0.2) rack-attack (5.0.1) rack rack-cors (0.4.1) rack-mini-profiler (0.10.2) rack (>= 1.2.0) - rack-protection (1.5.3) + rack-protection (2.0.0) rack rack-test (0.6.3) rack (>= 1.0) @@ -372,46 +373,48 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.2.1) + rainbow (2.2.2) + rake rake (11.3.0) rdoc (4.3.0) redis (3.3.3) - reek (4.5.6) + reek (4.6.2) codeclimate-engine-rb (~> 0.4.0) - parser (>= 2.3.1.2, < 2.5) + parser (>= 2.4.0.0, < 2.5) rainbow (~> 2.0) request_store (1.3.2) resource_kit (0.1.6) addressable (>= 2.3.6, < 3.0.0) - responders (2.3.0) - railties (>= 4.2.0, < 5.1) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) rmagick (2.16.0) - rspec (3.5.0) - rspec-core (~> 3.5.0) - rspec-expectations (~> 3.5.0) - rspec-mocks (~> 3.5.0) - rspec-core (3.5.4) - rspec-support (~> 3.5.0) - rspec-expectations (3.5.0) + rspec (3.6.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-mocks (3.5.0) + rspec-support (~> 3.6.0) + rspec-mocks (3.6.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-rails (3.5.2) + rspec-support (~> 3.6.0) + rspec-rails (3.6.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.5.0) - rspec-expectations (~> 3.5.0) - rspec-mocks (~> 3.5.0) - rspec-support (~> 3.5.0) - rspec-support (3.5.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) rspec_api_documentation (4.9.0) activesupport (>= 3.0.0) mustache (~> 1.0, >= 0.99.4) rspec (~> 3.0) - rubocop (0.48.0) + rubocop (0.48.1) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) @@ -419,7 +422,7 @@ GEM unicode-display_width (~> 1.0, >= 1.0.1) ruby-graphviz (1.2.3) ruby-progressbar (1.8.1) - ruby_parser (3.8.4) + ruby_parser (3.9.0) sexp_processor (~> 4.1) rubycritic (3.2.0) flay (~> 2.8) @@ -436,26 +439,29 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - searchkick (1.3.6) - activemodel + searchkick (2.3.0) + activemodel (>= 4.1) elasticsearch (>= 1) hashie - sexp_processor (4.8.0) + sexp_processor (4.9.0) shoulda (3.5.0) shoulda-context (~> 1.0, >= 1.0.1) shoulda-matchers (>= 1.4.1, < 3.0) shoulda-context (1.2.2) shoulda-matchers (2.8.0) activesupport (>= 3.0.0) - sidekiq (4.2.10) + sidekiq (5.0.0) concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.0) rack-protection (>= 1.5.0) - redis (~> 3.2, >= 3.2.1) - sinatra (1.0) - rack (>= 1.0) - slim (3.0.7) - temple (~> 0.7.6) + redis (~> 3.3, >= 3.3.3) + sinatra (2.0.0) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.0) + tilt (~> 2.0) + slim (3.0.8) + temple (>= 0.7.6, < 0.9) tilt (>= 1.3.3, < 2.1) spring (2.0.1) activesupport (>= 4.2) @@ -472,8 +478,8 @@ GEM stringex (1.5.1) sys-uname (1.0.3) ffi (>= 1.0.0) - temple (0.7.7) - terminal-table (1.7.3) + temple (0.8.0) + terminal-table (1.7.1) unicode-display_width (~> 1.1.1) thor (0.19.4) thread_safe (0.3.6) @@ -559,7 +565,7 @@ DEPENDENCIES rubyzip screencap sdoc (~> 0.4.0) - searchkick (~> 1.3.6) + searchkick shoulda sidekiq sinatra diff --git a/app/builders/learning_object_builder.rb b/app/builders/learning_object_builder.rb index 7f407e86f9eaee3d0e123786c00f192471442ca2..c986f3c70c1685e470c08ae7103c34870aa12634 100644 --- a/app/builders/learning_object_builder.rb +++ b/app/builders/learning_object_builder.rb @@ -7,6 +7,7 @@ class LearningObjectBuilder metadata: dspace_metadata_to_hash(item.metadata) ) + lo.curator = lo.get_metadata_value_of('dc.curator') institution = lo.get_metadata_value_of('dc.creator') institution = 'Desconhecido' if institution.blank? lo.publisher = Institution.where(name: institution).first_or_create diff --git a/app/controllers/v1/collections_controller.rb b/app/controllers/v1/collections_controller.rb index 2c8bf8df05159cf2ca8ac9b82cd2228df33c62af..f98194f415a493d02a97252fbfae90702ca218c2 100644 --- a/app/controllers/v1/collections_controller.rb +++ b/app/controllers/v1/collections_controller.rb @@ -56,6 +56,10 @@ class V1::CollectionsController < ApplicationController # DELETE /v1/collections/1 # DELETE /v1/collections/1.json def destroy + items = @collection.collection_items.select(:id) + if !items.blank? + @collection.delete_items(items) + end @collection.destroy render status: :ok end @@ -99,7 +103,7 @@ class V1::CollectionsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def collection_params - params.require(:collection).permit(:name, :description, :owner_id, :owner_type, :privacy, tags: []) + params.require(:collection).permit(:name, :curator, :description, :owner_id, :owner_type, :privacy, tags: []) end def extra_params diff --git a/app/controllers/v1/learning_objects_controller.rb b/app/controllers/v1/learning_objects_controller.rb index ad9935aa1361acecc8e1f0e33ee04d6cd9d4ed49..47809f9a5a0563862feb38b197cd386aed59d2bf 100644 --- a/app/controllers/v1/learning_objects_controller.rb +++ b/app/controllers/v1/learning_objects_controller.rb @@ -13,7 +13,7 @@ class V1::LearningObjectsController < ApplicationController 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] + before_action :authorize!, except: [:create, :tagging, :untagging, :download, :magnetlink] before_action :set_paper_trail_whodunnit, except: [:index, :show] def index @@ -67,6 +67,12 @@ class V1::LearningObjectsController < ApplicationController render status: :ok end + # GET /v1/learning_objects/magnetlink/:magnetlink + def magnetlink + render json: LearningObject.where(magnetlink: params[:magnetlink]) + end + + private def deleted_resource; LearningObject; end @@ -94,7 +100,7 @@ class V1::LearningObjectsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def learning_object_params return nil if params[:learning_object].nil? - params[:learning_object].permit(:author, :name, :object_type_id, :description, :license_id, :thumbnail, :software, :language_id, :link) + params[:learning_object].permit(:author, :name, :curator, :object_type_id, :description, :license_id, :thumbnail, :software, :language_id, :link, :magnetlink) end def extra_params diff --git a/app/models/collection.rb b/app/models/collection.rb index 632f2179105d5b251b5c79986c978475df9afd0c..cecb90f16d4d75fd3d81ab94a9ad6a647a919c06 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -36,6 +36,8 @@ class Collection < ApplicationRecord include Highlights include Complainable + acts_as_paranoid + has_many :collection_items, -> { order("position ASC") }, as: :collectionable, dependent: :destroy has_many :collections, through: :collection_items, source: :collectionable, source_type: 'Collection' has_many :learning_objects, through: :collection_items, source: :collectionable, source_type: 'LearningObject' @@ -50,7 +52,6 @@ class Collection < ApplicationRecord searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author], callbacks: :async - acts_as_paranoid has_paper_trail def search_data diff --git a/app/models/collection_item.rb b/app/models/collection_item.rb index 1a73aaed0001b832a727cc81d98110053ffd7b20..101e61d5b41f8ed4479647b771bfeccd66ac31aa 100644 --- a/app/models/collection_item.rb +++ b/app/models/collection_item.rb @@ -21,6 +21,8 @@ class CollectionItem < ApplicationRecord validates :collection, :collectionable, presence: true acts_as_list scope: :collection + acts_as_paranoid + def recipient collection end diff --git a/app/serializers/collection_serializer.rb b/app/serializers/collection_serializer.rb index 94f6bf6ce48c750ca922f5861f90359671b4ff15..a5f39efb52ecc4dc451d293efb9e9a2f24edfac4 100644 --- a/app/serializers/collection_serializer.rb +++ b/app/serializers/collection_serializer.rb @@ -28,7 +28,7 @@ class CollectionSerializer < ActiveModel::Serializer thumbs end - attributes :id, :name, :created_at, :updated_at, :description, :privacy, :score, :likes_count, :liked, :followed, :reviewed, :complained, :review_average, :thumbnail, :items_thumbnails + attributes :id, :name, :curator, :created_at, :updated_at, :description, :privacy, :score, :likes_count, :liked, :followed, :reviewed, :complained, :review_average, :thumbnail, :items_thumbnails belongs_to :owner has_many :tags diff --git a/app/serializers/learning_object_serializer.rb b/app/serializers/learning_object_serializer.rb index c1d51518ec5aee29bee9284c3c9b1f6da3271571..dbf2316da5ffef31800398cd2389208f4475a2bb 100644 --- a/app/serializers/learning_object_serializer.rb +++ b/app/serializers/learning_object_serializer.rb @@ -34,6 +34,7 @@ class LearningObjectSerializer < ActiveModel::Serializer :name, :description, :author, + :curator, :thumbnail, :object_type, :language, @@ -52,7 +53,8 @@ class LearningObjectSerializer < ActiveModel::Serializer :complained, :shares_count, :created_at, - :updated_at + :updated_at, + :magnetlink belongs_to :publisher has_many :tags diff --git a/app/services/learning_object_publisher.rb b/app/services/learning_object_publisher.rb index 096eff5bb2173550bddfab410e9d9b183b01eabf..c646d533d02bff320b1eafd62ef93c0be62a960f 100644 --- a/app/services/learning_object_publisher.rb +++ b/app/services/learning_object_publisher.rb @@ -68,7 +68,8 @@ class LearningObjectPublisher 'dc.type' => object.object_type.try(:name), 'dc.rights.license' => object.license.try(:name), # 'dc.subject.category' => object.subjects, - 'dc.date.submitted' => object.created_at.to_s + 'dc.date.submitted' => object.created_at.to_s, + 'dc.curator' => object.curator } end end diff --git a/app/services/search_service/collection.rb b/app/services/search_service/collection.rb index 5bd29469709d51634c3d8489b27f653afed1edd1..4bf4e400a3d5126fb3215aa46c1fdf4e735ade66 100644 --- a/app/services/search_service/collection.rb +++ b/app/services/search_service/collection.rb @@ -1,7 +1,7 @@ module SearchService class Collection < Model def search - ::Collection.search(query: mount_query, order: order_hash, page: @search.page, per_page: @search.results_per_page) + ::Collection.search(body: mount_query, order: order_hash, page: @search.page, per_page: @search.results_per_page) end def autocomplete diff --git a/app/services/search_service/learning_object.rb b/app/services/search_service/learning_object.rb index bff63f89f5d272e4c242eab493cea34bac8e619f..fbd32481d70ccacfc15170ff719e4e5add395ac0 100644 --- a/app/services/search_service/learning_object.rb +++ b/app/services/search_service/learning_object.rb @@ -2,7 +2,7 @@ module SearchService class LearningObject < Model def search fields = [:license, :tags, :subjects, :educational_stages, :taggings, :publisher, :language, :attachments, :reviews] - ::LearningObject.search(query: mount_query, includes: fields, order: order_hash, page: @search.page, per_page: @search.results_per_page) + ::LearningObject.search(body: mount_query, includes: fields, order: order_hash, page: @search.page, per_page: @search.results_per_page) end def autocomplete diff --git a/app/services/search_service/model.rb b/app/services/search_service/model.rb index d37c3fc8909628ef068b3ff8f1ecf7bb3f54f1c7..fe9b38f10442b65f22d68329482fe1f93b3b9a0d 100644 --- a/app/services/search_service/model.rb +++ b/app/services/search_service/model.rb @@ -38,24 +38,34 @@ module SearchService def mount_query match_all_query = { - bool: { - must: { - match_all: {} - }, - filter: mount_filter - } + query: { + bool: { + must: { + match_all: {} + }, + filter: mount_filter + } + }, + size: @search.results_per_page, + from: ((@search.page.to_i) * (@search.results_per_page.to_i)).to_s } return match_all_query if @search.query == '*' - { - function_score: { - query: { bool: { - must: { dis_max: { queries: mount_queries } }, - filter: mount_filter - } }, - functions: [{ script_score: { script: { lang: 'groovy', file: 'calculate_score' } } }] - } - } + { + query:{ + function_score: { + query: { bool: { + must: { dis_max: { queries: mount_queries } }, + filter: mount_filter + } }, + functions: [{ script_score: { script: { lang: 'groovy', file: 'calculate_score' } } }] + } + }, + # https://www.elastic.co/guide/en/elasticsearch/guide/current/pagination.html + # Comeca pagina 0 + size: @search.results_per_page, + from: ((@search.page.to_i) * (@search.results_per_page.to_i)).to_s + } end def mount_queries diff --git a/app/services/search_service/user.rb b/app/services/search_service/user.rb index c9afd7790f52d404f93c74aa426155a4d24bcc0a..ea8ef836da2db171ffc9327f8afe79f82bc8acde 100644 --- a/app/services/search_service/user.rb +++ b/app/services/search_service/user.rb @@ -1,7 +1,7 @@ module SearchService class User < Model def search - ::User.search(query: mount_query, order: order_hash, page: @search.page, per_page: @search.results_per_page) + ::User.search(body: mount_query, order: order_hash, page: @search.page, per_page: @search.results_per_page) end def autocomplete diff --git a/config/initializers/elasticsearch.rb b/config/initializers/elasticsearch.rb new file mode 100644 index 0000000000000000000000000000000000000000..e591a06b27196300668419e7f35019e6aef8f257 --- /dev/null +++ b/config/initializers/elasticsearch.rb @@ -0,0 +1,6 @@ +Searchkick.client = + Elasticsearch::Client.new( + url: 'localhost:9200', + transport_options: {request: {timeout: 550}} + ) + diff --git a/config/routes.rb b/config/routes.rb index c314a4533c81a8bfed191612d32c3f98c73169e8..df4dbc69e123122d8a2d473e6402c455aeb2d470 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -154,5 +154,6 @@ Rails.application.routes.draw do get '/subjects', to: 'subjects#index' get '/educational_stages', to: 'educational_stages#index' get '/activities/me', to: 'activities#me' + get 'learning_objects/magnetlink/:magnetlink', to: 'learning_objects#magnetlink', as: 'magnetlink_learning_objects' end end diff --git a/db/migrate/20170511161146_add_curator_to_learning_object.rb b/db/migrate/20170511161146_add_curator_to_learning_object.rb new file mode 100644 index 0000000000000000000000000000000000000000..d722347d41c2a6de5bcc448e21740fe0e7d31b8e --- /dev/null +++ b/db/migrate/20170511161146_add_curator_to_learning_object.rb @@ -0,0 +1,5 @@ +class AddCuratorToLearningObject < ActiveRecord::Migration[5.0] + def change + add_column :learning_objects, :curator, :string + end +end diff --git a/db/migrate/20170512092359_add_magnetlink_to_learning_object.rb b/db/migrate/20170512092359_add_magnetlink_to_learning_object.rb new file mode 100644 index 0000000000000000000000000000000000000000..6ee102f5debee49368eaa5e8f2f9e0094393be85 --- /dev/null +++ b/db/migrate/20170512092359_add_magnetlink_to_learning_object.rb @@ -0,0 +1,5 @@ +class AddMagnetlinkToLearningObject < ActiveRecord::Migration[5.0] + def change + add_column :learning_objects, :magnetlink, :string + end +end \ No newline at end of file diff --git a/db/migrate/20170516111857_add_deleted_at_to_collection_items.rb b/db/migrate/20170516111857_add_deleted_at_to_collection_items.rb new file mode 100644 index 0000000000000000000000000000000000000000..abbe878fe27d87f74b19feeed88a854d25c1b020 --- /dev/null +++ b/db/migrate/20170516111857_add_deleted_at_to_collection_items.rb @@ -0,0 +1,6 @@ +class AddDeletedAtToCollectionItems < ActiveRecord::Migration[5.0] + def change + add_column :collection_items, :deleted_at, :datetime + add_index :collection_items, :deleted_at + end +end \ No newline at end of file diff --git a/db/migrate/20170518120936_add_curator_to_collection.rb b/db/migrate/20170518120936_add_curator_to_collection.rb new file mode 100644 index 0000000000000000000000000000000000000000..29f69c17c5c0c588d4eb3cf98152b367cb921a34 --- /dev/null +++ b/db/migrate/20170518120936_add_curator_to_collection.rb @@ -0,0 +1,5 @@ +class AddCuratorToCollection < ActiveRecord::Migration[5.0] + def change + add_column :collections, :curator, :string + end +end diff --git a/spec/factories/downloads.rb b/spec/factories/downloads.rb new file mode 100644 index 0000000000000000000000000000000000000000..c4019c9f923dc119ff57c9667098e76f6a094ac2 --- /dev/null +++ b/spec/factories/downloads.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + + factory :download do |f| + f.ip { Faker::Internet.ip_v4_address } + downloadable + user + end + +end \ No newline at end of file