Commit d627abc8 authored by legton's avatar legton

SCRUM#389: Allow multiple languages for a resource when uploaded

parent d9738d71
......@@ -150,7 +150,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, :curator, :object_type_id, :description, :license_id, :terms_of_service, :thumbnail, :software, :language_id, :link, :magnetlink)
params[:learning_object].permit(:author, :name, :curator, :object_type_id, :description, :license_id, :terms_of_service, :thumbnail, :software, :link, :magnetlink, language_ids: [])
end
def extra_params
......
......@@ -33,7 +33,6 @@
# keywords :text
# publisher_id :integer
# publisher_type :string
# language_id :integer
# object_type_id :integer
# created_at :datetime not null
# updated_at :datetime not null
......@@ -74,8 +73,9 @@ class LearningObject < ApplicationRecord
has_many :collections, through: :collection_items
has_many :attachments, class_name: 'LearningObject::Attachment', autosave: true # autosave to allow import
has_and_belongs_to_many :language
belongs_to :publisher, polymorphic: true, counter_cache: true
belongs_to :language
belongs_to :license
belongs_to :object_type
belongs_to :attachment, class_name: 'LearningObject::Attachment'
......
class CreateJoinTableLanguageLearningObject < ActiveRecord::Migration[5.0]
def change
create_join_table :languages, :learning_objects do |t|
t.index [:language_id, :learning_object_id],
:name => 'index_lang_learning_objs_on_language_id_and_learning_object_id'
# t.index [:learning_object_id, :language_id]
end
LearningObject.with_deleted.all.each do |lo|
if (lo.language_id)
lo.update_attributes(language_ids: lo.language_id)
end
end
remove_column :learning_objects, :language_id
end
end
......@@ -39,7 +39,11 @@ namespace :language do
end
Language.find_each do |language|
unless is_valid? language
LearningObject.where(language: language).update_all(language_id: default_language.id)
learning_objects = LearningObject.includes(:language).where('languages.id' => language.id)
learning_objects.each do |learning_object|
learning_object.language.delete(language)
learning_object.language << default_language
end
language.destroy
end
end
......
......@@ -71,7 +71,7 @@ resource 'Learning Objects' do
parameter :subjects, 'Array with subjects ids', scope: :learning_object
parameter :educational_stages, 'Array with educational stages ids', scope: :learning_object
parameter :object_type_id, 'The id of object type', scope: :learning_object
parameter :language_id, 'The id of a language', scope: :learning_object
parameter :language_ids, 'Array with language ids', scope: :learning_object
parameter :license_id, 'The id of a license', scope: :learning_object
parameter :curator, 'The name of curator', scope: :learning_object
parameter :thumbnail, 'The learning_object thumbnail', scope: :learning_object
......@@ -82,11 +82,11 @@ resource 'Learning Objects' do
let(:thumbnail) { Faker::Avatar.image }
let(:description) { Faker::Lorem.paragraph }
let(:object_type_id) { object_types.first.id }
let(:language_id) { languages.first.id }
let(:license_id) { licenses.first.id }
let(:software) { Faker::Lorem::sentence }
let(:link) { Faker::Internet.url }
let(:tags) { [ {name: tag.first.name}, {name: tag.last.name} ] }
let(:language_ids) { [ languages.first.id ] }
let(:subjects) { [ subject.first.id] }
let(:educational_stages) { [ educational_stage.first.id ] }
let(:raw_post) { params.to_json }
......@@ -109,7 +109,7 @@ resource 'Learning Objects' do
parameter :subjects, 'Array with subjects ids'
parameter :educational_stages, 'Array with educational stages ids'
parameter :object_type_id, 'The id of object type'
parameter :language_id, 'The id of a language'
parameter :language_ids, 'Array with languages ids'
parameter :license_id, 'The id of a license'
#TODO: add items of array
......
......@@ -25,7 +25,7 @@ FactoryGirl.define do
score { rand(0.0..1.0) }
description { Faker::Lorem.paragraph }
object_type { ObjectType.all.sample }
language { Language.all.sample }
language { [Language.all.sample] }
author { Faker::Name.name }
state LearningObject.states[:published]
......
......@@ -33,7 +33,6 @@
# keywords :text
# publisher_id :integer
# publisher_type :string
# language_id :integer
# object_type_id :integer
# created_at :datetime not null
# updated_at :datetime not null
......
......@@ -33,7 +33,6 @@
# keywords :text
# publisher_id :integer
# publisher_type :string
# language_id :integer
# object_type_id :integer
# created_at :datetime not null
# updated_at :datetime not null
......@@ -59,7 +58,7 @@ class LearningObjectTest < ActiveSupport::TestCase
should have_many(:attachments).class_name('LearningObject::Attachment')
should belong_to :publisher
should belong_to :language
should have_and_belong_to_many :language
should belong_to(:attachment).class_name('LearningObject::Attachment')
should belong_to :object_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment