Skip to content

Commit

Permalink
Merge branch 'seek-1.14' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Sep 14, 2023
2 parents d7074a6 + 259e839 commit 4ffd32f
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 235 deletions.
20 changes: 16 additions & 4 deletions app/controllers/assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class AssaysController < ApplicationController
before_action :assays_enabled?
before_action :find_assets, :only=>[:index]
before_action :find_and_authorize_requested_item, :only=>[:edit, :update, :destroy, :manage, :manage_update, :show, :new_object_based_on_existing_one]
before_action :delete_linked_sample_types, only: [:destroy]

#project_membership_required_appended is an alias to project_membership_required, but is necessary to include the actions
#defined in the application controller
Expand All @@ -18,7 +19,7 @@ class AssaysController < ApplicationController
api_actions :index, :show, :create, :update, :destroy

def new_object_based_on_existing_one
@existing_assay = Assay.find(params[:id])
@existing_assay = Assay.find(params[:id])
@assay = @existing_assay.clone_with_associations

if @existing_assay.can_view?
Expand Down Expand Up @@ -62,9 +63,7 @@ def new_object_based_on_existing_one
flash[:error]="You do not have the necessary permissions to copy this #{t('assays.assay')}"
redirect_to @existing_assay
end


end
end

def new
@assay=setup_new_asset
Expand Down Expand Up @@ -112,6 +111,13 @@ def create
end
end


def delete_linked_sample_types
return unless is_single_page_assay?

@assay.sample_type.destroy
end

def update
update_assay_organisms @assay, params
update_assay_human_diseases @assay, params
Expand Down Expand Up @@ -177,4 +183,10 @@ def assay_params
assay_params[:model_ids].select! { |id| Model.find_by_id(id).try(:can_view?) } if assay_params.key?(:model_ids)
end
end

def is_single_page_assay?
return false unless params.key?(:return_to)

params[:return_to].start_with? '/single_pages/'
end
end
19 changes: 18 additions & 1 deletion app/controllers/studies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class StudiesController < ApplicationController
before_action :studies_enabled?
before_action :find_assets, only: [:index]
before_action :find_and_authorize_requested_item, only: %i[edit update destroy manage manage_update show new_object_based_on_existing_one]
before_action :delete_linked_sample_types, only: [:destroy]

# project_membership_required_appended is an alias to project_membership_required, but is necesary to include the actions
# defined in the application controller
Expand Down Expand Up @@ -88,6 +89,16 @@ def update
end
end

def delete_linked_sample_types
return unless is_single_page_study?

# 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
study_st_ids = @study.sample_types.map(&:id).sort { |a, b| b <=> a }
SampleType.destroy(study_st_ids)
end


def show
@study = Study.find(params[:id])

