Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ELIXIR-Belgium/seek into experime…
Browse files Browse the repository at this point in the history
…nt_template_make_over

Merge main branch in experiment_template_make_over.
  • Loading branch information
Kevin De Pelseneer committed Oct 15, 2023
2 parents 0116614 + 56a6f0f commit 0ff952c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/controllers/assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def create

def delete_linked_sample_types
return unless is_single_page_assay?
return if @assay.sample_type.nil?

@assay.sample_type.destroy
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/studies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def update

def delete_linked_sample_types
return unless is_single_page_study?
return if @study.sample_types.empty?

# The study sample types must be destroyed in reversed order
# otherwise the first sample type won't be removed becaused it is linked from the second
Expand Down
8 changes: 0 additions & 8 deletions app/models/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ def extracted?
!!originating_data_file
end

def projects
extracted? ? originating_data_file.projects : super
end

def project_ids
extracted? ? originating_data_file.project_ids : super
end

def creators
extracted? ? originating_data_file.creators : super
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/projects/guided_create/_programme_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<% else %>
<div id='programme-details' style="display:none;">
<% end %>
<div class="help-block">
Specify a title for a new <%= t('programme') %>, which your new <%= t('project') %> will be associated with.
</div>
<%= label_tag :programme_title, "Title" %><span class="required">*</span>
<%= text_field_tag 'programme[title]', '', class: 'form-control' %>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RenameCustomMetadataAttributeToExtendedMetadataAttribute < ActiveRecord::Migration[6.1]
def change
rename_table :extended_metadata_attributes, :extended_metadata_attributes
rename_table :custom_metadata_attributes, :extended_metadata_attributes

rename_column :extended_metadata_attributes, :custom_metadata_type_id, :extended_metadata_type_id
rename_column :extended_metadata_attributes, :linked_custom_metadata_type_id, :linked_extended_metadata_type_id
Expand Down
4 changes: 4 additions & 0 deletions lib/seek/samples/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def persist

last_id = Sample.last.try(:id) || 0
sample_type = samples.first.sample_type
project_ids = samples.first.project_ids
disable_authorization_checks { Sample.import(samples, validate: false, batch_size: 2000) }
SampleTypeUpdateJob.new(sample_type, false).queue_job

Expand All @@ -38,6 +39,9 @@ def persist
samples = Sample.where(sample_type: sample_type, title: samples.collect(&:title), contributor: contributor).where(
'id > ?', last_id
)
samples.each do |sample|
sample.project_ids = project_ids
end
ReindexingQueue.enqueue(samples)
AuthLookupUpdateQueue.enqueue(samples)
end
Expand Down
23 changes: 23 additions & 0 deletions lib/tasks/seek_upgrades.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace :seek do
task upgrade_version_tasks: %i[
environment
decouple_extracted_samples_policies
decouple_extracted_samples_projects
]

# these are the tasks that are executes for each upgrade as standard, and rarely change
Expand Down Expand Up @@ -61,6 +62,28 @@ namespace :seek do
puts " ... finished creating independent policies of #{decoupled.to_s} extracted samples"
end

task(decouple_extracted_samples_projects: [:environment]) do
puts '... copying project ids for extracted samples...'
decoupled = 0
hash_array = []
disable_authorization_checks do
Sample.find_each do |sample|
# check if the sample was extracted from a datafile and their projects are linked
if sample.extracted? && sample.project_ids.empty?
sample.originating_data_file.project_ids.each do |project_id|
hash_array << { project_id: project_id, sample_id: sample.id }
end
decoupled += 1
end
end
unless hash_array.empty?
class ProjectsSample < ActiveRecord::Base; end;
ProjectsSample.insert_all(hash_array)
end
end
puts " ... finished copying project ids of #{decoupled.to_s} extracted samples"
end

private

##
Expand Down
5 changes: 4 additions & 1 deletion test/unit/jobs/sample_data_persist_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ def setup
@person = FactoryBot.create(:project_administrator)
User.current_user = @person.user

@project_id = @person.projects.first.id

@data_file = FactoryBot.create :data_file, content_blob: FactoryBot.create(:sample_type_populated_template_content_blob),
policy: FactoryBot.create(:private_policy), contributor: @person
refute @data_file.sample_template?
assert_empty @data_file.possible_sample_types

@sample_type = SampleType.new title: 'from template', uploaded_template: true,
project_ids: [@person.projects.first.id], contributor: @person
project_ids: [@project_id], contributor: @person
@sample_type.content_blob = FactoryBot.create(:sample_type_template_content_blob)
@sample_type.build_attributes_from_template
# this is to force the full name to be 2 words, so that one row fails
Expand Down Expand Up @@ -47,6 +49,7 @@ def setup
assert_equal 3, @data_file.extracted_samples.count
assert_equal @sample_type, @data_file.extracted_samples.first.sample_type
assert_equal @person, @data_file.extracted_samples.first.contributor
assert_equal [@project_id], @data_file.extracted_samples.first.project_ids
end

test 'persists samples and associate with assay' do
Expand Down
8 changes: 4 additions & 4 deletions test/unit/sample_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ class SampleTest < ActiveSupport::TestCase
refute sample2.can_view?(nil)
end

test 'extracted samples inherit projects from data file' do
test 'extracted samples copy projects from data file' do
person = FactoryBot.create(:person)
create_sample_attribute_type
data_file = FactoryBot.create :data_file, content_blob: FactoryBot.create(:sample_type_populated_template_content_blob),
Expand All @@ -769,9 +769,9 @@ class SampleTest < ActiveSupport::TestCase
data_file.save!
end

assert_equal new_projects.sort, sample.projects.sort
assert_equal sample.projects.sort, data_file.projects.sort
assert_equal sample.project_ids.sort, data_file.project_ids.sort
assert_not_equal new_projects.sort, sample.projects.sort
assert_not_equal sample.projects.sort, data_file.projects.sort
assert_not_equal sample.project_ids.sort, data_file.project_ids.sort
end

test 'extracted samples inherit creators from data file' do
Expand Down

0 comments on commit 0ff952c

Please sign in to comment.