Expand Down Expand Up @@ -201,7 +212,7 @@ def batch_create
study_params = {
title: params[:studies][:title][index],
description: params[:studies][:description][index],
investigation_id: params[:study][:investigation_id],
investigation_id: params[:study][:investigation_id],
custom_metadata: CustomMetadata.new(
custom_metadata_type: metadata_types,
data: metadata
Expand Down Expand Up @@ -351,3 +362,9 @@ def study_params
{ custom_metadata_attributes: determine_custom_metadata_keys })
end
end

def is_single_page_study?
return false unless params.key?(:return_to)

params[:return_to].start_with? '/single_pages/'
end
6 changes: 3 additions & 3 deletions app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def task_status

def populate_template
uploaded_file = params[:template_json_file]
dir = Rails.root.join('config', 'default_data', 'source_types')
dir = Seek::Config.append_filestore_path('source_types')

if Dir.exist?(dir)
`rm #{dir}/*`
Expand Down Expand Up @@ -146,11 +146,11 @@ def set_status
end

def lockfile
Rails.root.join('tmp', 'populate_templates.lock')
Rails.root.join(Seek::Config.temporary_filestore_path, 'populate_templates.lock')
end

def resultfile
Rails.root.join('tmp', 'populate_templates.result')
Rails.root.join(Seek::Config.temporary_filestore_path, 'populate_templates.result')
end

def running!
Expand Down
6 changes: 5 additions & 1 deletion app/models/assay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def short_description
end

def state_allows_delete?(*args)
assets.empty? && publications.empty? && super
assets.empty? && publications.empty? && associated_samples_through_sample_type.empty? && super
end

# returns true if this is a modelling class of assay
Expand All @@ -90,6 +90,10 @@ def is_experimental?
!assay_class.nil? && assay_class.key == 'EXP'
end

def associated_samples_through_sample_type
(sample_type.nil? || sample_type.samples.nil?) ? [] : sample_type.samples
end

# Create or update relationship of this assay to another, with a specific relationship type and version
def associate(asset, options = {})
if asset.is_a?(Organism)
Expand Down
15 changes: 12 additions & 3 deletions app/models/study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Study < ApplicationRecord

enum status: [:planned, :running, :completed, :cancelled, :failed]
belongs_to :assignee, class_name: 'Person'

searchable(:auto_index => false) do
text :experimentalists
end if Seek::Config.solr_enabled
Expand All @@ -22,7 +22,7 @@ class Study < ApplicationRecord
has_many :sop_versions, through: :assays

has_one :external_asset, as: :seek_entity, dependent: :destroy

has_and_belongs_to_many :sops

has_and_belongs_to_many :sample_types
Expand All @@ -41,7 +41,16 @@ def assets
end

def state_allows_delete? *args
assays.empty? && super
assays.empty? && associated_samples_through_sample_type.empty? && super
end

def associated_samples_through_sample_type
return [] if sample_types.nil?
st_samples = []
sample_types.map do |st|
st.samples.map { |sts| st_samples.push sts }
end
st_samples
end

def clone_with_associations
Expand Down
4 changes: 4 additions & 0 deletions app/views/general/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
show_new_button = true unless local_assigns.has_key?(:show_new_button)
title ||= nil
subtitle ||= nil
isa_templates_enabled = Seek::Config.sample_type_template_enabled && Seek::Config.project_single_page_advanced_enabled
%>

<div class="pull-right">
<% if show_new_button && controller_model.can_create? %>
<% if isa_templates_enabled %>
<%= link_to "Query by #{t('template').pluralize}", query_form_samples_path, class: "btn btn-default btn" %>
<% end %>
<%= button_link_to(new_item_label, "new", new_item_path) %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/programmes/activation_review.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render :partial => "general/item_title",:locals => {:item=>@programme, :title_prefix=>"Acitivation required for: "} %>
<%= render :partial => "general/item_title",:locals => {:item=>@programme, :title_prefix=>"Activation required for: "} %>

<p>
A <%= t('programme') %> has been created by a user, and requires activation. The <%= t('programme') %> created is <%= link_to @programme.title, @programme %>.
Expand Down
6 changes: 3 additions & 3 deletions lib/seek/isa_templates/template_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.extract_templates
disable_authorization_checks do
client = Ebi::OlsClient.new
project = Project.find_or_create_by(title: 'Default Project')
directory = Rails.root.join('config', 'default_data', 'source_types')
directory = Seek::Config.append_filestore_path('source_types')
directory_files = Dir.exist?(directory) ? Dir.glob("#{directory}/*.json") : []
raise '<ul><li>Make sure to upload files that have the ".json" extension.</li></ul>' if directory_files == []

Expand Down Expand Up @@ -172,11 +172,11 @@ def self.seed_isa_tags
end

def self.lockfile
Rails.root.join('tmp', 'populate_templates.lock')
Rails.root.join(Seek::Config.temporary_filestore_path, 'populate_templates.lock')
end

def self.resultfile
Rails.root.join('tmp', 'populate_templates.result')
Rails.root.join(Seek::Config.temporary_filestore_path, 'populate_templates.result')
end
end
end
Expand Down
Loading

0 comments on commit 4ffd32f

Please sign in to comment.